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 "content/browser/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 6134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6145 web_contents->GetMainFrame()->GetProcess()->AddFilter(filter.get()); | 6145 web_contents->GetMainFrame()->GetProcess()->AddFilter(filter.get()); |
6146 | 6146 |
6147 // Navigate cross-origin, waiting for the commit to occur. | 6147 // Navigate cross-origin, waiting for the commit to occur. |
6148 UrlCommitObserver cross_origin_commit_observer(root, cross_origin_url); | 6148 UrlCommitObserver cross_origin_commit_observer(root, cross_origin_url); |
6149 UrlCommitObserver history_commit_observer(root, start_url); | 6149 UrlCommitObserver history_commit_observer(root, start_url); |
6150 shell()->LoadURL(cross_origin_url); | 6150 shell()->LoadURL(cross_origin_url); |
6151 cross_origin_commit_observer.Wait(); | 6151 cross_origin_commit_observer.Wait(); |
6152 EXPECT_EQ(cross_origin_url, web_contents->GetLastCommittedURL()); | 6152 EXPECT_EQ(cross_origin_url, web_contents->GetLastCommittedURL()); |
6153 EXPECT_EQ(2, web_contents->GetController().GetLastCommittedEntryIndex()); | 6153 EXPECT_EQ(2, web_contents->GetController().GetLastCommittedEntryIndex()); |
6154 | 6154 |
6155 // Wait for the back navigation to commit as well. | 6155 if (IsBrowserSideNavigationEnabled()) { |
6156 history_commit_observer.Wait(); | 6156 // With browser-side-navigation, the history navigation is dropped. |
6157 EXPECT_EQ(start_url, web_contents->GetLastCommittedURL()); | 6157 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
6158 EXPECT_EQ(0, web_contents->GetController().GetLastCommittedEntryIndex()); | 6158 EXPECT_EQ(2, web_contents->GetController().GetLastCommittedEntryIndex()); |
| 6159 EXPECT_EQ(3, web_contents->GetController().GetEntryCount()); |
6159 | 6160 |
6160 // Verify the expected origin through JavaScript. It also has the additional | 6161 // Verify the expected origin through JavaScript. It also has the additional |
6161 // verification of the process also being still alive. | 6162 // verification of the process also being still alive. |
6162 std::string origin; | 6163 std::string origin; |
6163 EXPECT_TRUE(ExecuteScriptAndExtractString( | 6164 EXPECT_TRUE(ExecuteScriptAndExtractString( |
6164 web_contents, "domAutomationController.send(document.origin)", &origin)); | 6165 web_contents, "domAutomationController.send(document.origin)", |
6165 EXPECT_EQ(start_url.GetOrigin().spec(), origin + "/"); | 6166 &origin)); |
| 6167 EXPECT_EQ(cross_origin_url.GetOrigin().spec(), origin + "/"); |
| 6168 |
| 6169 // Navigate back again. |
| 6170 web_contents->GetController().GoBack(); |
| 6171 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 6172 EXPECT_EQ(1, web_contents->GetController().GetLastCommittedEntryIndex()); |
| 6173 EXPECT_EQ(3, web_contents->GetController().GetEntryCount()); |
| 6174 |
| 6175 // Verify the expected origin through JavaScript. It also has the additional |
| 6176 // verification of the process also being still alive. |
| 6177 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 6178 web_contents, "domAutomationController.send(document.origin)", |
| 6179 &origin)); |
| 6180 EXPECT_EQ(same_page_url.GetOrigin().spec(), origin + "/"); |
| 6181 } else { |
| 6182 // Wait for the back navigation to commit as well. |
| 6183 history_commit_observer.Wait(); |
| 6184 EXPECT_EQ(start_url, web_contents->GetLastCommittedURL()); |
| 6185 EXPECT_EQ(0, web_contents->GetController().GetLastCommittedEntryIndex()); |
| 6186 EXPECT_EQ(3, web_contents->GetController().GetEntryCount()); |
| 6187 |
| 6188 // Verify the expected origin through JavaScript. It also has the additional |
| 6189 // verification of the process also being still alive. |
| 6190 std::string origin; |
| 6191 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 6192 web_contents, "domAutomationController.send(document.origin)", |
| 6193 &origin)); |
| 6194 EXPECT_EQ(start_url.GetOrigin().spec(), origin + "/"); |
| 6195 } |
6166 } | 6196 } |
6167 | 6197 |
6168 // Test that verifies that Referer and Origin http headers are correctly sent | 6198 // Test that verifies that Referer and Origin http headers are correctly sent |
6169 // to the final destination of a cross-site POST with a few redirects thrown in. | 6199 // to the final destination of a cross-site POST with a few redirects thrown in. |
6170 // This test is somewhat related to https://crbug.com/635400. | 6200 // This test is somewhat related to https://crbug.com/635400. |
6171 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 6201 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
6172 RefererAndOriginHeadersAfterRedirects) { | 6202 RefererAndOriginHeadersAfterRedirects) { |
6173 // Navigate to the page with form that posts via 307 redirection to | 6203 // Navigate to the page with form that posts via 307 redirection to |
6174 // |redirect_target_url| (cross-site from |form_url|). Using 307 (rather than | 6204 // |redirect_target_url| (cross-site from |form_url|). Using 307 (rather than |
6175 // 302) redirection is important to preserve the HTTP method and POST body. | 6205 // 302) redirection is important to preserve the HTTP method and POST body. |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6697 NavigationHandleCommitObserver handle_observer(shell()->web_contents(), | 6727 NavigationHandleCommitObserver handle_observer(shell()->web_contents(), |
6698 kFragmentURL); | 6728 kFragmentURL); |
6699 EXPECT_TRUE(NavigateToURL(shell(), kFragmentURL)); | 6729 EXPECT_TRUE(NavigateToURL(shell(), kFragmentURL)); |
6700 | 6730 |
6701 EXPECT_TRUE(handle_observer.has_committed()); | 6731 EXPECT_TRUE(handle_observer.has_committed()); |
6702 EXPECT_TRUE(handle_observer.was_same_page()); | 6732 EXPECT_TRUE(handle_observer.was_same_page()); |
6703 EXPECT_FALSE(handle_observer.was_renderer_initiated()); | 6733 EXPECT_FALSE(handle_observer.was_renderer_initiated()); |
6704 } | 6734 } |
6705 | 6735 |
6706 } // namespace content | 6736 } // namespace content |
OLD | NEW |