Repository: incubator-weex Updated Branches: refs/heads/master 4a3b952f4 -> dd2e5e8f9
+ [android] update test case about <web> component Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/dd2e5e8f Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/dd2e5e8f Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/dd2e5e8f Branch: refs/heads/master Commit: dd2e5e8f95a8135c1485052fa8cf14bb60359503 Parents: c542c2c Author: åéº <haonan....@alibaba-inc.com> Authored: Fri Mar 9 11:32:00 2018 +0800 Committer: misakuo <misa...@apache.org> Committed: Tue Mar 20 12:36:08 2018 +0800 ---------------------------------------------------------------------- .../com/taobao/weex/ui/component/WXWebTest.java | 33 ++++++++++++++++++-- .../com/taobao/weex/ui/view/WXWebViewTest.java | 20 +++++++++++- 2 files changed, 49 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/dd2e5e8f/android/sdk/src/test/java/com/taobao/weex/ui/component/WXWebTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXWebTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXWebTest.java index a582ac0..56b0b72 100644 --- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXWebTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXWebTest.java @@ -34,6 +34,8 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; import static org.junit.Assert.*; @@ -56,6 +58,7 @@ public class WXWebTest { IWebView mIWebView; OnPageListener mOnPageListener; OnErrorListener mOnErrorListener; + OnMessageListener mOnMessageListener; ProxyWebView(IWebView proxy){ mIWebView = proxy; @@ -77,6 +80,11 @@ public class WXWebTest { } @Override + public void loadDataWithBaseURL(String source) { + mIWebView.loadDataWithBaseURL(source); + } + + @Override public void reload() { mIWebView.reload(); } @@ -92,6 +100,9 @@ public class WXWebTest { } @Override + public void postMessage(Object msg) {} + + @Override public void setShowLoading(boolean shown) { mIWebView.setShowLoading(shown); } @@ -107,6 +118,12 @@ public class WXWebTest { mIWebView.setOnPageListener(listener); mOnPageListener = listener; } + + @Override + public void setOnMessageListener(OnMessageListener listener) { + mIWebView.setOnMessageListener(listener); + mOnMessageListener = listener; + } } @Before @@ -127,24 +144,34 @@ public class WXWebTest { public void testSetProperty() throws Exception { component.setProperty(Constants.Name.SHOW_LOADING,true); component.setProperty(Constants.Name.SRC,"http://taobao.com"); + component.setProperty(Constants.Name.SOURCE, "<p><span>hello weex</span></p>"); } @Test public void testSetAction() throws Exception { - component.setAction(WXWeb.GO_BACK); - component.setAction(WXWeb.GO_FORWARD); - component.setAction(WXWeb.RELOAD); + Map<String, Object> msg = new HashMap<>(); + msg.put("test1", 1); + msg.put("test2", "2"); + component.setAction(WXWeb.GO_BACK, null); + component.setAction(WXWeb.GO_FORWARD, null); + component.setAction(WXWeb.RELOAD, null); + component.setAction(WXWeb.POST_MESSAGE, msg); } @Test public void testListener() throws Exception { + Map<String, Object> msg = new HashMap<>(); + msg.put("test1", 1); + msg.put("test2", "2"); component.addEvent(Constants.Event.RECEIVEDTITLE); component.addEvent(Constants.Event.PAGESTART); component.addEvent(Constants.Event.PAGEFINISH); component.addEvent(Constants.Event.ERROR); + component.addEvent(Constants.Event.ONMESSAGE); mWebView.mOnPageListener.onPageFinish("http://taobao.com",true,true); mWebView.mOnPageListener.onReceivedTitle("test"); mWebView.mOnPageListener.onPageStart("http://taobao.com"); mWebView.mOnErrorListener.onError("test","error occurred"); + mWebView.mOnMessageListener.onMessage(msg); } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/dd2e5e8f/android/sdk/src/test/java/com/taobao/weex/ui/view/WXWebViewTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/view/WXWebViewTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/view/WXWebViewTest.java index fe1913c..7b8b5cd 100644 --- a/android/sdk/src/test/java/com/taobao/weex/ui/view/WXWebViewTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/ui/view/WXWebViewTest.java @@ -38,6 +38,9 @@ import org.robolectric.Shadows; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowWebView; +import java.util.HashMap; +import java.util.Map; + /** * Created by sospartan on 9/7/16. */ @@ -53,7 +56,7 @@ public class WXWebViewTest { @Before public void setUp() throws Exception { Activity activity = Robolectric.setupActivity(TestActivity.class); - view = new WXWebView(activity); + view = new WXWebView(activity, null); webView = (WebView)((ViewGroup)view.getView()).getChildAt(0);//first child shadow = Shadows.shadowOf(webView); } @@ -89,6 +92,13 @@ public class WXWebViewTest { } @Test + public void testLoadDataWithBaseURL() throws Exception { + String source = "<p><span>hello weex</span></p>"; + view.loadDataWithBaseURL(source); + } + + + @Test public void testReload() throws Exception { view.reload(); testLoadUrl(); @@ -107,4 +117,12 @@ public class WXWebViewTest { testGoBack(); view.goForward(); } + + @Test + public void testPostMessage() throws Exception { + Map<String, Object> msg = new HashMap<>(); + msg.put("test1", 1); + msg.put("test2", "2"); + view.postMessage(msg); + } }