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 = "<html><body></body></html>"; |
| 127 const GURL data_url = GURL("data:text/html;charset=utf-8," + data); |
| 128 |
| 129 const NavigationControllerImpl& controller = |
| 130 static_cast<const NavigationControllerImpl&>( |
| 131 shell()->web_contents()->GetController()); |
| 132 |
| 133 // Load data and commit. |
| 134 { |
| 135 TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); |
| 136 shell()->LoadDataWithBaseURL(history_url, data, base_url); |
| 137 same_tab_observer.Wait(); |
| 138 EXPECT_EQ(1, controller.GetEntryCount()); |
| 139 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
| 140 EXPECT_EQ(base_url, entry->GetBaseURLForDataURL()); |
| 141 EXPECT_EQ(history_url, entry->GetVirtualURL()); |
| 142 EXPECT_EQ(history_url, entry->GetHistoryURLForDataURL()); |
| 143 EXPECT_EQ(data_url, entry->GetURL()); |
| 144 } |
| 145 |
| 146 // TODO(boliu): Add test for in-page fragment navigation. See |
| 147 // crbug.com/561034. |
| 148 |
| 149 // Navigate with Javascript. |
| 150 { |
| 151 GURL navigate_url = embedded_test_server()->base_url(); |
| 152 std::string script = "document.location = '" + |
| 153 navigate_url.spec() + "';"; |
| 154 TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); |
| 155 EXPECT_TRUE(content::ExecuteScript(shell()->web_contents(), script)); |
| 156 same_tab_observer.Wait(); |
| 157 EXPECT_EQ(2, controller.GetEntryCount()); |
| 158 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
| 159 EXPECT_TRUE(entry->GetBaseURLForDataURL().is_empty()); |
| 160 EXPECT_TRUE(entry->GetHistoryURLForDataURL().is_empty()); |
| 161 EXPECT_EQ(navigate_url, entry->GetVirtualURL()); |
| 162 EXPECT_EQ(navigate_url, entry->GetURL()); |
| 163 } |
83 } | 164 } |
84 | 165 |
85 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, UniqueIDs) { | 166 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, UniqueIDs) { |
86 const NavigationControllerImpl& controller = | 167 const NavigationControllerImpl& controller = |
87 static_cast<const NavigationControllerImpl&>( | 168 static_cast<const NavigationControllerImpl&>( |
88 shell()->web_contents()->GetController()); | 169 shell()->web_contents()->GetController()); |
89 | 170 |
90 GURL main_url(embedded_test_server()->GetURL( | 171 GURL main_url(embedded_test_server()->GetURL( |
91 "/navigation_controller/page_with_link_to_load_iframe.html")); | 172 "/navigation_controller/page_with_link_to_load_iframe.html")); |
92 NavigateToURL(shell(), main_url); | 173 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); | 2599 EXPECT_EQ(original_url, capturer.all_params()[1].url); |
2519 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); | 2600 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
2520 } | 2601 } |
2521 | 2602 |
2522 // Make sure the renderer is still alive. | 2603 // Make sure the renderer is still alive. |
2523 EXPECT_TRUE( | 2604 EXPECT_TRUE( |
2524 ExecuteScript(shell()->web_contents(), "console.log('Success');")); | 2605 ExecuteScript(shell()->web_contents(), "console.log('Success');")); |
2525 } | 2606 } |
2526 | 2607 |
2527 } // namespace content | 2608 } // namespace content |
OLD | NEW |