### Question:
WXMetaModule extends WXModule { @JSMethod(uiThread = false) public void setViewport(String param) { if (!TextUtils.isEmpty(param)) { try { param = URLDecoder.decode(param, "utf-8"); JSONObject jsObj = JSON.parseObject(param); Context cxt = mWXSDKInstance.getContext(); if (DEVICE_WIDTH.endsWith(jsObj.getString(WIDTH))) { int width = (int)(WXViewUtils.getScreenWidth(cxt)/WXViewUtils.getScreenDensity(cxt)); mWXSDKInstance.setInstanceViewPortWidth(width); WXLogUtils.d("[WXMetaModule] setViewport success[device-width]=" + width); } else { int width = jsObj.getInteger(WIDTH); if (width > 0) { mWXSDKInstance.setInstanceViewPortWidth(width); } WXLogUtils.d("[WXMetaModule] setViewport success[width]=" + width); } } catch (Exception e) { WXLogUtils.e("[WXMetaModule] alert param parse error ", e); } } }  @JSMethod(uiThread = false) void setViewport(String param); @JSMethod(uiThread = true) void openLog(String open); @JSMethod(uiThread = false) void getPageInfo(JSCallback callback); static final String WIDTH; static final String DEVICE_WIDTH; }### Answer:
@Test public void setViewport() throws Exception { JSONObject jsonObject = new JSONObject(); jsonObject.put(WXMetaModule.WIDTH,640); mMeta.setViewport(jsonObject.toString()); assertTrue(mMeta.mWXSDKInstance.getInstanceViewPortWidth() == 640); jsonObject.put(WXMetaModule.WIDTH,320.5); mMeta.setViewport(jsonObject.toString()); assertTrue(mMeta.mWXSDKInstance.getInstanceViewPortWidth() == 320); jsonObject.put(WXMetaModule.WIDTH,"-200"); mMeta.setViewport(jsonObject.toString()); assertTrue(mMeta.mWXSDKInstance.getInstanceViewPortWidth() == 320); jsonObject.put(WXMetaModule.WIDTH,"error"); mMeta.setViewport(jsonObject.toString()); assertTrue(mMeta.mWXSDKInstance.getInstanceViewPortWidth() == 320); mMeta.setViewport("ads"); assertTrue(mMeta.mWXSDKInstance.getInstanceViewPortWidth() == 320); }