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

Side by Side Diff: android_webview/javatests/src/org/chromium/android_webview/test/WebViewModalDialogOverrideTest.java

Issue 11028094: [android_webview] Use AwContents loadUrl method instead of ContentViewCore. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase yet again Created 8 years, 2 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 unified diff | Download patch
« no previous file with comments | « android_webview/javatests/src/org/chromium/android_webview/test/WebViewFindApisTestBase.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** 5 /**
6 * Test suite for displaying and functioning of modal dialogs. 6 * Test suite for displaying and functioning of modal dialogs.
7 */ 7 */
8 8
9 package org.chromium.android_webview.test; 9 package org.chromium.android_webview.test;
10 10
11 import android.test.suitebuilder.annotation.MediumTest; 11 import android.test.suitebuilder.annotation.MediumTest;
12 import android.test.suitebuilder.annotation.SmallTest; 12 import android.test.suitebuilder.annotation.SmallTest;
13 13
14 import org.chromium.android_webview.AwContents;
14 import org.chromium.android_webview.JsPromptResultReceiver; 15 import org.chromium.android_webview.JsPromptResultReceiver;
15 import org.chromium.android_webview.JsResultReceiver; 16 import org.chromium.android_webview.JsResultReceiver;
16 import org.chromium.base.test.util.Feature; 17 import org.chromium.base.test.util.Feature;
17 import org.chromium.content.browser.ContentViewCore;
18 import org.chromium.content.browser.test.util.CallbackHelper; 18 import org.chromium.content.browser.test.util.CallbackHelper;
19 19
20 import java.util.concurrent.atomic.AtomicBoolean; 20 import java.util.concurrent.atomic.AtomicBoolean;
21 21
22 public class WebViewModalDialogOverrideTest extends AndroidWebViewTestBase { 22 public class WebViewModalDialogOverrideTest extends AndroidWebViewTestBase {
23 private final static String EMPTY_PAGE = 23 private final static String EMPTY_PAGE =
24 "<!doctype html>" + 24 "<!doctype html>" +
25 "<title>Modal Dialog Test</title><p>Testcase.</p>"; 25 "<title>Modal Dialog Test</title><p>Testcase.</p>";
26 private final static String BEFORE_UNLOAD_URL = 26 private final static String BEFORE_UNLOAD_URL =
27 "<!doctype html>" + 27 "<!doctype html>" +
(...skipping 13 matching lines...) Expand all
41 // Returning true from the callback should not show a dialog. 41 // Returning true from the callback should not show a dialog.
42 TestAwContentsClient client = new TestAwContentsClient() { 42 TestAwContentsClient client = new TestAwContentsClient() {
43 @Override 43 @Override
44 public void handleJsAlert(String url, String message, JsResultReceiv er res) { 44 public void handleJsAlert(String url, String message, JsResultReceiv er res) {
45 callbackCalled.set(true); 45 callbackCalled.set(true);
46 res.confirm(); 46 res.confirm();
47 assertEquals(ALERT_TEXT, message); 47 assertEquals(ALERT_TEXT, message);
48 } 48 }
49 }; 49 };
50 AwTestContainerView view = createAwTestContainerViewOnMainSync(client); 50 AwTestContainerView view = createAwTestContainerViewOnMainSync(client);
51 final ContentViewCore contentViewCore = view.getContentViewCore(); 51 final AwContents awContents = view.getAwContents();
52 52
53 enableJavaScriptOnUiThread(contentViewCore); 53 enableJavaScriptOnUiThread(awContents);
54 loadDataSync(contentViewCore, client.getOnPageFinishedHelper(), 54 loadDataSync(awContents, client.getOnPageFinishedHelper(),
55 EMPTY_PAGE, "text/html", false); 55 EMPTY_PAGE, "text/html", false);
56 executeJavaScriptAndWaitForResult(contentViewCore, client, 56 executeJavaScriptAndWaitForResult(awContents, client,
57 "alert('" + ALERT_TEXT + "')"); 57 "alert('" + ALERT_TEXT + "')");
58 assertTrue(callbackCalled.get()); 58 assertTrue(callbackCalled.get());
59 } 59 }
60 60
61 /* 61 /*
62 * Verify that when the AwContentsClient calls handleJsPrompt. 62 * Verify that when the AwContentsClient calls handleJsPrompt.
63 */ 63 */
64 @SmallTest 64 @SmallTest
65 @Feature({"Android-WebView"}) 65 @Feature({"Android-WebView"})
66 public void testOverridePromptHandling() throws Throwable { 66 public void testOverridePromptHandling() throws Throwable {
67 final String PROMPT_TEXT = "How do you like your eggs in the morning?"; 67 final String PROMPT_TEXT = "How do you like your eggs in the morning?";
68 final String PROMPT_DEFAULT = "Scrambled"; 68 final String PROMPT_DEFAULT = "Scrambled";
69 final String PROMPT_RESULT = "I like mine with a kiss"; 69 final String PROMPT_RESULT = "I like mine with a kiss";
70 70
71 final AtomicBoolean called = new AtomicBoolean(false); 71 final AtomicBoolean called = new AtomicBoolean(false);
72 // Returning true from the callback should not show a dialog. 72 // Returning true from the callback should not show a dialog.
73 final TestAwContentsClient client = new TestAwContentsClient() { 73 final TestAwContentsClient client = new TestAwContentsClient() {
74 @Override 74 @Override
75 public void handleJsPrompt(String url, String message, String defaul tValue, 75 public void handleJsPrompt(String url, String message, String defaul tValue,
76 JsPromptResultReceiver res) { 76 JsPromptResultReceiver res) {
77 assertEquals(PROMPT_TEXT, message); 77 assertEquals(PROMPT_TEXT, message);
78 assertEquals(PROMPT_DEFAULT, defaultValue); 78 assertEquals(PROMPT_DEFAULT, defaultValue);
79 res.confirm(PROMPT_RESULT); 79 res.confirm(PROMPT_RESULT);
80 called.set(true); 80 called.set(true);
81 } 81 }
82 }; 82 };
83 AwTestContainerView view = createAwTestContainerViewOnMainSync(client); 83 AwTestContainerView view = createAwTestContainerViewOnMainSync(client);
84 ContentViewCore contentViewCore = view.getContentViewCore(); 84 final AwContents awContents = view.getAwContents();
85 85
86 enableJavaScriptOnUiThread(contentViewCore); 86 enableJavaScriptOnUiThread(awContents);
87 loadDataSync(contentViewCore, client.getOnPageFinishedHelper(), 87 loadDataSync(awContents, client.getOnPageFinishedHelper(),
88 EMPTY_PAGE, "text/html", false); 88 EMPTY_PAGE, "text/html", false);
89 String result = executeJavaScriptAndWaitForResult(contentViewCore, clien t, 89 String result = executeJavaScriptAndWaitForResult(awContents, client,
90 "prompt('" + PROMPT_TEXT + "','" + PROMPT_DEFAULT + "')"); 90 "prompt('" + PROMPT_TEXT + "','" + PROMPT_DEFAULT + "')");
91 assertTrue(called.get()); 91 assertTrue(called.get());
92 assertEquals("\"" + PROMPT_RESULT + "\"", result); 92 assertEquals("\"" + PROMPT_RESULT + "\"", result);
93 } 93 }
94 94
95 /* 95 /*
96 * Verify that when the AwContentsClient calls handleJsConfirm and the clien t confirms. 96 * Verify that when the AwContentsClient calls handleJsConfirm and the clien t confirms.
97 */ 97 */
98 @SmallTest 98 @SmallTest
99 @Feature({"Android-WebView"}) 99 @Feature({"Android-WebView"})
100 public void testOverrideConfirmHandlingConfirmed() throws Throwable { 100 public void testOverrideConfirmHandlingConfirmed() throws Throwable {
101 final String CONFIRM_TEXT = "Would you like a cookie?"; 101 final String CONFIRM_TEXT = "Would you like a cookie?";
102 102
103 final AtomicBoolean called = new AtomicBoolean(false); 103 final AtomicBoolean called = new AtomicBoolean(false);
104 // Returning true from the callback should not show a dialog. 104 // Returning true from the callback should not show a dialog.
105 TestAwContentsClient client = new TestAwContentsClient() { 105 TestAwContentsClient client = new TestAwContentsClient() {
106 @Override 106 @Override
107 public void handleJsConfirm(String url, String message, JsResultRece iver res) { 107 public void handleJsConfirm(String url, String message, JsResultRece iver res) {
108 assertEquals(CONFIRM_TEXT, message); 108 assertEquals(CONFIRM_TEXT, message);
109 res.confirm(); 109 res.confirm();
110 called.set(true); 110 called.set(true);
111 } 111 }
112 }; 112 };
113 AwTestContainerView view = createAwTestContainerViewOnMainSync(client); 113 AwTestContainerView view = createAwTestContainerViewOnMainSync(client);
114 ContentViewCore contentViewCore = view.getContentViewCore(); 114 final AwContents awContents = view.getAwContents();
115 enableJavaScriptOnUiThread(contentViewCore); 115 enableJavaScriptOnUiThread(awContents);
116 116
117 loadDataSync(contentViewCore, client.getOnPageFinishedHelper(), 117 loadDataSync(awContents, client.getOnPageFinishedHelper(),
118 EMPTY_PAGE, "text/html", false); 118 EMPTY_PAGE, "text/html", false);
119 String result = executeJavaScriptAndWaitForResult(contentViewCore, clien t, 119 String result = executeJavaScriptAndWaitForResult(awContents, client,
120 "confirm('" + CONFIRM_TEXT + "')"); 120 "confirm('" + CONFIRM_TEXT + "')");
121 assertTrue(called.get()); 121 assertTrue(called.get());
122 assertEquals("true", result); 122 assertEquals("true", result);
123 } 123 }
124 124
125 /* 125 /*
126 * Verify that when the AwContentsClient calls handleJsConfirm and the clien t cancels. 126 * Verify that when the AwContentsClient calls handleJsConfirm and the clien t cancels.
127 */ 127 */
128 @SmallTest 128 @SmallTest
129 @Feature({"Android-WebView"}) 129 @Feature({"Android-WebView"})
130 public void testOverrideConfirmHandlingCancelled() throws Throwable { 130 public void testOverrideConfirmHandlingCancelled() throws Throwable {
131 final String CONFIRM_TEXT = "Would you like a cookie?"; 131 final String CONFIRM_TEXT = "Would you like a cookie?";
132 132
133 final AtomicBoolean called = new AtomicBoolean(false); 133 final AtomicBoolean called = new AtomicBoolean(false);
134 // Returning true from the callback should not show a dialog. 134 // Returning true from the callback should not show a dialog.
135 TestAwContentsClient client = new TestAwContentsClient() { 135 TestAwContentsClient client = new TestAwContentsClient() {
136 @Override 136 @Override
137 public void handleJsConfirm(String url, String message, JsResultRece iver res) { 137 public void handleJsConfirm(String url, String message, JsResultRece iver res) {
138 assertEquals(CONFIRM_TEXT, message); 138 assertEquals(CONFIRM_TEXT, message);
139 res.cancel(); 139 res.cancel();
140 called.set(true); 140 called.set(true);
141 } 141 }
142 }; 142 };
143 AwTestContainerView view = createAwTestContainerViewOnMainSync(client); 143 AwTestContainerView view = createAwTestContainerViewOnMainSync(client);
144 ContentViewCore contentViewCore = view.getContentViewCore(); 144 final AwContents awContents = view.getAwContents();
145 enableJavaScriptOnUiThread(contentViewCore); 145 enableJavaScriptOnUiThread(awContents);
146 146
147 loadDataSync(contentViewCore, client.getOnPageFinishedHelper(), 147 loadDataSync(awContents, client.getOnPageFinishedHelper(),
148 EMPTY_PAGE, "text/html", false); 148 EMPTY_PAGE, "text/html", false);
149 String result = executeJavaScriptAndWaitForResult(contentViewCore, clien t, 149 String result = executeJavaScriptAndWaitForResult(awContents, client,
150 "confirm('" + CONFIRM_TEXT + "')"); 150 "confirm('" + CONFIRM_TEXT + "')");
151 assertTrue(called.get()); 151 assertTrue(called.get());
152 assertEquals("false", result); 152 assertEquals("false", result);
153 } 153 }
154 154
155 /* 155 /*
156 * Verify that when the AwContentsClient calls handleJsBeforeUnload 156 * Verify that when the AwContentsClient calls handleJsBeforeUnload
157 */ 157 */
158 @MediumTest 158 @MediumTest
159 @Feature({"Android-WebView"}) 159 @Feature({"Android-WebView"})
160 public void testOverrideBeforeUnloadHandling() throws Throwable { 160 public void testOverrideBeforeUnloadHandling() throws Throwable {
161 final CallbackHelper jsBeforeUnloadHelper = new CallbackHelper(); 161 final CallbackHelper jsBeforeUnloadHelper = new CallbackHelper();
162 TestAwContentsClient client = new TestAwContentsClient() { 162 TestAwContentsClient client = new TestAwContentsClient() {
163 @Override 163 @Override
164 public void handleJsBeforeUnload(String url, String message, JsResul tReceiver res) { 164 public void handleJsBeforeUnload(String url, String message, JsResul tReceiver res) {
165 res.cancel(); 165 res.cancel();
166 jsBeforeUnloadHelper.notifyCalled(); 166 jsBeforeUnloadHelper.notifyCalled();
167 } 167 }
168 }; 168 };
169 AwTestContainerView view = createAwTestContainerViewOnMainSync(client); 169 AwTestContainerView view = createAwTestContainerViewOnMainSync(client);
170 ContentViewCore contentViewCore = view.getContentViewCore(); 170 final AwContents awContents = view.getAwContents();
171 enableJavaScriptOnUiThread(contentViewCore); 171 enableJavaScriptOnUiThread(awContents);
172 172
173 loadDataSync(contentViewCore, client.getOnPageFinishedHelper(), BEFORE_U NLOAD_URL, 173 loadDataSync(awContents, client.getOnPageFinishedHelper(), BEFORE_UNLOAD _URL,
174 "text/html", false); 174 "text/html", false);
175 enableJavaScriptOnUiThread(contentViewCore); 175 enableJavaScriptOnUiThread(awContents);
176 176
177 // Don't wait synchronously because we don't leave the page. 177 // Don't wait synchronously because we don't leave the page.
178 int currentCallCount = jsBeforeUnloadHelper.getCallCount(); 178 int currentCallCount = jsBeforeUnloadHelper.getCallCount();
179 loadDataAsync(contentViewCore, EMPTY_PAGE, "text/html", false); 179 loadDataAsync(awContents, EMPTY_PAGE, "text/html", false);
180 jsBeforeUnloadHelper.waitForCallback(currentCallCount); 180 jsBeforeUnloadHelper.waitForCallback(currentCallCount);
181 } 181 }
182 } 182 }
OLDNEW
« no previous file with comments | « android_webview/javatests/src/org/chromium/android_webview/test/WebViewFindApisTestBase.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698