From 78fca66434b0e5986b4501ea291175ae4b6b56df Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Wed, 16 Mar 2016 13:14:27 -0700 Subject: Store and use last base URL between DidStart / DidStopLoading As it turns out that the committed entry may omit the base URL if there has been a javascript: URL navigation after LoadDataWithBaseURL. Thus we have to store the base url on DidStartLoading and use it in DidStopLoading / DidFinishLoad. We have to preserve the old hack with SetToBaseURLForDataURLIfNeeded because if the base URL is not valid, DidFinishLoad doesn't receive it from the renderer. This change is a short-term workaround. The correct solution is to pass a flag that the load was through LoadDataWithBaseURL via Blink, so base URL can be restored correctly within NavigationController. BUG=594001 Review URL: https://codereview.chromium.org/1779363004 Cr-Commit-Position: refs/heads/master@{#381108} (cherry picked from commit ce1f4d009316d8f5f4c49b18e1bd94687d80c59d) Review URL: https://codereview.chromium.org/1806853005 . Cr-Commit-Position: refs/branch-heads/2623@{#627} Cr-Branched-From: 92d77538a86529ca35f9220bd3cd512cbea1f086-refs/heads/master@{#369907} --- .../test/LoadDataWithBaseUrlTest.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'android_webview') diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/LoadDataWithBaseUrlTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/LoadDataWithBaseUrlTest.java index 177f8c7..6fb0b3d 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/LoadDataWithBaseUrlTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/LoadDataWithBaseUrlTest.java @@ -373,4 +373,37 @@ public class LoadDataWithBaseUrlTest extends AwTestBase { assertEquals("true", executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, "window.gotToEndOfBody")); } + + @SmallTest + @Feature({"AndroidWebView"}) + public void testOnPageFinishedWhenInterrupted() throws Throwable { + // See crbug.com/594001 -- when a javascript: URL is loaded, the pending entry + // gets discarded and the previous load goes through a different path + // inside NavigationController. + final String pageHtml = "Hello, world!"; + final String baseUrl = "http://example.com/"; + final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = + mContentsClient.getOnPageFinishedHelper(); + final int callCount = onPageFinishedHelper.getCallCount(); + loadDataWithBaseUrlAsync(mAwContents, pageHtml, "text/html", false, baseUrl, null); + loadUrlAsync(mAwContents, "javascript:42"); + onPageFinishedHelper.waitForCallback(callCount); + assertEquals(baseUrl, onPageFinishedHelper.getUrl()); + } + + @SmallTest + @Feature({"AndroidWebView"}) + public void testOnPageFinishedWithInvalidBaseUrlWhenInterrupted() throws Throwable { + final String pageHtml = CommonResources.ABOUT_HTML; + final String invalidBaseUrl = "http://"; + final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = + mContentsClient.getOnPageFinishedHelper(); + final int callCount = onPageFinishedHelper.getCallCount(); + getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); + loadDataWithBaseUrlAsync(mAwContents, pageHtml, "text/html", false, invalidBaseUrl, null); + loadUrlAsync(mAwContents, "javascript:42"); + onPageFinishedHelper.waitForCallback(callCount); + // Verify that the load succeeds. The actual base url is undefined. + assertEquals(CommonResources.ABOUT_TITLE, getTitleOnUiThread(mAwContents)); + } } -- cgit v1.1