| 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 3044ddc5917a36b87d0d47d08314d70a7bb02781..a81e9070fd5577fddc9cde7cf413743f6c61260a 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
|
| @@ -8,10 +8,14 @@
|
| import android.test.suitebuilder.annotation.SmallTest;
|
|
|
| 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.net.test.util.TestWebServer;
|
| +
|
| +import java.util.concurrent.Callable;
|
| +import java.util.concurrent.TimeUnit;
|
|
|
| /**
|
| * Tests for pop up window flow.
|
| @@ -21,6 +25,9 @@
|
| private TestAwContentsClient mParentContentsClient;
|
| private AwTestContainerView mParentContainerView;
|
| private AwContents mParentContents;
|
| + private TestAwContentsClient mPopupContentsClient;
|
| + private AwTestContainerView mPopupContainerView;
|
| + private AwContents mPopupContents;
|
| private TestWebServer mWebServer;
|
|
|
| private static final String POPUP_TITLE = "Popup Window";
|
| @@ -42,22 +49,67 @@
|
| super.tearDown();
|
| }
|
|
|
| - @SmallTest
|
| - @Feature({"AndroidWebView"})
|
| - public void testPopupWindow() throws Throwable {
|
| + private void triggerPopup() throws Throwable {
|
| + enableJavaScriptOnUiThread(mParentContents);
|
| + getInstrumentation().runOnMainSync(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + mParentContents.getSettings().setSupportMultipleWindows(true);
|
| + mParentContents.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
|
| + }
|
| + });
|
| +
|
| final String popupPath = "/popup.html";
|
| - final String parentPageHtml = CommonResources.makeHtmlPageFrom("", "<script>"
|
| +
|
| + final String parentPageHtml = CommonResources.makeHtmlPageFrom("",
|
| + "<script>"
|
| + "function tryOpenWindow() {"
|
| + " var newWindow = window.open('" + popupPath + "');"
|
| - + "}</script>");
|
| -
|
| + + "}</script>"
|
| + + "<a class=\"full_view\" onclick=\"tryOpenWindow();\">Click me!</a>");
|
| final String popupPageHtml = CommonResources.makeHtmlPageFrom(
|
| "<title>" + POPUP_TITLE + "</title>",
|
| "This is a popup window");
|
|
|
| - triggerPopup(mParentContents, mParentContentsClient, mWebServer, parentPageHtml,
|
| - popupPageHtml, "/popup.html", "tryOpenWindow()");
|
| - AwContents popupContents = connectPendingPopup(mParentContents);
|
| - assertEquals(POPUP_TITLE, getTitleOnUiThread(popupContents));
|
| + final String parentUrl = mWebServer.setResponse("/popupParent.html", parentPageHtml, null);
|
| + mWebServer.setResponse(popupPath, popupPageHtml, null);
|
| +
|
| + mParentContentsClient.getOnCreateWindowHelper().setReturnValue(true);
|
| + loadUrlSync(mParentContents,
|
| + mParentContentsClient.getOnPageFinishedHelper(),
|
| + parentUrl);
|
| +
|
| + TestAwContentsClient.OnCreateWindowHelper onCreateWindowHelper =
|
| + mParentContentsClient.getOnCreateWindowHelper();
|
| + int currentCallCount = onCreateWindowHelper.getCallCount();
|
| + AwTestTouchUtils.simulateTouchCenterOfView(mParentContainerView);
|
| + onCreateWindowHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_MS,
|
| + TimeUnit.MILLISECONDS);
|
| + }
|
| +
|
| + private void connectPendingPopup() throws Exception {
|
| + mPopupContentsClient = new TestAwContentsClient();
|
| + mPopupContainerView = createAwTestContainerViewOnMainSync(mPopupContentsClient);
|
| + mPopupContents = mPopupContainerView.getAwContents();
|
| +
|
| + getInstrumentation().runOnMainSync(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + mParentContents.supplyContentsForPopup(mPopupContents);
|
| + }
|
| + });
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"AndroidWebView"})
|
| + public void testPopupWindow() throws Throwable {
|
| + triggerPopup();
|
| + connectPendingPopup();
|
| + poll(new Callable<Boolean>() {
|
| + @Override
|
| + public Boolean call() throws Exception {
|
| + return POPUP_TITLE.equals(getTitleOnUiThread(mPopupContents));
|
| + }
|
| + });
|
| }
|
| }
|
|
|