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.test.suitebuilder.annotation.MediumTest; | 7 import android.test.suitebuilder.annotation.MediumTest; |
8 | 8 |
9 import org.chromium.android_webview.AwContents; | 9 import org.chromium.android_webview.AwContents; |
10 import org.chromium.android_webview.test.util.CommonResources; | 10 import org.chromium.android_webview.test.util.CommonResources; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 int currentCallCount = onPageFinishedHelper.getCallCount(); | 44 int currentCallCount = onPageFinishedHelper.getCallCount(); |
45 loadDataAsync(mAwContents, html, "text/html", false); | 45 loadDataAsync(mAwContents, html, "text/html", false); |
46 | 46 |
47 onPageFinishedHelper.waitForCallback(currentCallCount); | 47 onPageFinishedHelper.waitForCallback(currentCallCount); |
48 assertEquals("data:text/html," + html, onPageFinishedHelper.getUrl()); | 48 assertEquals("data:text/html," + html, onPageFinishedHelper.getUrl()); |
49 } | 49 } |
50 | 50 |
51 @MediumTest | 51 @MediumTest |
52 @Feature({"AndroidWebView"}) | 52 @Feature({"AndroidWebView"}) |
53 public void testOnPageFinishedCalledAfterError() throws Throwable { | 53 public void testOnPageFinishedCalledAfterError() throws Throwable { |
54 setTestAwContentsClient(new TestAwContentsClient() { | 54 class LocalTestClient extends TestAwContentsClient { |
55 private boolean isOnReceivedErrorCalled = false; | 55 private boolean isOnReceivedErrorCalled = false; |
56 private boolean isOnPageFinishedCalled = false; | 56 private boolean isOnPageFinishedCalled = false; |
| 57 private boolean allowAboutBlank = false; |
57 | 58 |
58 @Override | 59 @Override |
59 public void onReceivedError(int errorCode, String description, Strin
g failingUrl) { | 60 public void onReceivedError(int errorCode, String description, Strin
g failingUrl) { |
| 61 assertEquals("onReceivedError called twice for " + failingUrl, |
| 62 false, isOnReceivedErrorCalled); |
60 isOnReceivedErrorCalled = true; | 63 isOnReceivedErrorCalled = true; |
61 // Make sure onReceivedError is called before onPageFinished | 64 assertEquals("onPageFinished called before onReceivedError for "
+ failingUrl, |
62 assertEquals(false, isOnPageFinishedCalled); | 65 false, isOnPageFinishedCalled); |
63 super.onReceivedError(errorCode, description, failingUrl); | 66 super.onReceivedError(errorCode, description, failingUrl); |
64 } | 67 } |
65 | 68 |
66 @Override | 69 @Override |
67 public void onPageFinished(String url) { | 70 public void onPageFinished(String url) { |
| 71 if (allowAboutBlank && "about:blank".equals(url)) { |
| 72 super.onPageFinished(url); |
| 73 return; |
| 74 } |
| 75 assertEquals("onPageFinished called twice for " + url, |
| 76 false, isOnPageFinishedCalled); |
68 isOnPageFinishedCalled = true; | 77 isOnPageFinishedCalled = true; |
69 // Make sure onReceivedError is called before onPageFinished | 78 assertEquals("onReceivedError not called before onPageFinished f
or " + url, |
70 assertEquals(true, isOnReceivedErrorCalled); | 79 true, isOnReceivedErrorCalled); |
71 super.onPageFinished(url); | 80 super.onPageFinished(url); |
72 } | 81 } |
73 }); | 82 |
| 83 void setAllowAboutBlank() { |
| 84 allowAboutBlank = true; |
| 85 } |
| 86 }; |
| 87 LocalTestClient testContentsClient = new LocalTestClient(); |
| 88 setTestAwContentsClient(testContentsClient); |
74 | 89 |
75 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper
= | 90 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper
= |
76 mContentsClient.getOnReceivedErrorHelper(); | 91 mContentsClient.getOnReceivedErrorHelper(); |
77 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = | 92 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = |
78 mContentsClient.getOnPageFinishedHelper(); | 93 mContentsClient.getOnPageFinishedHelper(); |
79 | 94 |
80 String invalidUrl = "http://localhost:7/non_existent"; | 95 String invalidUrl = "http://localhost:7/non_existent"; |
81 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); | |
82 int onPageFinishedCallCount = onPageFinishedHelper.getCallCount(); | |
83 loadUrlSync(mAwContents, onPageFinishedHelper, invalidUrl); | 96 loadUrlSync(mAwContents, onPageFinishedHelper, invalidUrl); |
84 | 97 |
85 assertEquals(invalidUrl, onReceivedErrorHelper.getFailingUrl()); | 98 assertEquals(invalidUrl, onReceivedErrorHelper.getFailingUrl()); |
86 assertEquals(invalidUrl, onPageFinishedHelper.getUrl()); | 99 assertEquals(invalidUrl, onPageFinishedHelper.getUrl()); |
| 100 |
| 101 // Rather than wait a fixed time to see that another onPageFinished call
back isn't issued |
| 102 // we load a valid page. Since callbacks arrive sequentially, this will
ensure that |
| 103 // any extra calls of onPageFinished / onReceivedError will arrive to ou
r client. |
| 104 testContentsClient.setAllowAboutBlank(); |
| 105 loadUrlSync(mAwContents, onPageFinishedHelper, "about:blank"); |
87 } | 106 } |
88 | 107 |
89 @MediumTest | 108 @MediumTest |
90 @Feature({"AndroidWebView"}) | 109 @Feature({"AndroidWebView"}) |
91 public void testOnPageFinishedCalledAfterRedirectedUrlIsOverridden() throws
Throwable { | 110 public void testOnPageFinishedCalledAfterRedirectedUrlIsOverridden() throws
Throwable { |
92 /* | 111 /* |
93 * If url1 is redirected url2, and url2 load is overridden, onPageFinish
ed should still be | 112 * If url1 is redirected url2, and url2 load is overridden, onPageFinish
ed should still be |
94 * called for url2. | 113 * called for url2. |
95 * Steps: | 114 * Steps: |
96 * 1. load url1. url1 onPageStarted | 115 * 1. load url1. url1 onPageStarted |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, | 279 executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, |
261 "window.history.go(-1)"); | 280 "window.history.go(-1)"); |
262 | 281 |
263 onPageFinishedHelper.waitForCallback(onPageFinishedCallCount); | 282 onPageFinishedHelper.waitForCallback(onPageFinishedCallCount); |
264 assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCoun
t()); | 283 assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCoun
t()); |
265 } finally { | 284 } finally { |
266 if (webServer != null) webServer.shutdown(); | 285 if (webServer != null) webServer.shutdown(); |
267 } | 286 } |
268 } | 287 } |
269 } | 288 } |
OLD | NEW |