Upstream version 9.37.195.0
[platform/framework/web/crosswalk.git] / src / xwalk / test / android / core / javatests / src / org / xwalk / core / xwview / test / XWalkViewTestBase.java
index 8be4a33..cfafe9a 100644 (file)
@@ -30,11 +30,12 @@ import org.xwalk.core.XWalkNavigationItem;
 import org.xwalk.core.XWalkResourceClient;
 import org.xwalk.core.XWalkUIClient;
 import org.xwalk.core.XWalkView;
-import org.xwalk.core.internal.XWalkSettings;
 
 public class XWalkViewTestBase
        extends ActivityInstrumentationTestCase2<XWalkViewTestRunnerActivity> {
     protected final static int WAIT_TIMEOUT_SECONDS = 15;
+    protected final static long WAIT_TIMEOUT_MS = 2000;
+    private final static int CHECK_INTERVAL = 100;
     private final static String TAG = "XWalkViewTestBase";
     private XWalkView mXWalkView;
     final TestHelperBridge mTestHelperBridge = new TestHelperBridge();
@@ -65,6 +66,11 @@ public class XWalkViewTestBase
         public void onJavascriptCloseWindow(XWalkView view) {
             mInnerContentsClient.onJavascriptCloseWindow();
         }
+
+        @Override
+        public void onScaleChanged(XWalkView view, float oldScale, float newScale) {
+            mInnerContentsClient.onScaleChanged(newScale);
+        }
     }
 
     class TestXWalkUIClient extends TestXWalkUIClientBase {
@@ -100,6 +106,11 @@ public class XWalkViewTestBase
         public void onProgressChanged(XWalkView view, int progressInPercent) {
             mTestHelperBridge.onProgressChanged(progressInPercent);
         }
+
+        @Override
+        public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
+            return mTestHelperBridge.shouldOverrideUrlLoading(url);
+        }
     }
 
     class TestXWalkResourceClient extends TestXWalkResourceClientBase {
@@ -126,37 +137,6 @@ public class XWalkViewTestBase
         });
     }
 
-    static class ViewPair {
-        private final XWalkView content0;
-        private final TestHelperBridge client0;
-        private final XWalkView content1;
-        private final TestHelperBridge client1;
-
-        ViewPair(XWalkView content0, TestHelperBridge client0,
-                XWalkView content1, TestHelperBridge client1) {
-            this.content0 = content0;
-            this.client0 = client0;
-            this.content1 = content1;
-            this.client1 = client1;
-        }
-
-        XWalkView getContent0() {
-            return content0;
-        }
-
-        TestHelperBridge getClient0() {
-            return client0;
-        }
-
-        XWalkView getContent1() {
-            return content1;
-        }
-
-        TestHelperBridge getClient1() {
-            return client1;
-        }
-    }
-
     public XWalkViewTestBase() {
         super(XWalkViewTestRunnerActivity.class);
     }
@@ -301,16 +281,6 @@ public class XWalkViewTestBase
         });
     }
 
-    protected XWalkSettings getXWalkSettingsOnUiThreadByContent(
-            final XWalkView xwalkContent) throws Exception {
-        return runTestOnUiThreadAndGetResult(new Callable<XWalkSettings>() {
-            @Override
-            public XWalkSettings call() throws Exception {
-                return xwalkContent.getSettings();
-            }
-        });
-    }
-
     protected XWalkView createXWalkViewContainerOnMainSync(
             final Context context,
             final XWalkUIClient uiClient,
@@ -330,29 +300,6 @@ public class XWalkViewTestBase
         return xWalkViewContainer.get();
     }
 
-    protected ViewPair createViewsOnMainSync(final TestHelperBridge helperBridge0,
-                                             final TestHelperBridge helperBridge1,
-                                             final XWalkUIClient uiClient0,
-                                             final XWalkUIClient uiClient1,
-                                             final XWalkResourceClient resourceClient0,
-                                             final XWalkResourceClient resourceClient1,
-                                             final Context context) throws Throwable {
-        final XWalkView walkView0 = createXWalkViewContainerOnMainSync(context,
-                uiClient0, resourceClient0);
-        final XWalkView walkView1 = createXWalkViewContainerOnMainSync(context,
-                uiClient1, resourceClient1);
-        final AtomicReference<ViewPair> viewPair = new AtomicReference<ViewPair>();
-
-        getInstrumentation().runOnMainSync(new Runnable() {
-            @Override
-            public void run() {
-                viewPair.set(new ViewPair(walkView0, helperBridge0, walkView1, helperBridge1));
-            }
-        });
-
-        return viewPair.get();
-    }
-
     protected void loadAssetFile(String fileName) throws Exception {
         String fileContent = getFileContent(fileName);
         loadDataSync(fileName, fileContent, "text/html", false);
@@ -503,22 +450,6 @@ public class XWalkViewTestBase
         return helper.getJsonResultAndClear();
     }
 
-    protected ViewPair createViews() throws Throwable {
-        TestHelperBridge helperBridge0 = new TestHelperBridge();
-        TestHelperBridge helperBridge1 = new TestHelperBridge();
-        TestXWalkUIClientBase uiClient0 = new TestXWalkUIClientBase(helperBridge0);
-        TestXWalkUIClientBase uiClient1 = new TestXWalkUIClientBase(helperBridge1);
-        TestXWalkResourceClientBase resourceClient0 =
-                new TestXWalkResourceClientBase(helperBridge0);
-        TestXWalkResourceClientBase resourceClient1 =
-                new TestXWalkResourceClientBase(helperBridge1);
-        ViewPair viewPair =
-                createViewsOnMainSync(helperBridge0, helperBridge1, uiClient0, uiClient1,
-                        resourceClient0, resourceClient1, getActivity());
-
-        return viewPair;
-    }
-
     protected String getUrlOnUiThread() throws Exception {
         return runTestOnUiThreadAndGetResult(new Callable<String>() {
             @Override
@@ -554,4 +485,31 @@ public class XWalkViewTestBase
             }
         });
     }
+
+    public void clickOnElementId(final String id) throws Exception {
+        Assert.assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
+            @Override
+            public boolean isSatisfied() {
+                try {
+                    String idIsNotNull = executeJavaScriptAndWaitForResult(
+                        "document.getElementById('" + id + "') != null");
+                    return idIsNotNull.equals("true");
+                } catch (Throwable t) {
+                    t.printStackTrace();
+                    Assert.fail("Failed to check if DOM is loaded: " + t.toString());
+                    return false;
+                }
+            }
+        }, WAIT_TIMEOUT_MS, CHECK_INTERVAL));
+
+        try {
+            String result = executeJavaScriptAndWaitForResult(
+                "var evObj = document.createEvent('Events'); " +
+                "evObj.initEvent('click', true, false); " +
+                "document.getElementById('" + id + "').dispatchEvent(evObj);" +
+                "console.log('element with id [" + id + "] clicked');");
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
 }