From e38bb6cdeb1170cb2cd7faae8507dc6c34c58c7d Mon Sep 17 00:00:00 2001 From: mnaganov Date: Thu, 26 Feb 2015 04:23:07 -0800 Subject: [Android WebView] Synthesize a fake page loading event on page source modification When a script modifies page source of a non-committed page, we need to notify clients, so they can update the URL bar to avoid confusion. BUG=458569 Review URL: https://codereview.chromium.org/924833003 Cr-Commit-Position: refs/heads/master@{#318222} --- .../android_webview/test/PopupWindowTest.java | 74 +++++++++++++++------- 1 file changed, 51 insertions(+), 23 deletions(-) (limited to 'android_webview/javatests/src') diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/PopupWindowTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/PopupWindowTest.java index a81e907..a59030d 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/PopupWindowTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/PopupWindowTest.java @@ -5,13 +5,14 @@ package org.chromium.android_webview.test; import android.os.Build; -import android.test.suitebuilder.annotation.SmallTest; +import android.test.suitebuilder.annotation.MediumTest; import org.chromium.android_webview.AwContents; import org.chromium.android_webview.test.util.AwTestTouchUtils; import org.chromium.android_webview.test.util.CommonResources; import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.MinAndroidSdkLevel; +import org.chromium.content.browser.test.util.TestCallbackHelperContainer; import org.chromium.net.test.util.TestWebServer; import java.util.concurrent.Callable; @@ -38,6 +39,9 @@ public class PopupWindowTest extends AwTestBase { mParentContentsClient = new TestAwContentsClient(); mParentContainerView = createAwTestContainerViewOnMainSync(mParentContentsClient); mParentContents = mParentContainerView.getAwContents(); + mPopupContentsClient = new TestAwContentsClient(); + mPopupContainerView = createAwTestContainerViewOnMainSync(mPopupContentsClient); + mPopupContents = mPopupContainerView.getAwContents(); mWebServer = TestWebServer.start(); } @@ -49,7 +53,9 @@ public class PopupWindowTest extends AwTestBase { super.tearDown(); } - private void triggerPopup() throws Throwable { + // It is expected that the parent page contains a link that opens a popup window, + // and the test server is already pre-loaded with both parent and popup pages. + private void triggerPopup(String parentUrl) throws Throwable { enableJavaScriptOnUiThread(mParentContents); getInstrumentation().runOnMainSync(new Runnable() { @Override @@ -59,21 +65,6 @@ public class PopupWindowTest extends AwTestBase { } }); - final String popupPath = "/popup.html"; - - final String parentPageHtml = CommonResources.makeHtmlPageFrom("", - "" - + "Click me!"); - final String popupPageHtml = CommonResources.makeHtmlPageFrom( - "" + POPUP_TITLE + "", - "This is a popup window"); - - final String parentUrl = mWebServer.setResponse("/popupParent.html", parentPageHtml, null); - mWebServer.setResponse(popupPath, popupPageHtml, null); - mParentContentsClient.getOnCreateWindowHelper().setReturnValue(true); loadUrlSync(mParentContents, mParentContentsClient.getOnPageFinishedHelper(), @@ -88,10 +79,6 @@ public class PopupWindowTest extends AwTestBase { } private void connectPendingPopup() throws Exception { - mPopupContentsClient = new TestAwContentsClient(); - mPopupContainerView = createAwTestContainerViewOnMainSync(mPopupContentsClient); - mPopupContents = mPopupContainerView.getAwContents(); - getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { @@ -100,10 +87,22 @@ public class PopupWindowTest extends AwTestBase { }); } - @SmallTest + @MediumTest @Feature({"AndroidWebView"}) public void testPopupWindow() throws Throwable { - triggerPopup(); + final String popupPath = "/popup.html"; + final String parentPageHtml = CommonResources.makeHtmlPageFrom("", + "" + + "Click me!"); + final String popupPageHtml = CommonResources.makeHtmlPageFrom( + "" + POPUP_TITLE + "", + "This is a popup window"); + final String parentUrl = mWebServer.setResponse("/popupParent.html", parentPageHtml, null); + mWebServer.setResponse(popupPath, popupPageHtml, null); + triggerPopup(parentUrl); connectPendingPopup(); poll(new Callable() { @Override @@ -112,4 +111,33 @@ public class PopupWindowTest extends AwTestBase { } }); } + + @MediumTest + @Feature({"AndroidWebView"}) + public void testOnPageFinishedCalledAfterModifyingPageSource() throws Throwable { + final String popupPath = "/popup.html"; + final String popupUrl = mWebServer.setResponseWithNoContentStatus(popupPath); + final String parentHtml = CommonResources.makeHtmlPageFrom("", + "" + + "Click me!"); + final String parentUrl = mWebServer.setResponse("/parent.html", parentHtml, null); + triggerPopup(parentUrl); + TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = + mPopupContentsClient.getOnPageFinishedHelper(); + int onPageFinishedCallCount = onPageFinishedHelper.getCallCount(); + connectPendingPopup(); + onPageFinishedHelper.waitForCallback(onPageFinishedCallCount); + + onPageFinishedCallCount = onPageFinishedHelper.getCallCount(); + executeJavaScriptAndWaitForResult(mParentContents, mParentContentsClient, + "modifyDomOfPopup()"); + onPageFinishedHelper.waitForCallback(onPageFinishedCallCount); + assertEquals("about:blank", onPageFinishedHelper.getUrl()); + } } -- cgit v1.1