OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.android_webview.test; | 5 package org.chromium.android_webview.test; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.os.Build; | 8 import android.os.Build; |
9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
10 | 10 |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 "<p id=\"par\" style=\"font-size:14px;\">"); | 868 "<p id=\"par\" style=\"font-size:14px;\">"); |
869 // Make the paragraph wide enough for being processed by the font au
tosizer. | 869 // Make the paragraph wide enough for being processed by the font au
tosizer. |
870 for (int i = 0; i < 100; i++) { | 870 for (int i = 0; i < 100; i++) { |
871 sb.append("Hello, World! "); | 871 sb.append("Hello, World! "); |
872 } | 872 } |
873 sb.append("</p></body></html>"); | 873 sb.append("</p></body></html>"); |
874 return sb.toString(); | 874 return sb.toString(); |
875 } | 875 } |
876 } | 876 } |
877 | 877 |
| 878 class AwSettingsJavaScriptPopupsTestHelper extends AwSettingsTestHelper<Bool
ean> { |
| 879 static private final String POPUP_ENABLED = "Popup enabled"; |
| 880 static private final String POPUP_BLOCKED = "Popup blocked"; |
| 881 |
| 882 AwSettingsJavaScriptPopupsTestHelper( |
| 883 AwContents awContents, |
| 884 TestAwContentsClient contentViewClient, |
| 885 int index) throws Throwable { |
| 886 super(awContents, contentViewClient, true); |
| 887 } |
| 888 |
| 889 @Override |
| 890 protected Boolean getAlteredValue() { |
| 891 return ENABLED; |
| 892 } |
| 893 |
| 894 @Override |
| 895 protected Boolean getInitialValue() { |
| 896 return DISABLED; |
| 897 } |
| 898 |
| 899 @Override |
| 900 protected Boolean getCurrentValue() { |
| 901 return mContentSettings.getJavaScriptCanOpenWindowsAutomatically(); |
| 902 } |
| 903 |
| 904 @Override |
| 905 protected void setCurrentValue(Boolean value) { |
| 906 mContentSettings.setJavaScriptCanOpenWindowsAutomatically(value); |
| 907 } |
| 908 |
| 909 @Override |
| 910 protected void doEnsureSettingHasValue(Boolean value) throws Throwable { |
| 911 loadDataSync(getData()); |
| 912 final boolean expectPopupEnabled = value; |
| 913 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
| 914 @Override |
| 915 public boolean isSatisfied() { |
| 916 try { |
| 917 String title = getTitleOnUiThread(); |
| 918 return expectPopupEnabled ? POPUP_ENABLED.equals(title)
: |
| 919 POPUP_BLOCKED.equals(title); |
| 920 } catch (Throwable t) { |
| 921 t.printStackTrace(); |
| 922 fail("Failed to getTitleOnUiThread: " + t.toString()); |
| 923 return false; |
| 924 } |
| 925 } |
| 926 }, TEST_TIMEOUT, CHECK_INTERVAL)); |
| 927 assertEquals(value ? POPUP_ENABLED : POPUP_BLOCKED, getTitleOnUiThre
ad()); |
| 928 } |
| 929 |
| 930 private String getData() { |
| 931 return "<html><head>" + |
| 932 "<script>" + |
| 933 " function tryOpenWindow() {" + |
| 934 " var newWindow = window.open(" + |
| 935 " 'data:text/html;charset=utf-8," + |
| 936 " <html><head><title>" + POPUP_ENABLED + "</title>
</head></html>');" + |
| 937 " if (!newWindow) document.title = '" + POPUP_BLOCKED
+ "';" + |
| 938 " }" + |
| 939 "</script></head>" + |
| 940 "<body onload='tryOpenWindow()'></body></html>"; |
| 941 } |
| 942 } |
| 943 |
878 // The test verifies that JavaScript is disabled upon WebView | 944 // The test verifies that JavaScript is disabled upon WebView |
879 // creation without accessing ContentSettings. If the test passes, | 945 // creation without accessing ContentSettings. If the test passes, |
880 // it means that WebView-specific web preferences configuration | 946 // it means that WebView-specific web preferences configuration |
881 // is applied on WebView creation. JS state is used, because it is | 947 // is applied on WebView creation. JS state is used, because it is |
882 // enabled by default in Chrome, but must be disabled by default | 948 // enabled by default in Chrome, but must be disabled by default |
883 // in WebView. | 949 // in WebView. |
884 @SmallTest | 950 @SmallTest |
885 @Feature({"Android-WebView", "Preferences"}) | 951 @Feature({"Android-WebView", "Preferences"}) |
886 public void testJavaScriptDisabledByDefault() throws Throwable { | 952 public void testJavaScriptDisabledByDefault() throws Throwable { |
887 final String JS_ENABLED_STRING = "JS has run"; | 953 final String JS_ENABLED_STRING = "JS has run"; |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1818 * Blocked on crbug/157563 | 1884 * Blocked on crbug/157563 |
1819 */ | 1885 */ |
1820 @DisabledTest | 1886 @DisabledTest |
1821 public void testTextZoomBoth() throws Throwable { | 1887 public void testTextZoomBoth() throws Throwable { |
1822 ViewPair views = createViews(NORMAL_VIEW, INCOGNITO_VIEW); | 1888 ViewPair views = createViews(NORMAL_VIEW, INCOGNITO_VIEW); |
1823 runPerViewSettingsTest( | 1889 runPerViewSettingsTest( |
1824 new AwSettingsTextZoomTestHelper(views.getContents0(), views.getClie
nt0()), | 1890 new AwSettingsTextZoomTestHelper(views.getContents0(), views.getClie
nt0()), |
1825 new AwSettingsTextZoomTestHelper(views.getContents1(), views.getClie
nt1())); | 1891 new AwSettingsTextZoomTestHelper(views.getContents1(), views.getClie
nt1())); |
1826 } | 1892 } |
1827 | 1893 |
| 1894 public void testJavaScriptPopupsNormal() throws Throwable { |
| 1895 ViewPair views = createViews(NORMAL_VIEW, NORMAL_VIEW); |
| 1896 runPerViewSettingsTest( |
| 1897 new AwSettingsJavaScriptPopupsTestHelper(views.getContents0(), views
.getClient0(), 0), |
| 1898 new AwSettingsJavaScriptPopupsTestHelper(views.getContents1(), views
.getClient1(), 1)); |
| 1899 } |
| 1900 |
| 1901 public void testJavaScriptPopupsIncognito() throws Throwable { |
| 1902 ViewPair views = createViews(INCOGNITO_VIEW, INCOGNITO_VIEW); |
| 1903 runPerViewSettingsTest( |
| 1904 new AwSettingsJavaScriptPopupsTestHelper(views.getContents0(), views
.getClient0(), 0), |
| 1905 new AwSettingsJavaScriptPopupsTestHelper(views.getContents1(), views
.getClient1(), 1)); |
| 1906 } |
| 1907 |
| 1908 public void testJavaScriptPopupsBoth() throws Throwable { |
| 1909 ViewPair views = createViews(NORMAL_VIEW, INCOGNITO_VIEW); |
| 1910 runPerViewSettingsTest( |
| 1911 new AwSettingsJavaScriptPopupsTestHelper(views.getContents0(), views
.getClient0(), 0), |
| 1912 new AwSettingsJavaScriptPopupsTestHelper(views.getContents1(), views
.getClient1(), 1)); |
| 1913 } |
| 1914 |
1828 class ViewPair { | 1915 class ViewPair { |
1829 private final AwContents contents0; | 1916 private final AwContents contents0; |
1830 private final TestAwContentsClient client0; | 1917 private final TestAwContentsClient client0; |
1831 private final AwContents contents1; | 1918 private final AwContents contents1; |
1832 private final TestAwContentsClient client1; | 1919 private final TestAwContentsClient client1; |
1833 | 1920 |
1834 ViewPair(AwContents contents0, TestAwContentsClient client0, | 1921 ViewPair(AwContents contents0, TestAwContentsClient client0, |
1835 AwContents contents1, TestAwContentsClient client1) { | 1922 AwContents contents1, TestAwContentsClient client1) { |
1836 this.contents0 = contents0; | 1923 this.contents0 = contents0; |
1837 this.client0 = client0; | 1924 this.client0 = client0; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2001 contentClient.getOnPageFinishedHelper(), | 2088 contentClient.getOnPageFinishedHelper(), |
2002 "file:///" + fileName); | 2089 "file:///" + fileName); |
2003 assertEquals(1, webServer.getRequestCount(httpPath)); | 2090 assertEquals(1, webServer.getRequestCount(httpPath)); |
2004 assertEquals("img_onload_fired", getTitleOnUiThread(awContents)); | 2091 assertEquals("img_onload_fired", getTitleOnUiThread(awContents)); |
2005 } finally { | 2092 } finally { |
2006 if (fileName != null) TestFileUtil.deleteFile(fileName); | 2093 if (fileName != null) TestFileUtil.deleteFile(fileName); |
2007 if (webServer != null) webServer.shutdown(); | 2094 if (webServer != null) webServer.shutdown(); |
2008 } | 2095 } |
2009 } | 2096 } |
2010 } | 2097 } |
OLD | NEW |