Index: content/browser/frame_host/navigation_controller_impl_browsertest.cc |
diff --git a/content/browser/frame_host/navigation_controller_impl_browsertest.cc b/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
index 1c93b3d35067b26423e2f6dc27f80e2027564909..1b31ca22b90af83502358775b16f88902e146e83 100644 |
--- a/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
+++ b/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
@@ -66,20 +66,113 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, LoadCrossSiteSubframe) { |
EXPECT_EQ(AreAllSitesIsolatedForTesting(), cross_process); |
} |
+// Verifies that the base, history, and data URLs for LoadDataWithBaseURL end up |
+// in the expected parts of the NavigationEntry in each stage of navigation, and |
+// that we don't kill the renderer on reload. See https://crbug.com/522567. |
IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, LoadDataWithBaseURL) { |
const GURL base_url("http://baseurl"); |
const GURL history_url("http://historyurl"); |
const std::string data = "<html><body>foo</body></html>"; |
+ const GURL data_url = GURL("data:text/html;charset=utf-8," + data); |
- const NavigationController& controller = |
- shell()->web_contents()->GetController(); |
- // Load data. Blocks until it is done. |
- content::LoadDataWithBaseURL(shell(), history_url, data, base_url); |
+ const NavigationControllerImpl& controller = |
+ static_cast<const NavigationControllerImpl&>( |
+ shell()->web_contents()->GetController()); |
+ |
+ // Load data, but don't commit yet. |
+ TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); |
+ shell()->LoadDataWithBaseURL(history_url, data, base_url); |
+ |
+ // Verify the pending NavigationEntry. |
+ NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); |
+ EXPECT_EQ(base_url, pending_entry->GetBaseURLForDataURL()); |
+ EXPECT_EQ(history_url, pending_entry->GetVirtualURL()); |
+ EXPECT_EQ(history_url, pending_entry->GetHistoryURLForDataURL()); |
+ EXPECT_EQ(data_url, pending_entry->GetURL()); |
+ |
+ // Let the navigation commit. |
+ same_tab_observer.Wait(); |
- // We should use history_url instead of the base_url as the original url of |
+ // Verify the last committed NavigationEntry. |
+ NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
+ EXPECT_EQ(base_url, entry->GetBaseURLForDataURL()); |
+ EXPECT_EQ(history_url, entry->GetVirtualURL()); |
+ EXPECT_EQ(history_url, entry->GetHistoryURLForDataURL()); |
+ EXPECT_EQ(data_url, entry->GetURL()); |
+ |
+ // We should use data_url instead of the base_url as the original url of |
// this navigation entry, because base_url is only used for resolving relative |
// paths in the data, or enforcing same origin policy. |
- EXPECT_EQ(controller.GetVisibleEntry()->GetOriginalRequestURL(), history_url); |
+ EXPECT_EQ(data_url, entry->GetOriginalRequestURL()); |
+ |
+ // Now reload and make sure the renderer isn't killed. |
+ ReloadBlockUntilNavigationsComplete(shell(), 1); |
+ EXPECT_TRUE(shell()->web_contents()->GetMainFrame()->IsRenderFrameLive()); |
+ |
+ // Verify the last committed NavigationEntry hasn't changed. |
+ NavigationEntryImpl* reload_entry = controller.GetLastCommittedEntry(); |
+ EXPECT_EQ(entry, reload_entry); |
+ EXPECT_EQ(base_url, reload_entry->GetBaseURLForDataURL()); |
+ EXPECT_EQ(history_url, reload_entry->GetVirtualURL()); |
+ EXPECT_EQ(history_url, reload_entry->GetHistoryURLForDataURL()); |
+ EXPECT_EQ(data_url, reload_entry->GetOriginalRequestURL()); |
+ EXPECT_EQ(data_url, reload_entry->GetURL()); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
+ NavigateFromLoadDataWithBaseURL) { |
+ const GURL base_url("http://baseurl"); |
+ const GURL history_url("http://historyurl"); |
+ const std::string data = |
+ "<html><body>" |
+ " <p id=\"frag\"><a id=\"fraglink\" href=\"#frag\">in-page nav</a></p>" |
Charlie Reis
2015/11/24 19:32:38
Let's leave the fragment out of the test for now.
|
+ "</body></html>"; |
+ const GURL data_url = GURL("data:text/html;charset=utf-8," + data); |
+ |
+ const NavigationControllerImpl& controller = |
+ static_cast<const NavigationControllerImpl&>( |
+ shell()->web_contents()->GetController()); |
+ |
+ // Load data and commit |
Charlie Reis
2015/11/24 19:32:38
nit: End with period.
|
+ { |
+ TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); |
+ shell()->LoadDataWithBaseURL(history_url, data, base_url); |
+ same_tab_observer.Wait(); |
+ EXPECT_EQ(1, controller.GetEntryCount()); |
+ NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
+ EXPECT_EQ(base_url, entry->GetBaseURLForDataURL()); |
+ EXPECT_EQ(history_url, entry->GetVirtualURL()); |
+ EXPECT_EQ(history_url, entry->GetHistoryURLForDataURL()); |
+ EXPECT_EQ(data_url, entry->GetURL()); |
+ } |
+ |
+ { |
+ std::string script = "document.getElementById('fraglink').click()"; |
Charlie Reis
2015/11/24 19:32:38
Let's leave this whole block out for now and just
Charlie Reis
2015/11/24 19:38:19
Actually, don't bother with pushState. pushState
|
+ TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); |
+ EXPECT_TRUE(content::ExecuteScript(shell()->web_contents(), script)); |
+ same_tab_observer.Wait(); |
+ EXPECT_EQ(2, controller.GetEntryCount()); |
+ NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
+ // TODO(boliu): Make these expectations pass. |
+ // EXPECT_EQ(base_url, entry->GetBaseURLForDataURL()); |
+ // EXPECT_EQ(history_url, entry->GetVirtualURL()); |
+ // EXPECT_EQ(history_url, entry->GetHistoryURLForDataURL()); |
+ EXPECT_EQ(data_url, entry->GetURL()); |
+ } |
+ |
+ { |
+ std::string script = "document.location = '" + |
+ embedded_test_server()->base_url().spec() + "';"; |
Charlie Reis
2015/11/24 19:32:38
nit: Store this URL in a local variable that we ca
|
+ TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); |
+ EXPECT_TRUE(content::ExecuteScript(shell()->web_contents(), script)); |
+ same_tab_observer.Wait(); |
+ EXPECT_EQ(3, controller.GetEntryCount()); |
+ NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
+ EXPECT_EQ(GURL(), entry->GetBaseURLForDataURL()); |
Charlie Reis
2015/11/24 19:32:38
nit: EXPECT_TRUE / .is_empty()
|
+ EXPECT_EQ(GURL(), entry->GetHistoryURLForDataURL()); |
Charlie Reis
2015/11/24 19:32:38
nit: EXPECT_TRUE / .is_empty()
|
+ EXPECT_EQ(embedded_test_server()->base_url(), entry->GetVirtualURL()); |
+ EXPECT_EQ(embedded_test_server()->base_url(), entry->GetURL()); |
+ } |
} |
IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, UniqueIDs) { |