| 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 ec9d887e604b58479cc69b5254579b30949af260..c438f0453ac24ee3a43a22d243c2773d5e712c86 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;
|
| @@ -870,4 +871,87 @@ public class AwContentsClientShouldOverrideUrlLoadingTest extends AwTestBase {
|
| }
|
| });
|
| }
|
| +
|
| + @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 String xhrPath = "/xhrPath.html";
|
| + final String xhrUrl = addPageToTestServer(mWebServer,
|
| + xhrPath,
|
| + CommonResources.makeHtmlPageFrom("", ""));
|
| +
|
| + 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);
|
| +
|
| + // TODO is the following line an OK way of delaying the xhr request?
|
| + // (we just call Thread.sleep() in mWebServer.getResponse...)
|
| + mWebServer.setResponseDelay(WAIT_TIMEOUT_MS / 5);
|
| +
|
| + setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadingHelper, true);
|
| +
|
| + clickOnLinkUsingJs(awContents, contentsClient);
|
| +
|
| + jsInterface.waitForEvent(WAIT_TIMEOUT_MS);
|
| + assertTrue(jsInterface.getValue());
|
| + assertEquals(1, mWebServer.getRequestCount(xhrPath));
|
| + }
|
| +
|
| + private class BooleanValueJavascriptObserver extends JavascriptEventObserver {
|
| + private boolean mValue = false;
|
| +
|
| + public void setValue(boolean value) {
|
| + mValue = value;
|
| + notifyJava();
|
| + }
|
| +
|
| + public boolean getValue() {
|
| + return mValue;
|
| + }
|
| + }
|
| +
|
| }
|
|
|