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

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/ClientOnPageFinishedTest.java

Issue 144283007: Call WebViewClient#onPageFinished when a main frame fails to load (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test onReceivedError is called before onPageFinished Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/javatests/src/org/chromium/android_webview/test/ClientOnPageFinishedTest.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/ClientOnPageFinishedTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/ClientOnPageFinishedTest.java
index aaaa6cc5860a6e385f7a1200c59f7d26345145a0..385b1ff55e847240ca74339a289008da90959792 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/ClientOnPageFinishedTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/ClientOnPageFinishedTest.java
@@ -72,6 +72,95 @@ public class ClientOnPageFinishedTest extends AwTestBase {
assertEquals(1, onReceivedErrorHelper.getCallCount());
}
+ /**
+ * If url1 is redirected url2, and url2 load is overridden, onPageFinished should still be
mkosiba (inactive) 2014/02/12 16:03:38 umm.. this isn't a "proper" JavaDoc, so please don
hush (inactive) 2014/02/12 18:40:40 Done.
+ * called for url2.
+ * Steps:
+ * 1. load url1. url1 onPageStarted
+ * 2. server redirects url1 to url2. url2 onPageStarted
+ * 3. shouldOverridedUrlLoading called for url2 and returns true
+ * 4. url2 onPageFinishedCalled
+ */
+ @MediumTest
+ @Feature({"AndroidWebView"})
+ public void testOnPageFinishedCalledAfterRedirectedUrlIsOverridden() throws Throwable {
+ TestWebServer webServer = null;
+ try {
+ webServer = new TestWebServer(false);
+ final String redirectTargetPath = "/redirect_target.html";
+ // If you visit redirectUrl, you will be redirected to redirectTargetUrl
mkosiba (inactive) 2014/02/12 16:03:38 IMHO this is pretty obvious from the code and does
hush (inactive) 2014/02/12 18:40:40 Done.
+ final String redirectTargetUrl = webServer.setResponse(redirectTargetPath,
+ "<html><body>hello world</body></html>", null);
+ final String redirectUrl = webServer.setRedirect("/302.html", redirectTargetUrl);
+
+ mContentsClient = new TestAwContentsClient() {
+ @Override
+ public boolean shouldOverrideUrlLoading(String url) {
mkosiba (inactive) 2014/02/12 16:03:38 I'd prefer either: a) moving the shouldOverrideUr
hush (inactive) 2014/02/12 18:40:40 Sure. Actually I would like to do some refactoring
+ if (url.equals(redirectTargetUrl)) {
mkosiba (inactive) 2014/02/12 16:03:38 I don't think you need this check - we shouldn't c
hush (inactive) 2014/02/12 18:40:40 you are right, I don't need this check. I was just
+ return true;
+ }
+ return false;
+ }
+ };
+ final AwTestContainerView testContainerView =
+ createAwTestContainerViewOnMainSync(mContentsClient);
+ mAwContents = testContainerView.getAwContents();
+
+ TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
+ mContentsClient.getOnPageFinishedHelper();
+
+ loadUrlSync(mAwContents, onPageFinishedHelper, redirectUrl);
+
+ // onPageFinished needs to be called for redirectTargetUrl, but not for redirectUrl
+ assertEquals(1, onPageFinishedHelper.getCallCount());
mkosiba (inactive) 2014/02/12 16:03:38 please don't use absolute for this. Grab the curre
hush (inactive) 2014/02/12 18:40:40 Done. I loadUrlAync then I waitforCallback to incr
+ assertEquals(redirectTargetUrl, onPageFinishedHelper.getUrl());
+ } finally {
+ if (webServer != null) webServer.shutdown();
+ }
+ }
+
+ /**
+ * Tests that onPageFinished is called after onReceivedError, if there is indeed an error
+ */
+ @MediumTest
+ @Feature({"AndroidWebView"})
+ public void testOnPageFinishedCalledAfterOnReceivedError() throws Throwable {
+ mContentsClient = new TestAwContentsClient() {
+ private boolean isOnReceivedErrorCalled = false;
+ private boolean isOnPageFinishedCalled = false;
+
+ @Override
+ public void onReceivedError(int errorCode, String description, String failingUrl) {
+ isOnReceivedErrorCalled = true;
+ // Make sure onReceivedError is not called before onPageFinished
mkosiba (inactive) 2014/02/12 16:03:38 is this really how Classic operated? sigh..
hush (inactive) 2014/02/12 18:40:40 sorry. I typed the wrong comments there. I meant "
hush (inactive) 2014/02/12 19:41:00 testOnPageFinishedCalledAfterError is not testing
+ assertEquals(false, isOnPageFinishedCalled);
+ super.onReceivedError(errorCode, description, failingUrl);
+ }
+
+ @Override
+ public void onPageFinished(String url) {
+ isOnPageFinishedCalled = true;
+ super.onPageFinished(url);
+ }
+ };
+
+ final AwTestContainerView testContainerView =
+ createAwTestContainerViewOnMainSync(mContentsClient);
+ mAwContents = testContainerView.getAwContents();
+
+ TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
+ mContentsClient.getOnPageFinishedHelper();
+
+ TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper =
+ mContentsClient.getOnReceivedErrorHelper();
+
+ final String invalidUrl = "foo://invalid.url.co";
+ loadUrlSync(mAwContents, onPageFinishedHelper, invalidUrl);
+
+ assertEquals(invalidUrl, onReceivedErrorHelper.getFailingUrl());
mkosiba (inactive) 2014/02/12 16:03:38 a couple of lines above you're checking that onRec
hush (inactive) 2014/02/12 18:40:40 Sorry. I was actually trying to test onReceivedErr
+ assertEquals(invalidUrl, onPageFinishedHelper.getUrl());
+ }
+
@MediumTest
@Feature({"AndroidWebView"})
public void testOnPageFinishedNotCalledForValidSubresources() throws Throwable {

Powered by Google App Engine
This is Rietveld 408576698