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

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

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

Powered by Google App Engine
This is Rietveld 408576698