| 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 06945019a603cc7b87afcfde174be35c9693b04f..e27672f62de416d3bbfe348ba7495144352314c0 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
|
| @@ -9,10 +9,8 @@ import android.util.Pair;
|
|
|
| import org.chromium.android_webview.AwContents;
|
| import org.chromium.android_webview.AwContentsClient;
|
| -import org.chromium.android_webview.test.TestAwContentsClient.OnFailedLoadHelper;
|
| 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.CommandLineFlags;
|
| import org.chromium.base.test.util.DisabledTest;
|
| @@ -20,7 +18,6 @@ import org.chromium.base.test.util.Feature;
|
| import org.chromium.content.browser.test.util.CallbackHelper;
|
| import org.chromium.content.browser.test.util.DOMUtils;
|
| import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper;
|
| -import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper;
|
| import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageStartedHelper;
|
| import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnReceivedErrorHelper;
|
| import org.chromium.content.common.ContentSwitches;
|
| @@ -30,7 +27,6 @@ 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;
|
|
|
| /**
|
| @@ -736,9 +732,7 @@ public class AwContentsClientShouldOverrideUrlLoadingTest extends AwTestBase {
|
| assertEquals(redirectTarget,
|
| mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl());
|
| assertEquals(serverSideRedirect, mShouldOverrideUrlLoadingHelper.isRedirect());
|
| - // We keep the user gesture from the initial navigation for serverside redirects but drop
|
| - // the user gesture for browser initiated redirects.
|
| - assertEquals(serverSideRedirect, mShouldOverrideUrlLoadingHelper.hasUserGesture());
|
| + assertFalse(mShouldOverrideUrlLoadingHelper.hasUserGesture());
|
| assertTrue(mShouldOverrideUrlLoadingHelper.isMainFrame());
|
| }
|
|
|
| @@ -1086,164 +1080,4 @@ public class AwContentsClientShouldOverrideUrlLoadingTest extends AwTestBase {
|
| public void testClickableAddressInIframe() throws Throwable {
|
| doTestClickableContent(TEST_ADDRESS, TEST_ADDRESS_URI, false);
|
| }
|
| -
|
| - @SmallTest
|
| - @Feature({"AndroidWebView"})
|
| - public void testXhrInLink() throws Throwable {
|
| - standardSetup();
|
| - 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(startPath, pageWithXhrLink);
|
| -
|
| - enableJavaScriptOnUiThread(mAwContents);
|
| - final BooleanValueJavascriptObserver jsInterface = new BooleanValueJavascriptObserver();
|
| -
|
| - // add javascript interface
|
| - getInstrumentation().runOnMainSync(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - jsInterface.register(mAwContents.getContentViewCore(), "jsInterface");
|
| - }
|
| - });
|
| -
|
| - loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), startUrl);
|
| -
|
| - setShouldOverrideUrlLoadingReturnValueOnUiThread(true);
|
| - final int shouldOverrideUrlLoadingCallCount =
|
| - mShouldOverrideUrlLoadingHelper.getCallCount();
|
| -
|
| - assertEquals(0, mWebServer.getRequestCount(xhrPath));
|
| -
|
| - clickOnLinkUsingJs();
|
| -
|
| - // Make the server xhr response wait until the navigation request is intercepted.
|
| - mShouldOverrideUrlLoadingHelper.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;
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * This is to test a bug where a JS redirect failing in its provisional state would prevent us
|
| - * from posting onPageFinished for the original page load.
|
| - * The original page contains an iframe so that we can commit the original load but then
|
| - * prevent it from finishing until the JS redirect fails by having the test server defer the
|
| - * response to the iframe.
|
| - */
|
| - @SmallTest
|
| - @Feature({"AndroidWebView"})
|
| - public void testOnPageFinishedOnFailedJSRedirect() throws Throwable {
|
| - final CountDownLatch jsRedirectSignal = new CountDownLatch(1);
|
| -
|
| - final String redirectTargetPath = "/redirectTargetPath.html";
|
| - final String redirectTargetUrl = mWebServer.setResponse(
|
| - redirectTargetPath, CommonResources.makeHtmlPageFrom("", ""), null);
|
| -
|
| - class DelayingOverrideClient extends TestAwContentsClient {
|
| - @Override
|
| - public boolean shouldOverrideUrlLoading(AwWebResourceRequest request) {
|
| - if (redirectTargetUrl.equals(request.url)) {
|
| - try {
|
| - // Wait here to make sure the load reaches its provisional state before we
|
| - // cancel it. Waiting for a callback to the WebContentsObserver to make sure
|
| - // we have reached the provisional state causes a deadlock here.
|
| - Thread.sleep(Math.min(WAIT_TIMEOUT_MS / 2, 2000));
|
| - } catch (InterruptedException e) {
|
| - }
|
| - return true;
|
| - }
|
| - return false;
|
| - }
|
| - }
|
| - mContentsClient = new DelayingOverrideClient();
|
| - setupWithProvidedContentsClient(mContentsClient);
|
| -
|
| - final String redirectJs = "window.location.href='" + redirectTargetUrl + "';";
|
| -
|
| - final String iframePath = "/iframePath.html";
|
| - final String iframeUrl = mWebServer.setResponseWithRunnableAction(
|
| - iframePath, CommonResources.makeHtmlPageFrom("", ""), null, new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - try {
|
| - mAwContents.evaluateJavaScriptForTests(redirectJs, null);
|
| - jsRedirectSignal.await();
|
| - } catch (InterruptedException e) {
|
| - }
|
| - }
|
| - });
|
| - final String iframeJs = "<iframe src='" + iframeUrl + "'></iframe>";
|
| -
|
| - String startPage = makeHtmlPageFrom("", iframeJs);
|
| - final String startPath = "/startPath.html";
|
| - final String startUrl = addPageToTestServer(startPath, startPage);
|
| -
|
| - enableJavaScriptOnUiThread(mAwContents);
|
| -
|
| - OnPageFinishedHelper onPageFinishedHelper = mContentsClient.getOnPageFinishedHelper();
|
| - int onPageFinishedCallCount = onPageFinishedHelper.getCallCount();
|
| -
|
| - OnFailedLoadHelper onFailedLoadHelper = mContentsClient.getOnFailedLoadHelper();
|
| - int onFailedLoadCallCount = onFailedLoadHelper.getCallCount();
|
| -
|
| - // load start url -> iframe -> JS redirect -> fail JS redirect -> finish start URL
|
| - loadUrlAsync(mAwContents, startUrl);
|
| -
|
| - onFailedLoadHelper.waitForCallback(onFailedLoadCallCount);
|
| - assertEquals(redirectTargetUrl, onFailedLoadHelper.getUrl());
|
| -
|
| - // let iframe finish
|
| - jsRedirectSignal.countDown();
|
| -
|
| - onPageFinishedHelper.waitForCallback(onPageFinishedCallCount);
|
| - assertEquals(startUrl, onPageFinishedHelper.getUrl());
|
| - }
|
| }
|
|
|