| Index: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldOverrideUrlLoadingTest.java
|
| diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldOverrideUrlLoadingTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldOverrideUrlLoadingTest.java
|
| index 24eb71a0730ade30fb15fc042f2bd00afca347b1..f6ee0d888506747dcd777f43a05a6a9dfdca2d8c 100644
|
| --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldOverrideUrlLoadingTest.java
|
| +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldOverrideUrlLoadingTest.java
|
| @@ -11,6 +11,7 @@ import android.util.Pair;
|
| import org.chromium.android_webview.AwContents;
|
| import org.chromium.android_webview.test.util.CommonResources;
|
| import org.chromium.android_webview.test.util.JSUtils;
|
| +import org.chromium.android_webview.test.util.JavascriptEventObserver;
|
| import org.chromium.base.annotations.SuppressFBWarnings;
|
| import org.chromium.base.test.util.DisabledTest;
|
| import org.chromium.base.test.util.Feature;
|
| @@ -25,6 +26,7 @@ import org.chromium.net.test.util.TestWebServer;
|
| import java.util.ArrayList;
|
| import java.util.List;
|
| import java.util.concurrent.Callable;
|
| +import java.util.concurrent.CountDownLatch;
|
| import java.util.concurrent.TimeUnit;
|
|
|
| /**
|
| @@ -964,4 +966,92 @@ public class AwContentsClientShouldOverrideUrlLoadingTest extends AwTestBase {
|
| getActivity().setIgnoreStartActivity(false);
|
| }
|
| }
|
| +
|
| + @SmallTest
|
| + @Feature({"AndroidWebView"})
|
| + public void testXhrInLink() throws Throwable {
|
| + final TestAwContentsClient contentsClient = new TestAwContentsClient();
|
| + final AwTestContainerView testContainerView =
|
| + createAwTestContainerViewOnMainSync(contentsClient);
|
| + final AwContents awContents = testContainerView.getAwContents();
|
| + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper =
|
| + contentsClient.getShouldOverrideUrlLoadingHelper();
|
| +
|
| + final CountDownLatch shouldOverrideUrlLoadingSignal = new CountDownLatch(1);
|
| +
|
| + final String xhrPath = "/xhrPath.html";
|
| + final String xhrUrl = mWebServer.setResponseWithRunnableAction(
|
| + xhrPath, CommonResources.makeHtmlPageFrom("", ""), null, new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + try {
|
| + shouldOverrideUrlLoadingSignal.await();
|
| + } catch (InterruptedException e) {
|
| + throw new RuntimeException(e);
|
| + }
|
| + }
|
| + });
|
| +
|
| + final String xhrJs = "function xhrFunction() {"
|
| + + " var xhr = new XMLHttpRequest();"
|
| + + " xhr.onload=function() {"
|
| + + " console.info('xhr loaded');"
|
| + + " window.jsInterface.setValue(true);"
|
| + + " };"
|
| + + " xhr.onerror=function() {"
|
| + + " console.info('xhr failed, status ' + xhr.status);"
|
| + + " window.jsInterface.setValue(false);"
|
| + + " };"
|
| + + " xhr.open('GET', '" + xhrUrl + "', true);"
|
| + + " xhr.send();"
|
| + + "};";
|
| +
|
| + String pageWithXhrLink = makeHtmlPageFrom(
|
| + "<script>" + xhrJs + "</script>",
|
| + "<img onclick=\"xhrFunction(); location.href='"
|
| + + "thiswillbe://intercepted/"
|
| + + "'\" class=\"big\" id=\"link\" />");
|
| +
|
| + final String startPath = "/startPath.html";
|
| + final String startUrl = addPageToTestServer(mWebServer, startPath, pageWithXhrLink);
|
| +
|
| + enableJavaScriptOnUiThread(awContents);
|
| + final BooleanValueJavascriptObserver jsInterface = new BooleanValueJavascriptObserver();
|
| +
|
| + // add javascript interface
|
| + getInstrumentation().runOnMainSync(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + jsInterface.register(awContents.getContentViewCore(), "jsInterface");
|
| + }
|
| + });
|
| +
|
| + loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), startUrl);
|
| +
|
| + setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadingHelper, true);
|
| + final int shouldOverrideUrlLoadingCallCount = shouldOverrideUrlLoadingHelper.getCallCount();
|
| +
|
| + clickOnLinkUsingJs(awContents, contentsClient);
|
| +
|
| + // Make the server xhr response wait until the navigation request is intercepted.
|
| + shouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount);
|
| + shouldOverrideUrlLoadingSignal.countDown();
|
| +
|
| + jsInterface.waitForEvent(WAIT_TIMEOUT_MS);
|
| + assertTrue(jsInterface.getValue());
|
| + assertEquals(1, mWebServer.getRequestCount(xhrPath));
|
| + }
|
| +
|
| + private static class BooleanValueJavascriptObserver extends JavascriptEventObserver {
|
| + private boolean mValue = false;
|
| +
|
| + public void setValue(boolean value) {
|
| + mValue = value;
|
| + notifyJava();
|
| + }
|
| +
|
| + public boolean getValue() {
|
| + return mValue;
|
| + }
|
| + }
|
| }
|
|
|