Commit 1fdb97b0 authored by mkosiba@chromium.org's avatar mkosiba@chromium.org

[android_webview] Don't call onPageFinished for history API.

Turns out the refactoring in r158146 made us use the incorrect
WebContentsObserver callback.

BUG=https://code.google.com/p/android/issues/detail?id=62100, b/11656658 
TEST=AndroidWebViewTest

Review URL: https://codereview.chromium.org/68763012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235785 0039d316-1c4b-4281-b951-d872f2087c98
parent a9a70412
......@@ -58,8 +58,9 @@ public abstract class AwContentsClient {
}
@Override
public void didStopLoading(String url) {
AwContentsClient.this.onPageFinished(url);
public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
if (isMainFrame)
AwContentsClient.this.onPageFinished(validatedUrl);
}
@Override
......
......@@ -514,7 +514,6 @@ public class AwContentsClientShouldOverrideUrlLoadingTest extends AwTestBase {
setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadingHelper, true);
int callCount = shouldOverrideUrlLoadingHelper.getCallCount();
int onPageFinishedCallCount = contentsClient.getOnPageFinishedHelper().getCallCount();
clickOnLinkUsingJs(awContents, contentsClient);
// Some time around here true should be returned from the shouldOverrideUrlLoading
// callback causing the navigation caused by calling clickOnLinkUsingJs to be ignored.
......@@ -523,8 +522,6 @@ public class AwContentsClientShouldOverrideUrlLoadingTest extends AwTestBase {
setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadingHelper, false);
// We need to wait for the navigation to complete before we can initiate another load.
contentsClient.getOnPageFinishedHelper().waitForCallback(onPageFinishedCallCount);
loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), synchronizationUrl);
assertEquals(1, mWebServer.getRequestCount(pageWithLinkToIgnorePath));
......
......@@ -111,4 +111,46 @@ public class ClientOnPageFinishedTest extends AwTestBase {
if (webServer != null) webServer.shutdown();
}
}
@MediumTest
@Feature({"AndroidWebView"})
public void testOnPageFinishedNotCalledForHistoryApi() throws Throwable {
TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
mContentsClient.getOnPageFinishedHelper();
enableJavaScriptOnUiThread(mAwContents);
TestWebServer webServer = null;
try {
webServer = new TestWebServer(false);
final String testHtml = "<html><head>Header</head><body>Body</body></html>";
final String testPath = "/test.html";
final String historyPath = "/history.html";
final String syncPath = "/sync.html";
final String testUrl = webServer.setResponse(testPath, testHtml, null);
final String historyUrl = webServer.getResponseUrl(historyPath);
final String syncUrl = webServer.setResponse(syncPath, testHtml, null);
assertEquals(0, onPageFinishedHelper.getCallCount());
loadUrlSync(mAwContents, onPageFinishedHelper, testUrl);
executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
"history.pushState(null, null, '" + historyUrl + "');");
// Rather than wait a fixed time to see that an onPageFinished callback isn't issued
// we load another valid page. Since callbacks arrive sequentially if the next callback
// we get is for the synchronizationUrl we know that the previous load did not schedule
// a callback for the iframe.
final int synchronizationPageCallCount = onPageFinishedHelper.getCallCount();
loadUrlAsync(mAwContents, syncUrl);
onPageFinishedHelper.waitForCallback(synchronizationPageCallCount);
assertEquals(syncUrl, onPageFinishedHelper.getUrl());
assertEquals(2, onPageFinishedHelper.getCallCount());
} finally {
if (webServer != null) webServer.shutdown();
}
}
}
......@@ -212,6 +212,18 @@ public class LoadDataWithBaseUrlTest extends AwTestBase {
getInstrumentation(), mContentViewCore));
}
@SmallTest
@Feature({"AndroidWebView"})
public void testOnPageFinishedUrlIsBaseUrl() throws Throwable {
final String pageHtml = "<html><body>Hello, world!</body></html>";
final String baseUrl = "http://example.com/";
loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, baseUrl);
loadDataWithBaseUrlSync(pageHtml, "text/html", false, baseUrl, baseUrl);
TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
mContentsClient.getOnPageFinishedHelper();
assertEquals(baseUrl, onPageFinishedHelper.getUrl());
}
@SmallTest
@Feature({"AndroidWebView"})
public void testHistoryUrlIgnoredWithDataSchemeBaseUrl() throws Throwable {
......
......@@ -90,19 +90,8 @@ void WebContentsObserverAndroid::DidStopLoading(
ScopedJavaLocalRef<jobject> obj(weak_java_observer_.get(env));
if (obj.is_null())
return;
std::string url_string;
NavigationEntry* entry =
web_contents()->GetController().GetLastCommittedEntry();
// Not that GetBaseURLForDataURL is only used by the Android WebView
if (entry && !entry->GetBaseURLForDataURL().is_empty()) {
url_string = entry->GetBaseURLForDataURL().possibly_invalid_spec();
} else {
url_string = web_contents()->GetLastCommittedURL().spec();
}
ScopedJavaLocalRef<jstring> jstring_url(
ConvertUTF8ToJavaString(env, url_string));
ScopedJavaLocalRef<jstring> jstring_url(ConvertUTF8ToJavaString(
env, web_contents()->GetLastCommittedURL().spec()));
Java_WebContentsObserverAndroid_didStopLoading(
env, obj.obj(), jstring_url.obj());
}
......@@ -211,8 +200,16 @@ void WebContentsObserverAndroid::DidFinishLoad(
ScopedJavaLocalRef<jobject> obj(weak_java_observer_.get(env));
if (obj.is_null())
return;
std::string url_string = validated_url.spec();
NavigationEntry* entry =
web_contents()->GetController().GetLastCommittedEntry();
// Note that GetBaseURLForDataURL is only used by the Android WebView.
if (entry && !entry->GetBaseURLForDataURL().is_empty())
url_string = entry->GetBaseURLForDataURL().possibly_invalid_spec();
ScopedJavaLocalRef<jstring> jstring_url(
ConvertUTF8ToJavaString(env, validated_url.spec()));
ConvertUTF8ToJavaString(env, url_string));
Java_WebContentsObserverAndroid_didFinishLoad(
env, obj.obj(), frame_id, jstring_url.obj(), is_main_frame);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment