Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / android_webview / javatests / src / org / chromium / android_webview / test / AwTestBase.java
index f362c37..fd90331 100644 (file)
@@ -24,6 +24,7 @@ import org.chromium.content.browser.test.util.CallbackHelper;
 import org.chromium.content.browser.test.util.Criteria;
 import org.chromium.content.browser.test.util.CriteriaHelper;
 
+import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.FutureTask;
 import java.util.concurrent.TimeUnit;
@@ -34,8 +35,8 @@ import java.util.concurrent.atomic.AtomicReference;
  */
 public class AwTestBase
         extends ActivityInstrumentationTestCase2<AwTestRunnerActivity> {
-    protected static final long WAIT_TIMEOUT_MS = scaleTimeout(15000);
-    protected static final int CHECK_INTERVAL = 100;
+    public static final long WAIT_TIMEOUT_MS = scaleTimeout(15000);
+    public static final int CHECK_INTERVAL = 100;
     private static final String TAG = "AwTestBase";
 
     public AwTestBase() {
@@ -79,7 +80,7 @@ public class AwTestBase
         return task.get();
     }
 
-    protected void enableJavaScriptOnUiThread(final AwContents awContents) {
+    public void enableJavaScriptOnUiThread(final AwContents awContents) {
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
@@ -88,7 +89,7 @@ public class AwTestBase
         });
     }
 
-    protected void setNetworkAvailableOnUiThread(final AwContents awContents,
+    public void setNetworkAvailableOnUiThread(final AwContents awContents,
             final boolean networkUp) {
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
@@ -101,16 +102,23 @@ public class AwTestBase
     /**
      * Loads url on the UI thread and blocks until onPageFinished is called.
      */
-    protected void loadUrlSync(final AwContents awContents,
+    public void loadUrlSync(final AwContents awContents,
                                CallbackHelper onPageFinishedHelper,
                                final String url) throws Exception {
+        loadUrlSync(awContents, onPageFinishedHelper, url, null);
+    }
+
+    public void loadUrlSync(final AwContents awContents,
+                               CallbackHelper onPageFinishedHelper,
+                               final String url,
+                               final Map<String, String> extraHeaders) throws Exception {
         int currentCallCount = onPageFinishedHelper.getCallCount();
-        loadUrlAsync(awContents, url);
+        loadUrlAsync(awContents, url, extraHeaders);
         onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_MS,
                 TimeUnit.MILLISECONDS);
     }
 
-    protected void loadUrlSyncAndExpectError(final AwContents awContents,
+    public void loadUrlSyncAndExpectError(final AwContents awContents,
             CallbackHelper onPageFinishedHelper,
             CallbackHelper onReceivedErrorHelper,
             final String url) throws Exception {
@@ -126,12 +134,20 @@ public class AwTestBase
     /**
      * Loads url on the UI thread but does not block.
      */
-    protected void loadUrlAsync(final AwContents awContents,
+    public void loadUrlAsync(final AwContents awContents,
                                 final String url) throws Exception {
+        loadUrlAsync(awContents, url, null);
+    }
+
+    public void loadUrlAsync(final AwContents awContents,
+                                final String url,
+                                final Map<String, String> extraHeaders) {
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
-                awContents.loadUrl(new LoadUrlParams(url));
+                LoadUrlParams params = new LoadUrlParams(url);
+                params.setExtraHeaders(extraHeaders);
+                awContents.loadUrl(params);
             }
         });
     }
@@ -139,7 +155,7 @@ public class AwTestBase
     /**
      * Posts url on the UI thread and blocks until onPageFinished is called.
      */
-    protected void postUrlSync(final AwContents awContents,
+    public void postUrlSync(final AwContents awContents,
             CallbackHelper onPageFinishedHelper, final String url,
             byte[] postData) throws Exception {
         int currentCallCount = onPageFinishedHelper.getCallCount();
@@ -151,7 +167,7 @@ public class AwTestBase
     /**
      * Loads url on the UI thread but does not block.
      */
-    protected void postUrlAsync(final AwContents awContents,
+    public void postUrlAsync(final AwContents awContents,
             final String url, byte[] postData) throws Exception {
         class PostUrl implements Runnable {
             byte[] mPostData;
@@ -170,7 +186,7 @@ public class AwTestBase
     /**
      * Loads data on the UI thread and blocks until onPageFinished is called.
      */
-    protected void loadDataSync(final AwContents awContents,
+    public void loadDataSync(final AwContents awContents,
                                 CallbackHelper onPageFinishedHelper,
                                 final String data, final String mimeType,
                                 final boolean isBase64Encoded) throws Exception {
@@ -180,7 +196,7 @@ public class AwTestBase
                 TimeUnit.MILLISECONDS);
     }
 
-    protected void loadDataSyncWithCharset(final AwContents awContents,
+    public void loadDataSyncWithCharset(final AwContents awContents,
                                            CallbackHelper onPageFinishedHelper,
                                            final String data, final String mimeType,
                                            final boolean isBase64Encoded, final String charset)
@@ -200,7 +216,7 @@ public class AwTestBase
     /**
      * Loads data on the UI thread but does not block.
      */
-    protected void loadDataAsync(final AwContents awContents, final String data,
+    public void loadDataAsync(final AwContents awContents, final String data,
                                  final String mimeType, final boolean isBase64Encoded)
             throws Exception {
         getInstrumentation().runOnMainSync(new Runnable() {
@@ -212,7 +228,7 @@ public class AwTestBase
         });
     }
 
-    protected void loadDataWithBaseUrlSync(final AwContents awContents,
+    public void loadDataWithBaseUrlSync(final AwContents awContents,
             CallbackHelper onPageFinishedHelper, final String data, final String mimeType,
             final boolean isBase64Encoded, final String baseUrl,
             final String historyUrl) throws Throwable {
@@ -222,7 +238,7 @@ public class AwTestBase
                 TimeUnit.MILLISECONDS);
     }
 
-    protected void loadDataWithBaseUrlAsync(final AwContents awContents,
+    public void loadDataWithBaseUrlAsync(final AwContents awContents,
             final String data, final String mimeType, final boolean isBase64Encoded,
             final String baseUrl, final String historyUrl) throws Throwable {
         runTestOnUiThread(new Runnable() {
@@ -237,7 +253,7 @@ public class AwTestBase
     /**
      * Reloads the current page synchronously.
      */
-    protected void reloadSync(final AwContents awContents,
+    public void reloadSync(final AwContents awContents,
                               CallbackHelper onPageFinishedHelper) throws Exception {
         int currentCallCount = onPageFinishedHelper.getCallCount();
         getInstrumentation().runOnMainSync(new Runnable() {
@@ -269,12 +285,12 @@ public class AwTestBase
         return new TestDependencyFactory();
     }
 
-    protected AwTestContainerView createAwTestContainerView(
+    public AwTestContainerView createAwTestContainerView(
             final AwContentsClient awContentsClient) {
         return createAwTestContainerView(awContentsClient, false);
     }
 
-    protected AwTestContainerView createAwTestContainerView(
+    public AwTestContainerView createAwTestContainerView(
             final AwContentsClient awContentsClient, boolean supportsLegacyQuirks) {
         AwTestContainerView testContainerView =
                 createDetachedAwTestContainerView(awContentsClient, supportsLegacyQuirks);
@@ -287,12 +303,12 @@ public class AwTestBase
     private AwBrowserContext mBrowserContext =
             new AwBrowserContext(new InMemorySharedPreferences());
 
-    protected AwTestContainerView createDetachedAwTestContainerView(
+    public AwTestContainerView createDetachedAwTestContainerView(
             final AwContentsClient awContentsClient) {
         return createDetachedAwTestContainerView(awContentsClient, false);
     }
 
-    protected AwTestContainerView createDetachedAwTestContainerView(
+    public AwTestContainerView createDetachedAwTestContainerView(
             final AwContentsClient awContentsClient, boolean supportsLegacyQuirks) {
         final TestDependencyFactory testDependencyFactory = createTestDependencyFactory();
         final AwTestContainerView testContainerView =
@@ -305,12 +321,12 @@ public class AwTestBase
         return testContainerView;
     }
 
-    protected AwTestContainerView createAwTestContainerViewOnMainSync(
+    public AwTestContainerView createAwTestContainerViewOnMainSync(
             final AwContentsClient client) throws Exception {
         return createAwTestContainerViewOnMainSync(client, false);
     }
 
-    protected AwTestContainerView createAwTestContainerViewOnMainSync(
+    public AwTestContainerView createAwTestContainerViewOnMainSync(
             final AwContentsClient client, final boolean supportsLegacyQuirks) throws Exception {
         final AtomicReference<AwTestContainerView> testContainerView =
                 new AtomicReference<AwTestContainerView>();
@@ -323,7 +339,7 @@ public class AwTestBase
         return testContainerView.get();
     }
 
-    protected void destroyAwContentsOnMainSync(final AwContents awContents) {
+    public void destroyAwContentsOnMainSync(final AwContents awContents) {
         if (awContents == null) return;
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
@@ -333,7 +349,7 @@ public class AwTestBase
         });
     }
 
-    protected String getTitleOnUiThread(final AwContents awContents) throws Exception {
+    public String getTitleOnUiThread(final AwContents awContents) throws Exception {
         return runTestOnUiThreadAndGetResult(new Callable<String>() {
             @Override
             public String call() throws Exception {
@@ -342,7 +358,7 @@ public class AwTestBase
         });
     }
 
-    protected ContentSettings getContentSettingsOnUiThread(
+    public ContentSettings getContentSettingsOnUiThread(
             final AwContents awContents) throws Exception {
         return runTestOnUiThreadAndGetResult(new Callable<ContentSettings>() {
             @Override
@@ -352,7 +368,7 @@ public class AwTestBase
         });
     }
 
-    protected AwSettings getAwSettingsOnUiThread(
+    public AwSettings getAwSettingsOnUiThread(
             final AwContents awContents) throws Exception {
         return runTestOnUiThreadAndGetResult(new Callable<AwSettings>() {
             @Override
@@ -366,7 +382,7 @@ public class AwTestBase
      * Executes the given snippet of JavaScript code within the given ContentView. Returns the
      * result of its execution in JSON format.
      */
-    protected String executeJavaScriptAndWaitForResult(final AwContents awContents,
+    public String executeJavaScriptAndWaitForResult(final AwContents awContents,
             TestAwContentsClient viewClient, final String code) throws Exception {
         return JSUtils.executeJavaScriptAndWaitForResult(this, awContents,
                 viewClient.getOnEvaluateJavaScriptResultHelper(),
@@ -377,7 +393,7 @@ public class AwTestBase
      * Wrapper around CriteriaHelper.pollForCriteria. This uses AwTestBase-specifc timeouts and
      * treats timeouts and exceptions as test failures automatically.
      */
-    protected static void poll(final Callable<Boolean> callable) throws Exception {
+    public static void poll(final Callable<Boolean> callable) throws Exception {
         assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
             @Override
             public boolean isSatisfied() {
@@ -394,7 +410,7 @@ public class AwTestBase
     /**
      * Wrapper around {@link AwTestBase#poll()} but runs the callable on the UI thread.
      */
-    protected void pollOnUiThread(final Callable<Boolean> callable) throws Exception {
+    public void pollOnUiThread(final Callable<Boolean> callable) throws Exception {
         poll(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
@@ -407,7 +423,7 @@ public class AwTestBase
      * Clears the resource cache. Note that the cache is per-application, so this will clear the
      * cache for all WebViews used.
      */
-    protected void clearCacheOnUiThread(
+    public void clearCacheOnUiThread(
             final AwContents awContents,
             final boolean includeDiskFiles) throws Exception {
         getInstrumentation().runOnMainSync(new Runnable() {
@@ -421,7 +437,7 @@ public class AwTestBase
     /**
      * Returns pure page scale.
      */
-    protected float getScaleOnUiThread(final AwContents awContents) throws Exception {
+    public float getScaleOnUiThread(final AwContents awContents) throws Exception {
         return runTestOnUiThreadAndGetResult(new Callable<Float>() {
             @Override
             public Float call() throws Exception {
@@ -433,7 +449,7 @@ public class AwTestBase
     /**
      * Returns page scale multiplied by the screen density.
      */
-    protected float getPixelScaleOnUiThread(final AwContents awContents) throws Exception {
+    public float getPixelScaleOnUiThread(final AwContents awContents) throws Exception {
         return runTestOnUiThreadAndGetResult(new Callable<Float>() {
             @Override
             public Float call() throws Exception {
@@ -445,7 +461,7 @@ public class AwTestBase
     /**
      * Returns whether a user can zoom the page in.
      */
-    protected boolean canZoomInOnUiThread(final AwContents awContents) throws Exception {
+    public boolean canZoomInOnUiThread(final AwContents awContents) throws Exception {
         return runTestOnUiThreadAndGetResult(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
@@ -457,7 +473,7 @@ public class AwTestBase
     /**
      * Returns whether a user can zoom the page out.
      */
-    protected boolean canZoomOutOnUiThread(final AwContents awContents) throws Exception {
+    public boolean canZoomOutOnUiThread(final AwContents awContents) throws Exception {
         return runTestOnUiThreadAndGetResult(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
@@ -465,4 +481,5 @@ public class AwTestBase
             }
         });
     }
+
 }