Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/frame_host/frame_navigation_entry.h" | 8 #include "content/browser/frame_host/frame_navigation_entry.h" |
| 9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
| 10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 "foo.com", "/navigation_controller/simple_page_1.html")); | 59 "foo.com", "/navigation_controller/simple_page_1.html")); |
| 60 NavigateFrameToURL(root->child_at(0), foo_url); | 60 NavigateFrameToURL(root->child_at(0), foo_url); |
| 61 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 61 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 62 | 62 |
| 63 // We should only have swapped processes in --site-per-process. | 63 // We should only have swapped processes in --site-per-process. |
| 64 bool cross_process = root->current_frame_host()->GetProcess() != | 64 bool cross_process = root->current_frame_host()->GetProcess() != |
| 65 root->child_at(0)->current_frame_host()->GetProcess(); | 65 root->child_at(0)->current_frame_host()->GetProcess(); |
| 66 EXPECT_EQ(AreAllSitesIsolatedForTesting(), cross_process); | 66 EXPECT_EQ(AreAllSitesIsolatedForTesting(), cross_process); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Verifies that the base, history, and data URLs for LoadDataWithBaseURL end up | |
| 70 // in the expected parts of the NavigationEntry in each stage of navigation, and | |
| 71 // that we don't kill the renderer on reload. See https://crbug.com/522567. | |
| 69 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, LoadDataWithBaseURL) { | 72 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, LoadDataWithBaseURL) { |
| 70 const GURL base_url("http://baseurl"); | 73 const GURL base_url("http://baseurl"); |
| 71 const GURL history_url("http://historyurl"); | 74 const GURL history_url("http://historyurl"); |
| 72 const std::string data = "<html><body>foo</body></html>"; | 75 const std::string data = "<html><body>foo</body></html>"; |
| 76 const GURL data_url = GURL("data:text/html;charset=utf-8," + data); | |
| 73 | 77 |
| 74 const NavigationController& controller = | 78 const NavigationControllerImpl& controller = |
| 75 shell()->web_contents()->GetController(); | 79 static_cast<const NavigationControllerImpl&>( |
| 76 // Load data. Blocks until it is done. | 80 shell()->web_contents()->GetController()); |
| 77 content::LoadDataWithBaseURL(shell(), history_url, data, base_url); | |
| 78 | 81 |
| 79 // We should use history_url instead of the base_url as the original url of | 82 // Load data, but don't commit yet. |
| 83 TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); | |
| 84 shell()->LoadDataWithBaseURL(history_url, data, base_url); | |
| 85 | |
| 86 // Verify the pending NavigationEntry. | |
| 87 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); | |
| 88 EXPECT_EQ(base_url, pending_entry->GetBaseURLForDataURL()); | |
| 89 EXPECT_EQ(history_url, pending_entry->GetVirtualURL()); | |
| 90 EXPECT_EQ(history_url, pending_entry->GetHistoryURLForDataURL()); | |
| 91 EXPECT_EQ(data_url, pending_entry->GetURL()); | |
| 92 | |
| 93 // Let the navigation commit. | |
| 94 same_tab_observer.Wait(); | |
| 95 | |
| 96 // Verify the last committed NavigationEntry. | |
| 97 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); | |
| 98 EXPECT_EQ(base_url, entry->GetBaseURLForDataURL()); | |
| 99 EXPECT_EQ(history_url, entry->GetVirtualURL()); | |
| 100 EXPECT_EQ(history_url, entry->GetHistoryURLForDataURL()); | |
| 101 EXPECT_EQ(data_url, entry->GetURL()); | |
| 102 | |
| 103 // We should use data_url instead of the base_url as the original url of | |
| 80 // this navigation entry, because base_url is only used for resolving relative | 104 // this navigation entry, because base_url is only used for resolving relative |
| 81 // paths in the data, or enforcing same origin policy. | 105 // paths in the data, or enforcing same origin policy. |
| 82 EXPECT_EQ(controller.GetVisibleEntry()->GetOriginalRequestURL(), history_url); | 106 EXPECT_EQ(data_url, entry->GetOriginalRequestURL()); |
| 107 | |
| 108 // Now reload and make sure the renderer isn't killed. | |
| 109 ReloadBlockUntilNavigationsComplete(shell(), 1); | |
| 110 EXPECT_TRUE(shell()->web_contents()->GetMainFrame()->IsRenderFrameLive()); | |
| 111 | |
| 112 // Verify the last committed NavigationEntry hasn't changed. | |
| 113 NavigationEntryImpl* reload_entry = controller.GetLastCommittedEntry(); | |
| 114 EXPECT_EQ(entry, reload_entry); | |
| 115 EXPECT_EQ(base_url, reload_entry->GetBaseURLForDataURL()); | |
| 116 EXPECT_EQ(history_url, reload_entry->GetVirtualURL()); | |
| 117 EXPECT_EQ(history_url, reload_entry->GetHistoryURLForDataURL()); | |
| 118 EXPECT_EQ(data_url, reload_entry->GetOriginalRequestURL()); | |
| 119 EXPECT_EQ(data_url, reload_entry->GetURL()); | |
| 120 } | |
| 121 | |
| 122 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 123 NavigateFromLoadDataWithBaseURL) { | |
| 124 const GURL base_url("http://baseurl"); | |
| 125 const GURL history_url("http://historyurl"); | |
| 126 const std::string data = | |
| 127 "<html><body>" | |
| 128 " <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.
| |
| 129 "</body></html>"; | |
| 130 const GURL data_url = GURL("data:text/html;charset=utf-8," + data); | |
| 131 | |
| 132 const NavigationControllerImpl& controller = | |
| 133 static_cast<const NavigationControllerImpl&>( | |
| 134 shell()->web_contents()->GetController()); | |
| 135 | |
| 136 // Load data and commit | |
|
Charlie Reis
2015/11/24 19:32:38
nit: End with period.
| |
| 137 { | |
| 138 TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); | |
| 139 shell()->LoadDataWithBaseURL(history_url, data, base_url); | |
| 140 same_tab_observer.Wait(); | |
| 141 EXPECT_EQ(1, controller.GetEntryCount()); | |
| 142 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); | |
| 143 EXPECT_EQ(base_url, entry->GetBaseURLForDataURL()); | |
| 144 EXPECT_EQ(history_url, entry->GetVirtualURL()); | |
| 145 EXPECT_EQ(history_url, entry->GetHistoryURLForDataURL()); | |
| 146 EXPECT_EQ(data_url, entry->GetURL()); | |
| 147 } | |
| 148 | |
| 149 { | |
| 150 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
| |
| 151 TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); | |
| 152 EXPECT_TRUE(content::ExecuteScript(shell()->web_contents(), script)); | |
| 153 same_tab_observer.Wait(); | |
| 154 EXPECT_EQ(2, controller.GetEntryCount()); | |
| 155 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); | |
| 156 // TODO(boliu): Make these expectations pass. | |
| 157 // EXPECT_EQ(base_url, entry->GetBaseURLForDataURL()); | |
| 158 // EXPECT_EQ(history_url, entry->GetVirtualURL()); | |
| 159 // EXPECT_EQ(history_url, entry->GetHistoryURLForDataURL()); | |
| 160 EXPECT_EQ(data_url, entry->GetURL()); | |
| 161 } | |
| 162 | |
| 163 { | |
| 164 std::string script = "document.location = '" + | |
| 165 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
| |
| 166 TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); | |
| 167 EXPECT_TRUE(content::ExecuteScript(shell()->web_contents(), script)); | |
| 168 same_tab_observer.Wait(); | |
| 169 EXPECT_EQ(3, controller.GetEntryCount()); | |
| 170 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); | |
| 171 EXPECT_EQ(GURL(), entry->GetBaseURLForDataURL()); | |
|
Charlie Reis
2015/11/24 19:32:38
nit: EXPECT_TRUE / .is_empty()
| |
| 172 EXPECT_EQ(GURL(), entry->GetHistoryURLForDataURL()); | |
|
Charlie Reis
2015/11/24 19:32:38
nit: EXPECT_TRUE / .is_empty()
| |
| 173 EXPECT_EQ(embedded_test_server()->base_url(), entry->GetVirtualURL()); | |
| 174 EXPECT_EQ(embedded_test_server()->base_url(), entry->GetURL()); | |
| 175 } | |
| 83 } | 176 } |
| 84 | 177 |
| 85 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, UniqueIDs) { | 178 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, UniqueIDs) { |
| 86 const NavigationControllerImpl& controller = | 179 const NavigationControllerImpl& controller = |
| 87 static_cast<const NavigationControllerImpl&>( | 180 static_cast<const NavigationControllerImpl&>( |
| 88 shell()->web_contents()->GetController()); | 181 shell()->web_contents()->GetController()); |
| 89 | 182 |
| 90 GURL main_url(embedded_test_server()->GetURL( | 183 GURL main_url(embedded_test_server()->GetURL( |
| 91 "/navigation_controller/page_with_link_to_load_iframe.html")); | 184 "/navigation_controller/page_with_link_to_load_iframe.html")); |
| 92 NavigateToURL(shell(), main_url); | 185 NavigateToURL(shell(), main_url); |
| (...skipping 2425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2518 EXPECT_EQ(original_url, capturer.all_params()[1].url); | 2611 EXPECT_EQ(original_url, capturer.all_params()[1].url); |
| 2519 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); | 2612 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
| 2520 } | 2613 } |
| 2521 | 2614 |
| 2522 // Make sure the renderer is still alive. | 2615 // Make sure the renderer is still alive. |
| 2523 EXPECT_TRUE( | 2616 EXPECT_TRUE( |
| 2524 ExecuteScript(shell()->web_contents(), "console.log('Success');")); | 2617 ExecuteScript(shell()->web_contents(), "console.log('Success');")); |
| 2525 } | 2618 } |
| 2526 | 2619 |
| 2527 } // namespace content | 2620 } // namespace content |
| OLD | NEW |