OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
11 #include "content/browser/renderer_host/render_view_host.h" | 11 #include "content/browser/renderer_host/render_view_host.h" |
12 #include "content/browser/site_instance.h" | 12 #include "content/browser/site_instance_impl.h" |
13 #include "content/browser/tab_contents/tab_contents.h" | 13 #include "content/browser/tab_contents/tab_contents.h" |
14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
17 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
18 #include "content/public/browser/render_view_host_observer.h" | 18 #include "content/public/browser/render_view_host_observer.h" |
19 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
20 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
21 #include "net/test/test_server.h" | 21 #include "net/test/test_server.h" |
22 | 22 |
(...skipping 29 matching lines...) Expand all Loading... |
52 // Load a page with links that open in a new window. | 52 // Load a page with links that open in a new window. |
53 std::string replacement_path; | 53 std::string replacement_path; |
54 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 54 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
55 "files/click-noreferrer-links.html", | 55 "files/click-noreferrer-links.html", |
56 https_server.host_port_pair(), | 56 https_server.host_port_pair(), |
57 &replacement_path)); | 57 &replacement_path)); |
58 ui_test_utils::NavigateToURL(browser(), | 58 ui_test_utils::NavigateToURL(browser(), |
59 test_server()->GetURL(replacement_path)); | 59 test_server()->GetURL(replacement_path)); |
60 | 60 |
61 // Get the original SiteInstance for later comparison. | 61 // Get the original SiteInstance for later comparison. |
62 scoped_refptr<SiteInstance> orig_site_instance( | 62 scoped_refptr<content::SiteInstance> orig_site_instance( |
63 browser()->GetSelectedWebContents()->GetSiteInstance()); | 63 browser()->GetSelectedWebContents()->GetSiteInstance()); |
64 EXPECT_TRUE(orig_site_instance != NULL); | 64 EXPECT_TRUE(orig_site_instance != NULL); |
65 | 65 |
66 // Test clicking a rel=noreferrer + target=blank link. | 66 // Test clicking a rel=noreferrer + target=blank link. |
67 bool success = false; | 67 bool success = false; |
68 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 68 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
69 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 69 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
70 L"window.domAutomationController.send(clickNoRefTargetBlankLink());", | 70 L"window.domAutomationController.send(clickNoRefTargetBlankLink());", |
71 &success)); | 71 &success)); |
72 EXPECT_TRUE(success); | 72 EXPECT_TRUE(success); |
73 | 73 |
74 // Wait for the tab to open. | 74 // Wait for the tab to open. |
75 if (browser()->tab_count() < 2) | 75 if (browser()->tab_count() < 2) |
76 ui_test_utils::WaitForNewTab(browser()); | 76 ui_test_utils::WaitForNewTab(browser()); |
77 | 77 |
78 // Opens in new tab. | 78 // Opens in new tab. |
79 EXPECT_EQ(2, browser()->tab_count()); | 79 EXPECT_EQ(2, browser()->tab_count()); |
80 EXPECT_EQ(1, browser()->active_index()); | 80 EXPECT_EQ(1, browser()->active_index()); |
81 EXPECT_EQ("/files/title2.html", | 81 EXPECT_EQ("/files/title2.html", |
82 browser()->GetSelectedWebContents()->GetURL().path()); | 82 browser()->GetSelectedWebContents()->GetURL().path()); |
83 | 83 |
84 // Wait for the cross-site transition in the new tab to finish. | 84 // Wait for the cross-site transition in the new tab to finish. |
85 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 85 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); |
86 TabContents* tab_contents = static_cast<TabContents*>( | 86 TabContents* tab_contents = static_cast<TabContents*>( |
87 browser()->GetSelectedWebContents()); | 87 browser()->GetSelectedWebContents()); |
88 EXPECT_FALSE(tab_contents->GetRenderManagerForTesting()-> | 88 EXPECT_FALSE(tab_contents->GetRenderManagerForTesting()-> |
89 pending_render_view_host()); | 89 pending_render_view_host()); |
90 | 90 |
91 // Should have a new SiteInstance. | 91 // Should have a new SiteInstance. |
92 scoped_refptr<SiteInstance> noref_blank_site_instance( | 92 scoped_refptr<content::SiteInstance> noref_blank_site_instance( |
93 browser()->GetSelectedWebContents()->GetSiteInstance()); | 93 browser()->GetSelectedWebContents()->GetSiteInstance()); |
94 EXPECT_NE(orig_site_instance, noref_blank_site_instance); | 94 EXPECT_NE(orig_site_instance, noref_blank_site_instance); |
95 } | 95 } |
96 | 96 |
97 // Test for crbug.com/24447. Following a cross-site link with just | 97 // Test for crbug.com/24447. Following a cross-site link with just |
98 // target=_blank should not create a new SiteInstance. | 98 // target=_blank should not create a new SiteInstance. |
99 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 99 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
100 DontSwapProcessWithOnlyTargetBlank) { | 100 DontSwapProcessWithOnlyTargetBlank) { |
101 // Start two servers with different sites. | 101 // Start two servers with different sites. |
102 ASSERT_TRUE(test_server()->Start()); | 102 ASSERT_TRUE(test_server()->Start()); |
103 net::TestServer https_server( | 103 net::TestServer https_server( |
104 net::TestServer::TYPE_HTTPS, | 104 net::TestServer::TYPE_HTTPS, |
105 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 105 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
106 ASSERT_TRUE(https_server.Start()); | 106 ASSERT_TRUE(https_server.Start()); |
107 | 107 |
108 // Load a page with links that open in a new window. | 108 // Load a page with links that open in a new window. |
109 std::string replacement_path; | 109 std::string replacement_path; |
110 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 110 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
111 "files/click-noreferrer-links.html", | 111 "files/click-noreferrer-links.html", |
112 https_server.host_port_pair(), | 112 https_server.host_port_pair(), |
113 &replacement_path)); | 113 &replacement_path)); |
114 ui_test_utils::NavigateToURL(browser(), | 114 ui_test_utils::NavigateToURL(browser(), |
115 test_server()->GetURL(replacement_path)); | 115 test_server()->GetURL(replacement_path)); |
116 | 116 |
117 // Get the original SiteInstance for later comparison. | 117 // Get the original SiteInstance for later comparison. |
118 scoped_refptr<SiteInstance> orig_site_instance( | 118 scoped_refptr<content::SiteInstance> orig_site_instance( |
119 browser()->GetSelectedWebContents()->GetSiteInstance()); | 119 browser()->GetSelectedWebContents()->GetSiteInstance()); |
120 EXPECT_TRUE(orig_site_instance != NULL); | 120 EXPECT_TRUE(orig_site_instance != NULL); |
121 | 121 |
122 // Test clicking a target=blank link. | 122 // Test clicking a target=blank link. |
123 bool success = false; | 123 bool success = false; |
124 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 124 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
125 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 125 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
126 L"window.domAutomationController.send(clickTargetBlankLink());", | 126 L"window.domAutomationController.send(clickTargetBlankLink());", |
127 &success)); | 127 &success)); |
128 EXPECT_TRUE(success); | 128 EXPECT_TRUE(success); |
129 | 129 |
130 // Wait for the tab to open. | 130 // Wait for the tab to open. |
131 if (browser()->tab_count() < 2) | 131 if (browser()->tab_count() < 2) |
132 ui_test_utils::WaitForNewTab(browser()); | 132 ui_test_utils::WaitForNewTab(browser()); |
133 | 133 |
134 // Opens in new tab. | 134 // Opens in new tab. |
135 EXPECT_EQ(2, browser()->tab_count()); | 135 EXPECT_EQ(2, browser()->tab_count()); |
136 EXPECT_EQ(1, browser()->active_index()); | 136 EXPECT_EQ(1, browser()->active_index()); |
137 | 137 |
138 // Wait for the cross-site transition in the new tab to finish. | 138 // Wait for the cross-site transition in the new tab to finish. |
139 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 139 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); |
140 EXPECT_EQ("/files/title2.html", | 140 EXPECT_EQ("/files/title2.html", |
141 browser()->GetSelectedWebContents()->GetURL().path()); | 141 browser()->GetSelectedWebContents()->GetURL().path()); |
142 | 142 |
143 // Should have the same SiteInstance. | 143 // Should have the same SiteInstance. |
144 scoped_refptr<SiteInstance> blank_site_instance( | 144 scoped_refptr<content::SiteInstance> blank_site_instance( |
145 browser()->GetSelectedWebContents()->GetSiteInstance()); | 145 browser()->GetSelectedWebContents()->GetSiteInstance()); |
146 EXPECT_EQ(orig_site_instance, blank_site_instance); | 146 EXPECT_EQ(orig_site_instance, blank_site_instance); |
147 } | 147 } |
148 | 148 |
149 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer | 149 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
150 // and no target=_blank should not create a new SiteInstance. | 150 // and no target=_blank should not create a new SiteInstance. |
151 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 151 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
152 DontSwapProcessWithOnlyRelNoreferrer) { | 152 DontSwapProcessWithOnlyRelNoreferrer) { |
153 // Start two servers with different sites. | 153 // Start two servers with different sites. |
154 ASSERT_TRUE(test_server()->Start()); | 154 ASSERT_TRUE(test_server()->Start()); |
155 net::TestServer https_server( | 155 net::TestServer https_server( |
156 net::TestServer::TYPE_HTTPS, | 156 net::TestServer::TYPE_HTTPS, |
157 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 157 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
158 ASSERT_TRUE(https_server.Start()); | 158 ASSERT_TRUE(https_server.Start()); |
159 | 159 |
160 // Load a page with links that open in a new window. | 160 // Load a page with links that open in a new window. |
161 std::string replacement_path; | 161 std::string replacement_path; |
162 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 162 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
163 "files/click-noreferrer-links.html", | 163 "files/click-noreferrer-links.html", |
164 https_server.host_port_pair(), | 164 https_server.host_port_pair(), |
165 &replacement_path)); | 165 &replacement_path)); |
166 ui_test_utils::NavigateToURL(browser(), | 166 ui_test_utils::NavigateToURL(browser(), |
167 test_server()->GetURL(replacement_path)); | 167 test_server()->GetURL(replacement_path)); |
168 | 168 |
169 // Get the original SiteInstance for later comparison. | 169 // Get the original SiteInstance for later comparison. |
170 scoped_refptr<SiteInstance> orig_site_instance( | 170 scoped_refptr<content::SiteInstance> orig_site_instance( |
171 browser()->GetSelectedWebContents()->GetSiteInstance()); | 171 browser()->GetSelectedWebContents()->GetSiteInstance()); |
172 EXPECT_TRUE(orig_site_instance != NULL); | 172 EXPECT_TRUE(orig_site_instance != NULL); |
173 | 173 |
174 // Test clicking a rel=noreferrer link. | 174 // Test clicking a rel=noreferrer link. |
175 bool success = false; | 175 bool success = false; |
176 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 176 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
177 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 177 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
178 L"window.domAutomationController.send(clickNoRefLink());", | 178 L"window.domAutomationController.send(clickNoRefLink());", |
179 &success)); | 179 &success)); |
180 EXPECT_TRUE(success); | 180 EXPECT_TRUE(success); |
181 | 181 |
182 // Wait for the cross-site transition in the current tab to finish. | 182 // Wait for the cross-site transition in the current tab to finish. |
183 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 183 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); |
184 | 184 |
185 // Opens in same tab. | 185 // Opens in same tab. |
186 EXPECT_EQ(1, browser()->tab_count()); | 186 EXPECT_EQ(1, browser()->tab_count()); |
187 EXPECT_EQ(0, browser()->active_index()); | 187 EXPECT_EQ(0, browser()->active_index()); |
188 EXPECT_EQ("/files/title2.html", | 188 EXPECT_EQ("/files/title2.html", |
189 browser()->GetSelectedWebContents()->GetURL().path()); | 189 browser()->GetSelectedWebContents()->GetURL().path()); |
190 | 190 |
191 // Should have the same SiteInstance. | 191 // Should have the same SiteInstance. |
192 scoped_refptr<SiteInstance> noref_site_instance( | 192 scoped_refptr<content::SiteInstance> noref_site_instance( |
193 browser()->GetSelectedWebContents()->GetSiteInstance()); | 193 browser()->GetSelectedWebContents()->GetSiteInstance()); |
194 EXPECT_EQ(orig_site_instance, noref_site_instance); | 194 EXPECT_EQ(orig_site_instance, noref_site_instance); |
195 } | 195 } |
196 | 196 |
197 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 | 197 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 |
198 // error should not make us ignore future renderer-initiated navigations. | 198 // error should not make us ignore future renderer-initiated navigations. |
199 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) { | 199 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ClickLinkAfter204Error) { |
200 // Start two servers with different sites. | 200 // Start two servers with different sites. |
201 ASSERT_TRUE(test_server()->Start()); | 201 ASSERT_TRUE(test_server()->Start()); |
202 net::TestServer https_server( | 202 net::TestServer https_server( |
203 net::TestServer::TYPE_HTTPS, | 203 net::TestServer::TYPE_HTTPS, |
204 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 204 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
205 ASSERT_TRUE(https_server.Start()); | 205 ASSERT_TRUE(https_server.Start()); |
206 | 206 |
207 // Load a page with links that open in a new window. | 207 // Load a page with links that open in a new window. |
208 // The links will point to the HTTPS server. | 208 // The links will point to the HTTPS server. |
209 std::string replacement_path; | 209 std::string replacement_path; |
210 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 210 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
211 "files/click-noreferrer-links.html", | 211 "files/click-noreferrer-links.html", |
212 https_server.host_port_pair(), | 212 https_server.host_port_pair(), |
213 &replacement_path)); | 213 &replacement_path)); |
214 ui_test_utils::NavigateToURL(browser(), | 214 ui_test_utils::NavigateToURL(browser(), |
215 test_server()->GetURL(replacement_path)); | 215 test_server()->GetURL(replacement_path)); |
216 | 216 |
217 // Get the original SiteInstance for later comparison. | 217 // Get the original SiteInstance for later comparison. |
218 scoped_refptr<SiteInstance> orig_site_instance( | 218 scoped_refptr<content::SiteInstance> orig_site_instance( |
219 browser()->GetSelectedWebContents()->GetSiteInstance()); | 219 browser()->GetSelectedWebContents()->GetSiteInstance()); |
220 EXPECT_TRUE(orig_site_instance != NULL); | 220 EXPECT_TRUE(orig_site_instance != NULL); |
221 | 221 |
222 // Load a cross-site page that fails with a 204 error. | 222 // Load a cross-site page that fails with a 204 error. |
223 ui_test_utils::NavigateToURL(browser(), https_server.GetURL("nocontent")); | 223 ui_test_utils::NavigateToURL(browser(), https_server.GetURL("nocontent")); |
224 | 224 |
225 // We should still be looking at the normal page. | 225 // We should still be looking at the normal page. |
226 scoped_refptr<SiteInstance> post_nav_site_instance( | 226 scoped_refptr<content::SiteInstance> post_nav_site_instance( |
227 browser()->GetSelectedWebContents()->GetSiteInstance()); | 227 browser()->GetSelectedWebContents()->GetSiteInstance()); |
228 EXPECT_EQ(orig_site_instance, post_nav_site_instance); | 228 EXPECT_EQ(orig_site_instance, post_nav_site_instance); |
229 EXPECT_EQ("/files/click-noreferrer-links.html", | 229 EXPECT_EQ("/files/click-noreferrer-links.html", |
230 browser()->GetSelectedWebContents()->GetURL().path()); | 230 browser()->GetSelectedWebContents()->GetURL().path()); |
231 | 231 |
232 // Renderer-initiated navigations should work. | 232 // Renderer-initiated navigations should work. |
233 bool success = false; | 233 bool success = false; |
234 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 234 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
235 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 235 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", |
236 L"window.domAutomationController.send(clickNoRefLink());", | 236 L"window.domAutomationController.send(clickNoRefLink());", |
237 &success)); | 237 &success)); |
238 EXPECT_TRUE(success); | 238 EXPECT_TRUE(success); |
239 | 239 |
240 // Wait for the cross-site transition in the current tab to finish. | 240 // Wait for the cross-site transition in the current tab to finish. |
241 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 241 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); |
242 | 242 |
243 // Opens in same tab. | 243 // Opens in same tab. |
244 EXPECT_EQ(1, browser()->tab_count()); | 244 EXPECT_EQ(1, browser()->tab_count()); |
245 EXPECT_EQ(0, browser()->active_index()); | 245 EXPECT_EQ(0, browser()->active_index()); |
246 EXPECT_EQ("/files/title2.html", | 246 EXPECT_EQ("/files/title2.html", |
247 browser()->GetSelectedWebContents()->GetURL().path()); | 247 browser()->GetSelectedWebContents()->GetURL().path()); |
248 | 248 |
249 // Should have the same SiteInstance. | 249 // Should have the same SiteInstance. |
250 scoped_refptr<SiteInstance> noref_site_instance( | 250 scoped_refptr<content::SiteInstance> noref_site_instance( |
251 browser()->GetSelectedWebContents()->GetSiteInstance()); | 251 browser()->GetSelectedWebContents()->GetSiteInstance()); |
252 EXPECT_EQ(orig_site_instance, noref_site_instance); | 252 EXPECT_EQ(orig_site_instance, noref_site_instance); |
253 } | 253 } |
254 | 254 |
255 // This class holds onto RenderViewHostObservers for as long as their observed | 255 // This class holds onto RenderViewHostObservers for as long as their observed |
256 // RenderViewHosts are alive. This allows us to confirm that all hosts have | 256 // RenderViewHosts are alive. This allows us to confirm that all hosts have |
257 // properly been shutdown. | 257 // properly been shutdown. |
258 class RenderViewHostObserverArray { | 258 class RenderViewHostObserverArray { |
259 public: | 259 public: |
260 ~RenderViewHostObserverArray() { | 260 ~RenderViewHostObserverArray() { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 // Now navigate to a different instance so that we swap out again. | 330 // Now navigate to a different instance so that we swap out again. |
331 ui_test_utils::NavigateToURL(browser(), | 331 ui_test_utils::NavigateToURL(browser(), |
332 https_server.GetURL("files/title2.html")); | 332 https_server.GetURL("files/title2.html")); |
333 rvh_observers.AddObserverToRVH(browser()->GetSelectedWebContents()-> | 333 rvh_observers.AddObserverToRVH(browser()->GetSelectedWebContents()-> |
334 GetRenderViewHost()); | 334 GetRenderViewHost()); |
335 | 335 |
336 // This used to leak a render view host. | 336 // This used to leak a render view host. |
337 browser()->CloseTabContents(browser()->GetSelectedWebContents()); | 337 browser()->CloseTabContents(browser()->GetSelectedWebContents()); |
338 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); | 338 EXPECT_EQ(0U, rvh_observers.GetNumObservers()); |
339 } | 339 } |
OLD | NEW |