OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/ref_counted.h" | 7 #include "base/ref_counted.h" |
8 #include "base/stringprintf.h" | |
9 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
10 #include "chrome/browser/download/download_manager.h" | 9 #include "chrome/browser/download/download_manager.h" |
11 #include "chrome/browser/extensions/extension_error_reporter.h" | 10 #include "chrome/browser/extensions/extension_error_reporter.h" |
12 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
13 #include "chrome/browser/renderer_host/site_instance.h" | 12 #include "chrome/browser/renderer_host/site_instance.h" |
14 #include "chrome/browser/tab_contents/tab_contents.h" | 13 #include "chrome/browser/tab_contents/tab_contents.h" |
15 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/notification_details.h" | 16 #include "chrome/common/notification_details.h" |
18 #include "chrome/common/notification_observer.h" | 17 #include "chrome/common/notification_observer.h" |
19 #include "chrome/common/notification_registrar.h" | 18 #include "chrome/common/notification_registrar.h" |
20 #include "chrome/common/notification_service.h" | 19 #include "chrome/common/notification_service.h" |
21 #include "chrome/common/notification_type.h" | 20 #include "chrome/common/notification_type.h" |
22 #include "chrome/test/in_process_browser_test.h" | 21 #include "chrome/test/in_process_browser_test.h" |
23 #include "chrome/test/ui_test_utils.h" | 22 #include "chrome/test/ui_test_utils.h" |
24 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
25 #include "net/test/test_server.h" | 24 #include "net/test/test_server.h" |
26 | 25 |
27 class RenderViewHostManagerTest : public InProcessBrowserTest { | 26 class RenderViewHostManagerTest : public InProcessBrowserTest { |
28 public: | 27 public: |
29 RenderViewHostManagerTest() { | 28 RenderViewHostManagerTest() { |
30 EnableDOMAutomation(); | 29 EnableDOMAutomation(); |
31 } | 30 } |
32 | 31 |
33 std::string GetFileWithHostAndPortReplacement( | 32 static bool GetFilePathWithHostAndPortReplacement( |
34 const std::string& original_path, | 33 const std::string& original_file_path, |
35 const net::HostPortPair& host_port_pair) const { | 34 const net::HostPortPair& host_port_pair, |
36 return StringPrintf("%s?replace_orig=%s&replace_new=%s", | 35 std::string* replacement_path) { |
37 original_path.c_str(), | 36 std::vector<std::string> replacement_text; |
38 kReplaceText_, | 37 replacement_text.push_back("REPLACE_WITH_HOST_AND_PORT"); |
39 host_port_pair.ToString().c_str()); | 38 replacement_text.push_back(host_port_pair.ToString()); |
| 39 return net::TestServer::GetFilePathWithReplacements( |
| 40 original_file_path, replacement_text, replacement_path); |
40 } | 41 } |
41 | |
42 private: | |
43 static const char* const kReplaceText_; | |
44 }; | 42 }; |
45 | 43 |
46 // static | |
47 const char* const RenderViewHostManagerTest::kReplaceText_ = | |
48 "REPLACE_WITH_HOST_AND_PORT"; | |
49 | |
50 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer | 44 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
51 // and target=_blank should create a new SiteInstance. | 45 // and target=_blank should create a new SiteInstance. |
52 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 46 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
53 SwapProcessWithRelNoreferrerAndTargetBlank) { | 47 SwapProcessWithRelNoreferrerAndTargetBlank) { |
54 // Start two servers with different sites. | 48 // Start two servers with different sites. |
55 ASSERT_TRUE(test_server()->Start()); | 49 ASSERT_TRUE(test_server()->Start()); |
56 net::TestServer https_server_( | 50 net::TestServer https_server_( |
57 net::TestServer::TYPE_HTTPS, | 51 net::TestServer::TYPE_HTTPS, |
58 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 52 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
59 ASSERT_TRUE(https_server_.Start()); | 53 ASSERT_TRUE(https_server_.Start()); |
60 | 54 |
61 // Load a page with links that open in a new window. | 55 // Load a page with links that open in a new window. |
62 std::string replacement_path = GetFileWithHostAndPortReplacement( | 56 std::string replacement_path; |
| 57 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
63 "files/click-noreferrer-links.html", | 58 "files/click-noreferrer-links.html", |
64 https_server_.host_port_pair()); | 59 https_server_.host_port_pair(), |
| 60 &replacement_path)); |
65 ui_test_utils::NavigateToURL(browser(), | 61 ui_test_utils::NavigateToURL(browser(), |
66 test_server()->GetURL(replacement_path)); | 62 test_server()->GetURL(replacement_path)); |
67 | 63 |
68 // Get the original SiteInstance for later comparison. | 64 // Get the original SiteInstance for later comparison. |
69 scoped_refptr<SiteInstance> orig_site_instance( | 65 scoped_refptr<SiteInstance> orig_site_instance( |
70 browser()->GetSelectedTabContents()->GetSiteInstance()); | 66 browser()->GetSelectedTabContents()->GetSiteInstance()); |
71 EXPECT_TRUE(orig_site_instance != NULL); | 67 EXPECT_TRUE(orig_site_instance != NULL); |
72 | 68 |
73 // Test clicking a rel=noreferrer + target=blank link. | 69 // Test clicking a rel=noreferrer + target=blank link. |
74 bool success = false; | 70 bool success = false; |
(...skipping 23 matching lines...) Expand all Loading... |
98 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 94 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
99 DontSwapProcessWithOnlyTargetBlank) { | 95 DontSwapProcessWithOnlyTargetBlank) { |
100 // Start two servers with different sites. | 96 // Start two servers with different sites. |
101 ASSERT_TRUE(test_server()->Start()); | 97 ASSERT_TRUE(test_server()->Start()); |
102 net::TestServer https_server_( | 98 net::TestServer https_server_( |
103 net::TestServer::TYPE_HTTPS, | 99 net::TestServer::TYPE_HTTPS, |
104 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 100 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
105 ASSERT_TRUE(https_server_.Start()); | 101 ASSERT_TRUE(https_server_.Start()); |
106 | 102 |
107 // Load a page with links that open in a new window. | 103 // Load a page with links that open in a new window. |
108 std::string replacement_path = GetFileWithHostAndPortReplacement( | 104 std::string replacement_path; |
| 105 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
109 "files/click-noreferrer-links.html", | 106 "files/click-noreferrer-links.html", |
110 https_server_.host_port_pair()); | 107 https_server_.host_port_pair(), |
| 108 &replacement_path)); |
111 ui_test_utils::NavigateToURL(browser(), | 109 ui_test_utils::NavigateToURL(browser(), |
112 test_server()->GetURL(replacement_path)); | 110 test_server()->GetURL(replacement_path)); |
113 | 111 |
114 // Get the original SiteInstance for later comparison. | 112 // Get the original SiteInstance for later comparison. |
115 scoped_refptr<SiteInstance> orig_site_instance( | 113 scoped_refptr<SiteInstance> orig_site_instance( |
116 browser()->GetSelectedTabContents()->GetSiteInstance()); | 114 browser()->GetSelectedTabContents()->GetSiteInstance()); |
117 EXPECT_TRUE(orig_site_instance != NULL); | 115 EXPECT_TRUE(orig_site_instance != NULL); |
118 | 116 |
119 // Test clicking a target=blank link. | 117 // Test clicking a target=blank link. |
120 bool success = false; | 118 bool success = false; |
(...skipping 23 matching lines...) Expand all Loading... |
144 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 142 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
145 DontSwapProcessWithOnlyRelNoreferrer) { | 143 DontSwapProcessWithOnlyRelNoreferrer) { |
146 // Start two servers with different sites. | 144 // Start two servers with different sites. |
147 ASSERT_TRUE(test_server()->Start()); | 145 ASSERT_TRUE(test_server()->Start()); |
148 net::TestServer https_server_( | 146 net::TestServer https_server_( |
149 net::TestServer::TYPE_HTTPS, | 147 net::TestServer::TYPE_HTTPS, |
150 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 148 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
151 ASSERT_TRUE(https_server_.Start()); | 149 ASSERT_TRUE(https_server_.Start()); |
152 | 150 |
153 // Load a page with links that open in a new window. | 151 // Load a page with links that open in a new window. |
154 std::string replacement_path = GetFileWithHostAndPortReplacement( | 152 std::string replacement_path; |
| 153 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
155 "files/click-noreferrer-links.html", | 154 "files/click-noreferrer-links.html", |
156 https_server_.host_port_pair()); | 155 https_server_.host_port_pair(), |
| 156 &replacement_path)); |
157 ui_test_utils::NavigateToURL(browser(), | 157 ui_test_utils::NavigateToURL(browser(), |
158 test_server()->GetURL(replacement_path)); | 158 test_server()->GetURL(replacement_path)); |
159 | 159 |
160 // Get the original SiteInstance for later comparison. | 160 // Get the original SiteInstance for later comparison. |
161 scoped_refptr<SiteInstance> orig_site_instance( | 161 scoped_refptr<SiteInstance> orig_site_instance( |
162 browser()->GetSelectedTabContents()->GetSiteInstance()); | 162 browser()->GetSelectedTabContents()->GetSiteInstance()); |
163 EXPECT_TRUE(orig_site_instance != NULL); | 163 EXPECT_TRUE(orig_site_instance != NULL); |
164 | 164 |
165 // Test clicking a rel=noreferrer link. | 165 // Test clicking a rel=noreferrer link. |
166 bool success = false; | 166 bool success = false; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 &result)); | 269 &result)); |
270 EXPECT_TRUE(result); | 270 EXPECT_TRUE(result); |
271 ui_test_utils::NavigateToURL(browser(), zip_url); | 271 ui_test_utils::NavigateToURL(browser(), zip_url); |
272 | 272 |
273 ui_test_utils::WaitForDownloadCount( | 273 ui_test_utils::WaitForDownloadCount( |
274 browser()->profile()->GetDownloadManager(), 1); | 274 browser()->profile()->GetDownloadManager(), 1); |
275 | 275 |
276 browser()->CloseWindow(); | 276 browser()->CloseWindow(); |
277 BrowserClosedObserver wait_for_close(browser()); | 277 BrowserClosedObserver wait_for_close(browser()); |
278 } | 278 } |
OLD | NEW |