OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 118 |
119 void NavigateToPageWithLinks(Shell* shell) { | 119 void NavigateToPageWithLinks(Shell* shell) { |
120 EXPECT_TRUE(NavigateToURL( | 120 EXPECT_TRUE(NavigateToURL( |
121 shell, embedded_test_server()->GetURL("/click-noreferrer-links.html"))); | 121 shell, embedded_test_server()->GetURL("/click-noreferrer-links.html"))); |
122 | 122 |
123 // Rewrite selected links on the page to be actual cross-site (bar.com) | 123 // Rewrite selected links on the page to be actual cross-site (bar.com) |
124 // URLs. This does not use the /cross-site/ redirector, since that creates | 124 // URLs. This does not use the /cross-site/ redirector, since that creates |
125 // links that initially look same-site. | 125 // links that initially look same-site. |
126 std::string script = "setOriginForLinks('http://bar.com:" + | 126 std::string script = "setOriginForLinks('http://bar.com:" + |
127 embedded_test_server()->base_url().port() + "/');"; | 127 embedded_test_server()->base_url().port() + "/');"; |
128 EXPECT_TRUE(ExecuteScript(shell->web_contents(), script)); | 128 EXPECT_TRUE(ExecuteScript(shell, script)); |
129 } | 129 } |
130 | 130 |
131 protected: | 131 protected: |
132 std::string foo_com_; | 132 std::string foo_com_; |
133 GURL::Replacements replace_host_; | 133 GURL::Replacements replace_host_; |
134 net::HostPortPair foo_host_port_; | 134 net::HostPortPair foo_host_port_; |
135 }; | 135 }; |
136 | 136 |
137 // Web pages should not have script access to the swapped out page. | 137 // Web pages should not have script access to the swapped out page. |
138 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, NoScriptAccessAfterSwapOut) { | 138 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, NoScriptAccessAfterSwapOut) { |
139 StartEmbeddedServer(); | 139 StartEmbeddedServer(); |
140 | 140 |
141 // Load a page with links that open in a new window. | 141 // Load a page with links that open in a new window. |
142 NavigateToPageWithLinks(shell()); | 142 NavigateToPageWithLinks(shell()); |
143 | 143 |
144 // Get the original SiteInstance for later comparison. | 144 // Get the original SiteInstance for later comparison. |
145 scoped_refptr<SiteInstance> orig_site_instance( | 145 scoped_refptr<SiteInstance> orig_site_instance( |
146 shell()->web_contents()->GetSiteInstance()); | 146 shell()->web_contents()->GetSiteInstance()); |
147 EXPECT_TRUE(orig_site_instance.get() != NULL); | 147 EXPECT_TRUE(orig_site_instance.get() != NULL); |
148 | 148 |
149 // Open a same-site link in a new window. | 149 // Open a same-site link in a new window. |
150 ShellAddedObserver new_shell_observer; | 150 ShellAddedObserver new_shell_observer; |
151 bool success = false; | 151 bool success = false; |
152 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 152 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
153 shell()->web_contents(), | 153 shell(), |
154 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 154 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
155 &success)); | 155 &success)); |
156 EXPECT_TRUE(success); | 156 EXPECT_TRUE(success); |
157 Shell* new_shell = new_shell_observer.GetShell(); | 157 Shell* new_shell = new_shell_observer.GetShell(); |
158 | 158 |
159 // Wait for the navigation in the new window to finish, if it hasn't. | 159 // Wait for the navigation in the new window to finish, if it hasn't. |
160 WaitForLoadStop(new_shell->web_contents()); | 160 WaitForLoadStop(new_shell->web_contents()); |
161 EXPECT_EQ("/navigate_opener.html", | 161 EXPECT_EQ("/navigate_opener.html", |
162 new_shell->web_contents()->GetLastCommittedURL().path()); | 162 new_shell->web_contents()->GetLastCommittedURL().path()); |
163 | 163 |
164 // Should have the same SiteInstance. | 164 // Should have the same SiteInstance. |
165 EXPECT_EQ(orig_site_instance, new_shell->web_contents()->GetSiteInstance()); | 165 EXPECT_EQ(orig_site_instance, new_shell->web_contents()->GetSiteInstance()); |
166 | 166 |
167 // We should have access to the opened window's location. | 167 // We should have access to the opened window's location. |
168 success = false; | 168 success = false; |
169 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 169 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
170 shell()->web_contents(), | 170 shell(), |
171 "window.domAutomationController.send(testScriptAccessToWindow());", | 171 "window.domAutomationController.send(testScriptAccessToWindow());", |
172 &success)); | 172 &success)); |
173 EXPECT_TRUE(success); | 173 EXPECT_TRUE(success); |
174 | 174 |
175 // Now navigate the new window to a different site. | 175 // Now navigate the new window to a different site. |
176 NavigateToURL(new_shell, | 176 NavigateToURL(new_shell, |
177 embedded_test_server()->GetURL("foo.com", "/title1.html")); | 177 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
178 scoped_refptr<SiteInstance> new_site_instance( | 178 scoped_refptr<SiteInstance> new_site_instance( |
179 new_shell->web_contents()->GetSiteInstance()); | 179 new_shell->web_contents()->GetSiteInstance()); |
180 EXPECT_NE(orig_site_instance, new_site_instance); | 180 EXPECT_NE(orig_site_instance, new_site_instance); |
181 | 181 |
182 // We should no longer have script access to the opened window's location. | 182 // We should no longer have script access to the opened window's location. |
183 success = false; | 183 success = false; |
184 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 184 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
185 shell()->web_contents(), | 185 shell(), |
186 "window.domAutomationController.send(testScriptAccessToWindow());", | 186 "window.domAutomationController.send(testScriptAccessToWindow());", |
187 &success)); | 187 &success)); |
188 EXPECT_FALSE(success); | 188 EXPECT_FALSE(success); |
189 | 189 |
190 // We now navigate the window to an about:blank page. | 190 // We now navigate the window to an about:blank page. |
191 success = false; | 191 success = false; |
192 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 192 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
193 shell()->web_contents(), | 193 shell(), "window.domAutomationController.send(clickBlankTargetedLink());", |
194 "window.domAutomationController.send(clickBlankTargetedLink());", | |
195 &success)); | 194 &success)); |
196 EXPECT_TRUE(success); | 195 EXPECT_TRUE(success); |
197 | 196 |
198 // Wait for the navigation in the new window to finish. | 197 // Wait for the navigation in the new window to finish. |
199 WaitForLoadStop(new_shell->web_contents()); | 198 WaitForLoadStop(new_shell->web_contents()); |
200 GURL blank_url(url::kAboutBlankURL); | 199 GURL blank_url(url::kAboutBlankURL); |
201 EXPECT_EQ(blank_url, | 200 EXPECT_EQ(blank_url, |
202 new_shell->web_contents()->GetLastCommittedURL()); | 201 new_shell->web_contents()->GetLastCommittedURL()); |
203 EXPECT_EQ(orig_site_instance, new_shell->web_contents()->GetSiteInstance()); | 202 EXPECT_EQ(orig_site_instance, new_shell->web_contents()->GetSiteInstance()); |
204 | 203 |
205 // We should have access to the opened window's location. | 204 // We should have access to the opened window's location. |
206 success = false; | 205 success = false; |
207 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 206 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
208 shell()->web_contents(), | 207 shell(), |
209 "window.domAutomationController.send(testScriptAccessToWindow());", | 208 "window.domAutomationController.send(testScriptAccessToWindow());", |
210 &success)); | 209 &success)); |
211 EXPECT_TRUE(success); | 210 EXPECT_TRUE(success); |
212 } | 211 } |
213 | 212 |
214 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer | 213 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
215 // and target=_blank should create a new SiteInstance. | 214 // and target=_blank should create a new SiteInstance. |
216 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 215 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
217 SwapProcessWithRelNoreferrerAndTargetBlank) { | 216 SwapProcessWithRelNoreferrerAndTargetBlank) { |
218 StartEmbeddedServer(); | 217 StartEmbeddedServer(); |
219 | 218 |
220 NavigateToPageWithLinks(shell()); | 219 NavigateToPageWithLinks(shell()); |
221 | 220 |
222 // Get the original SiteInstance for later comparison. | 221 // Get the original SiteInstance for later comparison. |
223 scoped_refptr<SiteInstance> orig_site_instance( | 222 scoped_refptr<SiteInstance> orig_site_instance( |
224 shell()->web_contents()->GetSiteInstance()); | 223 shell()->web_contents()->GetSiteInstance()); |
225 EXPECT_TRUE(orig_site_instance.get() != NULL); | 224 EXPECT_TRUE(orig_site_instance.get() != NULL); |
226 | 225 |
227 // Test clicking a rel=noreferrer + target=blank link. | 226 // Test clicking a rel=noreferrer + target=blank link. |
228 ShellAddedObserver new_shell_observer; | 227 ShellAddedObserver new_shell_observer; |
229 bool success = false; | 228 bool success = false; |
230 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 229 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
231 shell()->web_contents(), | 230 shell(), |
232 "window.domAutomationController.send(clickNoRefTargetBlankLink());", | 231 "window.domAutomationController.send(clickNoRefTargetBlankLink());", |
233 &success)); | 232 &success)); |
234 EXPECT_TRUE(success); | 233 EXPECT_TRUE(success); |
235 | 234 |
236 // Wait for the window to open. | 235 // Wait for the window to open. |
237 Shell* new_shell = new_shell_observer.GetShell(); | 236 Shell* new_shell = new_shell_observer.GetShell(); |
238 | 237 |
239 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path()); | 238 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path()); |
240 | 239 |
241 // Check that `window.opener` is not set. | 240 // Check that `window.opener` is not set. |
242 success = false; | 241 success = false; |
243 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 242 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
244 new_shell->web_contents(), | 243 new_shell, "window.domAutomationController.send(window.opener == null);", |
245 "window.domAutomationController.send(window.opener == null);", &success)); | 244 &success)); |
246 EXPECT_TRUE(success); | 245 EXPECT_TRUE(success); |
247 | 246 |
248 // Wait for the cross-site transition in the new tab to finish. | 247 // Wait for the cross-site transition in the new tab to finish. |
249 WaitForLoadStop(new_shell->web_contents()); | 248 WaitForLoadStop(new_shell->web_contents()); |
250 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 249 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
251 new_shell->web_contents()); | 250 new_shell->web_contents()); |
252 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> | 251 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> |
253 pending_render_view_host()); | 252 pending_render_view_host()); |
254 | 253 |
255 // Should have a new SiteInstance. | 254 // Should have a new SiteInstance. |
(...skipping 11 matching lines...) Expand all Loading... |
267 | 266 |
268 // Get the original SiteInstance for later comparison. | 267 // Get the original SiteInstance for later comparison. |
269 scoped_refptr<SiteInstance> orig_site_instance( | 268 scoped_refptr<SiteInstance> orig_site_instance( |
270 shell()->web_contents()->GetSiteInstance()); | 269 shell()->web_contents()->GetSiteInstance()); |
271 EXPECT_TRUE(orig_site_instance.get() != NULL); | 270 EXPECT_TRUE(orig_site_instance.get() != NULL); |
272 | 271 |
273 // Test clicking a rel=noreferrer + target=blank link. | 272 // Test clicking a rel=noreferrer + target=blank link. |
274 ShellAddedObserver new_shell_observer; | 273 ShellAddedObserver new_shell_observer; |
275 bool success = false; | 274 bool success = false; |
276 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 275 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
277 shell()->web_contents(), | 276 shell(), |
278 "window.domAutomationController.send(clickNoOpenerTargetBlankLink());", | 277 "window.domAutomationController.send(clickNoOpenerTargetBlankLink());", |
279 &success)); | 278 &success)); |
280 EXPECT_TRUE(success); | 279 EXPECT_TRUE(success); |
281 | 280 |
282 // Wait for the window to open. | 281 // Wait for the window to open. |
283 Shell* new_shell = new_shell_observer.GetShell(); | 282 Shell* new_shell = new_shell_observer.GetShell(); |
284 | 283 |
285 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path()); | 284 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path()); |
286 | 285 |
287 // Check that `window.opener` is not set. | 286 // Check that `window.opener` is not set. |
288 success = false; | 287 success = false; |
289 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 288 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
290 new_shell->web_contents(), | 289 new_shell, "window.domAutomationController.send(window.opener == null);", |
291 "window.domAutomationController.send(window.opener == null);", &success)); | 290 &success)); |
292 EXPECT_TRUE(success); | 291 EXPECT_TRUE(success); |
293 | 292 |
294 // Wait for the cross-site transition in the new tab to finish. | 293 // Wait for the cross-site transition in the new tab to finish. |
295 WaitForLoadStop(new_shell->web_contents()); | 294 WaitForLoadStop(new_shell->web_contents()); |
296 WebContentsImpl* web_contents = | 295 WebContentsImpl* web_contents = |
297 static_cast<WebContentsImpl*>(new_shell->web_contents()); | 296 static_cast<WebContentsImpl*>(new_shell->web_contents()); |
298 EXPECT_FALSE( | 297 EXPECT_FALSE( |
299 web_contents->GetRenderManagerForTesting()->pending_render_view_host()); | 298 web_contents->GetRenderManagerForTesting()->pending_render_view_host()); |
300 | 299 |
301 // Should have a new SiteInstance. | 300 // Should have a new SiteInstance. |
(...skipping 11 matching lines...) Expand all Loading... |
313 | 312 |
314 // Get the original SiteInstance for later comparison. | 313 // Get the original SiteInstance for later comparison. |
315 scoped_refptr<SiteInstance> orig_site_instance( | 314 scoped_refptr<SiteInstance> orig_site_instance( |
316 shell()->web_contents()->GetSiteInstance()); | 315 shell()->web_contents()->GetSiteInstance()); |
317 EXPECT_TRUE(orig_site_instance.get()); | 316 EXPECT_TRUE(orig_site_instance.get()); |
318 | 317 |
319 // Test opening a window with the 'noopener' feature. | 318 // Test opening a window with the 'noopener' feature. |
320 ShellAddedObserver new_shell_observer; | 319 ShellAddedObserver new_shell_observer; |
321 bool hasWindowReference = true; | 320 bool hasWindowReference = true; |
322 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 321 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
323 shell()->web_contents(), | 322 shell(), |
324 "window.domAutomationController.send(" | 323 "window.domAutomationController.send(" |
325 " openWindowWithTargetAndFeatures('/title2.html', '', 'noopener')" | 324 " openWindowWithTargetAndFeatures('/title2.html', '', 'noopener')" |
326 ");", | 325 ");", |
327 &hasWindowReference)); | 326 &hasWindowReference)); |
328 // We should not get a reference to the opened window. | 327 // We should not get a reference to the opened window. |
329 EXPECT_FALSE(hasWindowReference); | 328 EXPECT_FALSE(hasWindowReference); |
330 | 329 |
331 // Wait for the window to open. | 330 // Wait for the window to open. |
332 Shell* new_shell = new_shell_observer.GetShell(); | 331 Shell* new_shell = new_shell_observer.GetShell(); |
333 | 332 |
334 // Wait for the cross-site transition in the new tab to finish. | 333 // Wait for the cross-site transition in the new tab to finish. |
335 WaitForLoadStop(new_shell->web_contents()); | 334 WaitForLoadStop(new_shell->web_contents()); |
336 WebContentsImpl* web_contents = | 335 WebContentsImpl* web_contents = |
337 static_cast<WebContentsImpl*>(new_shell->web_contents()); | 336 static_cast<WebContentsImpl*>(new_shell->web_contents()); |
338 EXPECT_FALSE( | 337 EXPECT_FALSE( |
339 web_contents->GetRenderManagerForTesting()->pending_render_view_host()); | 338 web_contents->GetRenderManagerForTesting()->pending_render_view_host()); |
340 | 339 |
341 EXPECT_EQ("/title2.html", | 340 EXPECT_EQ("/title2.html", |
342 new_shell->web_contents()->GetLastCommittedURL().path()); | 341 new_shell->web_contents()->GetLastCommittedURL().path()); |
343 | 342 |
344 // Check that `window.opener` is not set. | 343 // Check that `window.opener` is not set. |
345 bool success = false; | 344 bool success = false; |
346 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 345 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
347 new_shell->web_contents(), | 346 new_shell, "window.domAutomationController.send(window.opener == null);", |
348 "window.domAutomationController.send(window.opener == null);", &success)); | 347 &success)); |
349 EXPECT_TRUE(success); | 348 EXPECT_TRUE(success); |
350 | 349 |
351 // Should have a new SiteInstance. | 350 // Should have a new SiteInstance. |
352 scoped_refptr<SiteInstance> noopener_blank_site_instance( | 351 scoped_refptr<SiteInstance> noopener_blank_site_instance( |
353 new_shell->web_contents()->GetSiteInstance()); | 352 new_shell->web_contents()->GetSiteInstance()); |
354 EXPECT_NE(orig_site_instance, noopener_blank_site_instance); | 353 EXPECT_NE(orig_site_instance, noopener_blank_site_instance); |
355 } | 354 } |
356 | 355 |
357 // As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance) | 356 // As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance) |
358 // for rel=noreferrer links in new windows, even to same site pages and named | 357 // for rel=noreferrer links in new windows, even to same site pages and named |
359 // targets. | 358 // targets. |
360 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 359 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
361 SwapProcessWithSameSiteRelNoreferrer) { | 360 SwapProcessWithSameSiteRelNoreferrer) { |
362 StartEmbeddedServer(); | 361 StartEmbeddedServer(); |
363 | 362 |
364 // Load a page with links that open in a new window. | 363 // Load a page with links that open in a new window. |
365 NavigateToPageWithLinks(shell()); | 364 NavigateToPageWithLinks(shell()); |
366 | 365 |
367 // Get the original SiteInstance for later comparison. | 366 // Get the original SiteInstance for later comparison. |
368 scoped_refptr<SiteInstance> orig_site_instance( | 367 scoped_refptr<SiteInstance> orig_site_instance( |
369 shell()->web_contents()->GetSiteInstance()); | 368 shell()->web_contents()->GetSiteInstance()); |
370 EXPECT_TRUE(orig_site_instance.get() != NULL); | 369 EXPECT_TRUE(orig_site_instance.get() != NULL); |
371 | 370 |
372 // Test clicking a same-site rel=noreferrer + target=foo link. | 371 // Test clicking a same-site rel=noreferrer + target=foo link. |
373 ShellAddedObserver new_shell_observer; | 372 ShellAddedObserver new_shell_observer; |
374 bool success = false; | 373 bool success = false; |
375 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 374 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
376 shell()->web_contents(), | 375 shell(), |
377 "window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", | 376 "window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", |
378 &success)); | 377 &success)); |
379 EXPECT_TRUE(success); | 378 EXPECT_TRUE(success); |
380 | 379 |
381 // Wait for the window to open. | 380 // Wait for the window to open. |
382 Shell* new_shell = new_shell_observer.GetShell(); | 381 Shell* new_shell = new_shell_observer.GetShell(); |
383 | 382 |
384 // Opens in new window. | 383 // Opens in new window. |
385 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path()); | 384 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path()); |
386 | 385 |
387 // Check that `window.opener` is not set. | 386 // Check that `window.opener` is not set. |
388 success = false; | 387 success = false; |
389 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 388 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
390 new_shell->web_contents(), | 389 new_shell, "window.domAutomationController.send(window.opener == null);", |
391 "window.domAutomationController.send(window.opener == null);", &success)); | 390 &success)); |
392 EXPECT_TRUE(success); | 391 EXPECT_TRUE(success); |
393 | 392 |
394 // Wait for the cross-site transition in the new tab to finish. | 393 // Wait for the cross-site transition in the new tab to finish. |
395 WaitForLoadStop(new_shell->web_contents()); | 394 WaitForLoadStop(new_shell->web_contents()); |
396 WebContentsImpl* web_contents = | 395 WebContentsImpl* web_contents = |
397 static_cast<WebContentsImpl*>(new_shell->web_contents()); | 396 static_cast<WebContentsImpl*>(new_shell->web_contents()); |
398 EXPECT_FALSE( | 397 EXPECT_FALSE( |
399 web_contents->GetRenderManagerForTesting()->pending_render_view_host()); | 398 web_contents->GetRenderManagerForTesting()->pending_render_view_host()); |
400 | 399 |
401 // Should have a new SiteInstance (in a new BrowsingInstance). | 400 // Should have a new SiteInstance (in a new BrowsingInstance). |
(...skipping 11 matching lines...) Expand all Loading... |
413 NavigateToPageWithLinks(shell()); | 412 NavigateToPageWithLinks(shell()); |
414 | 413 |
415 // Get the original SiteInstance for later comparison. | 414 // Get the original SiteInstance for later comparison. |
416 scoped_refptr<SiteInstance> orig_site_instance( | 415 scoped_refptr<SiteInstance> orig_site_instance( |
417 shell()->web_contents()->GetSiteInstance()); | 416 shell()->web_contents()->GetSiteInstance()); |
418 EXPECT_TRUE(orig_site_instance.get() != NULL); | 417 EXPECT_TRUE(orig_site_instance.get() != NULL); |
419 | 418 |
420 // Test clicking a same-site rel=noopener + target=foo link. | 419 // Test clicking a same-site rel=noopener + target=foo link. |
421 ShellAddedObserver new_shell_observer; | 420 ShellAddedObserver new_shell_observer; |
422 bool success = false; | 421 bool success = false; |
423 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell()->web_contents(), | 422 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), |
424 "window.domAutomationController.send(" | 423 "window.domAutomationController.send(" |
425 "clickSameSiteNoOpenerTargetedLink())" | 424 "clickSameSiteNoOpenerTargetedLink())" |
426 ";", | 425 ";", |
427 &success)); | 426 &success)); |
428 EXPECT_TRUE(success); | 427 EXPECT_TRUE(success); |
429 | 428 |
430 // Wait for the window to open. | 429 // Wait for the window to open. |
431 Shell* new_shell = new_shell_observer.GetShell(); | 430 Shell* new_shell = new_shell_observer.GetShell(); |
432 | 431 |
433 // Opens in new window. | 432 // Opens in new window. |
434 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path()); | 433 EXPECT_EQ("/title2.html", new_shell->web_contents()->GetVisibleURL().path()); |
435 | 434 |
436 // Check that `window.opener` is not set. | 435 // Check that `window.opener` is not set. |
437 success = false; | 436 success = false; |
438 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 437 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
439 new_shell->web_contents(), | 438 new_shell, "window.domAutomationController.send(window.opener == null);", |
440 "window.domAutomationController.send(window.opener == null);", &success)); | 439 &success)); |
441 EXPECT_TRUE(success); | 440 EXPECT_TRUE(success); |
442 | 441 |
443 // Wait for the cross-site transition in the new tab to finish. | 442 // Wait for the cross-site transition in the new tab to finish. |
444 WaitForLoadStop(new_shell->web_contents()); | 443 WaitForLoadStop(new_shell->web_contents()); |
445 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 444 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
446 new_shell->web_contents()); | 445 new_shell->web_contents()); |
447 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> | 446 EXPECT_FALSE(web_contents->GetRenderManagerForTesting()-> |
448 pending_render_view_host()); | 447 pending_render_view_host()); |
449 | 448 |
450 // Should have a new SiteInstance (in a new BrowsingInstance). | 449 // Should have a new SiteInstance (in a new BrowsingInstance). |
(...skipping 14 matching lines...) Expand all Loading... |
465 | 464 |
466 // Get the original SiteInstance for later comparison. | 465 // Get the original SiteInstance for later comparison. |
467 scoped_refptr<SiteInstance> orig_site_instance( | 466 scoped_refptr<SiteInstance> orig_site_instance( |
468 shell()->web_contents()->GetSiteInstance()); | 467 shell()->web_contents()->GetSiteInstance()); |
469 EXPECT_TRUE(orig_site_instance.get() != NULL); | 468 EXPECT_TRUE(orig_site_instance.get() != NULL); |
470 | 469 |
471 // Test clicking a target=blank link. | 470 // Test clicking a target=blank link. |
472 ShellAddedObserver new_shell_observer; | 471 ShellAddedObserver new_shell_observer; |
473 bool success = false; | 472 bool success = false; |
474 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 473 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
475 shell()->web_contents(), | 474 shell(), "window.domAutomationController.send(clickTargetBlankLink());", |
476 "window.domAutomationController.send(clickTargetBlankLink());", | |
477 &success)); | 475 &success)); |
478 EXPECT_TRUE(success); | 476 EXPECT_TRUE(success); |
479 | 477 |
480 // Wait for the window to open. | 478 // Wait for the window to open. |
481 Shell* new_shell = new_shell_observer.GetShell(); | 479 Shell* new_shell = new_shell_observer.GetShell(); |
482 | 480 |
483 // Wait for the cross-site transition in the new tab to finish. | 481 // Wait for the cross-site transition in the new tab to finish. |
484 EXPECT_TRUE(WaitForLoadStop(new_shell->web_contents())); | 482 EXPECT_TRUE(WaitForLoadStop(new_shell->web_contents())); |
485 EXPECT_EQ("/title2.html", | 483 EXPECT_EQ("/title2.html", |
486 new_shell->web_contents()->GetLastCommittedURL().path()); | 484 new_shell->web_contents()->GetLastCommittedURL().path()); |
(...skipping 17 matching lines...) Expand all Loading... |
504 NavigateToPageWithLinks(shell()); | 502 NavigateToPageWithLinks(shell()); |
505 | 503 |
506 // Get the original SiteInstance for later comparison. | 504 // Get the original SiteInstance for later comparison. |
507 scoped_refptr<SiteInstance> orig_site_instance( | 505 scoped_refptr<SiteInstance> orig_site_instance( |
508 shell()->web_contents()->GetSiteInstance()); | 506 shell()->web_contents()->GetSiteInstance()); |
509 EXPECT_TRUE(orig_site_instance.get() != NULL); | 507 EXPECT_TRUE(orig_site_instance.get() != NULL); |
510 | 508 |
511 // Test clicking a rel=noreferrer link. | 509 // Test clicking a rel=noreferrer link. |
512 bool success = false; | 510 bool success = false; |
513 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 511 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
514 shell()->web_contents(), | 512 shell(), "window.domAutomationController.send(clickNoRefLink());", |
515 "window.domAutomationController.send(clickNoRefLink());", &success)); | 513 &success)); |
516 EXPECT_TRUE(success); | 514 EXPECT_TRUE(success); |
517 | 515 |
518 // Wait for the cross-site transition in the current tab to finish. | 516 // Wait for the cross-site transition in the current tab to finish. |
519 WaitForLoadStop(shell()->web_contents()); | 517 WaitForLoadStop(shell()->web_contents()); |
520 | 518 |
521 // Opens in same window. | 519 // Opens in same window. |
522 EXPECT_EQ(1u, Shell::windows().size()); | 520 EXPECT_EQ(1u, Shell::windows().size()); |
523 EXPECT_EQ("/title2.html", | 521 EXPECT_EQ("/title2.html", |
524 shell()->web_contents()->GetLastCommittedURL().path()); | 522 shell()->web_contents()->GetLastCommittedURL().path()); |
525 | 523 |
(...skipping 15 matching lines...) Expand all Loading... |
541 NavigateToPageWithLinks(shell()); | 539 NavigateToPageWithLinks(shell()); |
542 | 540 |
543 // Get the original SiteInstance for later comparison. | 541 // Get the original SiteInstance for later comparison. |
544 scoped_refptr<SiteInstance> orig_site_instance( | 542 scoped_refptr<SiteInstance> orig_site_instance( |
545 shell()->web_contents()->GetSiteInstance()); | 543 shell()->web_contents()->GetSiteInstance()); |
546 EXPECT_TRUE(orig_site_instance.get() != NULL); | 544 EXPECT_TRUE(orig_site_instance.get() != NULL); |
547 | 545 |
548 // Test clicking a rel=noreferrer link. | 546 // Test clicking a rel=noreferrer link. |
549 bool success = false; | 547 bool success = false; |
550 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 548 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
551 shell()->web_contents(), | 549 shell(), "window.domAutomationController.send(clickNoRefLink());", |
552 "window.domAutomationController.send(clickNoRefLink());", | |
553 &success)); | 550 &success)); |
554 EXPECT_TRUE(success); | 551 EXPECT_TRUE(success); |
555 | 552 |
556 // Wait for the cross-site transition in the current tab to finish. | 553 // Wait for the cross-site transition in the current tab to finish. |
557 WaitForLoadStop(shell()->web_contents()); | 554 WaitForLoadStop(shell()->web_contents()); |
558 | 555 |
559 // Opens in same window. | 556 // Opens in same window. |
560 EXPECT_EQ(1u, Shell::windows().size()); | 557 EXPECT_EQ(1u, Shell::windows().size()); |
561 EXPECT_EQ("/title2.html", | 558 EXPECT_EQ("/title2.html", |
562 shell()->web_contents()->GetLastCommittedURL().path()); | 559 shell()->web_contents()->GetLastCommittedURL().path()); |
(...skipping 18 matching lines...) Expand all Loading... |
581 | 578 |
582 // Get the original SiteInstance for later comparison. | 579 // Get the original SiteInstance for later comparison. |
583 scoped_refptr<SiteInstance> orig_site_instance( | 580 scoped_refptr<SiteInstance> orig_site_instance( |
584 shell()->web_contents()->GetSiteInstance()); | 581 shell()->web_contents()->GetSiteInstance()); |
585 EXPECT_TRUE(orig_site_instance.get() != NULL); | 582 EXPECT_TRUE(orig_site_instance.get() != NULL); |
586 | 583 |
587 // Test clicking a target=foo link. | 584 // Test clicking a target=foo link. |
588 ShellAddedObserver new_shell_observer; | 585 ShellAddedObserver new_shell_observer; |
589 bool success = false; | 586 bool success = false; |
590 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 587 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
591 shell()->web_contents(), | 588 shell(), |
592 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 589 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
593 &success)); | 590 &success)); |
594 EXPECT_TRUE(success); | 591 EXPECT_TRUE(success); |
595 Shell* new_shell = new_shell_observer.GetShell(); | 592 Shell* new_shell = new_shell_observer.GetShell(); |
596 | 593 |
597 // Wait for the navigation in the new tab to finish, if it hasn't. | 594 // Wait for the navigation in the new tab to finish, if it hasn't. |
598 WaitForLoadStop(new_shell->web_contents()); | 595 WaitForLoadStop(new_shell->web_contents()); |
599 EXPECT_EQ("/navigate_opener.html", | 596 EXPECT_EQ("/navigate_opener.html", |
600 new_shell->web_contents()->GetLastCommittedURL().path()); | 597 new_shell->web_contents()->GetLastCommittedURL().path()); |
601 | 598 |
602 // Should have the same SiteInstance. | 599 // Should have the same SiteInstance. |
603 scoped_refptr<SiteInstance> blank_site_instance( | 600 scoped_refptr<SiteInstance> blank_site_instance( |
604 new_shell->web_contents()->GetSiteInstance()); | 601 new_shell->web_contents()->GetSiteInstance()); |
605 EXPECT_EQ(orig_site_instance, blank_site_instance); | 602 EXPECT_EQ(orig_site_instance, blank_site_instance); |
606 | 603 |
607 // Now navigate the new tab to a different site. | 604 // Now navigate the new tab to a different site. |
608 GURL cross_site_url( | 605 GURL cross_site_url( |
609 embedded_test_server()->GetURL("foo.com", "/title1.html")); | 606 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
610 NavigateToURL(new_shell, cross_site_url); | 607 NavigateToURL(new_shell, cross_site_url); |
611 scoped_refptr<SiteInstance> new_site_instance( | 608 scoped_refptr<SiteInstance> new_site_instance( |
612 new_shell->web_contents()->GetSiteInstance()); | 609 new_shell->web_contents()->GetSiteInstance()); |
613 EXPECT_NE(orig_site_instance, new_site_instance); | 610 EXPECT_NE(orig_site_instance, new_site_instance); |
614 | 611 |
615 // Clicking the original link in the first tab should cause us to swap back. | 612 // Clicking the original link in the first tab should cause us to swap back. |
616 TestNavigationObserver navigation_observer(new_shell->web_contents()); | 613 TestNavigationObserver navigation_observer(new_shell->web_contents()); |
617 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 614 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
618 shell()->web_contents(), | 615 shell(), |
619 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 616 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
620 &success)); | 617 &success)); |
621 EXPECT_TRUE(success); | 618 EXPECT_TRUE(success); |
622 navigation_observer.Wait(); | 619 navigation_observer.Wait(); |
623 | 620 |
624 // Should have swapped back and shown the new window again. | 621 // Should have swapped back and shown the new window again. |
625 scoped_refptr<SiteInstance> revisit_site_instance( | 622 scoped_refptr<SiteInstance> revisit_site_instance( |
626 new_shell->web_contents()->GetSiteInstance()); | 623 new_shell->web_contents()->GetSiteInstance()); |
627 EXPECT_EQ(orig_site_instance, revisit_site_instance); | 624 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
628 | 625 |
629 // If it navigates away to another process, the original window should | 626 // If it navigates away to another process, the original window should |
630 // still be able to close it (using a cross-process close message). | 627 // still be able to close it (using a cross-process close message). |
631 NavigateToURL(new_shell, cross_site_url); | 628 NavigateToURL(new_shell, cross_site_url); |
632 EXPECT_EQ(new_site_instance.get(), | 629 EXPECT_EQ(new_site_instance.get(), |
633 new_shell->web_contents()->GetSiteInstance()); | 630 new_shell->web_contents()->GetSiteInstance()); |
634 WebContentsDestroyedWatcher close_watcher(new_shell->web_contents()); | 631 WebContentsDestroyedWatcher close_watcher(new_shell->web_contents()); |
635 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 632 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
636 shell()->web_contents(), | 633 shell(), "window.domAutomationController.send(testCloseWindow());", |
637 "window.domAutomationController.send(testCloseWindow());", | |
638 &success)); | 634 &success)); |
639 EXPECT_TRUE(success); | 635 EXPECT_TRUE(success); |
640 close_watcher.Wait(); | 636 close_watcher.Wait(); |
641 } | 637 } |
642 | 638 |
643 // Test that setting the opener to null in a window affects cross-process | 639 // Test that setting the opener to null in a window affects cross-process |
644 // navigations, including those to existing entries. http://crbug.com/156669. | 640 // navigations, including those to existing entries. http://crbug.com/156669. |
645 // This test crashes under ThreadSanitizer, http://crbug.com/356758. | 641 // This test crashes under ThreadSanitizer, http://crbug.com/356758. |
646 #if defined(THREAD_SANITIZER) | 642 #if defined(THREAD_SANITIZER) |
647 #define MAYBE_DisownOpener DISABLED_DisownOpener | 643 #define MAYBE_DisownOpener DISABLED_DisownOpener |
648 #else | 644 #else |
649 #define MAYBE_DisownOpener DisownOpener | 645 #define MAYBE_DisownOpener DisownOpener |
650 #endif | 646 #endif |
651 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, MAYBE_DisownOpener) { | 647 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, MAYBE_DisownOpener) { |
652 StartEmbeddedServer(); | 648 StartEmbeddedServer(); |
653 | 649 |
654 // Load a page with links that open in a new window. | 650 // Load a page with links that open in a new window. |
655 NavigateToPageWithLinks(shell()); | 651 NavigateToPageWithLinks(shell()); |
656 | 652 |
657 // Get the original SiteInstance for later comparison. | 653 // Get the original SiteInstance for later comparison. |
658 scoped_refptr<SiteInstance> orig_site_instance( | 654 scoped_refptr<SiteInstance> orig_site_instance( |
659 shell()->web_contents()->GetSiteInstance()); | 655 shell()->web_contents()->GetSiteInstance()); |
660 EXPECT_TRUE(orig_site_instance.get() != NULL); | 656 EXPECT_TRUE(orig_site_instance.get() != NULL); |
661 | 657 |
662 // Test clicking a target=_blank link. | 658 // Test clicking a target=_blank link. |
663 ShellAddedObserver new_shell_observer; | 659 ShellAddedObserver new_shell_observer; |
664 bool success = false; | 660 bool success = false; |
665 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 661 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
666 shell()->web_contents(), | 662 shell(), |
667 "window.domAutomationController.send(clickSameSiteTargetBlankLink());", | 663 "window.domAutomationController.send(clickSameSiteTargetBlankLink());", |
668 &success)); | 664 &success)); |
669 EXPECT_TRUE(success); | 665 EXPECT_TRUE(success); |
670 Shell* new_shell = new_shell_observer.GetShell(); | 666 Shell* new_shell = new_shell_observer.GetShell(); |
671 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); | 667 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); |
672 | 668 |
673 // Wait for the navigation in the new tab to finish, if it hasn't. | 669 // Wait for the navigation in the new tab to finish, if it hasn't. |
674 WaitForLoadStop(new_shell->web_contents()); | 670 WaitForLoadStop(new_shell->web_contents()); |
675 EXPECT_EQ("/title2.html", | 671 EXPECT_EQ("/title2.html", |
676 new_shell->web_contents()->GetLastCommittedURL().path()); | 672 new_shell->web_contents()->GetLastCommittedURL().path()); |
677 | 673 |
678 // Should have the same SiteInstance. | 674 // Should have the same SiteInstance. |
679 scoped_refptr<SiteInstance> blank_site_instance( | 675 scoped_refptr<SiteInstance> blank_site_instance( |
680 new_shell->web_contents()->GetSiteInstance()); | 676 new_shell->web_contents()->GetSiteInstance()); |
681 EXPECT_EQ(orig_site_instance, blank_site_instance); | 677 EXPECT_EQ(orig_site_instance, blank_site_instance); |
682 | 678 |
683 // Now navigate the new tab to a different site. | 679 // Now navigate the new tab to a different site. |
684 GURL cross_site_url( | 680 GURL cross_site_url( |
685 embedded_test_server()->GetURL("foo.com", "/title1.html")); | 681 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
686 NavigateToURL(new_shell, cross_site_url); | 682 NavigateToURL(new_shell, cross_site_url); |
687 scoped_refptr<SiteInstance> new_site_instance( | 683 scoped_refptr<SiteInstance> new_site_instance( |
688 new_shell->web_contents()->GetSiteInstance()); | 684 new_shell->web_contents()->GetSiteInstance()); |
689 EXPECT_NE(orig_site_instance, new_site_instance); | 685 EXPECT_NE(orig_site_instance, new_site_instance); |
690 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); | 686 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); |
691 | 687 |
692 // Now disown the opener. | 688 // Now disown the opener. |
693 EXPECT_TRUE(ExecuteScript(new_shell->web_contents(), | 689 EXPECT_TRUE(ExecuteScript(new_shell, "window.opener = null;")); |
694 "window.opener = null;")); | |
695 EXPECT_FALSE(new_shell->web_contents()->HasOpener()); | 690 EXPECT_FALSE(new_shell->web_contents()->HasOpener()); |
696 | 691 |
697 // Go back and ensure the opener is still null. | 692 // Go back and ensure the opener is still null. |
698 { | 693 { |
699 TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); | 694 TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); |
700 new_shell->web_contents()->GetController().GoBack(); | 695 new_shell->web_contents()->GetController().GoBack(); |
701 back_nav_load_observer.Wait(); | 696 back_nav_load_observer.Wait(); |
702 } | 697 } |
703 success = false; | 698 success = false; |
704 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 699 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
705 new_shell->web_contents(), | 700 new_shell, "window.domAutomationController.send(window.opener == null);", |
706 "window.domAutomationController.send(window.opener == null);", | |
707 &success)); | 701 &success)); |
708 EXPECT_TRUE(success); | 702 EXPECT_TRUE(success); |
709 EXPECT_FALSE(new_shell->web_contents()->HasOpener()); | 703 EXPECT_FALSE(new_shell->web_contents()->HasOpener()); |
710 | 704 |
711 // Now navigate forward again (creating a new process) and check opener. | 705 // Now navigate forward again (creating a new process) and check opener. |
712 NavigateToURL(new_shell, cross_site_url); | 706 NavigateToURL(new_shell, cross_site_url); |
713 success = false; | 707 success = false; |
714 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 708 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
715 new_shell->web_contents(), | 709 new_shell, "window.domAutomationController.send(window.opener == null);", |
716 "window.domAutomationController.send(window.opener == null);", | |
717 &success)); | 710 &success)); |
718 EXPECT_TRUE(success); | 711 EXPECT_TRUE(success); |
719 EXPECT_FALSE(new_shell->web_contents()->HasOpener()); | 712 EXPECT_FALSE(new_shell->web_contents()->HasOpener()); |
720 } | 713 } |
721 | 714 |
722 // Test that subframes can disown their openers. http://crbug.com/225528. | 715 // Test that subframes can disown their openers. http://crbug.com/225528. |
723 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, DisownSubframeOpener) { | 716 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, DisownSubframeOpener) { |
724 const GURL frame_url("data:text/html,<iframe name=\"foo\"></iframe>"); | 717 const GURL frame_url("data:text/html,<iframe name=\"foo\"></iframe>"); |
725 NavigateToURL(shell(), frame_url); | 718 NavigateToURL(shell(), frame_url); |
726 | 719 |
727 // Give the frame an opener using window.open. | 720 // Give the frame an opener using window.open. |
728 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 721 EXPECT_TRUE(ExecuteScript(shell(), "window.open('about:blank','foo');")); |
729 "window.open('about:blank','foo');")); | |
730 | 722 |
731 // Check that the browser process updates the subframe's opener. | 723 // Check that the browser process updates the subframe's opener. |
732 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 724 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
733 ->GetFrameTree() | 725 ->GetFrameTree() |
734 ->root(); | 726 ->root(); |
735 EXPECT_EQ(root, root->child_at(0)->opener()); | 727 EXPECT_EQ(root, root->child_at(0)->opener()); |
736 | 728 |
737 // Now disown the frame's opener. Shouldn't crash. | 729 // Now disown the frame's opener. Shouldn't crash. |
738 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 730 EXPECT_TRUE(ExecuteScript(shell(), "window.frames[0].opener = null;")); |
739 "window.frames[0].opener = null;")); | |
740 | 731 |
741 // Check that the subframe's opener in the browser process is disowned. | 732 // Check that the subframe's opener in the browser process is disowned. |
742 EXPECT_EQ(nullptr, root->child_at(0)->opener()); | 733 EXPECT_EQ(nullptr, root->child_at(0)->opener()); |
743 } | 734 } |
744 | 735 |
745 // Check that window.name is preserved for top frames when they navigate | 736 // Check that window.name is preserved for top frames when they navigate |
746 // cross-process. See https://crbug.com/504164. | 737 // cross-process. See https://crbug.com/504164. |
747 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 738 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
748 PreserveTopFrameWindowNameOnCrossProcessNavigations) { | 739 PreserveTopFrameWindowNameOnCrossProcessNavigations) { |
749 StartEmbeddedServer(); | 740 StartEmbeddedServer(); |
750 | 741 |
751 GURL main_url(embedded_test_server()->GetURL("/title1.html")); | 742 GURL main_url(embedded_test_server()->GetURL("/title1.html")); |
752 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 743 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
753 | 744 |
754 // Get the original SiteInstance for later comparison. | 745 // Get the original SiteInstance for later comparison. |
755 scoped_refptr<SiteInstance> orig_site_instance( | 746 scoped_refptr<SiteInstance> orig_site_instance( |
756 shell()->web_contents()->GetSiteInstance()); | 747 shell()->web_contents()->GetSiteInstance()); |
757 EXPECT_TRUE(orig_site_instance.get() != NULL); | 748 EXPECT_TRUE(orig_site_instance.get() != NULL); |
758 | 749 |
759 // Open a popup using window.open with a 'foo' window.name. | 750 // Open a popup using window.open with a 'foo' window.name. |
760 Shell* new_shell = | 751 Shell* new_shell = OpenPopup(shell(), GURL(url::kAboutBlankURL), "foo"); |
761 OpenPopup(shell()->web_contents(), GURL(url::kAboutBlankURL), "foo"); | |
762 EXPECT_TRUE(new_shell); | 752 EXPECT_TRUE(new_shell); |
763 | 753 |
764 // The window.name for the new popup should be "foo". | 754 // The window.name for the new popup should be "foo". |
765 std::string name; | 755 std::string name; |
766 EXPECT_TRUE(ExecuteScriptAndExtractString( | 756 EXPECT_TRUE(ExecuteScriptAndExtractString( |
767 new_shell->web_contents(), | 757 new_shell, "window.domAutomationController.send(window.name);", &name)); |
768 "window.domAutomationController.send(window.name);", &name)); | |
769 EXPECT_EQ("foo", name); | 758 EXPECT_EQ("foo", name); |
770 | 759 |
771 // Now navigate the new tab to a different site. | 760 // Now navigate the new tab to a different site. |
772 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title2.html")); | 761 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title2.html")); |
773 EXPECT_TRUE(NavigateToURL(new_shell, foo_url)); | 762 EXPECT_TRUE(NavigateToURL(new_shell, foo_url)); |
774 scoped_refptr<SiteInstance> new_site_instance( | 763 scoped_refptr<SiteInstance> new_site_instance( |
775 new_shell->web_contents()->GetSiteInstance()); | 764 new_shell->web_contents()->GetSiteInstance()); |
776 EXPECT_NE(orig_site_instance, new_site_instance); | 765 EXPECT_NE(orig_site_instance, new_site_instance); |
777 | 766 |
778 // window.name should still be "foo". | 767 // window.name should still be "foo". |
779 name = ""; | 768 name = ""; |
780 EXPECT_TRUE(ExecuteScriptAndExtractString( | 769 EXPECT_TRUE(ExecuteScriptAndExtractString( |
781 new_shell->web_contents(), | 770 new_shell, "window.domAutomationController.send(window.name);", &name)); |
782 "window.domAutomationController.send(window.name);", &name)); | |
783 EXPECT_EQ("foo", name); | 771 EXPECT_EQ("foo", name); |
784 | 772 |
785 // Open another popup from the 'foo' popup and navigate it cross-site. | 773 // Open another popup from the 'foo' popup and navigate it cross-site. |
786 Shell* new_shell2 = | 774 Shell* new_shell2 = OpenPopup(new_shell, GURL(url::kAboutBlankURL), "bar"); |
787 OpenPopup(new_shell->web_contents(), GURL(url::kAboutBlankURL), "bar"); | |
788 EXPECT_TRUE(new_shell2); | 775 EXPECT_TRUE(new_shell2); |
789 GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title3.html")); | 776 GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title3.html")); |
790 EXPECT_TRUE(NavigateToURL(new_shell2, bar_url)); | 777 EXPECT_TRUE(NavigateToURL(new_shell2, bar_url)); |
791 | 778 |
792 // Check that the new popup's window.opener has name "foo", which verifies | 779 // Check that the new popup's window.opener has name "foo", which verifies |
793 // that new swapped-out RenderViews also propagate window.name. This has to | 780 // that new swapped-out RenderViews also propagate window.name. This has to |
794 // be done via window.open, since window.name isn't readable cross-origin. | 781 // be done via window.open, since window.name isn't readable cross-origin. |
795 bool success = false; | 782 bool success = false; |
796 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 783 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
797 new_shell2->web_contents(), | 784 new_shell2, |
798 "window.domAutomationController.send(" | 785 "window.domAutomationController.send(" |
799 " window.opener === window.open('','foo'));", | 786 " window.opener === window.open('','foo'));", |
800 &success)); | 787 &success)); |
801 EXPECT_TRUE(success); | 788 EXPECT_TRUE(success); |
802 } | 789 } |
803 | 790 |
804 // Test for crbug.com/99202. PostMessage calls should still work after | 791 // Test for crbug.com/99202. PostMessage calls should still work after |
805 // navigating the source and target windows to different sites. | 792 // navigating the source and target windows to different sites. |
806 // Specifically: | 793 // Specifically: |
807 // 1) Create 3 windows (opener, "foo", and _blank) and send "foo" cross-process. | 794 // 1) Create 3 windows (opener, "foo", and _blank) and send "foo" cross-process. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 foo_contents->GetLastCommittedURL().path()); | 833 foo_contents->GetLastCommittedURL().path()); |
847 NavigateToURL(new_shell, embedded_test_server()->GetURL( | 834 NavigateToURL(new_shell, embedded_test_server()->GetURL( |
848 "foo.com", "/post_message.html")); | 835 "foo.com", "/post_message.html")); |
849 scoped_refptr<SiteInstance> foo_site_instance( | 836 scoped_refptr<SiteInstance> foo_site_instance( |
850 foo_contents->GetSiteInstance()); | 837 foo_contents->GetSiteInstance()); |
851 EXPECT_NE(orig_site_instance, foo_site_instance); | 838 EXPECT_NE(orig_site_instance, foo_site_instance); |
852 | 839 |
853 // Second, a target=_blank window. | 840 // Second, a target=_blank window. |
854 ShellAddedObserver new_shell_observer2; | 841 ShellAddedObserver new_shell_observer2; |
855 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 842 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
856 shell()->web_contents(), | 843 shell(), |
857 "window.domAutomationController.send(clickSameSiteTargetBlankLink());", | 844 "window.domAutomationController.send(clickSameSiteTargetBlankLink());", |
858 &success)); | 845 &success)); |
859 EXPECT_TRUE(success); | 846 EXPECT_TRUE(success); |
860 | 847 |
861 // Wait for the navigation in the new window to finish, if it hasn't, then | 848 // Wait for the navigation in the new window to finish, if it hasn't, then |
862 // send it to post_message.html on the original site. | 849 // send it to post_message.html on the original site. |
863 Shell* new_shell2 = new_shell_observer2.GetShell(); | 850 Shell* new_shell2 = new_shell_observer2.GetShell(); |
864 WebContents* new_contents = new_shell2->web_contents(); | 851 WebContents* new_contents = new_shell2->web_contents(); |
865 WaitForLoadStop(new_contents); | 852 WaitForLoadStop(new_contents); |
866 EXPECT_EQ("/title2.html", new_contents->GetLastCommittedURL().path()); | 853 EXPECT_EQ("/title2.html", new_contents->GetLastCommittedURL().path()); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 // Now navigate the original (opener) tab to a different site. | 1053 // Now navigate the original (opener) tab to a different site. |
1067 NavigateToURL(shell(), | 1054 NavigateToURL(shell(), |
1068 embedded_test_server()->GetURL("foo.com", "/title1.html")); | 1055 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
1069 scoped_refptr<SiteInstance> new_site_instance( | 1056 scoped_refptr<SiteInstance> new_site_instance( |
1070 shell()->web_contents()->GetSiteInstance()); | 1057 shell()->web_contents()->GetSiteInstance()); |
1071 EXPECT_NE(orig_site_instance, new_site_instance); | 1058 EXPECT_NE(orig_site_instance, new_site_instance); |
1072 | 1059 |
1073 // The opened tab should be able to navigate the opener back to its process. | 1060 // The opened tab should be able to navigate the opener back to its process. |
1074 TestNavigationObserver navigation_observer(orig_contents); | 1061 TestNavigationObserver navigation_observer(orig_contents); |
1075 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 1062 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
1076 new_shell->web_contents(), | 1063 new_shell, "window.domAutomationController.send(navigateOpener());", |
1077 "window.domAutomationController.send(navigateOpener());", | |
1078 &success)); | 1064 &success)); |
1079 EXPECT_TRUE(success); | 1065 EXPECT_TRUE(success); |
1080 navigation_observer.Wait(); | 1066 navigation_observer.Wait(); |
1081 | 1067 |
1082 // Should have swapped back into this process. | 1068 // Should have swapped back into this process. |
1083 scoped_refptr<SiteInstance> revisit_site_instance( | 1069 scoped_refptr<SiteInstance> revisit_site_instance( |
1084 shell()->web_contents()->GetSiteInstance()); | 1070 shell()->web_contents()->GetSiteInstance()); |
1085 EXPECT_EQ(orig_site_instance, revisit_site_instance); | 1071 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
1086 } | 1072 } |
1087 | 1073 |
(...skipping 15 matching lines...) Expand all Loading... |
1103 EXPECT_NE(nullptr, orig_site_instance.get()); | 1089 EXPECT_NE(nullptr, orig_site_instance.get()); |
1104 | 1090 |
1105 // It is safe to obtain the root frame tree node here, as it doesn't change. | 1091 // It is safe to obtain the root frame tree node here, as it doesn't change. |
1106 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 1092 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
1107 ->GetFrameTree() | 1093 ->GetFrameTree() |
1108 ->root(); | 1094 ->root(); |
1109 ASSERT_EQ(1U, root->child_count()); | 1095 ASSERT_EQ(1U, root->child_count()); |
1110 EXPECT_EQ(frame_url, root->child_at(0)->current_url()); | 1096 EXPECT_EQ(frame_url, root->child_at(0)->current_url()); |
1111 | 1097 |
1112 // Register an unload handler that sends a postMessage to the top frame. | 1098 // Register an unload handler that sends a postMessage to the top frame. |
1113 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), | 1099 EXPECT_TRUE(ExecuteScript(root->child_at(0), "registerUnload();")); |
1114 "registerUnload();")); | |
1115 | 1100 |
1116 // Navigate the top frame cross-site. This will cause the top frame to be | 1101 // Navigate the top frame cross-site. This will cause the top frame to be |
1117 // swapped out and run unload handlers, and the original renderer process | 1102 // swapped out and run unload handlers, and the original renderer process |
1118 // should then terminate since it's not rendering any other frames. | 1103 // should then terminate since it's not rendering any other frames. |
1119 RenderProcessHostWatcher exit_observer( | 1104 RenderProcessHostWatcher exit_observer( |
1120 root->current_frame_host()->GetProcess(), | 1105 root->current_frame_host()->GetProcess(), |
1121 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); | 1106 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); |
1122 EXPECT_TRUE(NavigateToURL( | 1107 EXPECT_TRUE(NavigateToURL( |
1123 shell(), embedded_test_server()->GetURL("foo.com", "/title1.html"))); | 1108 shell(), embedded_test_server()->GetURL("foo.com", "/title1.html"))); |
1124 scoped_refptr<SiteInstance> new_site_instance( | 1109 scoped_refptr<SiteInstance> new_site_instance( |
(...skipping 17 matching lines...) Expand all Loading... |
1142 | 1127 |
1143 // Get the original SiteInstance for later comparison. | 1128 // Get the original SiteInstance for later comparison. |
1144 scoped_refptr<SiteInstance> orig_site_instance( | 1129 scoped_refptr<SiteInstance> orig_site_instance( |
1145 shell()->web_contents()->GetSiteInstance()); | 1130 shell()->web_contents()->GetSiteInstance()); |
1146 EXPECT_TRUE(orig_site_instance.get() != NULL); | 1131 EXPECT_TRUE(orig_site_instance.get() != NULL); |
1147 | 1132 |
1148 // Test clicking a target=foo link. | 1133 // Test clicking a target=foo link. |
1149 ShellAddedObserver new_shell_observer; | 1134 ShellAddedObserver new_shell_observer; |
1150 bool success = false; | 1135 bool success = false; |
1151 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 1136 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
1152 shell()->web_contents(), | 1137 shell(), |
1153 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 1138 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
1154 &success)); | 1139 &success)); |
1155 EXPECT_TRUE(success); | 1140 EXPECT_TRUE(success); |
1156 Shell* new_shell = new_shell_observer.GetShell(); | 1141 Shell* new_shell = new_shell_observer.GetShell(); |
1157 | 1142 |
1158 // Wait for the navigation in the new window to finish, if it hasn't. | 1143 // Wait for the navigation in the new window to finish, if it hasn't. |
1159 WaitForLoadStop(new_shell->web_contents()); | 1144 WaitForLoadStop(new_shell->web_contents()); |
1160 EXPECT_EQ("/navigate_opener.html", | 1145 EXPECT_EQ("/navigate_opener.html", |
1161 new_shell->web_contents()->GetLastCommittedURL().path()); | 1146 new_shell->web_contents()->GetLastCommittedURL().path()); |
1162 | 1147 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 EXPECT_EQ("/nocontent", | 1198 EXPECT_EQ("/nocontent", |
1214 shell()->web_contents()->GetVisibleURL().path()); | 1199 shell()->web_contents()->GetVisibleURL().path()); |
1215 EXPECT_FALSE( | 1200 EXPECT_FALSE( |
1216 shell()->web_contents()->GetController().GetLastCommittedEntry()); | 1201 shell()->web_contents()->GetController().GetLastCommittedEntry()); |
1217 | 1202 |
1218 // Renderer-initiated navigations should work. | 1203 // Renderer-initiated navigations should work. |
1219 base::string16 expected_title = ASCIIToUTF16("Title Of Awesomeness"); | 1204 base::string16 expected_title = ASCIIToUTF16("Title Of Awesomeness"); |
1220 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 1205 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
1221 GURL url = embedded_test_server()->GetURL("/title2.html"); | 1206 GURL url = embedded_test_server()->GetURL("/title2.html"); |
1222 EXPECT_TRUE(ExecuteScript( | 1207 EXPECT_TRUE(ExecuteScript( |
1223 shell()->web_contents(), | 1208 shell(), base::StringPrintf("location.href = '%s'", url.spec().c_str()))); |
1224 base::StringPrintf("location.href = '%s'", url.spec().c_str()))); | |
1225 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 1209 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
1226 | 1210 |
1227 // Opens in same tab. | 1211 // Opens in same tab. |
1228 EXPECT_EQ(1u, Shell::windows().size()); | 1212 EXPECT_EQ(1u, Shell::windows().size()); |
1229 EXPECT_EQ("/title2.html", | 1213 EXPECT_EQ("/title2.html", |
1230 shell()->web_contents()->GetLastCommittedURL().path()); | 1214 shell()->web_contents()->GetLastCommittedURL().path()); |
1231 | 1215 |
1232 // Should have the same SiteInstance. | 1216 // Should have the same SiteInstance. |
1233 scoped_refptr<SiteInstance> new_site_instance( | 1217 scoped_refptr<SiteInstance> new_site_instance( |
1234 shell()->web_contents()->GetSiteInstance()); | 1218 shell()->web_contents()->GetSiteInstance()); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 embedded_test_server()->GetURL("/remove_frame_on_unload.html")); | 1499 embedded_test_server()->GetURL("/remove_frame_on_unload.html")); |
1516 | 1500 |
1517 // Get the original SiteInstance for later comparison. | 1501 // Get the original SiteInstance for later comparison. |
1518 scoped_refptr<SiteInstance> orig_site_instance( | 1502 scoped_refptr<SiteInstance> orig_site_instance( |
1519 shell()->web_contents()->GetSiteInstance()); | 1503 shell()->web_contents()->GetSiteInstance()); |
1520 | 1504 |
1521 // Open a same-site page in a new window. | 1505 // Open a same-site page in a new window. |
1522 ShellAddedObserver new_shell_observer; | 1506 ShellAddedObserver new_shell_observer; |
1523 bool success = false; | 1507 bool success = false; |
1524 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 1508 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
1525 shell()->web_contents(), | 1509 shell(), "window.domAutomationController.send(openWindow());", &success)); |
1526 "window.domAutomationController.send(openWindow());", | |
1527 &success)); | |
1528 EXPECT_TRUE(success); | 1510 EXPECT_TRUE(success); |
1529 Shell* new_shell = new_shell_observer.GetShell(); | 1511 Shell* new_shell = new_shell_observer.GetShell(); |
1530 | 1512 |
1531 // Wait for the navigation in the new window to finish, if it hasn't. | 1513 // Wait for the navigation in the new window to finish, if it hasn't. |
1532 WaitForLoadStop(new_shell->web_contents()); | 1514 WaitForLoadStop(new_shell->web_contents()); |
1533 EXPECT_EQ("/title1.html", | 1515 EXPECT_EQ("/title1.html", |
1534 new_shell->web_contents()->GetLastCommittedURL().path()); | 1516 new_shell->web_contents()->GetLastCommittedURL().path()); |
1535 | 1517 |
1536 // Should have the same SiteInstance. | 1518 // Should have the same SiteInstance. |
1537 EXPECT_EQ(orig_site_instance.get(), | 1519 EXPECT_EQ(orig_site_instance.get(), |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1756 NavigateToURL(shell(), url1); | 1738 NavigateToURL(shell(), url1); |
1757 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 1739 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
1758 shell()->web_contents()->GetRenderProcessHost()->GetID())); | 1740 shell()->web_contents()->GetRenderProcessHost()->GetID())); |
1759 SiteInstance* site_instance1 = shell()->web_contents()->GetSiteInstance(); | 1741 SiteInstance* site_instance1 = shell()->web_contents()->GetSiteInstance(); |
1760 | 1742 |
1761 // Open a new tab. Initially it gets a render view in the original tab's | 1743 // Open a new tab. Initially it gets a render view in the original tab's |
1762 // current site instance. | 1744 // current site instance. |
1763 TestNavigationObserver nav_observer(NULL); | 1745 TestNavigationObserver nav_observer(NULL); |
1764 nav_observer.StartWatchingNewWebContents(); | 1746 nav_observer.StartWatchingNewWebContents(); |
1765 ShellAddedObserver shao; | 1747 ShellAddedObserver shao; |
1766 OpenUrlViaClickTarget(shell()->web_contents(), url2); | 1748 OpenUrlViaClickTarget(shell(), url2); |
1767 nav_observer.Wait(); | 1749 nav_observer.Wait(); |
1768 Shell* new_shell = shao.GetShell(); | 1750 Shell* new_shell = shao.GetShell(); |
1769 WebContentsImpl* new_web_contents = static_cast<WebContentsImpl*>( | 1751 WebContentsImpl* new_web_contents = static_cast<WebContentsImpl*>( |
1770 new_shell->web_contents()); | 1752 new_shell->web_contents()); |
1771 SiteInstance* site_instance2 = new_web_contents->GetSiteInstance(); | 1753 SiteInstance* site_instance2 = new_web_contents->GetSiteInstance(); |
1772 | 1754 |
1773 EXPECT_NE(site_instance2, site_instance1); | 1755 EXPECT_NE(site_instance2, site_instance1); |
1774 EXPECT_TRUE(site_instance2->IsRelatedSiteInstance(site_instance1)); | 1756 EXPECT_TRUE(site_instance2->IsRelatedSiteInstance(site_instance1)); |
1775 RenderViewHost* initial_rvh = new_web_contents-> | 1757 RenderViewHost* initial_rvh = new_web_contents-> |
1776 GetRenderManagerForTesting()->GetSwappedOutRenderViewHost(site_instance1); | 1758 GetRenderManagerForTesting()->GetSwappedOutRenderViewHost(site_instance1); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1849 base::FilePath file; | 1831 base::FilePath file; |
1850 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file)); | 1832 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file)); |
1851 file = file.AppendASCII("bar"); | 1833 file = file.AppendASCII("bar"); |
1852 | 1834 |
1853 // Navigate to url and get it to reference a file in its PageState. | 1835 // Navigate to url and get it to reference a file in its PageState. |
1854 GURL url1(embedded_test_server()->GetURL("/file_input.html")); | 1836 GURL url1(embedded_test_server()->GetURL("/file_input.html")); |
1855 NavigateToURL(shell(), url1); | 1837 NavigateToURL(shell(), url1); |
1856 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); | 1838 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); |
1857 std::unique_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file)); | 1839 std::unique_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file)); |
1858 shell()->web_contents()->SetDelegate(delegate.get()); | 1840 shell()->web_contents()->SetDelegate(delegate.get()); |
1859 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 1841 EXPECT_TRUE( |
1860 "document.getElementById('fileinput').click();")); | 1842 ExecuteScript(shell(), "document.getElementById('fileinput').click();")); |
1861 EXPECT_TRUE(delegate->file_chosen()); | 1843 EXPECT_TRUE(delegate->file_chosen()); |
1862 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 1844 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
1863 process_id, file)); | 1845 process_id, file)); |
1864 | 1846 |
1865 // Disable the swap out timer so we wait for the UpdateState message. | 1847 // Disable the swap out timer so we wait for the UpdateState message. |
1866 static_cast<WebContentsImpl*>(shell()->web_contents()) | 1848 static_cast<WebContentsImpl*>(shell()->web_contents()) |
1867 ->GetMainFrame() | 1849 ->GetMainFrame() |
1868 ->DisableSwapOutTimerForTesting(); | 1850 ->DisableSwapOutTimerForTesting(); |
1869 | 1851 |
1870 // Navigate to a different process without access to the file, and wait for | 1852 // Navigate to a different process without access to the file, and wait for |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1912 file = file.AppendASCII("bar"); | 1894 file = file.AppendASCII("bar"); |
1913 | 1895 |
1914 // Navigate to url and get it to reference a file in its PageState. | 1896 // Navigate to url and get it to reference a file in its PageState. |
1915 GURL url1(embedded_test_server()->GetURL("/file_input_subframe.html")); | 1897 GURL url1(embedded_test_server()->GetURL("/file_input_subframe.html")); |
1916 NavigateToURL(shell(), url1); | 1898 NavigateToURL(shell(), url1); |
1917 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | 1899 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); |
1918 FrameTreeNode* root = wc->GetFrameTree()->root(); | 1900 FrameTreeNode* root = wc->GetFrameTree()->root(); |
1919 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); | 1901 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); |
1920 std::unique_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file)); | 1902 std::unique_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file)); |
1921 shell()->web_contents()->SetDelegate(delegate.get()); | 1903 shell()->web_contents()->SetDelegate(delegate.get()); |
1922 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), | 1904 EXPECT_TRUE(ExecuteScript(root->child_at(0), |
1923 "document.getElementById('fileinput').click();")); | 1905 "document.getElementById('fileinput').click();")); |
1924 EXPECT_TRUE(delegate->file_chosen()); | 1906 EXPECT_TRUE(delegate->file_chosen()); |
1925 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 1907 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
1926 process_id, file)); | 1908 process_id, file)); |
1927 | 1909 |
1928 // Disable the swap out timer so we wait for the UpdateState message. | 1910 // Disable the swap out timer so we wait for the UpdateState message. |
1929 root->current_frame_host()->DisableSwapOutTimerForTesting(); | 1911 root->current_frame_host()->DisableSwapOutTimerForTesting(); |
1930 | 1912 |
1931 // Navigate to a different process without access to the file, and wait for | 1913 // Navigate to a different process without access to the file, and wait for |
1932 // the old process to exit. | 1914 // the old process to exit. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2046 | 2028 |
2047 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 2029 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
2048 ->GetFrameTree() | 2030 ->GetFrameTree() |
2049 ->root(); | 2031 ->root(); |
2050 | 2032 |
2051 scoped_refptr<SiteInstance> orig_site_instance( | 2033 scoped_refptr<SiteInstance> orig_site_instance( |
2052 shell()->web_contents()->GetSiteInstance()); | 2034 shell()->web_contents()->GetSiteInstance()); |
2053 EXPECT_TRUE(orig_site_instance); | 2035 EXPECT_TRUE(orig_site_instance); |
2054 | 2036 |
2055 // Open a popup and navigate it cross-site. | 2037 // Open a popup and navigate it cross-site. |
2056 Shell* new_shell = | 2038 Shell* new_shell = OpenPopup(shell(), GURL(url::kAboutBlankURL), "foo"); |
2057 OpenPopup(shell()->web_contents(), GURL(url::kAboutBlankURL), "foo"); | |
2058 EXPECT_TRUE(new_shell); | 2039 EXPECT_TRUE(new_shell); |
2059 FrameTreeNode* popup_root = | 2040 FrameTreeNode* popup_root = |
2060 static_cast<WebContentsImpl*>(new_shell->web_contents()) | 2041 static_cast<WebContentsImpl*>(new_shell->web_contents()) |
2061 ->GetFrameTree() | 2042 ->GetFrameTree() |
2062 ->root(); | 2043 ->root(); |
2063 | 2044 |
2064 GURL cross_site_url = | 2045 GURL cross_site_url = |
2065 embedded_test_server()->GetURL("foo.com", "/title2.html"); | 2046 embedded_test_server()->GetURL("foo.com", "/title2.html"); |
2066 EXPECT_TRUE(NavigateToURL(new_shell, cross_site_url)); | 2047 EXPECT_TRUE(NavigateToURL(new_shell, cross_site_url)); |
2067 | 2048 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2112 // It is safe to obtain the root frame tree node here, as it doesn't change. | 2093 // It is safe to obtain the root frame tree node here, as it doesn't change. |
2113 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 2094 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
2114 ->GetFrameTree() | 2095 ->GetFrameTree() |
2115 ->root(); | 2096 ->root(); |
2116 | 2097 |
2117 scoped_refptr<SiteInstance> orig_site_instance( | 2098 scoped_refptr<SiteInstance> orig_site_instance( |
2118 shell()->web_contents()->GetSiteInstance()); | 2099 shell()->web_contents()->GetSiteInstance()); |
2119 EXPECT_TRUE(orig_site_instance); | 2100 EXPECT_TRUE(orig_site_instance); |
2120 | 2101 |
2121 // Open a cross-site popup named "foo" and a same-site popup named "bar". | 2102 // Open a cross-site popup named "foo" and a same-site popup named "bar". |
2122 Shell* foo_shell = | 2103 Shell* foo_shell = OpenPopup(shell(), GURL(url::kAboutBlankURL), "foo"); |
2123 OpenPopup(shell()->web_contents(), GURL(url::kAboutBlankURL), "foo"); | |
2124 EXPECT_TRUE(foo_shell); | 2104 EXPECT_TRUE(foo_shell); |
2125 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/post_message.html")); | 2105 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/post_message.html")); |
2126 NavigateToURL(foo_shell, foo_url); | 2106 NavigateToURL(foo_shell, foo_url); |
2127 | 2107 |
2128 GURL bar_url(embedded_test_server()->GetURL( | 2108 GURL bar_url(embedded_test_server()->GetURL( |
2129 "/frame_tree/page_with_post_message_frames.html")); | 2109 "/frame_tree/page_with_post_message_frames.html")); |
2130 Shell* bar_shell = OpenPopup(shell()->web_contents(), bar_url, "bar"); | 2110 Shell* bar_shell = OpenPopup(shell(), bar_url, "bar"); |
2131 EXPECT_TRUE(bar_shell); | 2111 EXPECT_TRUE(bar_shell); |
2132 | 2112 |
2133 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 2113 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
2134 foo_shell->web_contents()->GetSiteInstance()); | 2114 foo_shell->web_contents()->GetSiteInstance()); |
2135 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 2115 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
2136 bar_shell->web_contents()->GetSiteInstance()); | 2116 bar_shell->web_contents()->GetSiteInstance()); |
2137 | 2117 |
2138 // Initially, both popups' openers should point to main window. | 2118 // Initially, both popups' openers should point to main window. |
2139 FrameTreeNode* foo_root = | 2119 FrameTreeNode* foo_root = |
2140 static_cast<WebContentsImpl*>(foo_shell->web_contents()) | 2120 static_cast<WebContentsImpl*>(foo_shell->web_contents()) |
2141 ->GetFrameTree() | 2121 ->GetFrameTree() |
2142 ->root(); | 2122 ->root(); |
2143 FrameTreeNode* bar_root = | 2123 FrameTreeNode* bar_root = |
2144 static_cast<WebContentsImpl*>(bar_shell->web_contents()) | 2124 static_cast<WebContentsImpl*>(bar_shell->web_contents()) |
2145 ->GetFrameTree() | 2125 ->GetFrameTree() |
2146 ->root(); | 2126 ->root(); |
2147 EXPECT_EQ(root, foo_root->opener()); | 2127 EXPECT_EQ(root, foo_root->opener()); |
2148 EXPECT_EQ(root, bar_root->opener()); | 2128 EXPECT_EQ(root, bar_root->opener()); |
2149 | 2129 |
2150 // From the bar process, use window.open to update foo's opener to point to | 2130 // From the bar process, use window.open to update foo's opener to point to |
2151 // bar. This is allowed since bar is same-origin with foo's opener. Use | 2131 // bar. This is allowed since bar is same-origin with foo's opener. Use |
2152 // window.open with an empty URL, which should return a reference to the | 2132 // window.open with an empty URL, which should return a reference to the |
2153 // target frame without navigating it. | 2133 // target frame without navigating it. |
2154 bool success = false; | 2134 bool success = false; |
2155 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 2135 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
2156 bar_shell->web_contents(), | 2136 bar_shell, |
2157 "window.domAutomationController.send(!!window.open('','foo'));", | 2137 "window.domAutomationController.send(!!window.open('','foo'));", |
2158 &success)); | 2138 &success)); |
2159 EXPECT_TRUE(success); | 2139 EXPECT_TRUE(success); |
2160 EXPECT_FALSE(foo_shell->web_contents()->IsLoading()); | 2140 EXPECT_FALSE(foo_shell->web_contents()->IsLoading()); |
2161 EXPECT_EQ(foo_url, foo_root->current_url()); | 2141 EXPECT_EQ(foo_url, foo_root->current_url()); |
2162 | 2142 |
2163 // Check that updated opener propagated to the browser process. | 2143 // Check that updated opener propagated to the browser process. |
2164 EXPECT_EQ(bar_root, foo_root->opener()); | 2144 EXPECT_EQ(bar_root, foo_root->opener()); |
2165 | 2145 |
2166 // Check that foo's opener was updated in foo's process. Send a postMessage | 2146 // Check that foo's opener was updated in foo's process. Send a postMessage |
2167 // to the opener and check that the right window (bar_shell) receives it. | 2147 // to the opener and check that the right window (bar_shell) receives it. |
2168 base::string16 expected_title = ASCIIToUTF16("opener-msg"); | 2148 base::string16 expected_title = ASCIIToUTF16("opener-msg"); |
2169 TitleWatcher title_watcher(bar_shell->web_contents(), expected_title); | 2149 TitleWatcher title_watcher(bar_shell->web_contents(), expected_title); |
2170 success = false; | 2150 success = false; |
2171 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 2151 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
2172 foo_shell->web_contents(), | 2152 foo_shell, |
2173 "window.domAutomationController.send(postToOpener('opener-msg', '*'));", | 2153 "window.domAutomationController.send(postToOpener('opener-msg', '*'));", |
2174 &success)); | 2154 &success)); |
2175 EXPECT_TRUE(success); | 2155 EXPECT_TRUE(success); |
2176 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 2156 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
2177 | 2157 |
2178 // Check that a non-null assignment to the opener doesn't change the opener | 2158 // Check that a non-null assignment to the opener doesn't change the opener |
2179 // in the browser process. | 2159 // in the browser process. |
2180 EXPECT_TRUE( | 2160 EXPECT_TRUE(ExecuteScript(foo_shell, "window.opener = window;")); |
2181 ExecuteScript(foo_shell->web_contents(), "window.opener = window;")); | |
2182 EXPECT_EQ(bar_root, foo_root->opener()); | 2161 EXPECT_EQ(bar_root, foo_root->opener()); |
2183 } | 2162 } |
2184 | 2163 |
2185 // Tests that when a popup is opened, which is then navigated cross-process and | 2164 // Tests that when a popup is opened, which is then navigated cross-process and |
2186 // back, it can be still accessed through the original window reference in | 2165 // back, it can be still accessed through the original window reference in |
2187 // JavaScript. See https://crbug.com/537657 | 2166 // JavaScript. See https://crbug.com/537657 |
2188 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 2167 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
2189 PopupKeepsWindowReferenceCrossProcesAndBack) { | 2168 PopupKeepsWindowReferenceCrossProcesAndBack) { |
2190 StartEmbeddedServer(); | 2169 StartEmbeddedServer(); |
2191 | 2170 |
2192 // Load a page with links that open in a new window. | 2171 // Load a page with links that open in a new window. |
2193 NavigateToPageWithLinks(shell()); | 2172 NavigateToPageWithLinks(shell()); |
2194 | 2173 |
2195 // Click a target=foo link to open a popup. | 2174 // Click a target=foo link to open a popup. |
2196 ShellAddedObserver new_shell_observer; | 2175 ShellAddedObserver new_shell_observer; |
2197 bool success = false; | 2176 bool success = false; |
2198 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 2177 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
2199 shell()->web_contents(), | 2178 shell(), |
2200 "window.domAutomationController.send(clickSameSiteTargetedLink());", | 2179 "window.domAutomationController.send(clickSameSiteTargetedLink());", |
2201 &success)); | 2180 &success)); |
2202 EXPECT_TRUE(success); | 2181 EXPECT_TRUE(success); |
2203 Shell* new_shell = new_shell_observer.GetShell(); | 2182 Shell* new_shell = new_shell_observer.GetShell(); |
2204 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); | 2183 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); |
2205 | 2184 |
2206 // Wait for the navigation in the popup to finish, if it hasn't. | 2185 // Wait for the navigation in the popup to finish, if it hasn't. |
2207 WaitForLoadStop(new_shell->web_contents()); | 2186 WaitForLoadStop(new_shell->web_contents()); |
2208 EXPECT_EQ("/navigate_opener.html", | 2187 EXPECT_EQ("/navigate_opener.html", |
2209 new_shell->web_contents()->GetLastCommittedURL().path()); | 2188 new_shell->web_contents()->GetLastCommittedURL().path()); |
2210 | 2189 |
2211 // Capture the window reference, so we can check that accessing its location | 2190 // Capture the window reference, so we can check that accessing its location |
2212 // works after navigating cross-process and back. | 2191 // works after navigating cross-process and back. |
2213 GURL expected_url = new_shell->web_contents()->GetLastCommittedURL(); | 2192 GURL expected_url = new_shell->web_contents()->GetLastCommittedURL(); |
2214 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 2193 EXPECT_TRUE(ExecuteScript(shell(), "saveWindowReference();")); |
2215 "saveWindowReference();")); | |
2216 | 2194 |
2217 // Now navigate the popup to a different site and then go back. | 2195 // Now navigate the popup to a different site and then go back. |
2218 NavigateToURL(new_shell, | 2196 NavigateToURL(new_shell, |
2219 embedded_test_server()->GetURL("foo.com", "/title1.html")); | 2197 embedded_test_server()->GetURL("foo.com", "/title1.html")); |
2220 TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); | 2198 TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); |
2221 new_shell->web_contents()->GetController().GoBack(); | 2199 new_shell->web_contents()->GetController().GoBack(); |
2222 back_nav_load_observer.Wait(); | 2200 back_nav_load_observer.Wait(); |
2223 | 2201 |
2224 // Check that the location.href window attribute is accessible and is correct. | 2202 // Check that the location.href window attribute is accessible and is correct. |
2225 std::string result; | 2203 std::string result; |
2226 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2204 EXPECT_TRUE(ExecuteScriptAndExtractString( |
2227 shell()->web_contents(), | 2205 shell(), |
2228 "window.domAutomationController.send(getLastOpenedWindowLocation());", | 2206 "window.domAutomationController.send(getLastOpenedWindowLocation());", |
2229 &result)); | 2207 &result)); |
2230 EXPECT_EQ(expected_url.spec(), result); | 2208 EXPECT_EQ(expected_url.spec(), result); |
2231 } | 2209 } |
2232 | 2210 |
2233 // Tests that going back to the same SiteInstance as a pending RenderFrameHost | 2211 // Tests that going back to the same SiteInstance as a pending RenderFrameHost |
2234 // doesn't create a duplicate RenderFrameProxyHost. For example: | 2212 // doesn't create a duplicate RenderFrameProxyHost. For example: |
2235 // 1. Navigate to a page on the opener site - a.com | 2213 // 1. Navigate to a page on the opener site - a.com |
2236 // 2. Navigate to a page on site b.com | 2214 // 2. Navigate to a page on site b.com |
2237 // 3. Start a navigation to another page on a.com, but commit is delayed. | 2215 // 3. Start a navigation to another page on a.com, but commit is delayed. |
2238 // 4. Go back. | 2216 // 4. Go back. |
2239 // See https://crbug.com/541619. | 2217 // See https://crbug.com/541619. |
2240 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 2218 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
2241 PopupPendingAndBackToSameSiteInstance) { | 2219 PopupPendingAndBackToSameSiteInstance) { |
2242 StartEmbeddedServer(); | 2220 StartEmbeddedServer(); |
2243 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | 2221 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
2244 NavigateToURL(shell(), main_url); | 2222 NavigateToURL(shell(), main_url); |
2245 | 2223 |
2246 // Open a popup to navigate. | 2224 // Open a popup to navigate. |
2247 Shell* new_shell = | 2225 Shell* new_shell = OpenPopup(shell(), GURL(url::kAboutBlankURL), "foo"); |
2248 OpenPopup(shell()->web_contents(), GURL(url::kAboutBlankURL), "foo"); | |
2249 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 2226 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
2250 new_shell->web_contents()->GetSiteInstance()); | 2227 new_shell->web_contents()->GetSiteInstance()); |
2251 | 2228 |
2252 // Navigate the popup to a different site. | 2229 // Navigate the popup to a different site. |
2253 NavigateToURL(new_shell, | 2230 NavigateToURL(new_shell, |
2254 embedded_test_server()->GetURL("b.com", "/title2.html")); | 2231 embedded_test_server()->GetURL("b.com", "/title2.html")); |
2255 | 2232 |
2256 // Navigate again to the original site, but to a page that will take a while | 2233 // Navigate again to the original site, but to a page that will take a while |
2257 // to commit. | 2234 // to commit. |
2258 GURL same_site_url(embedded_test_server()->GetURL("a.com", "/title3.html")); | 2235 GURL same_site_url(embedded_test_server()->GetURL("a.com", "/title3.html")); |
(...skipping 12 matching lines...) Expand all Loading... |
2271 // Tests that InputMsg type IPCs are ignored by swapped out RenderViews. It | 2248 // Tests that InputMsg type IPCs are ignored by swapped out RenderViews. It |
2272 // uses the SetFocus IPC, as RenderView has a CHECK to ensure that condition | 2249 // uses the SetFocus IPC, as RenderView has a CHECK to ensure that condition |
2273 // never happens. | 2250 // never happens. |
2274 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 2251 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
2275 InputMsgToSwappedOutRVHIsIgnored) { | 2252 InputMsgToSwappedOutRVHIsIgnored) { |
2276 StartEmbeddedServer(); | 2253 StartEmbeddedServer(); |
2277 EXPECT_TRUE(NavigateToURL( | 2254 EXPECT_TRUE(NavigateToURL( |
2278 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); | 2255 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); |
2279 | 2256 |
2280 // Open a popup to navigate cross-process. | 2257 // Open a popup to navigate cross-process. |
2281 Shell* new_shell = | 2258 Shell* new_shell = OpenPopup(shell(), GURL(url::kAboutBlankURL), "foo"); |
2282 OpenPopup(shell()->web_contents(), GURL(url::kAboutBlankURL), "foo"); | |
2283 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 2259 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
2284 new_shell->web_contents()->GetSiteInstance()); | 2260 new_shell->web_contents()->GetSiteInstance()); |
2285 | 2261 |
2286 // Keep a pointer to the RenderViewHost, which will be in swapped out | 2262 // Keep a pointer to the RenderViewHost, which will be in swapped out |
2287 // state after navigating cross-process. This is how this test is causing | 2263 // state after navigating cross-process. This is how this test is causing |
2288 // a swapped out RenderView to receive InputMsg IPC message. | 2264 // a swapped out RenderView to receive InputMsg IPC message. |
2289 WebContentsImpl* new_web_contents = | 2265 WebContentsImpl* new_web_contents = |
2290 static_cast<WebContentsImpl*>(new_shell->web_contents()); | 2266 static_cast<WebContentsImpl*>(new_shell->web_contents()); |
2291 FrameTreeNode* new_root = new_web_contents->GetFrameTree()->root(); | 2267 FrameTreeNode* new_root = new_web_contents->GetFrameTree()->root(); |
2292 RenderViewHostImpl* rvh = new_web_contents->GetRenderViewHost(); | 2268 RenderViewHostImpl* rvh = new_web_contents->GetRenderViewHost(); |
(...skipping 26 matching lines...) Expand all Loading... |
2319 // (whose process has been killed/crashed) recreates properly the RenderView and | 2295 // (whose process has been killed/crashed) recreates properly the RenderView and |
2320 // RenderFrameProxy on the renderer side. | 2296 // RenderFrameProxy on the renderer side. |
2321 // See https://crbug.com/544271 | 2297 // See https://crbug.com/544271 |
2322 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 2298 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
2323 RenderViewInitAfterProcessKill) { | 2299 RenderViewInitAfterProcessKill) { |
2324 StartEmbeddedServer(); | 2300 StartEmbeddedServer(); |
2325 EXPECT_TRUE(NavigateToURL( | 2301 EXPECT_TRUE(NavigateToURL( |
2326 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); | 2302 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); |
2327 | 2303 |
2328 // Open a popup to navigate. | 2304 // Open a popup to navigate. |
2329 Shell* new_shell = | 2305 Shell* new_shell = OpenPopup(shell(), GURL(url::kAboutBlankURL), "foo"); |
2330 OpenPopup(shell()->web_contents(), GURL(url::kAboutBlankURL), "foo"); | |
2331 FrameTreeNode* popup_root = | 2306 FrameTreeNode* popup_root = |
2332 static_cast<WebContentsImpl*>(new_shell->web_contents()) | 2307 static_cast<WebContentsImpl*>(new_shell->web_contents()) |
2333 ->GetFrameTree() | 2308 ->GetFrameTree() |
2334 ->root(); | 2309 ->root(); |
2335 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 2310 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
2336 new_shell->web_contents()->GetSiteInstance()); | 2311 new_shell->web_contents()->GetSiteInstance()); |
2337 | 2312 |
2338 // Navigate the popup to a different site. | 2313 // Navigate the popup to a different site. |
2339 EXPECT_TRUE(NavigateToURL( | 2314 EXPECT_TRUE(NavigateToURL( |
2340 new_shell, embedded_test_server()->GetURL("b.com", "/title2.html"))); | 2315 new_shell, embedded_test_server()->GetURL("b.com", "/title2.html"))); |
(...skipping 22 matching lines...) Expand all Loading... |
2363 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 2338 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
2364 CreateRenderViewAfterProcessKillAndClosedProxy) { | 2339 CreateRenderViewAfterProcessKillAndClosedProxy) { |
2365 StartEmbeddedServer(); | 2340 StartEmbeddedServer(); |
2366 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 2341 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
2367 ->GetFrameTree() | 2342 ->GetFrameTree() |
2368 ->root(); | 2343 ->root(); |
2369 | 2344 |
2370 // Give an initial page an unload handler that never completes. | 2345 // Give an initial page an unload handler that never completes. |
2371 EXPECT_TRUE(NavigateToURL( | 2346 EXPECT_TRUE(NavigateToURL( |
2372 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); | 2347 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); |
2373 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), | 2348 EXPECT_TRUE( |
2374 "window.onunload=function(e){ while(1); };\n")); | 2349 ExecuteScript(root, "window.onunload=function(e){ while(1); };\n")); |
2375 | 2350 |
2376 // Open a popup in the same process. | 2351 // Open a popup in the same process. |
2377 Shell* new_shell = | 2352 Shell* new_shell = OpenPopup(shell(), GURL(url::kAboutBlankURL), "foo"); |
2378 OpenPopup(shell()->web_contents(), GURL(url::kAboutBlankURL), "foo"); | |
2379 FrameTreeNode* popup_root = | 2353 FrameTreeNode* popup_root = |
2380 static_cast<WebContentsImpl*>(new_shell->web_contents()) | 2354 static_cast<WebContentsImpl*>(new_shell->web_contents()) |
2381 ->GetFrameTree() | 2355 ->GetFrameTree() |
2382 ->root(); | 2356 ->root(); |
2383 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 2357 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
2384 new_shell->web_contents()->GetSiteInstance()); | 2358 new_shell->web_contents()->GetSiteInstance()); |
2385 | 2359 |
2386 // Navigate the first tab to a different site, and only wait for commit, not | 2360 // Navigate the first tab to a different site, and only wait for commit, not |
2387 // load stop. | 2361 // load stop. |
2388 RenderFrameHostImpl* rfh_a = root->current_frame_host(); | 2362 RenderFrameHostImpl* rfh_a = root->current_frame_host(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2444 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 2418 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
2445 RenderViewInitAfterNewProxyAndProcessKill) { | 2419 RenderViewInitAfterNewProxyAndProcessKill) { |
2446 StartEmbeddedServer(); | 2420 StartEmbeddedServer(); |
2447 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 2421 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
2448 ->GetFrameTree() | 2422 ->GetFrameTree() |
2449 ->root(); | 2423 ->root(); |
2450 | 2424 |
2451 // Give an initial page an unload handler that never completes. | 2425 // Give an initial page an unload handler that never completes. |
2452 EXPECT_TRUE(NavigateToURL( | 2426 EXPECT_TRUE(NavigateToURL( |
2453 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); | 2427 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); |
2454 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), | 2428 EXPECT_TRUE( |
2455 "window.onunload=function(e){ while(1); };\n")); | 2429 ExecuteScript(root, "window.onunload=function(e){ while(1); };\n")); |
2456 | 2430 |
2457 // Navigate the tab to a different site, and only wait for commit, not load | 2431 // Navigate the tab to a different site, and only wait for commit, not load |
2458 // stop. | 2432 // stop. |
2459 RenderFrameHostImpl* rfh_a = root->current_frame_host(); | 2433 RenderFrameHostImpl* rfh_a = root->current_frame_host(); |
2460 rfh_a->DisableSwapOutTimerForTesting(); | 2434 rfh_a->DisableSwapOutTimerForTesting(); |
2461 SiteInstanceImpl* site_instance_a = rfh_a->GetSiteInstance(); | 2435 SiteInstanceImpl* site_instance_a = rfh_a->GetSiteInstance(); |
2462 TestFrameNavigationObserver commit_observer(root); | 2436 TestFrameNavigationObserver commit_observer(root); |
2463 shell()->LoadURL(embedded_test_server()->GetURL("b.com", "/title2.html")); | 2437 shell()->LoadURL(embedded_test_server()->GetURL("b.com", "/title2.html")); |
2464 commit_observer.WaitForCommit(); | 2438 commit_observer.WaitForCommit(); |
2465 EXPECT_NE(site_instance_a, shell()->web_contents()->GetSiteInstance()); | 2439 EXPECT_NE(site_instance_a, shell()->web_contents()->GetSiteInstance()); |
2466 | 2440 |
2467 // The previous RFH should still be pending deletion, as we wait for either | 2441 // The previous RFH should still be pending deletion, as we wait for either |
2468 // the SwapOut ACK or a timeout. | 2442 // the SwapOut ACK or a timeout. |
2469 ASSERT_TRUE(rfh_a->IsRenderFrameLive()); | 2443 ASSERT_TRUE(rfh_a->IsRenderFrameLive()); |
2470 ASSERT_FALSE(rfh_a->is_active()); | 2444 ASSERT_FALSE(rfh_a->is_active()); |
2471 | 2445 |
2472 // When the previous RFH was swapped out, it should have still gotten a | 2446 // When the previous RFH was swapped out, it should have still gotten a |
2473 // replacement proxy even though it's the last active frame in the process. | 2447 // replacement proxy even though it's the last active frame in the process. |
2474 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site_instance_a)); | 2448 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site_instance_a)); |
2475 | 2449 |
2476 // Open a popup in the new B process. | 2450 // Open a popup in the new B process. |
2477 Shell* new_shell = | 2451 Shell* new_shell = OpenPopup(shell(), GURL(url::kAboutBlankURL), "foo"); |
2478 OpenPopup(shell()->web_contents(), GURL(url::kAboutBlankURL), "foo"); | |
2479 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 2452 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
2480 new_shell->web_contents()->GetSiteInstance()); | 2453 new_shell->web_contents()->GetSiteInstance()); |
2481 | 2454 |
2482 // Navigate the popup to the original site, but don't wait for commit (which | 2455 // Navigate the popup to the original site, but don't wait for commit (which |
2483 // won't happen). This should reuse the proxy in the original tab, which at | 2456 // won't happen). This should reuse the proxy in the original tab, which at |
2484 // this point exists alongside the RFH pending deletion. | 2457 // this point exists alongside the RFH pending deletion. |
2485 new_shell->LoadURL(embedded_test_server()->GetURL("a.com", "/title2.html")); | 2458 new_shell->LoadURL(embedded_test_server()->GetURL("a.com", "/title2.html")); |
2486 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site_instance_a)); | 2459 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost(site_instance_a)); |
2487 | 2460 |
2488 // Kill the old process. | 2461 // Kill the old process. |
(...skipping 22 matching lines...) Expand all Loading... |
2511 // its site occurs before it commits. Otherwise the renderer process will have | 2484 // its site occurs before it commits. Otherwise the renderer process will have |
2512 // two competing pending RenderFrames that both try to swap with the same | 2485 // two competing pending RenderFrames that both try to swap with the same |
2513 // RenderFrameProxy. See https://crbug.com/545900. | 2486 // RenderFrameProxy. See https://crbug.com/545900. |
2514 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 2487 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
2515 ConsecutiveNavigationsToSite) { | 2488 ConsecutiveNavigationsToSite) { |
2516 StartEmbeddedServer(); | 2489 StartEmbeddedServer(); |
2517 EXPECT_TRUE(NavigateToURL( | 2490 EXPECT_TRUE(NavigateToURL( |
2518 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); | 2491 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); |
2519 | 2492 |
2520 // Open a popup and navigate it to b.com to keep the b.com process alive. | 2493 // Open a popup and navigate it to b.com to keep the b.com process alive. |
2521 Shell* new_shell = | 2494 Shell* new_shell = OpenPopup(shell(), GURL(url::kAboutBlankURL), "popup"); |
2522 OpenPopup(shell()->web_contents(), GURL(url::kAboutBlankURL), "popup"); | |
2523 NavigateToURL(new_shell, | 2495 NavigateToURL(new_shell, |
2524 embedded_test_server()->GetURL("b.com", "/title3.html")); | 2496 embedded_test_server()->GetURL("b.com", "/title3.html")); |
2525 | 2497 |
2526 // Start a cross-site navigation to the same site but don't commit. | 2498 // Start a cross-site navigation to the same site but don't commit. |
2527 GURL cross_site_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 2499 GURL cross_site_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
2528 NavigationStallDelegate stall_delegate(cross_site_url); | 2500 NavigationStallDelegate stall_delegate(cross_site_url); |
2529 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate); | 2501 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate); |
2530 shell()->LoadURL(cross_site_url); | 2502 shell()->LoadURL(cross_site_url); |
2531 | 2503 |
2532 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 2504 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2579 | 2551 |
2580 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | 2552 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
2581 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 2553 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
2582 | 2554 |
2583 // Add a sandboxed about:blank iframe. | 2555 // Add a sandboxed about:blank iframe. |
2584 { | 2556 { |
2585 std::string script = | 2557 std::string script = |
2586 "var frame = document.createElement('iframe');\n" | 2558 "var frame = document.createElement('iframe');\n" |
2587 "frame.sandbox = 'allow-scripts allow-popups';\n" | 2559 "frame.sandbox = 'allow-scripts allow-popups';\n" |
2588 "document.body.appendChild(frame);\n"; | 2560 "document.body.appendChild(frame);\n"; |
2589 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | 2561 EXPECT_TRUE(ExecuteScript(shell(), script)); |
2590 } | 2562 } |
2591 | 2563 |
2592 // Navigate iframe to a page with target=_blank links, and rewrite the links | 2564 // Navigate iframe to a page with target=_blank links, and rewrite the links |
2593 // to point to valid cross-site URLs. | 2565 // to point to valid cross-site URLs. |
2594 GURL frame_url( | 2566 GURL frame_url( |
2595 embedded_test_server()->GetURL("a.com", "/click-noreferrer-links.html")); | 2567 embedded_test_server()->GetURL("a.com", "/click-noreferrer-links.html")); |
2596 NavigateFrameToURL(root->child_at(0), frame_url); | 2568 NavigateFrameToURL(root->child_at(0), frame_url); |
2597 std::string script = "setOriginForLinks('http://b.com:" + | 2569 std::string script = "setOriginForLinks('http://b.com:" + |
2598 embedded_test_server()->base_url().port() + "/');"; | 2570 embedded_test_server()->base_url().port() + "/');"; |
2599 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script)); | 2571 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); |
2600 | 2572 |
2601 // Helper to click on the 'rel=noreferrer target=_blank' and 'rel=noopener | 2573 // Helper to click on the 'rel=noreferrer target=_blank' and 'rel=noopener |
2602 // target=_blank' links. Checks that these links open a popup that ends up | 2574 // target=_blank' links. Checks that these links open a popup that ends up |
2603 // in a new SiteInstance even without site-per-process and then verifies that | 2575 // in a new SiteInstance even without site-per-process and then verifies that |
2604 // the popup is still sandboxed. | 2576 // the popup is still sandboxed. |
2605 auto click_link_and_verify_popup = [this, | 2577 auto click_link_and_verify_popup = [this, |
2606 root](std::string link_opening_script) { | 2578 root](std::string link_opening_script) { |
2607 ShellAddedObserver new_shell_observer; | 2579 ShellAddedObserver new_shell_observer; |
2608 bool success = false; | 2580 bool success = false; |
2609 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 2581 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
2610 root->child_at(0)->current_frame_host(), | 2582 root->child_at(0), |
2611 "window.domAutomationController.send(" + link_opening_script + ")", | 2583 "window.domAutomationController.send(" + link_opening_script + ")", |
2612 &success)); | 2584 &success)); |
2613 EXPECT_TRUE(success); | 2585 EXPECT_TRUE(success); |
2614 | 2586 |
2615 Shell* new_shell = new_shell_observer.GetShell(); | 2587 Shell* new_shell = new_shell_observer.GetShell(); |
2616 EXPECT_TRUE(WaitForLoadStop(new_shell->web_contents())); | 2588 EXPECT_TRUE(WaitForLoadStop(new_shell->web_contents())); |
2617 EXPECT_NE(new_shell->web_contents()->GetSiteInstance(), | 2589 EXPECT_NE(new_shell->web_contents()->GetSiteInstance(), |
2618 shell()->web_contents()->GetSiteInstance()); | 2590 shell()->web_contents()->GetSiteInstance()); |
2619 | 2591 |
2620 // Check that the popup is sandboxed by checking its document.origin, which | 2592 // Check that the popup is sandboxed by checking its document.origin, which |
2621 // should be unique. | 2593 // should be unique. |
2622 std::string origin; | 2594 std::string origin; |
2623 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2595 EXPECT_TRUE(ExecuteScriptAndExtractString( |
2624 new_shell->web_contents(), | 2596 new_shell, "domAutomationController.send(document.origin)", &origin)); |
2625 "domAutomationController.send(document.origin)", &origin)); | |
2626 EXPECT_EQ("null", origin); | 2597 EXPECT_EQ("null", origin); |
2627 }; | 2598 }; |
2628 | 2599 |
2629 click_link_and_verify_popup("clickNoOpenerTargetBlankLink()"); | 2600 click_link_and_verify_popup("clickNoOpenerTargetBlankLink()"); |
2630 click_link_and_verify_popup("clickNoRefTargetBlankLink()"); | 2601 click_link_and_verify_popup("clickNoRefTargetBlankLink()"); |
2631 } | 2602 } |
2632 | 2603 |
2633 // When two frames are same-origin but cross-process, they should behave as if | 2604 // When two frames are same-origin but cross-process, they should behave as if |
2634 // they are not same-origin and should not crash. | 2605 // they are not same-origin and should not crash. |
2635 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 2606 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
2636 SameOriginFramesInDifferentProcesses) { | 2607 SameOriginFramesInDifferentProcesses) { |
2637 StartEmbeddedServer(); | 2608 StartEmbeddedServer(); |
2638 | 2609 |
2639 // Load a page with links that open in a new window. | 2610 // Load a page with links that open in a new window. |
2640 NavigateToURL(shell(), embedded_test_server()->GetURL( | 2611 NavigateToURL(shell(), embedded_test_server()->GetURL( |
2641 "a.com", "/click-noreferrer-links.html")); | 2612 "a.com", "/click-noreferrer-links.html")); |
2642 | 2613 |
2643 // Get the original SiteInstance for later comparison. | 2614 // Get the original SiteInstance for later comparison. |
2644 scoped_refptr<SiteInstance> orig_site_instance( | 2615 scoped_refptr<SiteInstance> orig_site_instance( |
2645 shell()->web_contents()->GetSiteInstance()); | 2616 shell()->web_contents()->GetSiteInstance()); |
2646 EXPECT_NE(nullptr, orig_site_instance.get()); | 2617 EXPECT_NE(nullptr, orig_site_instance.get()); |
2647 | 2618 |
2648 // Test clicking a target=foo link. | 2619 // Test clicking a target=foo link. |
2649 ShellAddedObserver new_shell_observer; | 2620 ShellAddedObserver new_shell_observer; |
2650 bool success = false; | 2621 bool success = false; |
2651 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 2622 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
2652 shell()->web_contents(), | 2623 shell(), |
2653 "window.domAutomationController.send(clickSameSiteTargetedLink());" | 2624 "window.domAutomationController.send(clickSameSiteTargetedLink());" |
2654 "saveWindowReference();", | 2625 "saveWindowReference();", |
2655 &success)); | 2626 &success)); |
2656 EXPECT_TRUE(success); | 2627 EXPECT_TRUE(success); |
2657 Shell* new_shell = new_shell_observer.GetShell(); | 2628 Shell* new_shell = new_shell_observer.GetShell(); |
2658 | 2629 |
2659 // Wait for the navigation in the new tab to finish, if it hasn't. | 2630 // Wait for the navigation in the new tab to finish, if it hasn't. |
2660 WaitForLoadStop(new_shell->web_contents()); | 2631 WaitForLoadStop(new_shell->web_contents()); |
2661 EXPECT_EQ("/navigate_opener.html", | 2632 EXPECT_EQ("/navigate_opener.html", |
2662 new_shell->web_contents()->GetLastCommittedURL().path()); | 2633 new_shell->web_contents()->GetLastCommittedURL().path()); |
(...skipping 10 matching lines...) Expand all Loading... |
2673 // redirect. So both windows will actually be in the same process. | 2644 // redirect. So both windows will actually be in the same process. |
2674 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 2645 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
2675 new_shell->web_contents()->GetSiteInstance()); | 2646 new_shell->web_contents()->GetSiteInstance()); |
2676 } else { | 2647 } else { |
2677 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 2648 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
2678 new_shell->web_contents()->GetSiteInstance()); | 2649 new_shell->web_contents()->GetSiteInstance()); |
2679 } | 2650 } |
2680 | 2651 |
2681 std::string result; | 2652 std::string result; |
2682 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2653 EXPECT_TRUE(ExecuteScriptAndExtractString( |
2683 shell()->web_contents(), | 2654 shell(), |
2684 "window.domAutomationController.send((function() {\n" | 2655 "window.domAutomationController.send((function() {\n" |
2685 " try {\n" | 2656 " try {\n" |
2686 " return getLastOpenedWindowLocation();\n" | 2657 " return getLastOpenedWindowLocation();\n" |
2687 " } catch (e) {\n" | 2658 " } catch (e) {\n" |
2688 " return e.toString();\n" | 2659 " return e.toString();\n" |
2689 " }\n" | 2660 " }\n" |
2690 "})())", | 2661 "})())", |
2691 &result)); | 2662 &result)); |
2692 if (AreAllSitesIsolatedForTesting() || IsBrowserSideNavigationEnabled()) { | 2663 if (AreAllSitesIsolatedForTesting() || IsBrowserSideNavigationEnabled()) { |
2693 EXPECT_THAT(result, | 2664 EXPECT_THAT(result, |
(...skipping 13 matching lines...) Expand all Loading... |
2707 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, CtrlClickSubframeLink) { | 2678 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, CtrlClickSubframeLink) { |
2708 StartEmbeddedServer(); | 2679 StartEmbeddedServer(); |
2709 | 2680 |
2710 // Load a page with a subframe link. | 2681 // Load a page with a subframe link. |
2711 NavigateToURL(shell(), embedded_test_server()->GetURL( | 2682 NavigateToURL(shell(), embedded_test_server()->GetURL( |
2712 "/ctrl-click-subframe-link.html")); | 2683 "/ctrl-click-subframe-link.html")); |
2713 | 2684 |
2714 // Simulate a ctrl click on the link. This won't actually create a new Shell | 2685 // Simulate a ctrl click on the link. This won't actually create a new Shell |
2715 // because Shell::OpenURLFromTab only supports CURRENT_TAB, but it's enough to | 2686 // because Shell::OpenURLFromTab only supports CURRENT_TAB, but it's enough to |
2716 // trigger the crash from https://crbug.com/605055. | 2687 // trigger the crash from https://crbug.com/605055. |
2717 EXPECT_TRUE( | 2688 EXPECT_TRUE(ExecuteScript( |
2718 ExecuteScript(shell()->web_contents(), | 2689 shell(), "window.domAutomationController.send(ctrlClickLink());")); |
2719 "window.domAutomationController.send(ctrlClickLink());")); | |
2720 } | 2690 } |
2721 | 2691 |
2722 // Ensure that we don't update the wrong NavigationEntry's title after an | 2692 // Ensure that we don't update the wrong NavigationEntry's title after an |
2723 // ignored commit during a cross-process navigation. | 2693 // ignored commit during a cross-process navigation. |
2724 // See https://crbug.con/577449. | 2694 // See https://crbug.con/577449. |
2725 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 2695 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
2726 UnloadPushStateOnCrossProcessNavigation) { | 2696 UnloadPushStateOnCrossProcessNavigation) { |
2727 StartEmbeddedServer(); | 2697 StartEmbeddedServer(); |
2728 WebContentsImpl* web_contents = | 2698 WebContentsImpl* web_contents = |
2729 static_cast<WebContentsImpl*>(shell()->web_contents()); | 2699 static_cast<WebContentsImpl*>(shell()->web_contents()); |
2730 FrameTreeNode* root = web_contents->GetFrameTree()->root(); | 2700 FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
2731 | 2701 |
2732 // Give an initial page an unload handler that does a pushState, which will be | 2702 // Give an initial page an unload handler that does a pushState, which will be |
2733 // ignored by the browser process. It then does a title update which is | 2703 // ignored by the browser process. It then does a title update which is |
2734 // meant for a NavigationEntry that will never be created. | 2704 // meant for a NavigationEntry that will never be created. |
2735 EXPECT_TRUE(NavigateToURL( | 2705 EXPECT_TRUE(NavigateToURL( |
2736 shell(), embedded_test_server()->GetURL("a.com", "/title2.html"))); | 2706 shell(), embedded_test_server()->GetURL("a.com", "/title2.html"))); |
2737 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), | 2707 EXPECT_TRUE(ExecuteScript(root, |
2738 "window.onunload=function(e){" | 2708 "window.onunload=function(e){" |
2739 "history.pushState({}, 'foo', 'foo');" | 2709 "history.pushState({}, 'foo', 'foo');" |
2740 "document.title='foo'; };\n")); | 2710 "document.title='foo'; };\n")); |
2741 base::string16 title = web_contents->GetTitle(); | 2711 base::string16 title = web_contents->GetTitle(); |
2742 NavigationEntryImpl* entry = web_contents->GetController().GetEntryAtIndex(0); | 2712 NavigationEntryImpl* entry = web_contents->GetController().GetEntryAtIndex(0); |
2743 | 2713 |
2744 // Navigate the first tab to a different site and wait for the old process to | 2714 // Navigate the first tab to a different site and wait for the old process to |
2745 // complete its unload handler and exit. | 2715 // complete its unload handler and exit. |
2746 RenderFrameHostImpl* rfh_a = root->current_frame_host(); | 2716 RenderFrameHostImpl* rfh_a = root->current_frame_host(); |
2747 rfh_a->DisableSwapOutTimerForTesting(); | 2717 rfh_a->DisableSwapOutTimerForTesting(); |
2748 RenderProcessHostWatcher exit_observer( | 2718 RenderProcessHostWatcher exit_observer( |
2749 rfh_a->GetProcess(), RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 2719 rfh_a->GetProcess(), RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
2750 TestNavigationObserver commit_observer(web_contents); | 2720 TestNavigationObserver commit_observer(web_contents); |
2751 shell()->LoadURL(embedded_test_server()->GetURL("b.com", "/title1.html")); | 2721 shell()->LoadURL(embedded_test_server()->GetURL("b.com", "/title1.html")); |
2752 commit_observer.Wait(); | 2722 commit_observer.Wait(); |
2753 exit_observer.Wait(); | 2723 exit_observer.Wait(); |
2754 | 2724 |
2755 // Ensure the entry's title hasn't changed after the ignored commit. | 2725 // Ensure the entry's title hasn't changed after the ignored commit. |
2756 EXPECT_EQ(title, entry->GetTitle()); | 2726 EXPECT_EQ(title, entry->GetTitle()); |
2757 } | 2727 } |
2758 | 2728 |
2759 } // namespace content | 2729 } // namespace content |
OLD | NEW |