Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: content/browser/renderer_host/render_view_host_manager_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698