Chromium Code Reviews| Index: android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java |
| diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java |
| index 07b7998f0b8042b027d70f791a37306c08af5e7c..dd7d1ef52cbe01c9d1e24d4472a49e94f53e9851 100644 |
| --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java |
| +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java |
| @@ -806,6 +806,72 @@ public class AwSettingsTest extends AndroidWebViewTestBase { |
| private String mTempDir; |
| } |
| + class AwSettingsJavaScriptPopupsTestHelper extends AwSettingsTestHelper<Boolean> { |
|
benm (inactive)
2012/10/19 11:02:59
This test seems to be verifying the behaviour of C
mnaganov (inactive)
2012/10/19 15:46:39
The test relies on the fact that when SupportMulti
|
| + static private final String POPUP_ENABLED = "Popup enabled"; |
| + static private final String POPUP_BLOCKED = "Popup blocked"; |
| + |
| + AwSettingsJavaScriptPopupsTestHelper( |
| + AwContents awContents, |
| + TestAwContentsClient contentViewClient, |
| + int index) throws Throwable { |
| + super(awContents, contentViewClient, true); |
| + } |
| + |
| + @Override |
| + protected Boolean getAlteredValue() { |
| + return ENABLED; |
| + } |
| + |
| + @Override |
| + protected Boolean getInitialValue() { |
| + return DISABLED; |
| + } |
| + |
| + @Override |
| + protected Boolean getCurrentValue() { |
| + return mContentSettings.getJavaScriptCanOpenWindowsAutomatically(); |
| + } |
| + |
| + @Override |
| + protected void setCurrentValue(Boolean value) { |
| + mContentSettings.setJavaScriptCanOpenWindowsAutomatically(value); |
| + } |
| + |
| + @Override |
| + protected void doEnsureSettingHasValue(Boolean value) throws Throwable { |
| + loadDataSync(getData()); |
| + final boolean expectPopupEnabled = value; |
| + assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + try { |
| + String title = getTitleOnUiThread(); |
| + return expectPopupEnabled ? POPUP_ENABLED.equals(title) : |
| + POPUP_BLOCKED.equals(title); |
| + } catch (Throwable t) { |
| + t.printStackTrace(); |
| + fail("Failed to getTitleOnUiThread: " + t.toString()); |
| + return false; |
| + } |
| + } |
| + }, TEST_TIMEOUT, CHECK_INTERVAL)); |
| + assertEquals(value ? POPUP_ENABLED : POPUP_BLOCKED, getTitleOnUiThread()); |
| + } |
| + |
| + private String getData() { |
| + return "<html><head>" + |
| + "<script>" + |
| + " function tryOpenWindow() {" + |
| + " var newWindow = window.open(" + |
| + " 'data:text/html;charset=utf-8," + |
| + " <html><head><title>" + POPUP_ENABLED + "</title></head></html>');" + |
| + " if (!newWindow) document.title = '" + POPUP_BLOCKED + "';" + |
| + " }" + |
| + "</script></head>" + |
| + "<body onload='tryOpenWindow()'></body></html>"; |
| + } |
| + } |
| + |
| // The test verifies that JavaScript is disabled upon WebView |
| // creation without accessing ContentSettings. If the test passes, |
| // it means that WebView-specific web preferences configuration |
| @@ -1682,6 +1748,27 @@ public class AwSettingsTest extends AndroidWebViewTestBase { |
| } |
| } |
| + public void testJavaScriptPopupsNormal() throws Throwable { |
| + ViewPair views = createViews(NORMAL_VIEW, NORMAL_VIEW); |
| + runPerViewSettingsTest( |
| + new AwSettingsJavaScriptPopupsTestHelper(views.getContents0(), views.getClient0(), 0), |
| + new AwSettingsJavaScriptPopupsTestHelper(views.getContents1(), views.getClient1(), 1)); |
| + } |
| + |
| + public void testJavaScriptPopupsIncognito() throws Throwable { |
| + ViewPair views = createViews(INCOGNITO_VIEW, INCOGNITO_VIEW); |
| + runPerViewSettingsTest( |
| + new AwSettingsJavaScriptPopupsTestHelper(views.getContents0(), views.getClient0(), 0), |
| + new AwSettingsJavaScriptPopupsTestHelper(views.getContents1(), views.getClient1(), 1)); |
| + } |
| + |
| + public void testJavaScriptPopupsBoth() throws Throwable { |
| + ViewPair views = createViews(NORMAL_VIEW, INCOGNITO_VIEW); |
| + runPerViewSettingsTest( |
| + new AwSettingsJavaScriptPopupsTestHelper(views.getContents0(), views.getClient0(), 0), |
| + new AwSettingsJavaScriptPopupsTestHelper(views.getContents1(), views.getClient1(), 1)); |
| + } |
| + |
| class ViewPair { |
| private final AwContents contents0; |
| private final TestAwContentsClient client0; |