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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/browser/frame_host/navigation_handle_impl.h" | |
| 11 #include "content/browser/frame_host/navigation_request.h" | |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
| 11 #include "content/common/site_isolation_policy.h" | 13 #include "content/common/site_isolation_policy.h" |
| 12 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
| 13 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 15 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
| 16 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
| 17 #include "content/public/test/content_browser_test.h" | 19 #include "content/public/test/content_browser_test.h" |
| 18 #include "content/public/test/content_browser_test_utils.h" | 20 #include "content/public/test/content_browser_test_utils.h" |
| 19 #include "content/public/test/test_navigation_observer.h" | 21 #include "content/public/test/test_navigation_observer.h" |
| 20 #include "content/shell/browser/shell.h" | 22 #include "content/shell/browser/shell.h" |
| 23 #include "content/shell/browser/shell_network_delegate.h" | |
| 21 #include "net/dns/mock_host_resolver.h" | 24 #include "net/dns/mock_host_resolver.h" |
| 22 #include "net/test/embedded_test_server/embedded_test_server.h" | 25 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 23 #include "net/test/url_request/url_request_failed_job.h" | 26 #include "net/test/url_request/url_request_failed_job.h" |
| 24 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 25 | 28 |
| 26 namespace content { | 29 namespace content { |
| 27 | 30 |
| 28 class BrowserSideNavigationBrowserTest : public ContentBrowserTest { | 31 class BrowserSideNavigationBrowserTest : public ContentBrowserTest { |
| 29 public: | 32 public: |
| 30 BrowserSideNavigationBrowserTest() {} | 33 BrowserSideNavigationBrowserTest() {} |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, | 280 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, |
| 278 UnloadDuringNavigation) { | 281 UnloadDuringNavigation) { |
| 279 content::WindowedNotificationObserver close_observer( | 282 content::WindowedNotificationObserver close_observer( |
| 280 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 283 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 281 content::Source<content::WebContents>(shell()->web_contents())); | 284 content::Source<content::WebContents>(shell()->web_contents())); |
| 282 shell()->LoadURL(GURL("chrome://resources/css/tabs.css")); | 285 shell()->LoadURL(GURL("chrome://resources/css/tabs.css")); |
| 283 shell()->web_contents()->DispatchBeforeUnload(); | 286 shell()->web_contents()->DispatchBeforeUnload(); |
| 284 close_observer.Wait(); | 287 close_observer.Wait(); |
| 285 } | 288 } |
| 286 | 289 |
| 290 // Ensure that the referrer of a navigation is properly sanitized. | |
| 291 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, SanitizeReferrer) { | |
| 292 const GURL kInsecureUrl(embedded_test_server()->GetURL("/title1.html")); | |
| 293 const Referrer kSecureReferrer( | |
| 294 GURL("https://secure-url.com"), | |
| 295 blink::WebReferrerPolicyNoReferrerWhenDowngrade); | |
| 296 ShellNetworkDelegate::SetCancelURLRequestWithPolicyViolatingReferrerHeader( | |
| 297 true); | |
| 298 | |
| 299 // Navigate to an insecure url with a secure referrer with a policy of no | |
| 300 // referrer on downgrades. The referrer url should be rewritten right away. | |
| 301 NavigationController::LoadURLParams load_params(kInsecureUrl); | |
| 302 load_params.referrer = kSecureReferrer; | |
| 303 TestNavigationManager manager(shell()->web_contents(), kInsecureUrl); | |
| 304 shell()->web_contents()->GetController().LoadURLWithParams(load_params); | |
| 305 EXPECT_TRUE(manager.WaitForRequestStart()); | |
| 306 | |
| 307 // The referrer should have been sanitized. | |
| 308 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 309 ->GetMainFrame() | |
| 310 ->frame_tree_node(); | |
| 311 CHECK(root->navigation_request()); | |
|
nasko
2017/03/22 17:11:12
nit: ASSERT_TRUE
clamy
2017/03/22 17:18:57
Done.
| |
| 312 EXPECT_EQ(GURL(), | |
| 313 root->navigation_request()->navigation_handle()->GetReferrer().url); | |
| 314 | |
| 315 // The navigation should commit without being blocked. | |
| 316 EXPECT_TRUE(manager.WaitForResponse()); | |
| 317 manager.WaitForNavigationFinished(); | |
| 318 NavigationEntry* entry = | |
| 319 shell()->web_contents()->GetController().GetLastCommittedEntry(); | |
| 320 CHECK(entry); | |
|
nasko
2017/03/22 17:11:12
nit: ASSERT_TRUE
clamy
2017/03/22 17:18:57
Done.
| |
| 321 EXPECT_EQ(kInsecureUrl, entry->GetURL()); | |
|
nasko
2017/03/22 17:11:12
nit: You could just call WebContents::GetLastCommi
clamy
2017/03/22 17:18:57
Done.
| |
| 322 } | |
| 323 | |
| 287 } // namespace content | 324 } // namespace content |
| OLD | NEW |