| 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/macros.h" | 5 #include "base/macros.h" |
| 6 #include "content/public/browser/navigation_handle.h" | 6 #include "content/public/browser/navigation_handle.h" |
| 7 #include "content/public/browser/resource_request_details.h" | 7 #include "content/public/browser/resource_request_details.h" |
| 8 #include "content/public/test/browser_test_utils.h" | 8 #include "content/public/test/browser_test_utils.h" |
| 9 #include "content/public/test/content_browser_test.h" | 9 #include "content/public/test/content_browser_test.h" |
| 10 #include "content/public/test/content_browser_test_utils.h" | 10 #include "content/public/test/content_browser_test_utils.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 private: | 40 private: |
| 41 GURL redirect_url_; | 41 GURL redirect_url_; |
| 42 GURL navigation_url_; | 42 GURL navigation_url_; |
| 43 | 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(NavigationObserver); | 44 DISALLOW_COPY_AND_ASSIGN(NavigationObserver); |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 class CrossSiteRedirectorBrowserTest : public ContentBrowserTest { | 47 class CrossSiteRedirectorBrowserTest : public ContentBrowserTest { |
| 48 public: | 48 public: |
| 49 CrossSiteRedirectorBrowserTest() {} | 49 CrossSiteRedirectorBrowserTest() {} |
| 50 |
| 51 void SetUpOnMainThread() override { |
| 52 // Map all hosts to localhost and setup the EmbeddedTestServer for |
| 53 // redirects. |
| 54 host_resolver()->AddRule("*", "127.0.0.1"); |
| 55 } |
| 50 }; | 56 }; |
| 51 | 57 |
| 52 IN_PROC_BROWSER_TEST_F(CrossSiteRedirectorBrowserTest, | 58 IN_PROC_BROWSER_TEST_F(CrossSiteRedirectorBrowserTest, |
| 53 VerifyCrossSiteRedirectURL) { | 59 VerifyCrossSiteRedirectURL) { |
| 54 // Map all hosts to localhost and setup the EmbeddedTestServer for redirects. | |
| 55 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 56 SetupCrossSiteRedirector(embedded_test_server()); | 60 SetupCrossSiteRedirector(embedded_test_server()); |
| 57 ASSERT_TRUE(embedded_test_server()->Start()); | 61 ASSERT_TRUE(embedded_test_server()->Start()); |
| 58 | 62 |
| 59 // Navigate to http://localhost:<port>/cross-site/foo.com/title2.html and | 63 // Navigate to http://localhost:<port>/cross-site/foo.com/title2.html and |
| 60 // ensure that the redirector forwards the navigation to | 64 // ensure that the redirector forwards the navigation to |
| 61 // http://foo.com:<port>/title2.html | 65 // http://foo.com:<port>/title2.html |
| 62 NavigationObserver observer(shell()->web_contents()); | 66 NavigationObserver observer(shell()->web_contents()); |
| 63 NavigateToURL( | 67 NavigateToURL( |
| 64 shell(), | 68 shell(), |
| 65 embedded_test_server()->GetURL("/cross-site/foo.com/title2.html")); | 69 embedded_test_server()->GetURL("/cross-site/foo.com/title2.html")); |
| 66 | 70 |
| 67 // The expectation is that the cross-site redirector will take the | 71 // The expectation is that the cross-site redirector will take the |
| 68 // hostname supplied in the URL and rewrite the URL. Build the | 72 // hostname supplied in the URL and rewrite the URL. Build the |
| 69 // expected URL to ensure navigation was properly redirected. | 73 // expected URL to ensure navigation was properly redirected. |
| 70 GURL::Replacements replace_host; | 74 GURL::Replacements replace_host; |
| 71 GURL expected_url(embedded_test_server()->GetURL("/title2.html")); | 75 GURL expected_url(embedded_test_server()->GetURL("/title2.html")); |
| 72 replace_host.SetHostStr("foo.com"); | 76 replace_host.SetHostStr("foo.com"); |
| 73 expected_url = expected_url.ReplaceComponents(replace_host); | 77 expected_url = expected_url.ReplaceComponents(replace_host); |
| 74 | 78 |
| 75 EXPECT_EQ(expected_url, observer.navigation_url()); | 79 EXPECT_EQ(expected_url, observer.navigation_url()); |
| 76 EXPECT_EQ(observer.redirect_url(), observer.navigation_url()); | 80 EXPECT_EQ(observer.redirect_url(), observer.navigation_url()); |
| 77 } | 81 } |
| 78 | 82 |
| 79 } // namespace content | 83 } // namespace content |
| OLD | NEW |