Chromium Code Reviews| 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..ed08c5a1ad6e6818c00b3ed4f1f856e96aff25bc 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,75 @@ public class AwContentsClientShouldOverrideUrlLoadingTest extends AwTestBase { |
| } |
| }); |
| } |
| + |
| + @SmallTest |
| + @Feature({"AndroidWebView"}) |
| + public void testXhrOnLoad() throws Throwable { |
| + final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
| + final AwTestContainerView testContainerView = |
| + createAwTestContainerViewOnMainSync(contentsClient); |
| + final AwContents awContents = testContainerView.getAwContents(); |
| + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = |
| + contentsClient.getShouldOverrideUrlLoadingHelper(); |
| + |
| + final String startPath = "/startPath.html"; |
| + final String startUrl = addPageToTestServer(mWebServer, |
| + startPath, |
| + CommonResources.makeHtmlPageFrom("", "")); |
| + |
| + final String xhrPath = "/xhrPath.html"; |
| + final String xhrUrl = addPageToTestServer(mWebServer, |
| + xhrPath, |
| + CommonResources.makeHtmlPageFrom("", "")); |
| + |
| + final String xhrJs = |
| + "(function() {" |
| + + " 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();" // TODO need to delay xhr request handling on the server to make |
| + // sure that xhr request won't be handled before shouldInterruptUrlLoading? |
|
mnaganov (inactive)
2015/06/04 19:09:27
typo: shouldOverrideUrlLoading?
|
| + + " window.location = 'interception://whatwhat/';" |
| + + "})();"; |
| + enableJavaScriptOnUiThread(awContents); |
| + final BooleanValueJavascriptObserver jsInterface = new BooleanValueJavascriptObserver(); |
| + |
| + // add javascript interface |
| + getInstrumentation().runOnMainSync(new Runnable() { |
| + @Override |
| + public void run() { |
| + jsInterface.register(awContents.getContentViewCore(), "jsInterface"); |
| + } |
| + }); |
| + |
| + setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadingHelper, true); |
| + |
| + loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), startUrl); |
| + |
| + executeJavaScriptAndWaitForResult(awContents, contentsClient, xhrJs); |
| + |
| + jsInterface.waitForEvent(WAIT_TIMEOUT_MS); // TODO waiting timeout ok? |
|
sgurun-gerrit only
2015/06/05 07:52:49
I was expecting a little bit different test: one w
|
| + 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; |
| + } |
| + } |
| } |