OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/json/json_reader.h" | 6 #include "base/json/json_reader.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "content/common/content_constants_internal.h" | 10 #include "content/common/content_constants_internal.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 // Get the original SiteInstance for later comparison. | 125 // Get the original SiteInstance for later comparison. |
126 scoped_refptr<SiteInstance> orig_site_instance( | 126 scoped_refptr<SiteInstance> orig_site_instance( |
127 shell()->web_contents()->GetSiteInstance()); | 127 shell()->web_contents()->GetSiteInstance()); |
128 EXPECT_TRUE(orig_site_instance != NULL); | 128 EXPECT_TRUE(orig_site_instance != NULL); |
129 | 129 |
130 // Open a same-site link in a new window. | 130 // Open a same-site link in a new window. |
131 ShellAddedObserver new_shell_observer; | 131 ShellAddedObserver new_shell_observer; |
132 bool success = false; | 132 bool success = false; |
133 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 133 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
134 shell()->web_contents()->GetRenderViewHost(), | 134 shell()->web_contents()->GetRenderViewHost(), L"", |
135 "", | 135 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
136 "window.domAutomationController.send(clickSameSiteTargetedLink());", | |
137 &success)); | 136 &success)); |
138 EXPECT_TRUE(success); | 137 EXPECT_TRUE(success); |
139 Shell* new_shell = new_shell_observer.GetShell(); | 138 Shell* new_shell = new_shell_observer.GetShell(); |
140 | 139 |
141 // Wait for the navigation in the new window to finish, if it hasn't. | 140 // Wait for the navigation in the new window to finish, if it hasn't. |
142 WaitForLoadStop(new_shell->web_contents()); | 141 WaitForLoadStop(new_shell->web_contents()); |
143 EXPECT_EQ("/files/navigate_opener.html", | 142 EXPECT_EQ("/files/navigate_opener.html", |
144 new_shell->web_contents()->GetURL().path()); | 143 new_shell->web_contents()->GetURL().path()); |
145 | 144 |
146 // Should have the same SiteInstance. | 145 // Should have the same SiteInstance. |
147 scoped_refptr<SiteInstance> blank_site_instance( | 146 scoped_refptr<SiteInstance> blank_site_instance( |
148 new_shell->web_contents()->GetSiteInstance()); | 147 new_shell->web_contents()->GetSiteInstance()); |
149 EXPECT_EQ(orig_site_instance, blank_site_instance); | 148 EXPECT_EQ(orig_site_instance, blank_site_instance); |
150 | 149 |
151 // We should have access to the opened window's location. | 150 // We should have access to the opened window's location. |
152 success = false; | 151 success = false; |
153 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 152 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
154 shell()->web_contents()->GetRenderViewHost(), | 153 shell()->web_contents()->GetRenderViewHost(), L"", |
155 "", | 154 L"window.domAutomationController.send(testScriptAccessToWindow());", |
156 "window.domAutomationController.send(testScriptAccessToWindow());", | |
157 &success)); | 155 &success)); |
158 EXPECT_TRUE(success); | 156 EXPECT_TRUE(success); |
159 | 157 |
160 // Now navigate the new window to a different site. | 158 // Now navigate the new window to a different site. |
161 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); | 159 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
162 scoped_refptr<SiteInstance> new_site_instance( | 160 scoped_refptr<SiteInstance> new_site_instance( |
163 new_shell->web_contents()->GetSiteInstance()); | 161 new_shell->web_contents()->GetSiteInstance()); |
164 EXPECT_NE(orig_site_instance, new_site_instance); | 162 EXPECT_NE(orig_site_instance, new_site_instance); |
165 | 163 |
166 // We should no longer have script access to the opened window's location. | 164 // We should no longer have script access to the opened window's location. |
167 success = false; | 165 success = false; |
168 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 166 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
169 shell()->web_contents()->GetRenderViewHost(), | 167 shell()->web_contents()->GetRenderViewHost(), L"", |
170 "", | 168 L"window.domAutomationController.send(testScriptAccessToWindow());", |
171 "window.domAutomationController.send(testScriptAccessToWindow());", | |
172 &success)); | 169 &success)); |
173 EXPECT_FALSE(success); | 170 EXPECT_FALSE(success); |
174 } | 171 } |
175 | 172 |
176 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer | 173 // Test for crbug.com/24447. Following a cross-site link with rel=noreferrer |
177 // and target=_blank should create a new SiteInstance. | 174 // and target=_blank should create a new SiteInstance. |
178 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, | 175 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
179 SwapProcessWithRelNoreferrerAndTargetBlank) { | 176 SwapProcessWithRelNoreferrerAndTargetBlank) { |
180 // Start two servers with different sites. | 177 // Start two servers with different sites. |
181 ASSERT_TRUE(test_server()->Start()); | 178 ASSERT_TRUE(test_server()->Start()); |
(...skipping 13 matching lines...) Expand all Loading... |
195 | 192 |
196 // Get the original SiteInstance for later comparison. | 193 // Get the original SiteInstance for later comparison. |
197 scoped_refptr<SiteInstance> orig_site_instance( | 194 scoped_refptr<SiteInstance> orig_site_instance( |
198 shell()->web_contents()->GetSiteInstance()); | 195 shell()->web_contents()->GetSiteInstance()); |
199 EXPECT_TRUE(orig_site_instance != NULL); | 196 EXPECT_TRUE(orig_site_instance != NULL); |
200 | 197 |
201 // Test clicking a rel=noreferrer + target=blank link. | 198 // Test clicking a rel=noreferrer + target=blank link. |
202 ShellAddedObserver new_shell_observer; | 199 ShellAddedObserver new_shell_observer; |
203 bool success = false; | 200 bool success = false; |
204 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 201 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
205 shell()->web_contents()->GetRenderViewHost(), | 202 shell()->web_contents()->GetRenderViewHost(), L"", |
206 "", | 203 L"window.domAutomationController.send(clickNoRefTargetBlankLink());", |
207 "window.domAutomationController.send(clickNoRefTargetBlankLink());", | |
208 &success)); | 204 &success)); |
209 EXPECT_TRUE(success); | 205 EXPECT_TRUE(success); |
210 | 206 |
211 // Wait for the window to open. | 207 // Wait for the window to open. |
212 Shell* new_shell = new_shell_observer.GetShell(); | 208 Shell* new_shell = new_shell_observer.GetShell(); |
213 | 209 |
214 EXPECT_EQ("/files/title2.html", new_shell->web_contents()->GetURL().path()); | 210 EXPECT_EQ("/files/title2.html", new_shell->web_contents()->GetURL().path()); |
215 | 211 |
216 // Wait for the cross-site transition in the new tab to finish. | 212 // Wait for the cross-site transition in the new tab to finish. |
217 WaitForLoadStop(new_shell->web_contents()); | 213 WaitForLoadStop(new_shell->web_contents()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 245 |
250 // Get the original SiteInstance for later comparison. | 246 // Get the original SiteInstance for later comparison. |
251 scoped_refptr<SiteInstance> orig_site_instance( | 247 scoped_refptr<SiteInstance> orig_site_instance( |
252 shell()->web_contents()->GetSiteInstance()); | 248 shell()->web_contents()->GetSiteInstance()); |
253 EXPECT_TRUE(orig_site_instance != NULL); | 249 EXPECT_TRUE(orig_site_instance != NULL); |
254 | 250 |
255 // Test clicking a same-site rel=noreferrer + target=foo link. | 251 // Test clicking a same-site rel=noreferrer + target=foo link. |
256 ShellAddedObserver new_shell_observer; | 252 ShellAddedObserver new_shell_observer; |
257 bool success = false; | 253 bool success = false; |
258 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 254 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
259 shell()->web_contents()->GetRenderViewHost(), | 255 shell()->web_contents()->GetRenderViewHost(), L"", |
260 "", | 256 L"window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", |
261 "window.domAutomationController.send(clickSameSiteNoRefTargetedLink());", | |
262 &success)); | 257 &success)); |
263 EXPECT_TRUE(success); | 258 EXPECT_TRUE(success); |
264 | 259 |
265 // Wait for the window to open. | 260 // Wait for the window to open. |
266 Shell* new_shell = new_shell_observer.GetShell(); | 261 Shell* new_shell = new_shell_observer.GetShell(); |
267 | 262 |
268 // Opens in new window. | 263 // Opens in new window. |
269 EXPECT_EQ("/files/title2.html", new_shell->web_contents()->GetURL().path()); | 264 EXPECT_EQ("/files/title2.html", new_shell->web_contents()->GetURL().path()); |
270 | 265 |
271 // Wait for the cross-site transition in the new tab to finish. | 266 // Wait for the cross-site transition in the new tab to finish. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 298 |
304 // Get the original SiteInstance for later comparison. | 299 // Get the original SiteInstance for later comparison. |
305 scoped_refptr<SiteInstance> orig_site_instance( | 300 scoped_refptr<SiteInstance> orig_site_instance( |
306 shell()->web_contents()->GetSiteInstance()); | 301 shell()->web_contents()->GetSiteInstance()); |
307 EXPECT_TRUE(orig_site_instance != NULL); | 302 EXPECT_TRUE(orig_site_instance != NULL); |
308 | 303 |
309 // Test clicking a target=blank link. | 304 // Test clicking a target=blank link. |
310 ShellAddedObserver new_shell_observer; | 305 ShellAddedObserver new_shell_observer; |
311 bool success = false; | 306 bool success = false; |
312 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 307 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
313 shell()->web_contents()->GetRenderViewHost(), | 308 shell()->web_contents()->GetRenderViewHost(), L"", |
314 "", | 309 L"window.domAutomationController.send(clickTargetBlankLink());", |
315 "window.domAutomationController.send(clickTargetBlankLink());", | |
316 &success)); | 310 &success)); |
317 EXPECT_TRUE(success); | 311 EXPECT_TRUE(success); |
318 | 312 |
319 // Wait for the window to open. | 313 // Wait for the window to open. |
320 Shell* new_shell = new_shell_observer.GetShell(); | 314 Shell* new_shell = new_shell_observer.GetShell(); |
321 | 315 |
322 // Wait for the cross-site transition in the new tab to finish. | 316 // Wait for the cross-site transition in the new tab to finish. |
323 WaitForLoadStop(new_shell->web_contents()); | 317 WaitForLoadStop(new_shell->web_contents()); |
324 EXPECT_EQ("/files/title2.html", | 318 EXPECT_EQ("/files/title2.html", |
325 new_shell->web_contents()->GetURL().path()); | 319 new_shell->web_contents()->GetURL().path()); |
(...skipping 25 matching lines...) Expand all Loading... |
351 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | 345 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
352 | 346 |
353 // Get the original SiteInstance for later comparison. | 347 // Get the original SiteInstance for later comparison. |
354 scoped_refptr<SiteInstance> orig_site_instance( | 348 scoped_refptr<SiteInstance> orig_site_instance( |
355 shell()->web_contents()->GetSiteInstance()); | 349 shell()->web_contents()->GetSiteInstance()); |
356 EXPECT_TRUE(orig_site_instance != NULL); | 350 EXPECT_TRUE(orig_site_instance != NULL); |
357 | 351 |
358 // Test clicking a rel=noreferrer link. | 352 // Test clicking a rel=noreferrer link. |
359 bool success = false; | 353 bool success = false; |
360 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 354 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
361 shell()->web_contents()->GetRenderViewHost(), | 355 shell()->web_contents()->GetRenderViewHost(), L"", |
362 "", | 356 L"window.domAutomationController.send(clickNoRefLink());", |
363 "window.domAutomationController.send(clickNoRefLink());", | |
364 &success)); | 357 &success)); |
365 EXPECT_TRUE(success); | 358 EXPECT_TRUE(success); |
366 | 359 |
367 // Wait for the cross-site transition in the current tab to finish. | 360 // Wait for the cross-site transition in the current tab to finish. |
368 WaitForLoadStop(shell()->web_contents()); | 361 WaitForLoadStop(shell()->web_contents()); |
369 | 362 |
370 // Opens in same window. | 363 // Opens in same window. |
371 EXPECT_EQ(1u, Shell::windows().size()); | 364 EXPECT_EQ(1u, Shell::windows().size()); |
372 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); | 365 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); |
373 | 366 |
(...skipping 25 matching lines...) Expand all Loading... |
399 | 392 |
400 // Get the original SiteInstance for later comparison. | 393 // Get the original SiteInstance for later comparison. |
401 scoped_refptr<SiteInstance> orig_site_instance( | 394 scoped_refptr<SiteInstance> orig_site_instance( |
402 shell()->web_contents()->GetSiteInstance()); | 395 shell()->web_contents()->GetSiteInstance()); |
403 EXPECT_TRUE(orig_site_instance != NULL); | 396 EXPECT_TRUE(orig_site_instance != NULL); |
404 | 397 |
405 // Test clicking a target=foo link. | 398 // Test clicking a target=foo link. |
406 ShellAddedObserver new_shell_observer; | 399 ShellAddedObserver new_shell_observer; |
407 bool success = false; | 400 bool success = false; |
408 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 401 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
409 shell()->web_contents()->GetRenderViewHost(), | 402 shell()->web_contents()->GetRenderViewHost(), L"", |
410 "", | 403 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
411 "window.domAutomationController.send(clickSameSiteTargetedLink());", | |
412 &success)); | 404 &success)); |
413 EXPECT_TRUE(success); | 405 EXPECT_TRUE(success); |
414 Shell* new_shell = new_shell_observer.GetShell(); | 406 Shell* new_shell = new_shell_observer.GetShell(); |
415 | 407 |
416 // Wait for the navigation in the new tab to finish, if it hasn't. | 408 // Wait for the navigation in the new tab to finish, if it hasn't. |
417 WaitForLoadStop(new_shell->web_contents()); | 409 WaitForLoadStop(new_shell->web_contents()); |
418 EXPECT_EQ("/files/navigate_opener.html", | 410 EXPECT_EQ("/files/navigate_opener.html", |
419 new_shell->web_contents()->GetURL().path()); | 411 new_shell->web_contents()->GetURL().path()); |
420 | 412 |
421 // Should have the same SiteInstance. | 413 // Should have the same SiteInstance. |
422 scoped_refptr<SiteInstance> blank_site_instance( | 414 scoped_refptr<SiteInstance> blank_site_instance( |
423 new_shell->web_contents()->GetSiteInstance()); | 415 new_shell->web_contents()->GetSiteInstance()); |
424 EXPECT_EQ(orig_site_instance, blank_site_instance); | 416 EXPECT_EQ(orig_site_instance, blank_site_instance); |
425 | 417 |
426 // Now navigate the new tab to a different site. | 418 // Now navigate the new tab to a different site. |
427 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); | 419 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
428 scoped_refptr<SiteInstance> new_site_instance( | 420 scoped_refptr<SiteInstance> new_site_instance( |
429 new_shell->web_contents()->GetSiteInstance()); | 421 new_shell->web_contents()->GetSiteInstance()); |
430 EXPECT_NE(orig_site_instance, new_site_instance); | 422 EXPECT_NE(orig_site_instance, new_site_instance); |
431 | 423 |
432 // Clicking the original link in the first tab should cause us to swap back. | 424 // Clicking the original link in the first tab should cause us to swap back. |
433 WindowedNotificationObserver navigation_observer( | 425 WindowedNotificationObserver navigation_observer( |
434 NOTIFICATION_NAV_ENTRY_COMMITTED, | 426 NOTIFICATION_NAV_ENTRY_COMMITTED, |
435 Source<NavigationController>( | 427 Source<NavigationController>( |
436 &new_shell->web_contents()->GetController())); | 428 &new_shell->web_contents()->GetController())); |
437 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 429 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
438 shell()->web_contents()->GetRenderViewHost(), | 430 shell()->web_contents()->GetRenderViewHost(), L"", |
439 "", | 431 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
440 "window.domAutomationController.send(clickSameSiteTargetedLink());", | |
441 &success)); | 432 &success)); |
442 EXPECT_TRUE(success); | 433 EXPECT_TRUE(success); |
443 navigation_observer.Wait(); | 434 navigation_observer.Wait(); |
444 | 435 |
445 // Should have swapped back and shown the new window again. | 436 // Should have swapped back and shown the new window again. |
446 scoped_refptr<SiteInstance> revisit_site_instance( | 437 scoped_refptr<SiteInstance> revisit_site_instance( |
447 new_shell->web_contents()->GetSiteInstance()); | 438 new_shell->web_contents()->GetSiteInstance()); |
448 EXPECT_EQ(orig_site_instance, revisit_site_instance); | 439 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
449 | 440 |
450 // If it navigates away to another process, the original window should | 441 // If it navigates away to another process, the original window should |
451 // still be able to close it (using a cross-process close message). | 442 // still be able to close it (using a cross-process close message). |
452 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); | 443 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
453 EXPECT_EQ(new_site_instance, | 444 EXPECT_EQ(new_site_instance, |
454 new_shell->web_contents()->GetSiteInstance()); | 445 new_shell->web_contents()->GetSiteInstance()); |
455 WindowedNotificationObserver close_observer( | 446 WindowedNotificationObserver close_observer( |
456 NOTIFICATION_WEB_CONTENTS_DESTROYED, | 447 NOTIFICATION_WEB_CONTENTS_DESTROYED, |
457 Source<WebContents>(new_shell->web_contents())); | 448 Source<WebContents>(new_shell->web_contents())); |
458 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 449 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
459 shell()->web_contents()->GetRenderViewHost(), | 450 shell()->web_contents()->GetRenderViewHost(), L"", |
460 "", | 451 L"window.domAutomationController.send(testCloseWindow());", |
461 "window.domAutomationController.send(testCloseWindow());", | |
462 &success)); | 452 &success)); |
463 EXPECT_TRUE(success); | 453 EXPECT_TRUE(success); |
464 close_observer.Wait(); | 454 close_observer.Wait(); |
465 } | 455 } |
466 | 456 |
467 // Test that setting the opener to null in a window affects cross-process | 457 // Test that setting the opener to null in a window affects cross-process |
468 // navigations, including those to existing entries. http://crbug.com/156669. | 458 // navigations, including those to existing entries. http://crbug.com/156669. |
469 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, DisownOpener) { | 459 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, DisownOpener) { |
470 // Start two servers with different sites. | 460 // Start two servers with different sites. |
471 ASSERT_TRUE(test_server()->Start()); | 461 ASSERT_TRUE(test_server()->Start()); |
(...skipping 13 matching lines...) Expand all Loading... |
485 | 475 |
486 // Get the original SiteInstance for later comparison. | 476 // Get the original SiteInstance for later comparison. |
487 scoped_refptr<SiteInstance> orig_site_instance( | 477 scoped_refptr<SiteInstance> orig_site_instance( |
488 shell()->web_contents()->GetSiteInstance()); | 478 shell()->web_contents()->GetSiteInstance()); |
489 EXPECT_TRUE(orig_site_instance != NULL); | 479 EXPECT_TRUE(orig_site_instance != NULL); |
490 | 480 |
491 // Test clicking a target=_blank link. | 481 // Test clicking a target=_blank link. |
492 ShellAddedObserver new_shell_observer; | 482 ShellAddedObserver new_shell_observer; |
493 bool success = false; | 483 bool success = false; |
494 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 484 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
495 shell()->web_contents()->GetRenderViewHost(), | 485 shell()->web_contents()->GetRenderViewHost(), L"", |
496 "", | 486 L"window.domAutomationController.send(clickSameSiteTargetBlankLink());", |
497 "window.domAutomationController.send(clickSameSiteTargetBlankLink());", | |
498 &success)); | 487 &success)); |
499 EXPECT_TRUE(success); | 488 EXPECT_TRUE(success); |
500 Shell* new_shell = new_shell_observer.GetShell(); | 489 Shell* new_shell = new_shell_observer.GetShell(); |
501 | 490 |
502 // Wait for the navigation in the new tab to finish, if it hasn't. | 491 // Wait for the navigation in the new tab to finish, if it hasn't. |
503 WaitForLoadStop(new_shell->web_contents()); | 492 WaitForLoadStop(new_shell->web_contents()); |
504 EXPECT_EQ("/files/title2.html", | 493 EXPECT_EQ("/files/title2.html", |
505 new_shell->web_contents()->GetURL().path()); | 494 new_shell->web_contents()->GetURL().path()); |
506 | 495 |
507 // Should have the same SiteInstance. | 496 // Should have the same SiteInstance. |
508 scoped_refptr<SiteInstance> blank_site_instance( | 497 scoped_refptr<SiteInstance> blank_site_instance( |
509 new_shell->web_contents()->GetSiteInstance()); | 498 new_shell->web_contents()->GetSiteInstance()); |
510 EXPECT_EQ(orig_site_instance, blank_site_instance); | 499 EXPECT_EQ(orig_site_instance, blank_site_instance); |
511 | 500 |
512 // Now navigate the new tab to a different site. | 501 // Now navigate the new tab to a different site. |
513 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); | 502 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
514 scoped_refptr<SiteInstance> new_site_instance( | 503 scoped_refptr<SiteInstance> new_site_instance( |
515 new_shell->web_contents()->GetSiteInstance()); | 504 new_shell->web_contents()->GetSiteInstance()); |
516 EXPECT_NE(orig_site_instance, new_site_instance); | 505 EXPECT_NE(orig_site_instance, new_site_instance); |
517 | 506 |
518 // Now disown the opener. | 507 // Now disown the opener. |
519 EXPECT_TRUE(ExecuteJavaScript( | 508 EXPECT_TRUE(ExecuteJavaScript( |
520 new_shell->web_contents()->GetRenderViewHost(), | 509 new_shell->web_contents()->GetRenderViewHost(), L"", |
521 "", | 510 L"window.opener = null;")); |
522 "window.opener = null;")); | |
523 | 511 |
524 // Go back and ensure the opener is still null. | 512 // Go back and ensure the opener is still null. |
525 { | 513 { |
526 WindowedNotificationObserver back_nav_load_observer( | 514 WindowedNotificationObserver back_nav_load_observer( |
527 NOTIFICATION_NAV_ENTRY_COMMITTED, | 515 NOTIFICATION_NAV_ENTRY_COMMITTED, |
528 Source<NavigationController>( | 516 Source<NavigationController>( |
529 &new_shell->web_contents()->GetController())); | 517 &new_shell->web_contents()->GetController())); |
530 new_shell->web_contents()->GetController().GoBack(); | 518 new_shell->web_contents()->GetController().GoBack(); |
531 back_nav_load_observer.Wait(); | 519 back_nav_load_observer.Wait(); |
532 } | 520 } |
533 success = false; | 521 success = false; |
534 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 522 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
535 new_shell->web_contents()->GetRenderViewHost(), | 523 new_shell->web_contents()->GetRenderViewHost(), L"", |
536 "", | 524 L"window.domAutomationController.send(window.opener == null);", |
537 "window.domAutomationController.send(window.opener == null);", | |
538 &success)); | 525 &success)); |
539 EXPECT_TRUE(success); | 526 EXPECT_TRUE(success); |
540 | 527 |
541 // Now navigate forward again (creating a new process) and check opener. | 528 // Now navigate forward again (creating a new process) and check opener. |
542 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); | 529 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
543 success = false; | 530 success = false; |
544 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 531 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
545 new_shell->web_contents()->GetRenderViewHost(), | 532 new_shell->web_contents()->GetRenderViewHost(), L"", |
546 "", | 533 L"window.domAutomationController.send(window.opener == null);", |
547 "window.domAutomationController.send(window.opener == null);", | |
548 &success)); | 534 &success)); |
549 EXPECT_TRUE(success); | 535 EXPECT_TRUE(success); |
550 } | 536 } |
551 | 537 |
552 // Test for crbug.com/99202. PostMessage calls should still work after | 538 // Test for crbug.com/99202. PostMessage calls should still work after |
553 // navigating the source and target windows to different sites. | 539 // navigating the source and target windows to different sites. |
554 // Specifically: | 540 // Specifically: |
555 // 1) Create 3 windows (opener, "foo", and _blank) and send "foo" cross-process. | 541 // 1) Create 3 windows (opener, "foo", and _blank) and send "foo" cross-process. |
556 // 2) Fail to post a message from "foo" to opener with the wrong target origin. | 542 // 2) Fail to post a message from "foo" to opener with the wrong target origin. |
557 // 3) Post a message from "foo" to opener, which replies back to "foo". | 543 // 3) Post a message from "foo" to opener, which replies back to "foo". |
(...skipping 27 matching lines...) Expand all Loading... |
585 static_cast<WebContentsImpl*>(opener_contents)-> | 571 static_cast<WebContentsImpl*>(opener_contents)-> |
586 GetRenderManagerForTesting(); | 572 GetRenderManagerForTesting(); |
587 | 573 |
588 // 1) Open two more windows, one named. These initially have openers but no | 574 // 1) Open two more windows, one named. These initially have openers but no |
589 // reference to each other. We will later post a message between them. | 575 // reference to each other. We will later post a message between them. |
590 | 576 |
591 // First, a named target=foo window. | 577 // First, a named target=foo window. |
592 ShellAddedObserver new_shell_observer; | 578 ShellAddedObserver new_shell_observer; |
593 bool success = false; | 579 bool success = false; |
594 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 580 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
595 opener_contents->GetRenderViewHost(), | 581 opener_contents->GetRenderViewHost(), L"", |
596 "", | 582 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
597 "window.domAutomationController.send(clickSameSiteTargetedLink());", | |
598 &success)); | 583 &success)); |
599 EXPECT_TRUE(success); | 584 EXPECT_TRUE(success); |
600 Shell* new_shell = new_shell_observer.GetShell(); | 585 Shell* new_shell = new_shell_observer.GetShell(); |
601 | 586 |
602 // Wait for the navigation in the new window to finish, if it hasn't, then | 587 // Wait for the navigation in the new window to finish, if it hasn't, then |
603 // send it to post_message.html on a different site. | 588 // send it to post_message.html on a different site. |
604 WebContents* foo_contents = new_shell->web_contents(); | 589 WebContents* foo_contents = new_shell->web_contents(); |
605 WaitForLoadStop(foo_contents); | 590 WaitForLoadStop(foo_contents); |
606 EXPECT_EQ("/files/navigate_opener.html", foo_contents->GetURL().path()); | 591 EXPECT_EQ("/files/navigate_opener.html", foo_contents->GetURL().path()); |
607 NavigateToURL(new_shell, https_server.GetURL("files/post_message.html")); | 592 NavigateToURL(new_shell, https_server.GetURL("files/post_message.html")); |
608 scoped_refptr<SiteInstance> foo_site_instance( | 593 scoped_refptr<SiteInstance> foo_site_instance( |
609 foo_contents->GetSiteInstance()); | 594 foo_contents->GetSiteInstance()); |
610 EXPECT_NE(orig_site_instance, foo_site_instance); | 595 EXPECT_NE(orig_site_instance, foo_site_instance); |
611 | 596 |
612 // Second, a target=_blank window. | 597 // Second, a target=_blank window. |
613 ShellAddedObserver new_shell_observer2; | 598 ShellAddedObserver new_shell_observer2; |
614 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 599 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
615 shell()->web_contents()->GetRenderViewHost(), | 600 shell()->web_contents()->GetRenderViewHost(), L"", |
616 "", | 601 L"window.domAutomationController.send(clickSameSiteTargetBlankLink());", |
617 "window.domAutomationController.send(clickSameSiteTargetBlankLink());", | |
618 &success)); | 602 &success)); |
619 EXPECT_TRUE(success); | 603 EXPECT_TRUE(success); |
620 | 604 |
621 // Wait for the navigation in the new window to finish, if it hasn't, then | 605 // Wait for the navigation in the new window to finish, if it hasn't, then |
622 // send it to post_message.html on the original site. | 606 // send it to post_message.html on the original site. |
623 Shell* new_shell2 = new_shell_observer2.GetShell(); | 607 Shell* new_shell2 = new_shell_observer2.GetShell(); |
624 WebContents* new_contents = new_shell2->web_contents(); | 608 WebContents* new_contents = new_shell2->web_contents(); |
625 WaitForLoadStop(new_contents); | 609 WaitForLoadStop(new_contents); |
626 EXPECT_EQ("/files/title2.html", new_contents->GetURL().path()); | 610 EXPECT_EQ("/files/title2.html", new_contents->GetURL().path()); |
627 NavigateToURL(new_shell2, test_server()->GetURL("files/post_message.html")); | 611 NavigateToURL(new_shell2, test_server()->GetURL("files/post_message.html")); |
628 EXPECT_EQ(orig_site_instance, new_contents->GetSiteInstance()); | 612 EXPECT_EQ(orig_site_instance, new_contents->GetSiteInstance()); |
629 RenderViewHostManager* new_manager = | 613 RenderViewHostManager* new_manager = |
630 static_cast<WebContentsImpl*>(new_contents)->GetRenderManagerForTesting(); | 614 static_cast<WebContentsImpl*>(new_contents)->GetRenderManagerForTesting(); |
631 | 615 |
632 // We now have three windows. The opener should have a swapped out RVH | 616 // We now have three windows. The opener should have a swapped out RVH |
633 // for the new SiteInstance, but the _blank window should not. | 617 // for the new SiteInstance, but the _blank window should not. |
634 EXPECT_EQ(3u, Shell::windows().size()); | 618 EXPECT_EQ(3u, Shell::windows().size()); |
635 EXPECT_TRUE(opener_manager->GetSwappedOutRenderViewHost(foo_site_instance)); | 619 EXPECT_TRUE(opener_manager->GetSwappedOutRenderViewHost(foo_site_instance)); |
636 EXPECT_FALSE(new_manager->GetSwappedOutRenderViewHost(foo_site_instance)); | 620 EXPECT_FALSE(new_manager->GetSwappedOutRenderViewHost(foo_site_instance)); |
637 | 621 |
638 // 2) Fail to post a message from the foo window to the opener if the target | 622 // 2) Fail to post a message from the foo window to the opener if the target |
639 // origin is wrong. We won't see an error, but we can check for the right | 623 // origin is wrong. We won't see an error, but we can check for the right |
640 // number of received messages below. | 624 // number of received messages below. |
641 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 625 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
642 foo_contents->GetRenderViewHost(), | 626 foo_contents->GetRenderViewHost(), L"", |
643 "", | 627 L"window.domAutomationController.send(postToOpener('msg'," |
644 "window.domAutomationController.send(postToOpener('msg'," | 628 L"'http://google.com'));", |
645 "'http://google.com'));", | |
646 &success)); | 629 &success)); |
647 EXPECT_TRUE(success); | 630 EXPECT_TRUE(success); |
648 ASSERT_FALSE(opener_manager->GetSwappedOutRenderViewHost(orig_site_instance)); | 631 ASSERT_FALSE(opener_manager->GetSwappedOutRenderViewHost(orig_site_instance)); |
649 | 632 |
650 // 3) Post a message from the foo window to the opener. The opener will | 633 // 3) Post a message from the foo window to the opener. The opener will |
651 // reply, causing the foo window to update its own title. | 634 // reply, causing the foo window to update its own title. |
652 WindowedNotificationObserver title_observer( | 635 WindowedNotificationObserver title_observer( |
653 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, | 636 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
654 Source<WebContents>(foo_contents)); | 637 Source<WebContents>(foo_contents)); |
655 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 638 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
656 foo_contents->GetRenderViewHost(), | 639 foo_contents->GetRenderViewHost(), L"", |
657 "", | 640 L"window.domAutomationController.send(postToOpener('msg','*'));", |
658 "window.domAutomationController.send(postToOpener('msg','*'));", | |
659 &success)); | 641 &success)); |
660 EXPECT_TRUE(success); | 642 EXPECT_TRUE(success); |
661 ASSERT_FALSE(opener_manager->GetSwappedOutRenderViewHost(orig_site_instance)); | 643 ASSERT_FALSE(opener_manager->GetSwappedOutRenderViewHost(orig_site_instance)); |
662 title_observer.Wait(); | 644 title_observer.Wait(); |
663 | 645 |
664 // We should have received only 1 message in the opener and "foo" tabs, | 646 // We should have received only 1 message in the opener and "foo" tabs, |
665 // and updated the title. | 647 // and updated the title. |
666 int opener_received_messages = 0; | 648 int opener_received_messages = 0; |
667 EXPECT_TRUE(ExecuteJavaScriptAndExtractInt( | 649 EXPECT_TRUE(ExecuteJavaScriptAndExtractInt( |
668 opener_contents->GetRenderViewHost(), | 650 opener_contents->GetRenderViewHost(), L"", |
669 "", | 651 L"window.domAutomationController.send(window.receivedMessages);", |
670 "window.domAutomationController.send(window.receivedMessages);", | |
671 &opener_received_messages)); | 652 &opener_received_messages)); |
672 int foo_received_messages = 0; | 653 int foo_received_messages = 0; |
673 EXPECT_TRUE(ExecuteJavaScriptAndExtractInt( | 654 EXPECT_TRUE(ExecuteJavaScriptAndExtractInt( |
674 foo_contents->GetRenderViewHost(), | 655 foo_contents->GetRenderViewHost(), L"", |
675 "", | 656 L"window.domAutomationController.send(window.receivedMessages);", |
676 "window.domAutomationController.send(window.receivedMessages);", | |
677 &foo_received_messages)); | 657 &foo_received_messages)); |
678 EXPECT_EQ(1, foo_received_messages); | 658 EXPECT_EQ(1, foo_received_messages); |
679 EXPECT_EQ(1, opener_received_messages); | 659 EXPECT_EQ(1, opener_received_messages); |
680 EXPECT_EQ(ASCIIToUTF16("msg"), foo_contents->GetTitle()); | 660 EXPECT_EQ(ASCIIToUTF16("msg"), foo_contents->GetTitle()); |
681 | 661 |
682 // 4) Now post a message from the _blank window to the foo window. The | 662 // 4) Now post a message from the _blank window to the foo window. The |
683 // foo window will update its title and will not reply. | 663 // foo window will update its title and will not reply. |
684 WindowedNotificationObserver title_observer2( | 664 WindowedNotificationObserver title_observer2( |
685 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, | 665 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
686 Source<WebContents>(foo_contents)); | 666 Source<WebContents>(foo_contents)); |
687 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 667 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
688 new_contents->GetRenderViewHost(), | 668 new_contents->GetRenderViewHost(), L"", |
689 "", | 669 L"window.domAutomationController.send(postToFoo('msg2'));", |
690 "window.domAutomationController.send(postToFoo('msg2'));", | |
691 &success)); | 670 &success)); |
692 EXPECT_TRUE(success); | 671 EXPECT_TRUE(success); |
693 title_observer2.Wait(); | 672 title_observer2.Wait(); |
694 EXPECT_EQ(ASCIIToUTF16("msg2"), foo_contents->GetTitle()); | 673 EXPECT_EQ(ASCIIToUTF16("msg2"), foo_contents->GetTitle()); |
695 | 674 |
696 // This postMessage should have created a swapped out RVH for the new | 675 // This postMessage should have created a swapped out RVH for the new |
697 // SiteInstance in the target=_blank window. | 676 // SiteInstance in the target=_blank window. |
698 EXPECT_TRUE(new_manager->GetSwappedOutRenderViewHost(foo_site_instance)); | 677 EXPECT_TRUE(new_manager->GetSwappedOutRenderViewHost(foo_site_instance)); |
699 | 678 |
700 // TODO(nasko): Test subframe targeting of postMessage once | 679 // TODO(nasko): Test subframe targeting of postMessage once |
(...skipping 23 matching lines...) Expand all Loading... |
724 // Get the original tab and SiteInstance for later comparison. | 703 // Get the original tab and SiteInstance for later comparison. |
725 WebContents* orig_contents = shell()->web_contents(); | 704 WebContents* orig_contents = shell()->web_contents(); |
726 scoped_refptr<SiteInstance> orig_site_instance( | 705 scoped_refptr<SiteInstance> orig_site_instance( |
727 orig_contents->GetSiteInstance()); | 706 orig_contents->GetSiteInstance()); |
728 EXPECT_TRUE(orig_site_instance != NULL); | 707 EXPECT_TRUE(orig_site_instance != NULL); |
729 | 708 |
730 // Test clicking a target=foo link. | 709 // Test clicking a target=foo link. |
731 ShellAddedObserver new_shell_observer; | 710 ShellAddedObserver new_shell_observer; |
732 bool success = false; | 711 bool success = false; |
733 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 712 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
734 orig_contents->GetRenderViewHost(), | 713 orig_contents->GetRenderViewHost(), L"", |
735 "", | 714 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
736 "window.domAutomationController.send(clickSameSiteTargetedLink());", | |
737 &success)); | 715 &success)); |
738 EXPECT_TRUE(success); | 716 EXPECT_TRUE(success); |
739 Shell* new_shell = new_shell_observer.GetShell(); | 717 Shell* new_shell = new_shell_observer.GetShell(); |
740 | 718 |
741 // Wait for the navigation in the new window to finish, if it hasn't. | 719 // Wait for the navigation in the new window to finish, if it hasn't. |
742 WaitForLoadStop(new_shell->web_contents()); | 720 WaitForLoadStop(new_shell->web_contents()); |
743 EXPECT_EQ("/files/navigate_opener.html", | 721 EXPECT_EQ("/files/navigate_opener.html", |
744 new_shell->web_contents()->GetURL().path()); | 722 new_shell->web_contents()->GetURL().path()); |
745 | 723 |
746 // Should have the same SiteInstance. | 724 // Should have the same SiteInstance. |
747 scoped_refptr<SiteInstance> blank_site_instance( | 725 scoped_refptr<SiteInstance> blank_site_instance( |
748 new_shell->web_contents()->GetSiteInstance()); | 726 new_shell->web_contents()->GetSiteInstance()); |
749 EXPECT_EQ(orig_site_instance, blank_site_instance); | 727 EXPECT_EQ(orig_site_instance, blank_site_instance); |
750 | 728 |
751 // Now navigate the original (opener) tab to a different site. | 729 // Now navigate the original (opener) tab to a different site. |
752 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); | 730 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); |
753 scoped_refptr<SiteInstance> new_site_instance( | 731 scoped_refptr<SiteInstance> new_site_instance( |
754 shell()->web_contents()->GetSiteInstance()); | 732 shell()->web_contents()->GetSiteInstance()); |
755 EXPECT_NE(orig_site_instance, new_site_instance); | 733 EXPECT_NE(orig_site_instance, new_site_instance); |
756 | 734 |
757 // The opened tab should be able to navigate the opener back to its process. | 735 // The opened tab should be able to navigate the opener back to its process. |
758 WindowedNotificationObserver navigation_observer( | 736 WindowedNotificationObserver navigation_observer( |
759 NOTIFICATION_NAV_ENTRY_COMMITTED, | 737 NOTIFICATION_NAV_ENTRY_COMMITTED, |
760 Source<NavigationController>( | 738 Source<NavigationController>( |
761 &orig_contents->GetController())); | 739 &orig_contents->GetController())); |
762 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 740 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
763 new_shell->web_contents()->GetRenderViewHost(), | 741 new_shell->web_contents()->GetRenderViewHost(), L"", |
764 "", | 742 L"window.domAutomationController.send(navigateOpener());", |
765 "window.domAutomationController.send(navigateOpener());", | |
766 &success)); | 743 &success)); |
767 EXPECT_TRUE(success); | 744 EXPECT_TRUE(success); |
768 navigation_observer.Wait(); | 745 navigation_observer.Wait(); |
769 | 746 |
770 // Should have swapped back into this process. | 747 // Should have swapped back into this process. |
771 scoped_refptr<SiteInstance> revisit_site_instance( | 748 scoped_refptr<SiteInstance> revisit_site_instance( |
772 shell()->web_contents()->GetSiteInstance()); | 749 shell()->web_contents()->GetSiteInstance()); |
773 EXPECT_EQ(orig_site_instance, revisit_site_instance); | 750 EXPECT_EQ(orig_site_instance, revisit_site_instance); |
774 } | 751 } |
775 | 752 |
(...skipping 20 matching lines...) Expand all Loading... |
796 | 773 |
797 // Get the original SiteInstance for later comparison. | 774 // Get the original SiteInstance for later comparison. |
798 scoped_refptr<SiteInstance> orig_site_instance( | 775 scoped_refptr<SiteInstance> orig_site_instance( |
799 shell()->web_contents()->GetSiteInstance()); | 776 shell()->web_contents()->GetSiteInstance()); |
800 EXPECT_TRUE(orig_site_instance != NULL); | 777 EXPECT_TRUE(orig_site_instance != NULL); |
801 | 778 |
802 // Test clicking a target=foo link. | 779 // Test clicking a target=foo link. |
803 ShellAddedObserver new_shell_observer; | 780 ShellAddedObserver new_shell_observer; |
804 bool success = false; | 781 bool success = false; |
805 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 782 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
806 shell()->web_contents()->GetRenderViewHost(), | 783 shell()->web_contents()->GetRenderViewHost(), L"", |
807 "", | 784 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
808 "window.domAutomationController.send(clickSameSiteTargetedLink());", | |
809 &success)); | 785 &success)); |
810 EXPECT_TRUE(success); | 786 EXPECT_TRUE(success); |
811 Shell* new_shell = new_shell_observer.GetShell(); | 787 Shell* new_shell = new_shell_observer.GetShell(); |
812 | 788 |
813 // Wait for the navigation in the new window to finish, if it hasn't. | 789 // Wait for the navigation in the new window to finish, if it hasn't. |
814 WaitForLoadStop(new_shell->web_contents()); | 790 WaitForLoadStop(new_shell->web_contents()); |
815 EXPECT_EQ("/files/navigate_opener.html", | 791 EXPECT_EQ("/files/navigate_opener.html", |
816 new_shell->web_contents()->GetURL().path()); | 792 new_shell->web_contents()->GetURL().path()); |
817 | 793 |
818 // Should have the same SiteInstance. | 794 // Should have the same SiteInstance. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 shell()->web_contents()->GetSiteInstance()); | 854 shell()->web_contents()->GetSiteInstance()); |
879 EXPECT_EQ(orig_site_instance, post_nav_site_instance); | 855 EXPECT_EQ(orig_site_instance, post_nav_site_instance); |
880 EXPECT_EQ("/nocontent", shell()->web_contents()->GetURL().path()); | 856 EXPECT_EQ("/nocontent", shell()->web_contents()->GetURL().path()); |
881 EXPECT_EQ("/files/click-noreferrer-links.html", | 857 EXPECT_EQ("/files/click-noreferrer-links.html", |
882 shell()->web_contents()->GetController(). | 858 shell()->web_contents()->GetController(). |
883 GetLastCommittedEntry()->GetVirtualURL().path()); | 859 GetLastCommittedEntry()->GetVirtualURL().path()); |
884 | 860 |
885 // Renderer-initiated navigations should work. | 861 // Renderer-initiated navigations should work. |
886 bool success = false; | 862 bool success = false; |
887 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 863 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
888 shell()->web_contents()->GetRenderViewHost(), | 864 shell()->web_contents()->GetRenderViewHost(), L"", |
889 "", | 865 L"window.domAutomationController.send(clickNoRefLink());", |
890 "window.domAutomationController.send(clickNoRefLink());", | |
891 &success)); | 866 &success)); |
892 EXPECT_TRUE(success); | 867 EXPECT_TRUE(success); |
893 | 868 |
894 // Wait for the cross-site transition in the current tab to finish. | 869 // Wait for the cross-site transition in the current tab to finish. |
895 WaitForLoadStop(shell()->web_contents()); | 870 WaitForLoadStop(shell()->web_contents()); |
896 | 871 |
897 // Opens in same tab. | 872 // Opens in same tab. |
898 EXPECT_EQ(1u, Shell::windows().size()); | 873 EXPECT_EQ(1u, Shell::windows().size()); |
899 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); | 874 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); |
900 | 875 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | 1013 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
1039 "files/click-noreferrer-links.html", | 1014 "files/click-noreferrer-links.html", |
1040 https_server.host_port_pair(), | 1015 https_server.host_port_pair(), |
1041 &replacement_path)); | 1016 &replacement_path)); |
1042 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | 1017 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); |
1043 | 1018 |
1044 // Open a same-site link in a new widnow. | 1019 // Open a same-site link in a new widnow. |
1045 ShellAddedObserver new_shell_observer; | 1020 ShellAddedObserver new_shell_observer; |
1046 bool success = false; | 1021 bool success = false; |
1047 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 1022 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
1048 shell()->web_contents()->GetRenderViewHost(), | 1023 shell()->web_contents()->GetRenderViewHost(), L"", |
1049 "", | 1024 L"window.domAutomationController.send(clickSameSiteTargetedLink());", |
1050 "window.domAutomationController.send(clickSameSiteTargetedLink());", | |
1051 &success)); | 1025 &success)); |
1052 EXPECT_TRUE(success); | 1026 EXPECT_TRUE(success); |
1053 Shell* new_shell = new_shell_observer.GetShell(); | 1027 Shell* new_shell = new_shell_observer.GetShell(); |
1054 | 1028 |
1055 // Wait for the navigation in the new tab to finish, if it hasn't. | 1029 // Wait for the navigation in the new tab to finish, if it hasn't. |
1056 WaitForLoadStop(new_shell->web_contents()); | 1030 WaitForLoadStop(new_shell->web_contents()); |
1057 EXPECT_EQ("/files/navigate_opener.html", | 1031 EXPECT_EQ("/files/navigate_opener.html", |
1058 new_shell->web_contents()->GetURL().path()); | 1032 new_shell->web_contents()->GetURL().path()); |
1059 | 1033 |
1060 RenderViewHost* rvh = new_shell->web_contents()->GetRenderViewHost(); | 1034 RenderViewHost* rvh = new_shell->web_contents()->GetRenderViewHost(); |
1061 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 1035 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
1062 rvh, | 1036 rvh, L"", |
1063 "", | 1037 L"window.domAutomationController.send(" |
1064 "window.domAutomationController.send(" | 1038 L"document.webkitVisibilityState == 'visible');", |
1065 "document.webkitVisibilityState == 'visible');", | |
1066 &success)); | 1039 &success)); |
1067 EXPECT_TRUE(success); | 1040 EXPECT_TRUE(success); |
1068 | 1041 |
1069 // Now navigate the new window to a different site. This should swap out the | 1042 // Now navigate the new window to a different site. This should swap out the |
1070 // tab's existing RenderView, causing it become hidden. | 1043 // tab's existing RenderView, causing it become hidden. |
1071 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); | 1044 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
1072 | 1045 |
1073 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 1046 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
1074 rvh, | 1047 rvh, L"", |
1075 "", | 1048 L"window.domAutomationController.send(" |
1076 "window.domAutomationController.send(" | 1049 L"document.webkitVisibilityState == 'hidden');", |
1077 "document.webkitVisibilityState == 'hidden');", | |
1078 &success)); | 1050 &success)); |
1079 EXPECT_TRUE(success); | 1051 EXPECT_TRUE(success); |
1080 | 1052 |
1081 // Going back should make the previously swapped-out view to become visible | 1053 // Going back should make the previously swapped-out view to become visible |
1082 // again. | 1054 // again. |
1083 { | 1055 { |
1084 WindowedNotificationObserver back_nav_load_observer( | 1056 WindowedNotificationObserver back_nav_load_observer( |
1085 NOTIFICATION_NAV_ENTRY_COMMITTED, | 1057 NOTIFICATION_NAV_ENTRY_COMMITTED, |
1086 Source<NavigationController>( | 1058 Source<NavigationController>( |
1087 &new_shell->web_contents()->GetController())); | 1059 &new_shell->web_contents()->GetController())); |
1088 new_shell->web_contents()->GetController().GoBack(); | 1060 new_shell->web_contents()->GetController().GoBack(); |
1089 back_nav_load_observer.Wait(); | 1061 back_nav_load_observer.Wait(); |
1090 } | 1062 } |
1091 | 1063 |
1092 | 1064 |
1093 EXPECT_EQ("/files/navigate_opener.html", | 1065 EXPECT_EQ("/files/navigate_opener.html", |
1094 new_shell->web_contents()->GetURL().path()); | 1066 new_shell->web_contents()->GetURL().path()); |
1095 | 1067 |
1096 EXPECT_EQ(rvh, new_shell->web_contents()->GetRenderViewHost()); | 1068 EXPECT_EQ(rvh, new_shell->web_contents()->GetRenderViewHost()); |
1097 | 1069 |
1098 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 1070 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
1099 rvh, | 1071 rvh, L"", |
1100 "", | 1072 L"window.domAutomationController.send(" |
1101 "window.domAutomationController.send(" | 1073 L"document.webkitVisibilityState == 'visible');", |
1102 "document.webkitVisibilityState == 'visible');", | |
1103 &success)); | 1074 &success)); |
1104 EXPECT_TRUE(success); | 1075 EXPECT_TRUE(success); |
1105 } | 1076 } |
1106 | 1077 |
1107 // This class holds onto RenderViewHostObservers for as long as their observed | 1078 // This class holds onto RenderViewHostObservers for as long as their observed |
1108 // RenderViewHosts are alive. This allows us to confirm that all hosts have | 1079 // RenderViewHosts are alive. This allows us to confirm that all hosts have |
1109 // properly been shutdown. | 1080 // properly been shutdown. |
1110 class RenderViewHostObserverArray { | 1081 class RenderViewHostObserverArray { |
1111 public: | 1082 public: |
1112 ~RenderViewHostObserverArray() { | 1083 ~RenderViewHostObserverArray() { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 frames = GetTree(opener_rvhm->current_host()); | 1232 frames = GetTree(opener_rvhm->current_host()); |
1262 EXPECT_TRUE(frames->GetList(kFrameTreeNodeSubtreeKey, &subtree)); | 1233 EXPECT_TRUE(frames->GetList(kFrameTreeNodeSubtreeKey, &subtree)); |
1263 EXPECT_TRUE(subtree->GetSize() == 3); | 1234 EXPECT_TRUE(subtree->GetSize() == 3); |
1264 | 1235 |
1265 scoped_refptr<SiteInstance> orig_site_instance( | 1236 scoped_refptr<SiteInstance> orig_site_instance( |
1266 opener_contents->GetSiteInstance()); | 1237 opener_contents->GetSiteInstance()); |
1267 EXPECT_TRUE(orig_site_instance != NULL); | 1238 EXPECT_TRUE(orig_site_instance != NULL); |
1268 | 1239 |
1269 ShellAddedObserver shell_observer1; | 1240 ShellAddedObserver shell_observer1; |
1270 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 1241 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
1271 opener_contents->GetRenderViewHost(), | 1242 opener_contents->GetRenderViewHost(), L"", |
1272 "", | 1243 L"window.domAutomationController.send(openWindow('1-3.html'));", |
1273 "window.domAutomationController.send(openWindow('1-3.html'));", | |
1274 &success)); | 1244 &success)); |
1275 EXPECT_TRUE(success); | 1245 EXPECT_TRUE(success); |
1276 | 1246 |
1277 Shell* shell1 = shell_observer1.GetShell(); | 1247 Shell* shell1 = shell_observer1.GetShell(); |
1278 WebContents* contents1 = shell1->web_contents(); | 1248 WebContents* contents1 = shell1->web_contents(); |
1279 WaitForLoadStop(contents1); | 1249 WaitForLoadStop(contents1); |
1280 RenderViewHostManager* rvhm1 = static_cast<WebContentsImpl*>( | 1250 RenderViewHostManager* rvhm1 = static_cast<WebContentsImpl*>( |
1281 contents1)->GetRenderManagerForTesting(); | 1251 contents1)->GetRenderManagerForTesting(); |
1282 EXPECT_EQ("/files/frame_tree/1-3.html", contents1->GetURL().path()); | 1252 EXPECT_EQ("/files/frame_tree/1-3.html", contents1->GetURL().path()); |
1283 | 1253 |
1284 // Now navigate the new window to a different SiteInstance. | 1254 // Now navigate the new window to a different SiteInstance. |
1285 NavigateToURL(shell1, https_server.GetURL("files/title1.html")); | 1255 NavigateToURL(shell1, https_server.GetURL("files/title1.html")); |
1286 EXPECT_EQ("/files/title1.html", contents1->GetURL().path()); | 1256 EXPECT_EQ("/files/title1.html", contents1->GetURL().path()); |
1287 scoped_refptr<SiteInstance> site_instance1( | 1257 scoped_refptr<SiteInstance> site_instance1( |
1288 contents1->GetSiteInstance()); | 1258 contents1->GetSiteInstance()); |
1289 EXPECT_NE(orig_site_instance, site_instance1); | 1259 EXPECT_NE(orig_site_instance, site_instance1); |
1290 | 1260 |
1291 ShellAddedObserver shell_observer2; | 1261 ShellAddedObserver shell_observer2; |
1292 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 1262 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
1293 opener_contents->GetRenderViewHost(), | 1263 opener_contents->GetRenderViewHost(), L"", |
1294 "", | 1264 L"window.domAutomationController.send(openWindow('../title2.html'));", |
1295 "window.domAutomationController.send(openWindow('../title2.html'));", | |
1296 &success)); | 1265 &success)); |
1297 EXPECT_TRUE(success); | 1266 EXPECT_TRUE(success); |
1298 | 1267 |
1299 Shell* shell2 = shell_observer2.GetShell(); | 1268 Shell* shell2 = shell_observer2.GetShell(); |
1300 WebContents* contents2 = shell2->web_contents(); | 1269 WebContents* contents2 = shell2->web_contents(); |
1301 WaitForLoadStop(contents2); | 1270 WaitForLoadStop(contents2); |
1302 EXPECT_EQ("/files/title2.html", contents2->GetURL().path()); | 1271 EXPECT_EQ("/files/title2.html", contents2->GetURL().path()); |
1303 | 1272 |
1304 // Navigate the second new window to a different SiteInstance as well. | 1273 // Navigate the second new window to a different SiteInstance as well. |
1305 NavigateToURL(shell2, remote_frame); | 1274 NavigateToURL(shell2, remote_frame); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 GetTree(opener_rvhm->GetSwappedOutRenderViewHost(site_instance2)))); | 1313 GetTree(opener_rvhm->GetSwappedOutRenderViewHost(site_instance2)))); |
1345 | 1314 |
1346 EXPECT_FALSE(CompareTrees( | 1315 EXPECT_FALSE(CompareTrees( |
1347 GetTree(opener_rvhm->current_host()), GetTree(rvhm1->current_host()))); | 1316 GetTree(opener_rvhm->current_host()), GetTree(rvhm1->current_host()))); |
1348 EXPECT_FALSE(CompareTrees( | 1317 EXPECT_FALSE(CompareTrees( |
1349 GetTree(opener_rvhm->current_host()), GetTree(rvhm2->current_host()))); | 1318 GetTree(opener_rvhm->current_host()), GetTree(rvhm2->current_host()))); |
1350 | 1319 |
1351 // Now let's ensure that using JS to add/remove frames results in proper | 1320 // Now let's ensure that using JS to add/remove frames results in proper |
1352 // updates. | 1321 // updates. |
1353 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 1322 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
1354 opener_contents->GetRenderViewHost(), | 1323 opener_contents->GetRenderViewHost(), L"", |
1355 "", | 1324 L"window.domAutomationController.send(removeFrame());", |
1356 "window.domAutomationController.send(removeFrame());", | |
1357 &success)); | 1325 &success)); |
1358 EXPECT_TRUE(success); | 1326 EXPECT_TRUE(success); |
1359 frames = GetTree(opener_rvhm->current_host()); | 1327 frames = GetTree(opener_rvhm->current_host()); |
1360 EXPECT_TRUE(frames->GetList(kFrameTreeNodeSubtreeKey, &subtree)); | 1328 EXPECT_TRUE(frames->GetList(kFrameTreeNodeSubtreeKey, &subtree)); |
1361 EXPECT_EQ(subtree->GetSize(), 2U); | 1329 EXPECT_EQ(subtree->GetSize(), 2U); |
1362 | 1330 |
1363 // Create a load observer for the iframe that will be created by the | 1331 // Create a load observer for the iframe that will be created by the |
1364 // JavaScript code we will execute. | 1332 // JavaScript code we will execute. |
1365 WindowedNotificationObserver load_observer( | 1333 WindowedNotificationObserver load_observer( |
1366 NOTIFICATION_LOAD_STOP, | 1334 NOTIFICATION_LOAD_STOP, |
1367 Source<NavigationController>( | 1335 Source<NavigationController>( |
1368 &opener_contents->GetController())); | 1336 &opener_contents->GetController())); |
1369 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 1337 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
1370 opener_contents->GetRenderViewHost(), | 1338 opener_contents->GetRenderViewHost(), L"", |
1371 "", | 1339 L"window.domAutomationController.send(addFrame());", |
1372 "window.domAutomationController.send(addFrame());", | |
1373 &success)); | 1340 &success)); |
1374 EXPECT_TRUE(success); | 1341 EXPECT_TRUE(success); |
1375 load_observer.Wait(); | 1342 load_observer.Wait(); |
1376 | 1343 |
1377 frames = GetTree(opener_rvhm->current_host()); | 1344 frames = GetTree(opener_rvhm->current_host()); |
1378 EXPECT_TRUE(frames->GetList(kFrameTreeNodeSubtreeKey, &subtree)); | 1345 EXPECT_TRUE(frames->GetList(kFrameTreeNodeSubtreeKey, &subtree)); |
1379 EXPECT_EQ(subtree->GetSize(), 3U); | 1346 EXPECT_EQ(subtree->GetSize(), 3U); |
1380 | 1347 |
1381 EXPECT_TRUE(CompareTrees( | 1348 EXPECT_TRUE(CompareTrees( |
1382 GetTree(opener_rvhm->current_host()), | 1349 GetTree(opener_rvhm->current_host()), |
(...skipping 29 matching lines...) Expand all Loading... |
1412 test_server()->GetURL("files/remove_frame_on_unload.html")); | 1379 test_server()->GetURL("files/remove_frame_on_unload.html")); |
1413 | 1380 |
1414 // Get the original SiteInstance for later comparison. | 1381 // Get the original SiteInstance for later comparison. |
1415 scoped_refptr<SiteInstance> orig_site_instance( | 1382 scoped_refptr<SiteInstance> orig_site_instance( |
1416 shell()->web_contents()->GetSiteInstance()); | 1383 shell()->web_contents()->GetSiteInstance()); |
1417 | 1384 |
1418 // Open a same-site page in a new window. | 1385 // Open a same-site page in a new window. |
1419 ShellAddedObserver new_shell_observer; | 1386 ShellAddedObserver new_shell_observer; |
1420 bool success = false; | 1387 bool success = false; |
1421 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( | 1388 EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( |
1422 shell()->web_contents()->GetRenderViewHost(), | 1389 shell()->web_contents()->GetRenderViewHost(), L"", |
1423 "", | 1390 L"window.domAutomationController.send(openWindow());", |
1424 "window.domAutomationController.send(openWindow());", | |
1425 &success)); | 1391 &success)); |
1426 EXPECT_TRUE(success); | 1392 EXPECT_TRUE(success); |
1427 Shell* new_shell = new_shell_observer.GetShell(); | 1393 Shell* new_shell = new_shell_observer.GetShell(); |
1428 | 1394 |
1429 // Wait for the navigation in the new window to finish, if it hasn't. | 1395 // Wait for the navigation in the new window to finish, if it hasn't. |
1430 WaitForLoadStop(new_shell->web_contents()); | 1396 WaitForLoadStop(new_shell->web_contents()); |
1431 EXPECT_EQ("/files/title1.html", | 1397 EXPECT_EQ("/files/title1.html", |
1432 new_shell->web_contents()->GetURL().path()); | 1398 new_shell->web_contents()->GetURL().path()); |
1433 | 1399 |
1434 // Should have the same SiteInstance. | 1400 // Should have the same SiteInstance. |
1435 EXPECT_EQ(orig_site_instance, new_shell->web_contents()->GetSiteInstance()); | 1401 EXPECT_EQ(orig_site_instance, new_shell->web_contents()->GetSiteInstance()); |
1436 | 1402 |
1437 // 2. Send the second tab to a different process. | 1403 // 2. Send the second tab to a different process. |
1438 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); | 1404 NavigateToURL(new_shell, https_server.GetURL("files/title1.html")); |
1439 scoped_refptr<SiteInstance> new_site_instance( | 1405 scoped_refptr<SiteInstance> new_site_instance( |
1440 new_shell->web_contents()->GetSiteInstance()); | 1406 new_shell->web_contents()->GetSiteInstance()); |
1441 EXPECT_NE(orig_site_instance, new_site_instance); | 1407 EXPECT_NE(orig_site_instance, new_site_instance); |
1442 | 1408 |
1443 // 3. Send the first tab to the second tab's process. | 1409 // 3. Send the first tab to the second tab's process. |
1444 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); | 1410 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); |
1445 | 1411 |
1446 // Make sure it ends up at the right page. | 1412 // Make sure it ends up at the right page. |
1447 WaitForLoadStop(shell()->web_contents()); | 1413 WaitForLoadStop(shell()->web_contents()); |
1448 EXPECT_EQ(https_server.GetURL("files/title1.html"), | 1414 EXPECT_EQ(https_server.GetURL("files/title1.html"), |
1449 shell()->web_contents()->GetURL()); | 1415 shell()->web_contents()->GetURL()); |
1450 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance()); | 1416 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance()); |
1451 } | 1417 } |
1452 | 1418 |
1453 } // namespace content | 1419 } // namespace content |
OLD | NEW |