diff options
author | mnaganov <mnaganov@chromium.org> | 2015-02-26 04:23:07 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-26 12:23:56 +0000 |
commit | e38bb6cdeb1170cb2cd7faae8507dc6c34c58c7d (patch) | |
tree | ae75dc1fecdf3c65e27c773aea23790ae48f908c /android_webview/javatests/src | |
parent | 24c195f8b43b0eb75d1744e4d1eb95d7bd2fb2a6 (diff) | |
download | chromium_src-e38bb6cdeb1170cb2cd7faae8507dc6c34c58c7d.zip chromium_src-e38bb6cdeb1170cb2cd7faae8507dc6c34c58c7d.tar.gz chromium_src-e38bb6cdeb1170cb2cd7faae8507dc6c34c58c7d.tar.bz2 |
[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}
Diffstat (limited to 'android_webview/javatests/src')
-rw-r--r-- | android_webview/javatests/src/org/chromium/android_webview/test/PopupWindowTest.java | 74 |
1 files changed, 51 insertions, 23 deletions
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("", - "<script>" - + "function tryOpenWindow() {" - + " var newWindow = window.open('" + popupPath + "');" - + "}</script>" - + "<a class=\"full_view\" onclick=\"tryOpenWindow();\">Click me!</a>"); - final String popupPageHtml = CommonResources.makeHtmlPageFrom( - "<title>" + POPUP_TITLE + "</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("", + "<script>" + + "function tryOpenWindow() {" + + " var newWindow = window.open('" + popupPath + "');" + + "}</script>" + + "<a class=\"full_view\" onclick=\"tryOpenWindow();\">Click me!</a>"); + final String popupPageHtml = CommonResources.makeHtmlPageFrom( + "<title>" + POPUP_TITLE + "</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<Boolean>() { @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("", + "<script>" + + "function tryOpenWindow() {" + + " window.popupWindow = window.open('" + popupPath + "');" + + "}" + + "function modifyDomOfPopup() {" + + " window.popupWindow.document.body.innerHTML = 'Hello from the parent!';" + + "}</script>" + + "<a class='full_view' onclick='tryOpenWindow();'>Click me!</a>"); + 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()); + } } |