WXDomModule extends WXModule { public void callDomMethod(JSONObject task) { if (task == null) { return; } String method = (String) task.get(WXBridgeManager.METHOD); JSONArray args = (JSONArray) task.get(WXBridgeManager.ARGS); if (method == null) { return; } try { switch (method) { case CREATE_BODY: if (args == null) { return; } createBody((JSONObject) args.get(0)); break; case UPDATE_ATTRS: if (args == null) { return; } updateAttrs((String) args.get(0), (JSONObject) args.get(1)); break; case UPDATE_STYLE: if (args == null) { return; } updateStyle((String) args.get(0), (JSONObject) args.get(1)); break; case REMOVE_ELEMENT: if (args == null) { return; } removeElement((String) args.get(0)); break; case ADD_ELEMENT: if (args == null) { return; } addElement((String) args.get(0), (JSONObject) args.get(1), (Integer) args.get(2)); break; case MOVE_ELEMENT: if (args == null) { return; } moveElement((String) args.get(0), (String) args.get(1), (Integer) args.get(2)); break; case ADD_EVENT: if (args == null) { return; } addEvent((String) args.get(0), (String) args.get(1)); break; case REMOVE_EVENT: if (args == null) { return; } removeEvent((String) args.get(0), (String) args.get(1)); break; case CREATE_FINISH: createFinish(); break; case REFRESH_FINISH: refreshFinish(); break; case UPDATE_FINISH: updateFinish(); break; case SCROLL_TO_ELEMENT: if (args == null) { return; } scrollToElement((String) args.get(0), (JSONObject) args.get(1)); break; case ADD_RULE: if (args == null) { return; } addRule((String) args.get(0), (JSONObject) args.get(1)); } } catch (IndexOutOfBoundsException e) { e.printStackTrace(); WXLogUtils.e("Dom module call miss arguments."); } catch (ClassCastException cce) { WXLogUtils.e("Dom module call arguments format error!!"); } }  void callDomMethod(JSONObject task); void createBody(JSONObject element); void updateAttrs(String ref, JSONObject attr); void updateStyle(String ref, JSONObject style); void removeElement(String ref); void addElement(String parentRef, JSONObject element, Integer index); void moveElement(String ref, String parentRef, Integer index); void addEvent(String ref, String type); void removeEvent(String ref, String type); void createFinish(); void refreshFinish(); void updateFinish(); void scrollToElement(String ref, JSONObject options); void addRule(String type, JSONObject options); static final String WXDOM; static final String[] METHODS; }
@Test public void testCallDomMethod() throws Exception { module.callDomMethod(null); JSONObject obj = new JSONObject(); for (String m : METHODS) { obj.put(WXBridgeManager.METHOD,m); module.callDomMethod(obj); } obj = new JSONObject(); for (Object[] args:ARGS_CASES ) { JSONArray ary = new JSONArray(); if(args == null){ ary = null; }else { for (Object arg : args ) { ary.add(arg); } } obj.put(WXBridgeManager.ARGS,ary); for (String m : METHODS) { obj.put(WXBridgeManager.METHOD,m); module.callDomMethod(obj); } } }