OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 static org.chromium.android_webview.test.AwTestCommon.WAIT_TIMEOUT_MS; | |
8 | |
7 import android.content.Context; | 9 import android.content.Context; |
8 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
9 import android.graphics.BitmapFactory; | 11 import android.graphics.BitmapFactory; |
10 import android.graphics.Canvas; | 12 import android.graphics.Canvas; |
11 import android.os.Handler; | 13 import android.os.Handler; |
12 import android.os.Looper; | 14 import android.os.Looper; |
13 import android.os.Message; | 15 import android.os.Message; |
16 import android.support.test.InstrumentationRegistry; | |
14 import android.support.test.filters.LargeTest; | 17 import android.support.test.filters.LargeTest; |
15 import android.support.test.filters.SmallTest; | 18 import android.support.test.filters.SmallTest; |
16 import android.test.UiThreadTest; | |
17 import android.util.Pair; | 19 import android.util.Pair; |
18 import android.view.KeyEvent; | 20 import android.view.KeyEvent; |
19 import android.view.View; | 21 import android.view.View; |
20 import android.webkit.JavascriptInterface; | 22 import android.webkit.JavascriptInterface; |
21 | 23 |
24 import org.junit.Assert; | |
25 import org.junit.Rule; | |
26 import org.junit.Test; | |
27 import org.junit.runner.RunWith; | |
28 | |
22 import org.chromium.android_webview.AwContents; | 29 import org.chromium.android_webview.AwContents; |
23 import org.chromium.android_webview.AwSettings; | 30 import org.chromium.android_webview.AwSettings; |
24 import org.chromium.android_webview.AwSwitches; | 31 import org.chromium.android_webview.AwSwitches; |
25 import org.chromium.android_webview.renderer_priority.RendererPriority; | 32 import org.chromium.android_webview.renderer_priority.RendererPriority; |
26 import org.chromium.android_webview.test.TestAwContentsClient.OnDownloadStartHel per; | 33 import org.chromium.android_webview.test.TestAwContentsClient.OnDownloadStartHel per; |
27 import org.chromium.android_webview.test.util.CommonResources; | 34 import org.chromium.android_webview.test.util.CommonResources; |
28 import org.chromium.android_webview.test.util.JSUtils; | 35 import org.chromium.android_webview.test.util.JSUtils; |
29 import org.chromium.base.annotations.SuppressFBWarnings; | 36 import org.chromium.base.annotations.SuppressFBWarnings; |
30 import org.chromium.base.process_launcher.ChildProcessConnection; | 37 import org.chromium.base.process_launcher.ChildProcessConnection; |
31 import org.chromium.base.test.util.CallbackHelper; | 38 import org.chromium.base.test.util.CallbackHelper; |
32 import org.chromium.base.test.util.CommandLineFlags; | 39 import org.chromium.base.test.util.CommandLineFlags; |
33 import org.chromium.base.test.util.Feature; | 40 import org.chromium.base.test.util.Feature; |
34 import org.chromium.base.test.util.parameter.SkipCommandLineParameterization; | 41 import org.chromium.base.test.util.parameter.SkipCommandLineParameterization; |
boliu
2017/07/20 21:22:47
does all of these imports needs to be fixed now? o
the real yoland
2017/07/27 00:29:47
I was able to verify locally that the number of Aw
| |
35 import org.chromium.content.browser.BindingManager; | 42 import org.chromium.content.browser.BindingManager; |
36 import org.chromium.content.browser.ChildProcessLauncherHelper; | 43 import org.chromium.content.browser.ChildProcessLauncherHelper; |
37 import org.chromium.content_public.common.ContentUrlConstants; | 44 import org.chromium.content_public.common.ContentUrlConstants; |
38 import org.chromium.net.test.EmbeddedTestServer; | 45 import org.chromium.net.test.EmbeddedTestServer; |
39 import org.chromium.net.test.util.TestWebServer; | 46 import org.chromium.net.test.util.TestWebServer; |
40 | 47 |
41 import java.io.InputStream; | 48 import java.io.InputStream; |
42 import java.net.URL; | 49 import java.net.URL; |
43 import java.util.ArrayList; | 50 import java.util.ArrayList; |
44 import java.util.HashMap; | 51 import java.util.HashMap; |
45 import java.util.List; | 52 import java.util.List; |
46 import java.util.Map; | 53 import java.util.Map; |
47 import java.util.concurrent.Callable; | 54 import java.util.concurrent.Callable; |
48 import java.util.concurrent.Semaphore; | 55 import java.util.concurrent.Semaphore; |
49 import java.util.concurrent.TimeUnit; | 56 import java.util.concurrent.TimeUnit; |
50 import java.util.concurrent.atomic.AtomicInteger; | 57 import java.util.concurrent.atomic.AtomicInteger; |
51 | 58 |
52 /** | 59 /** |
53 * AwContents tests. | 60 * AwContents tests. |
54 */ | 61 */ |
55 public class AwContentsTest extends AwTestBase { | 62 @RunWith(AwJUnit4ClassRunner.class) |
63 public class AwContentsTest { | |
64 @Rule | |
65 public AwActivityTestRule mActivityTestRule = new AwActivityTestRule(); | |
56 | 66 |
57 private TestAwContentsClient mContentsClient = new TestAwContentsClient(); | 67 private TestAwContentsClient mContentsClient = new TestAwContentsClient(); |
58 | 68 |
69 @Test | |
59 @SmallTest | 70 @SmallTest |
60 @Feature({"AndroidWebView"}) | 71 @Feature({"AndroidWebView"}) |
61 @UiThreadTest | |
62 public void testCreateDestroy() throws Throwable { | 72 public void testCreateDestroy() throws Throwable { |
63 // NOTE this test runs on UI thread, so we cannot call any async methods . | 73 // NOTE this test runs on UI thread, so we cannot call any async methods . |
64 createAwTestContainerView(mContentsClient).getAwContents().destroy(); | 74 mActivityTestRule.runOnUiThread(new Runnable() { |
75 @Override | |
76 public void run() { | |
77 mActivityTestRule.createAwTestContainerView(mContentsClient) | |
78 .getAwContents() | |
79 .destroy(); | |
80 } | |
81 }); | |
65 } | 82 } |
66 | 83 |
84 @Test | |
67 @SmallTest | 85 @SmallTest |
68 @Feature({"AndroidWebView"}) | 86 @Feature({"AndroidWebView"}) |
69 public void testCreateLoadPageDestroy() throws Throwable { | 87 public void testCreateLoadPageDestroy() throws Throwable { |
70 AwTestContainerView awTestContainerView = | 88 AwTestContainerView awTestContainerView = |
71 createAwTestContainerViewOnMainSync(mContentsClient); | 89 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); |
72 loadDataSync(awTestContainerView.getAwContents(), mContentsClient.getOnP ageFinishedHelper(), | 90 mActivityTestRule.loadDataSync(awTestContainerView.getAwContents(), |
73 CommonResources.ABOUT_HTML, "text/html", false); | 91 mContentsClient.getOnPageFinishedHelper(), CommonResources.ABOUT _HTML, "text/html", |
92 false); | |
74 | 93 |
75 destroyAwContentsOnMainSync(awTestContainerView.getAwContents()); | 94 mActivityTestRule.destroyAwContentsOnMainSync(awTestContainerView.getAwC ontents()); |
76 // It should be safe to call destroy multiple times. | 95 // It should be safe to call destroy multiple times. |
77 destroyAwContentsOnMainSync(awTestContainerView.getAwContents()); | 96 mActivityTestRule.destroyAwContentsOnMainSync(awTestContainerView.getAwC ontents()); |
78 } | 97 } |
79 | 98 |
99 @Test | |
80 @LargeTest | 100 @LargeTest |
81 @Feature({"AndroidWebView"}) | 101 @Feature({"AndroidWebView"}) |
82 public void testCreateLoadDestroyManyTimes() throws Throwable { | 102 public void testCreateLoadDestroyManyTimes() throws Throwable { |
83 for (int i = 0; i < 10; ++i) { | 103 for (int i = 0; i < 10; ++i) { |
84 AwTestContainerView testView = createAwTestContainerViewOnMainSync(m ContentsClient); | 104 AwTestContainerView testView = |
105 mActivityTestRule.createAwTestContainerViewOnMainSync(mConte ntsClient); | |
85 AwContents awContents = testView.getAwContents(); | 106 AwContents awContents = testView.getAwContents(); |
86 | 107 |
87 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), | 108 mActivityTestRule.loadUrlSync(awContents, mContentsClient.getOnPageF inishedHelper(), |
88 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); | 109 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); |
89 destroyAwContentsOnMainSync(awContents); | 110 mActivityTestRule.destroyAwContentsOnMainSync(awContents); |
90 } | 111 } |
91 } | 112 } |
92 | 113 |
114 @Test | |
93 @LargeTest | 115 @LargeTest |
94 @Feature({"AndroidWebView"}) | 116 @Feature({"AndroidWebView"}) |
95 public void testCreateLoadDestroyManyAtOnce() throws Throwable { | 117 public void testCreateLoadDestroyManyAtOnce() throws Throwable { |
96 AwTestContainerView views[] = new AwTestContainerView[10]; | 118 AwTestContainerView views[] = new AwTestContainerView[10]; |
97 | 119 |
98 for (int i = 0; i < views.length; ++i) { | 120 for (int i = 0; i < views.length; ++i) { |
99 views[i] = createAwTestContainerViewOnMainSync(mContentsClient); | 121 views[i] = mActivityTestRule.createAwTestContainerViewOnMainSync(mCo ntentsClient); |
100 loadUrlSync(views[i].getAwContents(), mContentsClient.getOnPageFinis hedHelper(), | 122 mActivityTestRule.loadUrlSync(views[i].getAwContents(), |
123 mContentsClient.getOnPageFinishedHelper(), | |
101 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); | 124 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); |
102 } | 125 } |
103 | 126 |
104 for (int i = 0; i < views.length; ++i) { | 127 for (int i = 0; i < views.length; ++i) { |
105 destroyAwContentsOnMainSync(views[i].getAwContents()); | 128 mActivityTestRule.destroyAwContentsOnMainSync(views[i].getAwContents ()); |
106 views[i] = null; | 129 views[i] = null; |
107 } | 130 } |
108 } | 131 } |
109 | 132 |
133 @Test | |
110 @SmallTest | 134 @SmallTest |
111 @Feature({"AndroidWebView"}) | 135 @Feature({"AndroidWebView"}) |
112 @UiThreadTest | |
113 public void testWebViewApisFailGracefullyAfterDestruction() throws Throwable { | 136 public void testWebViewApisFailGracefullyAfterDestruction() throws Throwable { |
114 AwContents awContents = | 137 mActivityTestRule.runOnUiThread(new Runnable() { |
115 createAwTestContainerView(mContentsClient).getAwContents(); | 138 @Override |
116 awContents.destroy(); | 139 public void run() { |
140 AwContents awContents = mActivityTestRule.createAwTestContainerV iew(mContentsClient) | |
141 .getAwContents(); | |
142 awContents.destroy(); | |
117 | 143 |
118 // The documentation for WebView#destroy() reads "This method should be called | 144 // The documentation for WebView#destroy() reads "This method sh ould be called |
119 // after this WebView has been removed from the view system. No other me thods | 145 // after this WebView has been removed from the view system. No other methods |
120 // may be called on this WebView after destroy". | 146 // may be called on this WebView after destroy". |
121 // However, some apps do not respect that restriction so we need to ensu re that | 147 // However, some apps do not respect that restriction so we need to ensure that |
122 // we fail gracefully and do not crash when APIs are invoked after destr uction. | 148 // we fail gracefully and do not crash when APIs are invoked aft er destruction. |
123 // Due to the large number of APIs we only test a representative selecti on here. | 149 // Due to the large number of APIs we only test a representative selection here. |
124 awContents.clearHistory(); | 150 awContents.clearHistory(); |
125 awContents.loadUrl("http://www.google.com"); | 151 awContents.loadUrl("http://www.google.com"); |
126 awContents.findAllAsync("search"); | 152 awContents.findAllAsync("search"); |
127 assertNull(awContents.getUrl()); | 153 Assert.assertNull(awContents.getUrl()); |
128 assertFalse(awContents.canGoBack()); | 154 Assert.assertFalse(awContents.canGoBack()); |
129 awContents.disableJavascriptInterfacesInspection(); | 155 awContents.disableJavascriptInterfacesInspection(); |
130 awContents.invokeZoomPicker(); | 156 awContents.invokeZoomPicker(); |
131 awContents.onResume(); | 157 awContents.onResume(); |
132 awContents.stopLoading(); | 158 awContents.stopLoading(); |
133 awContents.onWindowVisibilityChanged(View.VISIBLE); | 159 awContents.onWindowVisibilityChanged(View.VISIBLE); |
134 awContents.requestFocus(); | 160 awContents.requestFocus(); |
135 awContents.isMultiTouchZoomSupported(); | 161 awContents.isMultiTouchZoomSupported(); |
136 awContents.setOverScrollMode(View.OVER_SCROLL_NEVER); | 162 awContents.setOverScrollMode(View.OVER_SCROLL_NEVER); |
137 awContents.pauseTimers(); | 163 awContents.pauseTimers(); |
138 awContents.onContainerViewScrollChanged(200, 200, 100, 100); | 164 awContents.onContainerViewScrollChanged(200, 200, 100, 100); |
139 awContents.computeScroll(); | 165 awContents.computeScroll(); |
140 awContents.onMeasure(100, 100); | 166 awContents.onMeasure(100, 100); |
141 awContents.onDraw(new Canvas()); | 167 awContents.onDraw(new Canvas()); |
142 awContents.getMostRecentProgress(); | 168 awContents.getMostRecentProgress(); |
143 assertEquals(0, awContents.computeHorizontalScrollOffset()); | 169 Assert.assertEquals(0, awContents.computeHorizontalScrollOffset( )); |
144 assertEquals(0, awContents.getContentWidthCss()); | 170 Assert.assertEquals(0, awContents.getContentWidthCss()); |
145 awContents.onKeyUp(KeyEvent.KEYCODE_BACK, | 171 awContents.onKeyUp(KeyEvent.KEYCODE_BACK, |
146 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MENU)); | 172 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MENU )); |
173 } | |
174 }); | |
147 } | 175 } |
148 | 176 |
177 @Test | |
149 @SmallTest | 178 @SmallTest |
150 @Feature({"AndroidWebView"}) | 179 @Feature({"AndroidWebView"}) |
151 public void testUseAwSettingsAfterDestroy() throws Throwable { | 180 public void testUseAwSettingsAfterDestroy() throws Throwable { |
152 AwTestContainerView awTestContainerView = | 181 AwTestContainerView awTestContainerView = |
153 createAwTestContainerViewOnMainSync(mContentsClient); | 182 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); |
154 AwSettings awSettings = getAwSettingsOnUiThread(awTestContainerView.getA wContents()); | 183 AwSettings awSettings = |
155 loadDataSync(awTestContainerView.getAwContents(), mContentsClient.getOnP ageFinishedHelper(), | 184 mActivityTestRule.getAwSettingsOnUiThread(awTestContainerView.ge tAwContents()); |
156 CommonResources.ABOUT_HTML, "text/html", false); | 185 mActivityTestRule.loadDataSync(awTestContainerView.getAwContents(), |
157 destroyAwContentsOnMainSync(awTestContainerView.getAwContents()); | 186 mContentsClient.getOnPageFinishedHelper(), CommonResources.ABOUT _HTML, "text/html", |
187 false); | |
188 mActivityTestRule.destroyAwContentsOnMainSync(awTestContainerView.getAwC ontents()); | |
158 | 189 |
159 // AwSettings should still be usable even after native side is destroyed . | 190 // AwSettings should still be usable even after native side is destroyed . |
160 String newFontFamily = "serif"; | 191 String newFontFamily = "serif"; |
161 awSettings.setStandardFontFamily(newFontFamily); | 192 awSettings.setStandardFontFamily(newFontFamily); |
162 assertEquals(newFontFamily, awSettings.getStandardFontFamily()); | 193 Assert.assertEquals(newFontFamily, awSettings.getStandardFontFamily()); |
163 boolean newBlockNetworkLoads = !awSettings.getBlockNetworkLoads(); | 194 boolean newBlockNetworkLoads = !awSettings.getBlockNetworkLoads(); |
164 awSettings.setBlockNetworkLoads(newBlockNetworkLoads); | 195 awSettings.setBlockNetworkLoads(newBlockNetworkLoads); |
165 assertEquals(newBlockNetworkLoads, awSettings.getBlockNetworkLoads()); | 196 Assert.assertEquals(newBlockNetworkLoads, awSettings.getBlockNetworkLoad s()); |
166 } | 197 } |
167 | 198 |
168 private int callDocumentHasImagesSync(final AwContents awContents) | 199 private int callDocumentHasImagesSync(final AwContents awContents) |
169 throws Throwable, InterruptedException { | 200 throws Throwable, InterruptedException { |
170 // Set up a container to hold the result object and a semaphore to | 201 // Set up a container to hold the result object and a semaphore to |
171 // make the test wait for the result. | 202 // make the test wait for the result. |
172 final AtomicInteger val = new AtomicInteger(); | 203 final AtomicInteger val = new AtomicInteger(); |
173 final Semaphore s = new Semaphore(0); | 204 final Semaphore s = new Semaphore(0); |
174 final Message msg = Message.obtain(new Handler(Looper.getMainLooper()) { | 205 final Message msg = Message.obtain(new Handler(Looper.getMainLooper()) { |
175 @Override | 206 @Override |
176 public void handleMessage(Message msg) { | 207 public void handleMessage(Message msg) { |
177 val.set(msg.arg1); | 208 val.set(msg.arg1); |
178 s.release(); | 209 s.release(); |
179 } | 210 } |
180 }); | 211 }); |
181 runTestOnUiThread(new Runnable() { | 212 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable( ) { |
182 @Override | 213 @Override |
183 public void run() { | 214 public void run() { |
184 awContents.documentHasImages(msg); | 215 awContents.documentHasImages(msg); |
185 } | 216 } |
186 }); | 217 }); |
187 assertTrue(s.tryAcquire(WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS)); | 218 Assert.assertTrue(s.tryAcquire(AwActivityTestRule.WAIT_TIMEOUT_MS, TimeU nit.MILLISECONDS)); |
188 int result = val.get(); | 219 int result = val.get(); |
189 return result; | 220 return result; |
190 } | 221 } |
191 | 222 |
223 @Test | |
192 @SmallTest | 224 @SmallTest |
193 @Feature({"AndroidWebView"}) | 225 @Feature({"AndroidWebView"}) |
194 public void testDocumentHasImages() throws Throwable { | 226 public void testDocumentHasImages() throws Throwable { |
195 AwTestContainerView testView = createAwTestContainerViewOnMainSync(mCont entsClient); | 227 AwTestContainerView testView = |
228 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); | |
196 AwContents awContents = testView.getAwContents(); | 229 AwContents awContents = testView.getAwContents(); |
197 | 230 |
198 final CallbackHelper loadHelper = mContentsClient.getOnPageFinishedHelpe r(); | 231 final CallbackHelper loadHelper = mContentsClient.getOnPageFinishedHelpe r(); |
199 | 232 |
200 final String mime = "text/html"; | 233 final String mime = "text/html"; |
201 final String emptyDoc = "<head/><body/>"; | 234 final String emptyDoc = "<head/><body/>"; |
202 final String imageDoc = "<head/><body><img/><img/></body>"; | 235 final String imageDoc = "<head/><body><img/><img/></body>"; |
203 | 236 |
204 // Make sure a document that does not have images returns 0 | 237 // Make sure a document that does not have images returns 0 |
205 loadDataSync(awContents, loadHelper, emptyDoc, mime, false); | 238 mActivityTestRule.loadDataSync(awContents, loadHelper, emptyDoc, mime, f alse); |
206 int result = callDocumentHasImagesSync(awContents); | 239 int result = callDocumentHasImagesSync(awContents); |
207 assertEquals(0, result); | 240 Assert.assertEquals(0, result); |
208 | 241 |
209 // Make sure a document that does have images returns 1 | 242 // Make sure a document that does have images returns 1 |
210 loadDataSync(awContents, loadHelper, imageDoc, mime, false); | 243 mActivityTestRule.loadDataSync(awContents, loadHelper, imageDoc, mime, f alse); |
211 result = callDocumentHasImagesSync(awContents); | 244 result = callDocumentHasImagesSync(awContents); |
212 assertEquals(1, result); | 245 Assert.assertEquals(1, result); |
213 } | 246 } |
214 | 247 |
248 @Test | |
215 @SmallTest | 249 @SmallTest |
216 @Feature({"AndroidWebView"}) | 250 @Feature({"AndroidWebView"}) |
217 public void testClearCacheMemoryAndDisk() throws Throwable { | 251 public void testClearCacheMemoryAndDisk() throws Throwable { |
218 final AwTestContainerView testContainer = | 252 final AwTestContainerView testContainer = |
219 createAwTestContainerViewOnMainSync(mContentsClient); | 253 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); |
220 final AwContents awContents = testContainer.getAwContents(); | 254 final AwContents awContents = testContainer.getAwContents(); |
221 | 255 |
222 TestWebServer webServer = TestWebServer.start(); | 256 TestWebServer webServer = TestWebServer.start(); |
223 try { | 257 try { |
224 final String pagePath = "/clear_cache_test.html"; | 258 final String pagePath = "/clear_cache_test.html"; |
225 List<Pair<String, String>> headers = new ArrayList<Pair<String, Stri ng>>(); | 259 List<Pair<String, String>> headers = new ArrayList<Pair<String, Stri ng>>(); |
226 // Set Cache-Control headers to cache this request. One century shou ld be long enough. | 260 // Set Cache-Control headers to cache this request. One century shou ld be long enough. |
227 headers.add(Pair.create("Cache-Control", "max-age=3153600000")); | 261 headers.add(Pair.create("Cache-Control", "max-age=3153600000")); |
228 headers.add(Pair.create("Last-Modified", "Wed, 3 Oct 2012 00:00:00 G MT")); | 262 headers.add(Pair.create("Last-Modified", "Wed, 3 Oct 2012 00:00:00 G MT")); |
229 final String pageUrl = webServer.setResponse( | 263 final String pageUrl = webServer.setResponse( |
230 pagePath, "<html><body>foo</body></html>", headers); | 264 pagePath, "<html><body>foo</body></html>", headers); |
231 | 265 |
232 // First load to populate cache. | 266 // First load to populate cache. |
233 clearCacheOnUiThread(awContents, true); | 267 mActivityTestRule.clearCacheOnUiThread(awContents, true); |
234 loadUrlSync(awContents, | 268 mActivityTestRule.loadUrlSync( |
235 mContentsClient.getOnPageFinishedHelper(), | 269 awContents, mContentsClient.getOnPageFinishedHelper(), pageU rl); |
236 pageUrl); | 270 Assert.assertEquals(1, webServer.getRequestCount(pagePath)); |
237 assertEquals(1, webServer.getRequestCount(pagePath)); | |
238 | 271 |
239 // Load about:blank so next load is not treated as reload by webkit and force | 272 // Load about:blank so next load is not treated as reload by webkit and force |
240 // revalidate with the server. | 273 // revalidate with the server. |
241 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), | 274 mActivityTestRule.loadUrlSync(awContents, mContentsClient.getOnPageF inishedHelper(), |
242 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); | 275 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); |
243 | 276 |
244 // No clearCache call, so should be loaded from cache. | 277 // No clearCache call, so should be loaded from cache. |
245 loadUrlSync(awContents, | 278 mActivityTestRule.loadUrlSync( |
246 mContentsClient.getOnPageFinishedHelper(), | 279 awContents, mContentsClient.getOnPageFinishedHelper(), pageU rl); |
247 pageUrl); | 280 Assert.assertEquals(1, webServer.getRequestCount(pagePath)); |
248 assertEquals(1, webServer.getRequestCount(pagePath)); | |
249 | 281 |
250 // Same as above. | 282 // Same as above. |
251 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), | 283 mActivityTestRule.loadUrlSync(awContents, mContentsClient.getOnPageF inishedHelper(), |
252 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); | 284 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); |
253 | 285 |
254 // Clear cache, so should hit server again. | 286 // Clear cache, so should hit server again. |
255 clearCacheOnUiThread(awContents, true); | 287 mActivityTestRule.clearCacheOnUiThread(awContents, true); |
256 loadUrlSync(awContents, | 288 mActivityTestRule.loadUrlSync( |
257 mContentsClient.getOnPageFinishedHelper(), | 289 awContents, mContentsClient.getOnPageFinishedHelper(), pageU rl); |
258 pageUrl); | 290 Assert.assertEquals(2, webServer.getRequestCount(pagePath)); |
259 assertEquals(2, webServer.getRequestCount(pagePath)); | |
260 } finally { | 291 } finally { |
261 webServer.shutdown(); | 292 webServer.shutdown(); |
262 } | 293 } |
263 } | 294 } |
264 | 295 |
296 @Test | |
265 @SmallTest | 297 @SmallTest |
266 @Feature({"AndroidWebView"}) | 298 @Feature({"AndroidWebView"}) |
267 public void testClearCacheInQuickSuccession() throws Throwable { | 299 public void testClearCacheInQuickSuccession() throws Throwable { |
268 final AwTestContainerView testContainer = | 300 final AwTestContainerView testContainer = |
269 createAwTestContainerViewOnMainSync(new TestAwContentsClient()); | 301 mActivityTestRule.createAwTestContainerViewOnMainSync(new TestAw ContentsClient()); |
270 final AwContents awContents = testContainer.getAwContents(); | 302 final AwContents awContents = testContainer.getAwContents(); |
271 | 303 |
272 runTestOnUiThread(new Runnable() { | 304 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable( ) { |
273 @Override | 305 @Override |
274 public void run() { | 306 public void run() { |
275 for (int i = 0; i < 10; ++i) { | 307 for (int i = 0; i < 10; ++i) { |
276 awContents.clearCache(true); | 308 awContents.clearCache(true); |
277 } | 309 } |
278 } | 310 } |
279 }); | 311 }); |
280 } | 312 } |
281 | 313 |
314 @Test | |
282 @SmallTest | 315 @SmallTest |
283 @Feature({"AndroidWebView"}) | 316 @Feature({"AndroidWebView"}) |
284 public void testGetFavicon() throws Throwable { | 317 public void testGetFavicon() throws Throwable { |
285 AwContents.setShouldDownloadFavicons(); | 318 AwContents.setShouldDownloadFavicons(); |
286 final AwTestContainerView testView = createAwTestContainerViewOnMainSync (mContentsClient); | 319 final AwTestContainerView testView = |
320 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); | |
287 final AwContents awContents = testView.getAwContents(); | 321 final AwContents awContents = testView.getAwContents(); |
288 | 322 |
289 TestWebServer webServer = TestWebServer.start(); | 323 TestWebServer webServer = TestWebServer.start(); |
290 try { | 324 try { |
291 final String faviconUrl = webServer.setResponseBase64( | 325 final String faviconUrl = webServer.setResponseBase64( |
292 "/" + CommonResources.FAVICON_FILENAME, CommonResources.FAVI CON_DATA_BASE64, | 326 "/" + CommonResources.FAVICON_FILENAME, CommonResources.FAVI CON_DATA_BASE64, |
293 CommonResources.getImagePngHeaders(false)); | 327 CommonResources.getImagePngHeaders(false)); |
294 final String pageUrl = webServer.setResponse("/favicon.html", | 328 final String pageUrl = webServer.setResponse("/favicon.html", |
295 CommonResources.FAVICON_STATIC_HTML, null); | 329 CommonResources.FAVICON_STATIC_HTML, null); |
296 | 330 |
297 // The getFavicon will return the right icon a certain time after | 331 // The getFavicon will return the right icon a certain time after |
298 // the page load completes which makes it slightly hard to test. | 332 // the page load completes which makes it slightly hard to test. |
299 final Bitmap defaultFavicon = awContents.getFavicon(); | 333 final Bitmap defaultFavicon = awContents.getFavicon(); |
300 | 334 |
301 getAwSettingsOnUiThread(awContents).setImagesEnabled(true); | 335 mActivityTestRule.getAwSettingsOnUiThread(awContents).setImagesEnabl ed(true); |
302 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), p ageUrl); | 336 mActivityTestRule.loadUrlSync( |
337 awContents, mContentsClient.getOnPageFinishedHelper(), pageU rl); | |
303 | 338 |
304 pollUiThread(new Callable<Boolean>() { | 339 mActivityTestRule.pollUiThread(new Callable<Boolean>() { |
305 @Override | 340 @Override |
306 public Boolean call() { | 341 public Boolean call() { |
307 return awContents.getFavicon() != null | 342 return awContents.getFavicon() != null |
308 && !awContents.getFavicon().sameAs(defaultFavicon); | 343 && !awContents.getFavicon().sameAs(defaultFavicon); |
309 } | 344 } |
310 }); | 345 }); |
311 | 346 |
312 final Object originalFaviconSource = (new URL(faviconUrl)).getConten t(); | 347 final Object originalFaviconSource = (new URL(faviconUrl)).getConten t(); |
313 final Bitmap originalFavicon = | 348 final Bitmap originalFavicon = |
314 BitmapFactory.decodeStream((InputStream) originalFaviconSour ce); | 349 BitmapFactory.decodeStream((InputStream) originalFaviconSour ce); |
315 assertNotNull(originalFavicon); | 350 Assert.assertNotNull(originalFavicon); |
316 | 351 |
317 assertTrue(awContents.getFavicon().sameAs(originalFavicon)); | 352 Assert.assertTrue(awContents.getFavicon().sameAs(originalFavicon)); |
318 | 353 |
319 } finally { | 354 } finally { |
320 webServer.shutdown(); | 355 webServer.shutdown(); |
321 } | 356 } |
322 } | 357 } |
323 | 358 |
359 @Test | |
324 @Feature({"AndroidWebView", "Downloads"}) | 360 @Feature({"AndroidWebView", "Downloads"}) |
325 @SmallTest | 361 @SmallTest |
326 public void testDownload() throws Throwable { | 362 public void testDownload() throws Throwable { |
327 AwTestContainerView testView = createAwTestContainerViewOnMainSync(mCont entsClient); | 363 AwTestContainerView testView = |
364 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); | |
328 AwContents awContents = testView.getAwContents(); | 365 AwContents awContents = testView.getAwContents(); |
329 | 366 |
330 final String data = "download data"; | 367 final String data = "download data"; |
331 final String contentDisposition = "attachment;filename=\"download.txt\"" ; | 368 final String contentDisposition = "attachment;filename=\"download.txt\"" ; |
332 final String mimeType = "text/plain"; | 369 final String mimeType = "text/plain"; |
333 | 370 |
334 List<Pair<String, String>> downloadHeaders = new ArrayList<Pair<String, String>>(); | 371 List<Pair<String, String>> downloadHeaders = new ArrayList<Pair<String, String>>(); |
335 downloadHeaders.add(Pair.create("Content-Disposition", contentDispositio n)); | 372 downloadHeaders.add(Pair.create("Content-Disposition", contentDispositio n)); |
336 downloadHeaders.add(Pair.create("Content-Type", mimeType)); | 373 downloadHeaders.add(Pair.create("Content-Type", mimeType)); |
337 downloadHeaders.add(Pair.create("Content-Length", Integer.toString(data. length()))); | 374 downloadHeaders.add(Pair.create("Content-Length", Integer.toString(data. length()))); |
338 | 375 |
339 TestWebServer webServer = TestWebServer.start(); | 376 TestWebServer webServer = TestWebServer.start(); |
340 try { | 377 try { |
341 final String pageUrl = webServer.setResponse( | 378 final String pageUrl = webServer.setResponse( |
342 "/download.txt", data, downloadHeaders); | 379 "/download.txt", data, downloadHeaders); |
343 final OnDownloadStartHelper downloadStartHelper = | 380 final OnDownloadStartHelper downloadStartHelper = |
344 mContentsClient.getOnDownloadStartHelper(); | 381 mContentsClient.getOnDownloadStartHelper(); |
345 final int callCount = downloadStartHelper.getCallCount(); | 382 final int callCount = downloadStartHelper.getCallCount(); |
346 loadUrlAsync(awContents, pageUrl); | 383 mActivityTestRule.loadUrlAsync(awContents, pageUrl); |
347 downloadStartHelper.waitForCallback(callCount); | 384 downloadStartHelper.waitForCallback(callCount); |
348 | 385 |
349 assertEquals(pageUrl, downloadStartHelper.getUrl()); | 386 Assert.assertEquals(pageUrl, downloadStartHelper.getUrl()); |
350 assertEquals(contentDisposition, downloadStartHelper.getContentDispo sition()); | 387 Assert.assertEquals(contentDisposition, downloadStartHelper.getConte ntDisposition()); |
351 assertEquals(mimeType, downloadStartHelper.getMimeType()); | 388 Assert.assertEquals(mimeType, downloadStartHelper.getMimeType()); |
352 assertEquals(data.length(), downloadStartHelper.getContentLength()); | 389 Assert.assertEquals(data.length(), downloadStartHelper.getContentLen gth()); |
353 } finally { | 390 } finally { |
354 webServer.shutdown(); | 391 webServer.shutdown(); |
355 } | 392 } |
356 } | 393 } |
357 | 394 |
395 @Test | |
358 @Feature({"AndroidWebView", "setNetworkAvailable"}) | 396 @Feature({"AndroidWebView", "setNetworkAvailable"}) |
359 @SmallTest | 397 @SmallTest |
360 public void testSetNetworkAvailable() throws Throwable { | 398 public void testSetNetworkAvailable() throws Throwable { |
361 AwTestContainerView testView = createAwTestContainerViewOnMainSync(mCont entsClient); | 399 AwTestContainerView testView = |
400 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); | |
362 AwContents awContents = testView.getAwContents(); | 401 AwContents awContents = testView.getAwContents(); |
363 String script = "navigator.onLine"; | 402 String script = "navigator.onLine"; |
364 | 403 |
365 enableJavaScriptOnUiThread(awContents); | 404 mActivityTestRule.enableJavaScriptOnUiThread(awContents); |
366 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), | 405 mActivityTestRule.loadUrlSync(awContents, mContentsClient.getOnPageFinis hedHelper(), |
367 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); | 406 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); |
368 | 407 |
369 // Default to "online". | 408 // Default to "online". |
370 assertEquals("true", executeJavaScriptAndWaitForResult(awContents, mCont entsClient, | 409 Assert.assertEquals("true", |
371 script)); | 410 mActivityTestRule.executeJavaScriptAndWaitForResult( |
411 awContents, mContentsClient, script)); | |
372 | 412 |
373 // Forcing "offline". | 413 // Forcing "offline". |
374 setNetworkAvailableOnUiThread(awContents, false); | 414 mActivityTestRule.setNetworkAvailableOnUiThread(awContents, false); |
375 assertEquals("false", executeJavaScriptAndWaitForResult(awContents, mCon tentsClient, | 415 Assert.assertEquals("false", |
376 script)); | 416 mActivityTestRule.executeJavaScriptAndWaitForResult( |
417 awContents, mContentsClient, script)); | |
377 | 418 |
378 // Forcing "online". | 419 // Forcing "online". |
379 setNetworkAvailableOnUiThread(awContents, true); | 420 mActivityTestRule.setNetworkAvailableOnUiThread(awContents, true); |
380 assertEquals("true", executeJavaScriptAndWaitForResult(awContents, mCont entsClient, | 421 Assert.assertEquals("true", |
381 script)); | 422 mActivityTestRule.executeJavaScriptAndWaitForResult( |
423 awContents, mContentsClient, script)); | |
382 } | 424 } |
383 | 425 |
384 | 426 |
385 static class JavaScriptObject { | 427 static class JavaScriptObject { |
386 private CallbackHelper mCallbackHelper; | 428 private CallbackHelper mCallbackHelper; |
387 public JavaScriptObject(CallbackHelper callbackHelper) { | 429 public JavaScriptObject(CallbackHelper callbackHelper) { |
388 mCallbackHelper = callbackHelper; | 430 mCallbackHelper = callbackHelper; |
389 } | 431 } |
390 | 432 |
391 @JavascriptInterface | 433 @JavascriptInterface |
392 public void run() { | 434 public void run() { |
393 mCallbackHelper.notifyCalled(); | 435 mCallbackHelper.notifyCalled(); |
394 } | 436 } |
395 } | 437 } |
396 | 438 |
439 @Test | |
397 @Feature({"AndroidWebView", "Android-JavaBridge"}) | 440 @Feature({"AndroidWebView", "Android-JavaBridge"}) |
398 @SmallTest | 441 @SmallTest |
399 public void testJavaBridge() throws Throwable { | 442 public void testJavaBridge() throws Throwable { |
400 final AwTestContainerView testView = createAwTestContainerViewOnMainSync (mContentsClient); | 443 final AwTestContainerView testView = |
444 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); | |
401 final CallbackHelper callback = new CallbackHelper(); | 445 final CallbackHelper callback = new CallbackHelper(); |
402 | 446 |
403 runTestOnUiThread(new Runnable() { | 447 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable( ) { |
404 @Override | 448 @Override |
405 public void run() { | 449 public void run() { |
406 AwContents awContents = testView.getAwContents(); | 450 AwContents awContents = testView.getAwContents(); |
407 AwSettings awSettings = awContents.getSettings(); | 451 AwSettings awSettings = awContents.getSettings(); |
408 awSettings.setJavaScriptEnabled(true); | 452 awSettings.setJavaScriptEnabled(true); |
409 awContents.addJavascriptInterface(new JavaScriptObject(callback) , "bridge"); | 453 awContents.addJavascriptInterface(new JavaScriptObject(callback) , "bridge"); |
410 awContents.evaluateJavaScriptForTests("window.bridge.run();", nu ll); | 454 awContents.evaluateJavaScriptForTests("window.bridge.run();", nu ll); |
411 } | 455 } |
412 }); | 456 }); |
413 callback.waitForCallback(0, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS); | 457 callback.waitForCallback(0, 1, AwActivityTestRule.WAIT_TIMEOUT_MS, TimeU nit.MILLISECONDS); |
414 } | 458 } |
415 | 459 |
460 @Test | |
416 @Feature({"AndroidWebView"}) | 461 @Feature({"AndroidWebView"}) |
417 @SmallTest | 462 @SmallTest |
418 public void testEscapingOfErrorPage() throws Throwable { | 463 public void testEscapingOfErrorPage() throws Throwable { |
419 AwTestContainerView testView = createAwTestContainerViewOnMainSync(mCont entsClient); | 464 AwTestContainerView testView = |
465 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); | |
420 AwContents awContents = testView.getAwContents(); | 466 AwContents awContents = testView.getAwContents(); |
421 String script = "window.failed == true"; | 467 String script = "window.failed == true"; |
422 | 468 |
423 enableJavaScriptOnUiThread(awContents); | 469 mActivityTestRule.enableJavaScriptOnUiThread(awContents); |
424 CallbackHelper onPageFinishedHelper = mContentsClient.getOnPageFinishedH elper(); | 470 CallbackHelper onPageFinishedHelper = mContentsClient.getOnPageFinishedH elper(); |
425 int currentCallCount = onPageFinishedHelper.getCallCount(); | 471 int currentCallCount = onPageFinishedHelper.getCallCount(); |
426 loadUrlAsync(awContents, | 472 mActivityTestRule.loadUrlAsync(awContents, |
427 "file:///file-that-does-not-exist#<script>window.failed = true;< /script>"); | 473 "file:///file-that-does-not-exist#<script>window.failed = true;< /script>"); |
428 onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_M S, | 474 onPageFinishedHelper.waitForCallback( |
429 TimeUnit.MILLISECONDS); | 475 currentCallCount, 1, AwActivityTestRule.WAIT_TIMEOUT_MS, TimeUni t.MILLISECONDS); |
430 | 476 |
431 assertEquals("false", executeJavaScriptAndWaitForResult(awContents, mCon tentsClient, | 477 Assert.assertEquals("false", |
432 script)); | 478 mActivityTestRule.executeJavaScriptAndWaitForResult( |
479 awContents, mContentsClient, script)); | |
433 } | 480 } |
434 | 481 |
482 @Test | |
435 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") | 483 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") |
436 @Feature({"AndroidWebView"}) | 484 @Feature({"AndroidWebView"}) |
437 @SmallTest | 485 @SmallTest |
438 public void testCanInjectHeaders() throws Throwable { | 486 public void testCanInjectHeaders() throws Throwable { |
439 final AwTestContainerView testContainer = | 487 final AwTestContainerView testContainer = |
440 createAwTestContainerViewOnMainSync(mContentsClient); | 488 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); |
441 final AwContents awContents = testContainer.getAwContents(); | 489 final AwContents awContents = testContainer.getAwContents(); |
442 | 490 |
443 enableJavaScriptOnUiThread(awContents); | 491 mActivityTestRule.enableJavaScriptOnUiThread(awContents); |
444 | 492 |
445 EmbeddedTestServer testServer = | 493 EmbeddedTestServer testServer = EmbeddedTestServer.createAndStartServer( |
446 EmbeddedTestServer.createAndStartServer(getInstrumentation().get Context()); | 494 InstrumentationRegistry.getInstrumentation().getContext()); |
447 | 495 |
448 try { | 496 try { |
449 String url = testServer.getURL("/echoheader?X-foo"); | 497 String url = testServer.getURL("/echoheader?X-foo"); |
450 | 498 |
451 final Map<String, String> extraHeaders = new HashMap<String, String> (); | 499 final Map<String, String> extraHeaders = new HashMap<String, String> (); |
452 extraHeaders.put("X-foo", "bar"); | 500 extraHeaders.put("X-foo", "bar"); |
453 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), u rl, extraHeaders); | 501 mActivityTestRule.loadUrlSync( |
502 awContents, mContentsClient.getOnPageFinishedHelper(), url, extraHeaders); | |
454 | 503 |
455 String xfoo = getJavaScriptResultBodyTextContent(awContents, mConten tsClient); | 504 String xfoo = mActivityTestRule.maybeStripDoubleQuotes( |
boliu
2017/07/20 21:22:47
add this to Rules?
the real yoland
2017/07/27 00:29:47
Done
| |
456 assertEquals("bar", xfoo); | 505 JSUtils.executeJavaScriptAndWaitForResult( |
506 InstrumentationRegistry.getInstrumentation(), awCont ents, | |
507 mContentsClient.getOnEvaluateJavaScriptResultHelper( ), | |
508 "document.body.textContent")); | |
509 Assert.assertEquals("bar", xfoo); | |
457 | 510 |
458 url = testServer.getURL("/echoheader?Referer"); | 511 url = testServer.getURL("/echoheader?Referer"); |
459 | 512 |
460 extraHeaders.clear(); | 513 extraHeaders.clear(); |
461 extraHeaders.put("Referer", "http://www.example.com/"); | 514 extraHeaders.put("Referer", "http://www.example.com/"); |
462 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), u rl, extraHeaders); | 515 mActivityTestRule.loadUrlSync( |
516 awContents, mContentsClient.getOnPageFinishedHelper(), url, extraHeaders); | |
463 | 517 |
464 String referer = getJavaScriptResultBodyTextContent(awContents, mCon tentsClient); | 518 String referer = mActivityTestRule.maybeStripDoubleQuotes( |
465 assertEquals("http://www.example.com/", referer); | 519 JSUtils.executeJavaScriptAndWaitForResult( |
520 InstrumentationRegistry.getInstrumentation(), awCont ents, | |
521 mContentsClient.getOnEvaluateJavaScriptResultHelper( ), | |
522 "document.body.textContent")); | |
523 Assert.assertEquals("http://www.example.com/", referer); | |
466 } finally { | 524 } finally { |
467 testServer.stopAndDestroyServer(); | 525 testServer.stopAndDestroyServer(); |
468 } | 526 } |
469 } | 527 } |
470 | 528 |
471 // This is a meta test that we don't accidentally turn off hardware | 529 // This is a meta test that we don't accidentally turn off hardware |
472 // acceleration in instrumentation tests without notice. Do not add the | 530 // acceleration in instrumentation tests without notice. Do not add the |
473 // @DisableHardwareAccelerationForTest annotation for this test. | 531 // @DisableHardwareAccelerationForTest annotation for this test. |
532 @Test | |
474 @Feature({"AndroidWebView"}) | 533 @Feature({"AndroidWebView"}) |
475 @SmallTest | 534 @SmallTest |
476 public void testHardwareModeWorks() throws Throwable { | 535 public void testHardwareModeWorks() throws Throwable { |
477 AwTestContainerView testContainer = | 536 AwTestContainerView testContainer = |
478 createAwTestContainerViewOnMainSync(mContentsClient); | 537 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); |
479 assertTrue(testContainer.isHardwareAccelerated()); | 538 Assert.assertTrue(testContainer.isHardwareAccelerated()); |
480 assertTrue(testContainer.isBackedByHardwareView()); | 539 Assert.assertTrue(testContainer.isBackedByHardwareView()); |
481 } | 540 } |
482 | 541 |
483 // TODO(hush): more ssl tests. And put the ssl tests into a separate test | 542 // TODO(hush): more ssl tests. And put the ssl tests into a separate test |
484 // class. | 543 // class. |
544 @Test | |
485 @Feature({"AndroidWebView"}) | 545 @Feature({"AndroidWebView"}) |
486 @SmallTest | 546 @SmallTest |
487 // If the user allows the ssl error, the same ssl error will not trigger | 547 // If the user allows the ssl error, the same ssl error will not trigger |
488 // the onReceivedSslError callback; If the user denies it, the same ssl | 548 // the onReceivedSslError callback; If the user denies it, the same ssl |
489 // error will still trigger the onReceivedSslError callback. | 549 // error will still trigger the onReceivedSslError callback. |
490 public void testSslPreferences() throws Throwable { | 550 public void testSslPreferences() throws Throwable { |
491 final AwTestContainerView testContainer = | 551 final AwTestContainerView testContainer = |
492 createAwTestContainerViewOnMainSync(mContentsClient); | 552 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); |
493 final AwContents awContents = testContainer.getAwContents(); | 553 final AwContents awContents = testContainer.getAwContents(); |
494 TestWebServer webServer = TestWebServer.startSsl(); | 554 TestWebServer webServer = TestWebServer.startSsl(); |
495 final String pagePath = "/hello.html"; | 555 final String pagePath = "/hello.html"; |
496 final String pageUrl = | 556 final String pageUrl = |
497 webServer.setResponse(pagePath, "<html><body>hello world</body>< /html>", null); | 557 webServer.setResponse(pagePath, "<html><body>hello world</body>< /html>", null); |
498 final CallbackHelper onReceivedSslErrorHelper = | 558 final CallbackHelper onReceivedSslErrorHelper = |
499 mContentsClient.getOnReceivedSslErrorHelper(); | 559 mContentsClient.getOnReceivedSslErrorHelper(); |
500 int onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount(); | 560 int onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount(); |
501 | 561 |
502 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageU rl); | 562 mActivityTestRule.loadUrlSync( |
563 awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); | |
503 | 564 |
504 assertEquals(onSslErrorCallCount + 1, onReceivedSslErrorHelper.getCallCo unt()); | 565 Assert.assertEquals(onSslErrorCallCount + 1, onReceivedSslErrorHelper.ge tCallCount()); |
505 assertEquals(1, webServer.getRequestCount(pagePath)); | 566 Assert.assertEquals(1, webServer.getRequestCount(pagePath)); |
506 | 567 |
507 // Now load the page again. This time, we expect no ssl error, because | 568 // Now load the page again. This time, we expect no ssl error, because |
508 // user's decision should be remembered. | 569 // user's decision should be remembered. |
509 onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount(); | 570 onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount(); |
510 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageU rl); | 571 mActivityTestRule.loadUrlSync( |
511 assertEquals(onSslErrorCallCount, onReceivedSslErrorHelper.getCallCount( )); | 572 awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); |
573 Assert.assertEquals(onSslErrorCallCount, onReceivedSslErrorHelper.getCal lCount()); | |
512 | 574 |
513 // Now clear the ssl preferences then load the same url again. Expect to see | 575 // Now clear the ssl preferences then load the same url again. Expect to see |
514 // onReceivedSslError getting called again. | 576 // onReceivedSslError getting called again. |
515 awContents.clearSslPreferences(); | 577 awContents.clearSslPreferences(); |
516 onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount(); | 578 onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount(); |
517 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageU rl); | 579 mActivityTestRule.loadUrlSync( |
518 assertEquals(onSslErrorCallCount + 1, onReceivedSslErrorHelper.getCallCo unt()); | 580 awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); |
581 Assert.assertEquals(onSslErrorCallCount + 1, onReceivedSslErrorHelper.ge tCallCount()); | |
519 | 582 |
520 // Now clear the stored decisions and tell the client to deny ssl errors . | 583 // Now clear the stored decisions and tell the client to deny ssl errors . |
521 awContents.clearSslPreferences(); | 584 awContents.clearSslPreferences(); |
522 mContentsClient.setAllowSslError(false); | 585 mContentsClient.setAllowSslError(false); |
523 onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount(); | 586 onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount(); |
524 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageU rl); | 587 mActivityTestRule.loadUrlSync( |
525 assertEquals(onSslErrorCallCount + 1, onReceivedSslErrorHelper.getCallCo unt()); | 588 awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); |
589 Assert.assertEquals(onSslErrorCallCount + 1, onReceivedSslErrorHelper.ge tCallCount()); | |
526 | 590 |
527 // Now load the same page again. This time, we still expect onReceivedSs lError, | 591 // Now load the same page again. This time, we still expect onReceivedSs lError, |
528 // because we only remember user's decision if it is "allow". | 592 // because we only remember user's decision if it is "allow". |
529 onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount(); | 593 onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount(); |
530 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageU rl); | 594 mActivityTestRule.loadUrlSync( |
531 assertEquals(onSslErrorCallCount + 1, onReceivedSslErrorHelper.getCallCo unt()); | 595 awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); |
596 Assert.assertEquals(onSslErrorCallCount + 1, onReceivedSslErrorHelper.ge tCallCount()); | |
532 } | 597 } |
533 | 598 |
534 /** | 599 /** |
535 * Verifies that Web Notifications and the Push API are not exposed in WebVi ew. | 600 * Verifies that Web Notifications and the Push API are not exposed in WebVi ew. |
536 */ | 601 */ |
602 @Test | |
537 @Feature({"AndroidWebView"}) | 603 @Feature({"AndroidWebView"}) |
538 @SmallTest | 604 @SmallTest |
539 public void testPushAndNotificationsDisabled() throws Throwable { | 605 public void testPushAndNotificationsDisabled() throws Throwable { |
540 AwTestContainerView testView = createAwTestContainerViewOnMainSync(mCont entsClient); | 606 AwTestContainerView testView = |
607 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); | |
541 AwContents awContents = testView.getAwContents(); | 608 AwContents awContents = testView.getAwContents(); |
542 | 609 |
543 String script = "window.Notification || window.PushManager"; | 610 String script = "window.Notification || window.PushManager"; |
544 | 611 |
545 enableJavaScriptOnUiThread(awContents); | 612 mActivityTestRule.enableJavaScriptOnUiThread(awContents); |
546 loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), | 613 mActivityTestRule.loadUrlSync(awContents, mContentsClient.getOnPageFinis hedHelper(), |
547 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); | 614 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); |
548 assertEquals("null", executeJavaScriptAndWaitForResult(awContents, mCont entsClient, | 615 Assert.assertEquals("null", |
549 script)); | 616 mActivityTestRule.executeJavaScriptAndWaitForResult( |
617 awContents, mContentsClient, script)); | |
550 } | 618 } |
551 | 619 |
552 private static class MockBindingManager implements BindingManager { | 620 private static class MockBindingManager implements BindingManager { |
553 private boolean mIsChildProcessCreated; | 621 private boolean mIsChildProcessCreated; |
554 | 622 |
555 private Object mForegroundStateLock; | 623 private Object mForegroundStateLock; |
556 private ArrayList<Boolean> mForegroundState; | 624 private ArrayList<Boolean> mForegroundState; |
557 | 625 |
558 public MockBindingManager() { | 626 public MockBindingManager() { |
559 super(); | 627 super(); |
560 mForegroundStateLock = new Object(); | 628 mForegroundStateLock = new Object(); |
561 mForegroundState = new ArrayList<Boolean>(); | 629 mForegroundState = new ArrayList<Boolean>(); |
562 } | 630 } |
563 | 631 |
564 boolean isChildProcessCreated() { | 632 boolean isChildProcessCreated() { |
565 return mIsChildProcessCreated; | 633 return mIsChildProcessCreated; |
566 } | 634 } |
567 | 635 |
568 void assertSetInForegroundCall(boolean inForeground) { | 636 void assertSetInForegroundCall(boolean inForeground) { |
569 synchronized (mForegroundStateLock) { | 637 synchronized (mForegroundStateLock) { |
570 if (mForegroundState.size() == 0) { | 638 if (mForegroundState.size() == 0) { |
571 try { | 639 try { |
572 mForegroundStateLock.wait(WAIT_TIMEOUT_MS); | 640 mForegroundStateLock.wait(AwActivityTestRule.WAIT_TIMEOU T_MS); |
573 } catch (InterruptedException e) { | 641 } catch (InterruptedException e) { |
574 } | 642 } |
575 } | 643 } |
576 assertTrue(mForegroundState.size() != 0); | 644 Assert.assertTrue(mForegroundState.size() != 0); |
577 assertEquals(inForeground, mForegroundState.get(0).booleanValue( )); | 645 Assert.assertEquals(inForeground, mForegroundState.get(0)); |
578 mForegroundState.remove(0); | 646 mForegroundState.remove(0); |
579 return; | 647 return; |
580 } | 648 } |
581 } | 649 } |
582 | 650 |
583 @Override | 651 @Override |
584 public void addNewConnection(int pid, ChildProcessConnection connection) { | 652 public void addNewConnection(int pid, ChildProcessConnection connection) { |
585 mIsChildProcessCreated = true; | 653 mIsChildProcessCreated = true; |
586 } | 654 } |
587 | 655 |
(...skipping 17 matching lines...) Expand all Loading... | |
605 @Override | 673 @Override |
606 public void startModerateBindingManagement(Context context, int maxSize) {} | 674 public void startModerateBindingManagement(Context context, int maxSize) {} |
607 | 675 |
608 @Override | 676 @Override |
609 public void releaseAllModerateBindings() {} | 677 public void releaseAllModerateBindings() {} |
610 } | 678 } |
611 | 679 |
612 /** | 680 /** |
613 * Verifies that a child process is actually gets created with WEBVIEW_SANDB OXED_RENDERER flag. | 681 * Verifies that a child process is actually gets created with WEBVIEW_SANDB OXED_RENDERER flag. |
614 */ | 682 */ |
683 @Test | |
615 @Feature({"AndroidWebView"}) | 684 @Feature({"AndroidWebView"}) |
616 @SmallTest | 685 @SmallTest |
617 @CommandLineFlags.Add(AwSwitches.WEBVIEW_SANDBOXED_RENDERER) | 686 @CommandLineFlags.Add(AwSwitches.WEBVIEW_SANDBOXED_RENDERER) |
618 @SkipCommandLineParameterization | 687 @SkipCommandLineParameterization |
619 public void testSandboxedRendererWorks() throws Throwable { | 688 public void testSandboxedRendererWorks() throws Throwable { |
620 MockBindingManager bindingManager = new MockBindingManager(); | 689 MockBindingManager bindingManager = new MockBindingManager(); |
621 ChildProcessLauncherHelper.setBindingManagerForTesting(bindingManager); | 690 ChildProcessLauncherHelper.setBindingManagerForTesting(bindingManager); |
622 assertFalse(bindingManager.isChildProcessCreated()); | 691 Assert.assertFalse(bindingManager.isChildProcessCreated()); |
623 | 692 |
624 AwTestContainerView testView = createAwTestContainerViewOnMainSync(mCont entsClient); | 693 AwTestContainerView testView = |
694 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); | |
625 AwContents awContents = testView.getAwContents(); | 695 AwContents awContents = testView.getAwContents(); |
626 final String pageTitle = "I am sandboxed"; | 696 final String pageTitle = "I am sandboxed"; |
627 loadDataSync(awContents, mContentsClient.getOnPageFinishedHelper(), | 697 mActivityTestRule.loadDataSync(awContents, mContentsClient.getOnPageFini shedHelper(), |
628 "<html><head><title>" + pageTitle + "</title></head></html>", "t ext/html", false); | 698 "<html><head><title>" + pageTitle + "</title></head></html>", "t ext/html", false); |
629 assertEquals(pageTitle, getTitleOnUiThread(awContents)); | 699 Assert.assertEquals(pageTitle, mActivityTestRule.getTitleOnUiThread(awCo ntents)); |
630 | 700 |
631 assertTrue(bindingManager.isChildProcessCreated()); | 701 Assert.assertTrue(bindingManager.isChildProcessCreated()); |
632 | 702 |
633 // Test end-to-end interaction with the renderer. | 703 // Test end-to-end interaction with the renderer. |
634 AwSettings awSettings = getAwSettingsOnUiThread(awContents); | 704 AwSettings awSettings = mActivityTestRule.getAwSettingsOnUiThread(awCont ents); |
635 awSettings.setJavaScriptEnabled(true); | 705 awSettings.setJavaScriptEnabled(true); |
636 assertEquals("42", JSUtils.executeJavaScriptAndWaitForResult(this, awCon tents, | 706 Assert.assertEquals("42", |
707 JSUtils.executeJavaScriptAndWaitForResult( | |
708 InstrumentationRegistry.getInstrumentation(), awContents , | |
637 mContentsClient.getOnEvaluateJavaScriptResultHelper(), " 21 + 21")); | 709 mContentsClient.getOnEvaluateJavaScriptResultHelper(), " 21 + 21")); |
638 } | 710 } |
639 | 711 |
640 /** | 712 /** |
641 * By default the renderer should be considererd to be in the | 713 * By default the renderer should be considererd to be in the |
642 * foreground. | 714 * foreground. |
643 */ | 715 */ |
716 @Test | |
644 @Feature({"AndroidWebView"}) | 717 @Feature({"AndroidWebView"}) |
645 @SmallTest | 718 @SmallTest |
646 @CommandLineFlags.Add(AwSwitches.WEBVIEW_SANDBOXED_RENDERER) | 719 @CommandLineFlags.Add(AwSwitches.WEBVIEW_SANDBOXED_RENDERER) |
647 @SkipCommandLineParameterization | 720 @SkipCommandLineParameterization |
648 public void testRendererPriorityStartsHigh() throws Throwable { | 721 public void testRendererPriorityStartsHigh() throws Throwable { |
649 MockBindingManager bindingManager = new MockBindingManager(); | 722 MockBindingManager bindingManager = new MockBindingManager(); |
650 ChildProcessLauncherHelper.setBindingManagerForTesting(bindingManager); | 723 ChildProcessLauncherHelper.setBindingManagerForTesting(bindingManager); |
651 assertFalse(bindingManager.isChildProcessCreated()); | 724 Assert.assertFalse(bindingManager.isChildProcessCreated()); |
652 | 725 |
653 AwTestContainerView testView = createAwTestContainerViewOnMainSync(mCont entsClient); | 726 AwTestContainerView testView = |
727 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); | |
654 AwContents awContents = testView.getAwContents(); | 728 AwContents awContents = testView.getAwContents(); |
655 loadDataSync(awContents, mContentsClient.getOnPageFinishedHelper(), "<ht ml></html>", | 729 mActivityTestRule.loadDataSync(awContents, mContentsClient.getOnPageFini shedHelper(), |
656 "text/html", false); | 730 "<html></html>", "text/html", false); |
657 | 731 |
658 assertTrue(bindingManager.isChildProcessCreated()); | 732 Assert.assertTrue(bindingManager.isChildProcessCreated()); |
659 bindingManager.assertSetInForegroundCall(true); | 733 bindingManager.assertSetInForegroundCall(true); |
660 } | 734 } |
661 | 735 |
662 /** | 736 /** |
663 * If we specify that the priority is WAIVED, then the renderer | 737 * If we specify that the priority is WAIVED, then the renderer |
664 * should not be in the foreground. | 738 * should not be in the foreground. |
665 */ | 739 */ |
740 @Test | |
666 @Feature({"AndroidWebView"}) | 741 @Feature({"AndroidWebView"}) |
667 @SmallTest | 742 @SmallTest |
668 @CommandLineFlags.Add(AwSwitches.WEBVIEW_SANDBOXED_RENDERER) | 743 @CommandLineFlags.Add(AwSwitches.WEBVIEW_SANDBOXED_RENDERER) |
669 @SkipCommandLineParameterization | 744 @SkipCommandLineParameterization |
670 public void testRendererPriorityLow() throws Throwable { | 745 public void testRendererPriorityLow() throws Throwable { |
671 MockBindingManager bindingManager = new MockBindingManager(); | 746 MockBindingManager bindingManager = new MockBindingManager(); |
672 ChildProcessLauncherHelper.setBindingManagerForTesting(bindingManager); | 747 ChildProcessLauncherHelper.setBindingManagerForTesting(bindingManager); |
673 assertFalse(bindingManager.isChildProcessCreated()); | 748 Assert.assertFalse(bindingManager.isChildProcessCreated()); |
674 | 749 |
675 final AwTestContainerView testView = createAwTestContainerViewOnMainSync (mContentsClient); | 750 final AwTestContainerView testView = |
751 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); | |
676 final AwContents awContents = testView.getAwContents(); | 752 final AwContents awContents = testView.getAwContents(); |
677 runTestOnUiThread(new Runnable() { | 753 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable( ) { |
678 @Override | 754 @Override |
679 public void run() { | 755 public void run() { |
680 awContents.setRendererPriorityPolicy(RendererPriority.WAIVED, fa lse); | 756 awContents.setRendererPriorityPolicy(RendererPriority.WAIVED, fa lse); |
681 } | 757 } |
682 }); | 758 }); |
683 loadDataSync(awContents, mContentsClient.getOnPageFinishedHelper(), "<ht ml></html>", | 759 mActivityTestRule.loadDataSync(awContents, mContentsClient.getOnPageFini shedHelper(), |
684 "text/html", false); | 760 "<html></html>", "text/html", false); |
685 | 761 |
686 assertTrue(awContents.isPageVisible()); | 762 Assert.assertTrue(awContents.isPageVisible()); |
687 assertTrue(bindingManager.isChildProcessCreated()); | 763 Assert.assertTrue(bindingManager.isChildProcessCreated()); |
688 bindingManager.assertSetInForegroundCall(false); | 764 bindingManager.assertSetInForegroundCall(false); |
689 } | 765 } |
690 | 766 |
691 /** | 767 /** |
692 * If we specify that the priority is HIGH, but WAIVED when in the | 768 * If we specify that the priority is HIGH, but WAIVED when in the |
693 * background, then pausing the view should send the renderer to | 769 * background, then pausing the view should send the renderer to |
694 * the background. | 770 * the background. |
695 */ | 771 */ |
772 @Test | |
696 @Feature({"AndroidWebView"}) | 773 @Feature({"AndroidWebView"}) |
697 @SmallTest | 774 @SmallTest |
698 @CommandLineFlags.Add(AwSwitches.WEBVIEW_SANDBOXED_RENDERER) | 775 @CommandLineFlags.Add(AwSwitches.WEBVIEW_SANDBOXED_RENDERER) |
699 @SkipCommandLineParameterization | 776 @SkipCommandLineParameterization |
700 public void testRendererPriorityManaged() throws Throwable { | 777 public void testRendererPriorityManaged() throws Throwable { |
701 MockBindingManager bindingManager = new MockBindingManager(); | 778 MockBindingManager bindingManager = new MockBindingManager(); |
702 ChildProcessLauncherHelper.setBindingManagerForTesting(bindingManager); | 779 ChildProcessLauncherHelper.setBindingManagerForTesting(bindingManager); |
703 assertFalse(bindingManager.isChildProcessCreated()); | 780 Assert.assertFalse(bindingManager.isChildProcessCreated()); |
704 | 781 |
705 final AwTestContainerView testView = createAwTestContainerViewOnMainSync (mContentsClient); | 782 final AwTestContainerView testView = |
783 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); | |
706 final AwContents awContents = testView.getAwContents(); | 784 final AwContents awContents = testView.getAwContents(); |
707 runTestOnUiThread(new Runnable() { | 785 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable( ) { |
708 @Override | 786 @Override |
709 public void run() { | 787 public void run() { |
710 awContents.setRendererPriorityPolicy(RendererPriority.HIGH, true ); | 788 awContents.setRendererPriorityPolicy(RendererPriority.HIGH, true ); |
711 } | 789 } |
712 }); | 790 }); |
713 loadDataSync(awContents, mContentsClient.getOnPageFinishedHelper(), "<ht ml></html>", | 791 mActivityTestRule.loadDataSync(awContents, mContentsClient.getOnPageFini shedHelper(), |
714 "text/html", false); | 792 "<html></html>", "text/html", false); |
715 | 793 |
716 assertTrue(awContents.isPageVisible()); | 794 Assert.assertTrue(awContents.isPageVisible()); |
717 assertTrue(bindingManager.isChildProcessCreated()); | 795 Assert.assertTrue(bindingManager.isChildProcessCreated()); |
718 bindingManager.assertSetInForegroundCall(true); | 796 bindingManager.assertSetInForegroundCall(true); |
719 runTestOnUiThread(new Runnable() { | 797 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable( ) { |
720 @Override | 798 @Override |
721 public void run() { | 799 public void run() { |
722 awContents.onPause(); | 800 awContents.onPause(); |
723 } | 801 } |
724 }); | 802 }); |
725 bindingManager.assertSetInForegroundCall(false); | 803 bindingManager.assertSetInForegroundCall(false); |
726 } | 804 } |
727 | 805 |
806 @Test | |
728 @Feature({"AndroidWebView"}) | 807 @Feature({"AndroidWebView"}) |
729 @SmallTest | 808 @SmallTest |
730 @UiThreadTest | |
731 @CommandLineFlags.Add(AwSwitches.WEBVIEW_SANDBOXED_RENDERER) | 809 @CommandLineFlags.Add(AwSwitches.WEBVIEW_SANDBOXED_RENDERER) |
732 @SkipCommandLineParameterization | 810 @SkipCommandLineParameterization |
733 public void testPauseDestroyResume() throws Throwable { | 811 public void testPauseDestroyResume() throws Throwable { |
734 AwContents awContents; | 812 mActivityTestRule.runOnUiThread(new Runnable() { |
735 awContents = createAwTestContainerView(mContentsClient).getAwContents(); | 813 @Override |
736 awContents.pauseTimers(); | 814 public void run() { |
737 awContents.pauseTimers(); | 815 AwContents awContents; |
738 awContents.destroy(); | 816 awContents = mActivityTestRule.createAwTestContainerView(mConten tsClient) |
739 awContents = createAwTestContainerView(mContentsClient).getAwContents(); | 817 .getAwContents(); |
740 awContents.resumeTimers(); | 818 awContents.pauseTimers(); |
819 awContents.pauseTimers(); | |
820 awContents.destroy(); | |
821 awContents = mActivityTestRule.createAwTestContainerView(mConten tsClient) | |
822 .getAwContents(); | |
823 awContents.resumeTimers(); | |
824 } | |
825 }); | |
741 } | 826 } |
742 | 827 |
743 /** Regression test for https://crbug.com/732976. Load a data URL, then imme diately | 828 /** Regression test for https://crbug.com/732976. Load a data URL, then imme diately |
744 * after that load a javascript URL. The data URL navigation shouldn't be bl ocked. | 829 * after that load a javascript URL. The data URL navigation shouldn't be bl ocked. |
745 */ | 830 */ |
831 @Test | |
746 @LargeTest | 832 @LargeTest |
747 @Feature({"AndroidWebView"}) | 833 @Feature({"AndroidWebView"}) |
748 public void testJavaScriptUrlAfterLoadData() throws Throwable { | 834 public void testJavaScriptUrlAfterLoadData() throws Throwable { |
749 AwTestContainerView testView = createAwTestContainerViewOnMainSync(mCont entsClient); | 835 AwTestContainerView testView = |
836 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsC lient); | |
750 final AwContents awContents = testView.getAwContents(); | 837 final AwContents awContents = testView.getAwContents(); |
751 getInstrumentation().runOnMainSync(new Runnable() { | 838 mActivityTestRule.runOnUiThread(new Runnable() { |
752 @Override | 839 @Override |
753 public void run() { | 840 public void run() { |
754 // Run javascript navigation immediately, without waiting for th e completion of data | 841 // Run javascript navigation immediately, without waiting for th e completion of data |
755 // URL. | 842 // URL. |
756 awContents.loadData("<html>test</html>", "text/html", "utf-8"); | 843 awContents.loadData("<html>test</html>", "text/html", "utf-8"); |
757 awContents.loadUrl("javascript: void(0)"); | 844 awContents.loadUrl("javascript: void(0)"); |
758 } | 845 } |
759 }); | 846 }); |
760 | 847 |
761 mContentsClient.getOnPageFinishedHelper().waitForCallback( | 848 mContentsClient.getOnPageFinishedHelper().waitForCallback( |
762 0, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS); | 849 0, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS); |
763 assertEquals("data:text/html,<html>test</html>", awContents.getLastCommi ttedUrl()); | 850 Assert.assertEquals("data:text/html,<html>test</html>", awContents.getLa stCommittedUrl()); |
764 | 851 |
765 TestAwContentsClient.AddMessageToConsoleHelper consoleHelper = | 852 TestAwContentsClient.AddMessageToConsoleHelper consoleHelper = |
766 mContentsClient.getAddMessageToConsoleHelper(); | 853 mContentsClient.getAddMessageToConsoleHelper(); |
767 assertEquals(0, consoleHelper.getMessages().size()); | 854 Assert.assertEquals(0, consoleHelper.getMessages().size()); |
768 } | 855 } |
769 } | 856 } |
OLD | NEW |