Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1638)

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/PopupWindowTest.java

Issue 924833003: [Android WebView] Synthesize a fake page loading event on page source modification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed extra space Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « android_webview/java_library_common.mk ('k') | android_webview/libwebviewchromium.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/javatests/src/org/chromium/android_webview/test/PopupWindowTest.java
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 a81e9070fd5577fddc9cde7cf413743f6c61260a..a59030da71ac59acc63c087bd5110e0ca6f6aaef 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());
+ }
}
« no previous file with comments | « android_webview/java_library_common.mk ('k') | android_webview/libwebviewchromium.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698