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 android.os.Build; | 7 import android.os.Build; |
8 import android.test.suitebuilder.annotation.MediumTest; | 8 import android.test.suitebuilder.annotation.MediumTest; |
9 | 9 |
10 import org.chromium.android_webview.AwContents; | 10 import org.chromium.android_webview.AwContents; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 272 |
273 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, | 273 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, |
274 "window.history.go(-1)"); | 274 "window.history.go(-1)"); |
275 | 275 |
276 onPageFinishedHelper.waitForCallback(onPageFinishedCallCount); | 276 onPageFinishedHelper.waitForCallback(onPageFinishedCallCount); |
277 assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCoun
t()); | 277 assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCoun
t()); |
278 } finally { | 278 } finally { |
279 webServer.shutdown(); | 279 webServer.shutdown(); |
280 } | 280 } |
281 } | 281 } |
| 282 |
| 283 @MediumTest |
| 284 @Feature({"AndroidWebView"}) |
| 285 public void testOnPageFinishedNotCalledOnDomModificationForBlankWebView() th
rows Throwable { |
| 286 TestWebServer webServer = TestWebServer.start(); |
| 287 try { |
| 288 doTestOnPageFinishedNotCalledOnDomMutation(webServer); |
| 289 } finally { |
| 290 webServer.shutdown(); |
| 291 } |
| 292 } |
| 293 |
| 294 @MediumTest |
| 295 @Feature({"AndroidWebView"}) |
| 296 public void testOnPageFinishedCalledOnDomModificationAfterNonCommittedLoad()
throws Throwable { |
| 297 enableJavaScriptOnUiThread(mAwContents); |
| 298 TestWebServer webServer = TestWebServer.start(); |
| 299 try { |
| 300 final String noContentUrl = webServer.setResponseWithNoContentStatus
("/nocontent.html"); |
| 301 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelpe
r = |
| 302 mContentsClient.getOnPageFinishedHelper(); |
| 303 final int onPageFinishedCallCount = onPageFinishedHelper.getCallCoun
t(); |
| 304 loadUrlAsync(mAwContents, noContentUrl); |
| 305 // Mutate DOM. |
| 306 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, |
| 307 "document.body.innerHTML='Hello, World!'"); |
| 308 onPageFinishedHelper.waitForCallback(onPageFinishedCallCount); |
| 309 assertEquals("about:blank", onPageFinishedHelper.getUrl()); |
| 310 } finally { |
| 311 webServer.shutdown(); |
| 312 } |
| 313 } |
| 314 |
| 315 @MediumTest |
| 316 @Feature({"AndroidWebView"}) |
| 317 public void testOnPageFinishedNotCalledOnDomModificationAfterLoadUrl() throw
s Throwable { |
| 318 TestWebServer webServer = TestWebServer.start(); |
| 319 try { |
| 320 final String testUrl = |
| 321 webServer.setResponse("/test.html", CommonResources.ABOUT_HT
ML, null); |
| 322 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
testUrl); |
| 323 doTestOnPageFinishedNotCalledOnDomMutation(webServer); |
| 324 } finally { |
| 325 webServer.shutdown(); |
| 326 } |
| 327 } |
| 328 |
| 329 @MediumTest |
| 330 @Feature({"AndroidWebView"}) |
| 331 public void testOnPageFinishedNotCalledOnDomModificationAfterLoadData() |
| 332 throws Throwable { |
| 333 TestWebServer webServer = TestWebServer.start(); |
| 334 try { |
| 335 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
| 336 CommonResources.ABOUT_HTML, "text/html", false); |
| 337 doTestOnPageFinishedNotCalledOnDomMutation(webServer); |
| 338 } finally { |
| 339 webServer.shutdown(); |
| 340 } |
| 341 } |
| 342 |
| 343 private void doTestOnPageFinishedNotCalledOnDomMutation(TestWebServer webSer
ver) |
| 344 throws Throwable { |
| 345 enableJavaScriptOnUiThread(mAwContents); |
| 346 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = |
| 347 mContentsClient.getOnPageFinishedHelper(); |
| 348 final int onPageFinishedCallCount = onPageFinishedHelper.getCallCount(); |
| 349 // Mutate DOM. |
| 350 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, |
| 351 "document.body.innerHTML='Hello, World!'"); |
| 352 // Rather than wait a fixed time to see that an onPageFinished callback
isn't issued |
| 353 // we load another valid page. Since callbacks arrive sequentially if th
e next callback |
| 354 // we get is for the synchronizationUrl we know that DOM mutation did no
t schedule |
| 355 // a callback for the iframe. |
| 356 final String syncUrl = webServer.setResponse("/sync.html", "", null); |
| 357 loadUrlAsync(mAwContents, syncUrl); |
| 358 onPageFinishedHelper.waitForCallback(onPageFinishedCallCount); |
| 359 assertEquals(syncUrl, onPageFinishedHelper.getUrl()); |
| 360 assertEquals(onPageFinishedCallCount + 1, onPageFinishedHelper.getCallCo
unt()); |
| 361 } |
282 } | 362 } |
OLD | NEW |