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

Side by Side Diff: chrome/browser/web_contents_unittest.cc

Issue 8186: Plumb the referrer throughout the OpenURL APIs.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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
« no previous file with comments | « chrome/browser/web_contents.cc ('k') | chrome/browser/web_drop_target.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/logging.h" 5 #include "base/logging.h"
6 #include "chrome/browser/interstitial_page.h" 6 #include "chrome/browser/interstitial_page.h"
7 #include "chrome/browser/navigation_controller.h" 7 #include "chrome/browser/navigation_controller.h"
8 #include "chrome/browser/navigation_entry.h" 8 #include "chrome/browser/navigation_entry.h"
9 #include "chrome/browser/render_view_host.h" 9 #include "chrome/browser/render_view_host.h"
10 #include "chrome/browser/render_widget_host_view.h" 10 #include "chrome/browser/render_widget_host_view.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 TEST_F(WebContentsTest, SimpleNavigation) { 315 TEST_F(WebContentsTest, SimpleNavigation) {
316 TestRenderViewHost* orig_rvh = contents->rvh(); 316 TestRenderViewHost* orig_rvh = contents->rvh();
317 SiteInstance* instance1 = contents->GetSiteInstance(); 317 SiteInstance* instance1 = contents->GetSiteInstance();
318 EXPECT_TRUE(contents->pending_rvh() == NULL); 318 EXPECT_TRUE(contents->pending_rvh() == NULL);
319 EXPECT_TRUE(contents->original_rvh() == NULL); 319 EXPECT_TRUE(contents->original_rvh() == NULL);
320 EXPECT_TRUE(contents->interstitial_rvh() == NULL); 320 EXPECT_TRUE(contents->interstitial_rvh() == NULL);
321 EXPECT_FALSE(orig_rvh->is_loading); 321 EXPECT_FALSE(orig_rvh->is_loading);
322 322
323 // Navigate to URL 323 // Navigate to URL
324 const GURL url("http://www.google.com"); 324 const GURL url("http://www.google.com");
325 contents->controller()->LoadURL(url, PageTransition::TYPED); 325 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
326 EXPECT_TRUE(contents->state_is_normal()); 326 EXPECT_TRUE(contents->state_is_normal());
327 EXPECT_TRUE(orig_rvh->is_loading); 327 EXPECT_TRUE(orig_rvh->is_loading);
328 EXPECT_EQ(instance1, orig_rvh->site_instance()); 328 EXPECT_EQ(instance1, orig_rvh->site_instance());
329 // Controller's pending entry will have a NULL site instance until we assign 329 // Controller's pending entry will have a NULL site instance until we assign
330 // it in DidNavigate. 330 // it in DidNavigate.
331 EXPECT_TRUE( 331 EXPECT_TRUE(
332 contents->controller()->GetActiveEntry()->site_instance() == NULL); 332 contents->controller()->GetActiveEntry()->site_instance() == NULL);
333 333
334 // DidNavigate from the page 334 // DidNavigate from the page
335 ViewHostMsg_FrameNavigate_Params params; 335 ViewHostMsg_FrameNavigate_Params params;
(...skipping 12 matching lines...) Expand all
348 // without proceeding. 348 // without proceeding.
349 TEST_F(WebContentsTest, ShowInterstitialDontProceed) { 349 TEST_F(WebContentsTest, ShowInterstitialDontProceed) {
350 TestRenderViewHost* orig_rvh = contents->rvh(); 350 TestRenderViewHost* orig_rvh = contents->rvh();
351 EXPECT_TRUE(contents->pending_rvh() == NULL); 351 EXPECT_TRUE(contents->pending_rvh() == NULL);
352 EXPECT_TRUE(contents->original_rvh() == NULL); 352 EXPECT_TRUE(contents->original_rvh() == NULL);
353 EXPECT_TRUE(contents->interstitial_rvh() == NULL); 353 EXPECT_TRUE(contents->interstitial_rvh() == NULL);
354 EXPECT_FALSE(orig_rvh->is_loading); 354 EXPECT_FALSE(orig_rvh->is_loading);
355 355
356 // Navigate to URL 356 // Navigate to URL
357 const GURL url("http://www.google.com"); 357 const GURL url("http://www.google.com");
358 contents->controller()->LoadURL(url, PageTransition::TYPED); 358 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
359 EXPECT_TRUE(contents->state_is_normal()); 359 EXPECT_TRUE(contents->state_is_normal());
360 EXPECT_TRUE(orig_rvh->is_loading); 360 EXPECT_TRUE(orig_rvh->is_loading);
361 361
362 // Show interstitial 362 // Show interstitial
363 const GURL interstitial_url("http://interstitial"); 363 const GURL interstitial_url("http://interstitial");
364 InterstitialPage* interstitial = new InterstitialPage(contents, 364 InterstitialPage* interstitial = new InterstitialPage(contents,
365 true, 365 true,
366 interstitial_url); 366 interstitial_url);
367 interstitial->Show(); 367 interstitial->Show();
368 EXPECT_TRUE(contents->state_is_entering_interstitial()); 368 EXPECT_TRUE(contents->state_is_entering_interstitial());
(...skipping 20 matching lines...) Expand all
389 389
390 // Test navigating to a page that shows an interstitial, then proceeding. 390 // Test navigating to a page that shows an interstitial, then proceeding.
391 TEST_F(WebContentsTest, ShowInterstitialProceed) { 391 TEST_F(WebContentsTest, ShowInterstitialProceed) {
392 TestRenderViewHost* orig_rvh = contents->rvh(); 392 TestRenderViewHost* orig_rvh = contents->rvh();
393 393
394 // The RenderViewHost's SiteInstance should not yet have a site. 394 // The RenderViewHost's SiteInstance should not yet have a site.
395 EXPECT_EQ(GURL(), contents->rvh()->site_instance()->site()); 395 EXPECT_EQ(GURL(), contents->rvh()->site_instance()->site());
396 396
397 // Navigate to URL 397 // Navigate to URL
398 const GURL url("http://www.google.com"); 398 const GURL url("http://www.google.com");
399 contents->controller()->LoadURL(url, PageTransition::TYPED); 399 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
400 400
401 // Show interstitial 401 // Show interstitial
402 const GURL interstitial_url("http://interstitial"); 402 const GURL interstitial_url("http://interstitial");
403 InterstitialPage* interstitial = new InterstitialPage(contents, 403 InterstitialPage* interstitial = new InterstitialPage(contents,
404 true, 404 true,
405 interstitial_url); 405 interstitial_url);
406 interstitial->Show(); 406 interstitial->Show();
407 TestRenderViewHost* interstitial_rvh = contents->interstitial_rvh(); 407 TestRenderViewHost* interstitial_rvh = contents->interstitial_rvh();
408 408
409 // DidNavigate from the interstitial 409 // DidNavigate from the interstitial
(...skipping 25 matching lines...) Expand all
435 // Since we weren't viewing a page before, we shouldn't be able to go back. 435 // Since we weren't viewing a page before, we shouldn't be able to go back.
436 EXPECT_FALSE(contents->controller()->CanGoBack()); 436 EXPECT_FALSE(contents->controller()->CanGoBack());
437 } 437 }
438 438
439 // Test navigating to a page that shows an interstitial, then navigating away. 439 // Test navigating to a page that shows an interstitial, then navigating away.
440 TEST_F(WebContentsTest, ShowInterstitialThenNavigate) { 440 TEST_F(WebContentsTest, ShowInterstitialThenNavigate) {
441 TestRenderViewHost* orig_rvh = contents->rvh(); 441 TestRenderViewHost* orig_rvh = contents->rvh();
442 442
443 // Navigate to URL 443 // Navigate to URL
444 const GURL url("http://www.google.com"); 444 const GURL url("http://www.google.com");
445 contents->controller()->LoadURL(url, PageTransition::TYPED); 445 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
446 446
447 // Show interstitial 447 // Show interstitial
448 const GURL interstitial_url("http://interstitial"); 448 const GURL interstitial_url("http://interstitial");
449 InterstitialPage* interstitial = new InterstitialPage(contents, 449 InterstitialPage* interstitial = new InterstitialPage(contents,
450 true, 450 true,
451 interstitial_url); 451 interstitial_url);
452 interstitial->Show(); 452 interstitial->Show();
453 TestRenderViewHost* interstitial_rvh = contents->interstitial_rvh(); 453 TestRenderViewHost* interstitial_rvh = contents->interstitial_rvh();
454 454
455 // DidNavigate from the interstitial 455 // DidNavigate from the interstitial
456 ViewHostMsg_FrameNavigate_Params params; 456 ViewHostMsg_FrameNavigate_Params params;
457 InitNavigateParams(&params, 1, url); 457 InitNavigateParams(&params, 1, url);
458 contents->TestDidNavigate(interstitial_rvh, params); 458 contents->TestDidNavigate(interstitial_rvh, params);
459 459
460 // While interstitial showing, navigate to a new URL. 460 // While interstitial showing, navigate to a new URL.
461 const GURL url2("http://www.yahoo.com"); 461 const GURL url2("http://www.yahoo.com");
462 contents->controller()->LoadURL(url2, PageTransition::TYPED); 462 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
463 EXPECT_TRUE(contents->state_is_leaving_interstitial()); 463 EXPECT_TRUE(contents->state_is_leaving_interstitial());
464 EXPECT_EQ(interstitial_rvh, contents->render_view_host()); 464 EXPECT_EQ(interstitial_rvh, contents->render_view_host());
465 EXPECT_TRUE(orig_rvh->is_loading); 465 EXPECT_TRUE(orig_rvh->is_loading);
466 EXPECT_FALSE(interstitial_rvh->is_loading); 466 EXPECT_FALSE(interstitial_rvh->is_loading);
467 467
468 // DidNavigate from the new URL. In the old process model, we'll still have 468 // DidNavigate from the new URL. In the old process model, we'll still have
469 // the same RenderViewHost. 469 // the same RenderViewHost.
470 ViewHostMsg_FrameNavigate_Params params2; 470 ViewHostMsg_FrameNavigate_Params params2;
471 InitNavigateParams(&params2, 2, url2); 471 InitNavigateParams(&params2, 2, url2);
472 contents->TestDidNavigate(orig_rvh, params2); 472 contents->TestDidNavigate(orig_rvh, params2);
473 EXPECT_TRUE(contents->state_is_normal()); 473 EXPECT_TRUE(contents->state_is_normal());
474 EXPECT_EQ(orig_rvh, contents->render_view_host()); 474 EXPECT_EQ(orig_rvh, contents->render_view_host());
475 EXPECT_FALSE(orig_rvh->is_loading); 475 EXPECT_FALSE(orig_rvh->is_loading);
476 } 476 }
477 477
478 // Ensures that an interstitial cannot be cancelled if a notification for a 478 // Ensures that an interstitial cannot be cancelled if a notification for a
479 // navigation from an IFrame from the previous page is received while the 479 // navigation from an IFrame from the previous page is received while the
480 // interstitial is being shown (bug #1182394). 480 // interstitial is being shown (bug #1182394).
481 TEST_F(WebContentsTest, ShowInterstitialIFrameNavigate) { 481 TEST_F(WebContentsTest, ShowInterstitialIFrameNavigate) {
482 TestRenderViewHost* orig_rvh = contents->rvh(); 482 TestRenderViewHost* orig_rvh = contents->rvh();
483 EXPECT_TRUE(contents->pending_rvh() == NULL); 483 EXPECT_TRUE(contents->pending_rvh() == NULL);
484 EXPECT_TRUE(contents->original_rvh() == NULL); 484 EXPECT_TRUE(contents->original_rvh() == NULL);
485 EXPECT_TRUE(contents->interstitial_rvh() == NULL); 485 EXPECT_TRUE(contents->interstitial_rvh() == NULL);
486 EXPECT_FALSE(orig_rvh->is_loading); 486 EXPECT_FALSE(orig_rvh->is_loading);
487 487
488 // Navigate to URL. 488 // Navigate to URL.
489 const GURL url("http://www.google.com"); 489 const GURL url("http://www.google.com");
490 contents->controller()->LoadURL(url, PageTransition::TYPED); 490 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
491 EXPECT_TRUE(contents->state_is_normal()); 491 EXPECT_TRUE(contents->state_is_normal());
492 EXPECT_TRUE(orig_rvh->is_loading); 492 EXPECT_TRUE(orig_rvh->is_loading);
493 ViewHostMsg_FrameNavigate_Params params1; 493 ViewHostMsg_FrameNavigate_Params params1;
494 InitNavigateParams(&params1, 1, url); 494 InitNavigateParams(&params1, 1, url);
495 contents->TestDidNavigate(orig_rvh, params1); 495 contents->TestDidNavigate(orig_rvh, params1);
496 496
497 // Show interstitial (in real world would probably be triggered by a resource 497 // Show interstitial (in real world would probably be triggered by a resource
498 // in the page). 498 // in the page).
499 const GURL interstitial_url("http://interstitial"); 499 const GURL interstitial_url("http://interstitial");
500 InterstitialPage* interstitial = new InterstitialPage(contents, 500 InterstitialPage* interstitial = new InterstitialPage(contents,
(...skipping 21 matching lines...) Expand all
522 } 522 }
523 523
524 // Test navigating to an interstitial page from a normal page. Also test 524 // Test navigating to an interstitial page from a normal page. Also test
525 // visiting the interstitial-inducing URL twice (bug 1079784), and test 525 // visiting the interstitial-inducing URL twice (bug 1079784), and test
526 // that going back shows the first page and not the interstitial. 526 // that going back shows the first page and not the interstitial.
527 TEST_F(WebContentsTest, VisitInterstitialURLTwice) { 527 TEST_F(WebContentsTest, VisitInterstitialURLTwice) {
528 TestRenderViewHost* orig_rvh = contents->rvh(); 528 TestRenderViewHost* orig_rvh = contents->rvh();
529 529
530 // Navigate to URL 530 // Navigate to URL
531 const GURL url("http://www.google.com"); 531 const GURL url("http://www.google.com");
532 contents->controller()->LoadURL(url, PageTransition::TYPED); 532 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
533 ViewHostMsg_FrameNavigate_Params params1; 533 ViewHostMsg_FrameNavigate_Params params1;
534 InitNavigateParams(&params1, 1, url); 534 InitNavigateParams(&params1, 1, url);
535 contents->TestDidNavigate(orig_rvh, params1); 535 contents->TestDidNavigate(orig_rvh, params1);
536 536
537 // Now navigate to an interstitial-inducing URL 537 // Now navigate to an interstitial-inducing URL
538 const GURL url2("https://www.google.com"); 538 const GURL url2("https://www.google.com");
539 contents->controller()->LoadURL(url2, PageTransition::TYPED); 539 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
540 const GURL interstitial_url("http://interstitial"); 540 const GURL interstitial_url("http://interstitial");
541 InterstitialPage* interstitial = new InterstitialPage(contents, 541 InterstitialPage* interstitial = new InterstitialPage(contents,
542 true, 542 true,
543 interstitial_url); 543 interstitial_url);
544 interstitial->Show(); 544 interstitial->Show();
545 EXPECT_TRUE(contents->state_is_entering_interstitial()); 545 EXPECT_TRUE(contents->state_is_entering_interstitial());
546 int interstitial_delete_counter = 0; 546 int interstitial_delete_counter = 0;
547 TestRenderViewHost* interstitial_rvh = contents->interstitial_rvh(); 547 TestRenderViewHost* interstitial_rvh = contents->interstitial_rvh();
548 interstitial_rvh->set_delete_counter(&interstitial_delete_counter); 548 interstitial_rvh->set_delete_counter(&interstitial_delete_counter);
549 549
550 // DidNavigate from the interstitial 550 // DidNavigate from the interstitial
551 ViewHostMsg_FrameNavigate_Params params2; 551 ViewHostMsg_FrameNavigate_Params params2;
552 InitNavigateParams(&params2, 2, url2); 552 InitNavigateParams(&params2, 2, url2);
553 contents->TestDidNavigate(interstitial_rvh, params2); 553 contents->TestDidNavigate(interstitial_rvh, params2);
554 EXPECT_TRUE(contents->state_is_interstitial()); 554 EXPECT_TRUE(contents->state_is_interstitial());
555 EXPECT_EQ(interstitial_rvh, contents->render_view_host()); 555 EXPECT_EQ(interstitial_rvh, contents->render_view_host());
556 556
557 // While interstitial showing, navigate to the same URL. 557 // While interstitial showing, navigate to the same URL.
558 contents->controller()->LoadURL(url2, PageTransition::TYPED); 558 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
559 EXPECT_TRUE(contents->state_is_leaving_interstitial()); 559 EXPECT_TRUE(contents->state_is_leaving_interstitial());
560 EXPECT_EQ(interstitial_rvh, contents->render_view_host()); 560 EXPECT_EQ(interstitial_rvh, contents->render_view_host());
561 561
562 // Interstitial shown a second time in a different RenderViewHost. 562 // Interstitial shown a second time in a different RenderViewHost.
563 interstitial = new InterstitialPage(contents, true, interstitial_url); 563 interstitial = new InterstitialPage(contents, true, interstitial_url);
564 interstitial->Show(); 564 interstitial->Show();
565 EXPECT_TRUE(contents->state_is_entering_interstitial()); 565 EXPECT_TRUE(contents->state_is_entering_interstitial());
566 // We expect the original interstitial has been deleted. 566 // We expect the original interstitial has been deleted.
567 EXPECT_EQ(interstitial_delete_counter, 1); 567 EXPECT_EQ(interstitial_delete_counter, 1);
568 TestRenderViewHost* interstitial_rvh2 = contents->interstitial_rvh(); 568 TestRenderViewHost* interstitial_rvh2 = contents->interstitial_rvh();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 // with a new SiteInstance. Going back should do the same. 602 // with a new SiteInstance. Going back should do the same.
603 TEST_F(WebContentsTest, CrossSiteBoundaries) { 603 TEST_F(WebContentsTest, CrossSiteBoundaries) {
604 contents->transition_cross_site = true; 604 contents->transition_cross_site = true;
605 TestRenderViewHost* orig_rvh = contents->rvh(); 605 TestRenderViewHost* orig_rvh = contents->rvh();
606 int orig_rvh_delete_count = 0; 606 int orig_rvh_delete_count = 0;
607 orig_rvh->set_delete_counter(&orig_rvh_delete_count); 607 orig_rvh->set_delete_counter(&orig_rvh_delete_count);
608 SiteInstance* instance1 = contents->GetSiteInstance(); 608 SiteInstance* instance1 = contents->GetSiteInstance();
609 609
610 // Navigate to URL. First URL should use first RenderViewHost. 610 // Navigate to URL. First URL should use first RenderViewHost.
611 const GURL url("http://www.google.com"); 611 const GURL url("http://www.google.com");
612 contents->controller()->LoadURL(url, PageTransition::TYPED); 612 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
613 ViewHostMsg_FrameNavigate_Params params1; 613 ViewHostMsg_FrameNavigate_Params params1;
614 InitNavigateParams(&params1, 1, url); 614 InitNavigateParams(&params1, 1, url);
615 contents->TestDidNavigate(orig_rvh, params1); 615 contents->TestDidNavigate(orig_rvh, params1);
616 616
617 EXPECT_TRUE(contents->state_is_normal()); 617 EXPECT_TRUE(contents->state_is_normal());
618 EXPECT_EQ(orig_rvh, contents->render_view_host()); 618 EXPECT_EQ(orig_rvh, contents->render_view_host());
619 EXPECT_TRUE(contents->original_rvh() == NULL); 619 EXPECT_TRUE(contents->original_rvh() == NULL);
620 EXPECT_TRUE(contents->interstitial_rvh() == NULL); 620 EXPECT_TRUE(contents->interstitial_rvh() == NULL);
621 621
622 // Navigate to new site 622 // Navigate to new site
623 const GURL url2("http://www.yahoo.com"); 623 const GURL url2("http://www.yahoo.com");
624 contents->controller()->LoadURL(url2, PageTransition::TYPED); 624 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
625 EXPECT_TRUE(contents->state_is_pending()); 625 EXPECT_TRUE(contents->state_is_pending());
626 TestRenderViewHost* pending_rvh = contents->pending_rvh(); 626 TestRenderViewHost* pending_rvh = contents->pending_rvh();
627 int pending_rvh_delete_count = 0; 627 int pending_rvh_delete_count = 0;
628 pending_rvh->set_delete_counter(&pending_rvh_delete_count); 628 pending_rvh->set_delete_counter(&pending_rvh_delete_count);
629 629
630 // DidNavigate from the pending page 630 // DidNavigate from the pending page
631 ViewHostMsg_FrameNavigate_Params params2; 631 ViewHostMsg_FrameNavigate_Params params2;
632 InitNavigateParams(&params2, 1, url2); 632 InitNavigateParams(&params2, 1, url2);
633 contents->TestDidNavigate(pending_rvh, params2); 633 contents->TestDidNavigate(pending_rvh, params2);
634 SiteInstance* instance2 = contents->GetSiteInstance(); 634 SiteInstance* instance2 = contents->GetSiteInstance();
(...skipping 24 matching lines...) Expand all
659 // RVH without requiring a cross-site transition (i.e., PENDING state). 659 // RVH without requiring a cross-site transition (i.e., PENDING state).
660 TEST_F(WebContentsTest, CrossSiteBoundariesAfterCrash) { 660 TEST_F(WebContentsTest, CrossSiteBoundariesAfterCrash) {
661 contents->transition_cross_site = true; 661 contents->transition_cross_site = true;
662 TestRenderViewHost* orig_rvh = contents->rvh(); 662 TestRenderViewHost* orig_rvh = contents->rvh();
663 int orig_rvh_delete_count = 0; 663 int orig_rvh_delete_count = 0;
664 orig_rvh->set_delete_counter(&orig_rvh_delete_count); 664 orig_rvh->set_delete_counter(&orig_rvh_delete_count);
665 SiteInstance* instance1 = contents->GetSiteInstance(); 665 SiteInstance* instance1 = contents->GetSiteInstance();
666 666
667 // Navigate to URL. First URL should use first RenderViewHost. 667 // Navigate to URL. First URL should use first RenderViewHost.
668 const GURL url("http://www.google.com"); 668 const GURL url("http://www.google.com");
669 contents->controller()->LoadURL(url, PageTransition::TYPED); 669 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
670 ViewHostMsg_FrameNavigate_Params params1; 670 ViewHostMsg_FrameNavigate_Params params1;
671 InitNavigateParams(&params1, 1, url); 671 InitNavigateParams(&params1, 1, url);
672 contents->TestDidNavigate(orig_rvh, params1); 672 contents->TestDidNavigate(orig_rvh, params1);
673 673
674 EXPECT_TRUE(contents->state_is_normal()); 674 EXPECT_TRUE(contents->state_is_normal());
675 EXPECT_EQ(orig_rvh, contents->render_view_host()); 675 EXPECT_EQ(orig_rvh, contents->render_view_host());
676 EXPECT_TRUE(contents->original_rvh() == NULL); 676 EXPECT_TRUE(contents->original_rvh() == NULL);
677 EXPECT_TRUE(contents->interstitial_rvh() == NULL); 677 EXPECT_TRUE(contents->interstitial_rvh() == NULL);
678 678
679 // Crash the renderer. 679 // Crash the renderer.
680 orig_rvh->is_created = false; 680 orig_rvh->is_created = false;
681 681
682 // Navigate to new site. We should not go into PENDING. 682 // Navigate to new site. We should not go into PENDING.
683 const GURL url2("http://www.yahoo.com"); 683 const GURL url2("http://www.yahoo.com");
684 contents->controller()->LoadURL(url2, PageTransition::TYPED); 684 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
685 TestRenderViewHost* new_rvh = contents->rvh(); 685 TestRenderViewHost* new_rvh = contents->rvh();
686 EXPECT_TRUE(contents->state_is_normal()); 686 EXPECT_TRUE(contents->state_is_normal());
687 EXPECT_TRUE(contents->pending_rvh() == NULL); 687 EXPECT_TRUE(contents->pending_rvh() == NULL);
688 EXPECT_TRUE(contents->original_rvh() == NULL); 688 EXPECT_TRUE(contents->original_rvh() == NULL);
689 EXPECT_TRUE(contents->interstitial_rvh() == NULL); 689 EXPECT_TRUE(contents->interstitial_rvh() == NULL);
690 EXPECT_NE(orig_rvh, new_rvh); 690 EXPECT_NE(orig_rvh, new_rvh);
691 EXPECT_EQ(orig_rvh_delete_count, 1); 691 EXPECT_EQ(orig_rvh_delete_count, 1);
692 692
693 // DidNavigate from the new page 693 // DidNavigate from the new page
694 ViewHostMsg_FrameNavigate_Params params2; 694 ViewHostMsg_FrameNavigate_Params params2;
(...skipping 11 matching lines...) Expand all
706 706
707 // Test state transitions when showing an interstitial in the new process 707 // Test state transitions when showing an interstitial in the new process
708 // model, and then choosing DontProceed. 708 // model, and then choosing DontProceed.
709 TEST_F(WebContentsTest, CrossSiteInterstitialDontProceed) { 709 TEST_F(WebContentsTest, CrossSiteInterstitialDontProceed) {
710 contents->transition_cross_site = true; 710 contents->transition_cross_site = true;
711 TestRenderViewHost* orig_rvh = contents->rvh(); 711 TestRenderViewHost* orig_rvh = contents->rvh();
712 SiteInstance* instance1 = contents->GetSiteInstance(); 712 SiteInstance* instance1 = contents->GetSiteInstance();
713 713
714 // Navigate to URL. First URL should use first RenderViewHost. 714 // Navigate to URL. First URL should use first RenderViewHost.
715 const GURL url("http://www.google.com"); 715 const GURL url("http://www.google.com");
716 contents->controller()->LoadURL(url, PageTransition::TYPED); 716 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
717 ViewHostMsg_FrameNavigate_Params params1; 717 ViewHostMsg_FrameNavigate_Params params1;
718 InitNavigateParams(&params1, 1, url); 718 InitNavigateParams(&params1, 1, url);
719 contents->TestDidNavigate(orig_rvh, params1); 719 contents->TestDidNavigate(orig_rvh, params1);
720 720
721 EXPECT_TRUE(contents->state_is_normal()); 721 EXPECT_TRUE(contents->state_is_normal());
722 EXPECT_EQ(orig_rvh, contents->render_view_host()); 722 EXPECT_EQ(orig_rvh, contents->render_view_host());
723 723
724 // Navigate to new site 724 // Navigate to new site
725 const GURL url2("https://www.google.com"); 725 const GURL url2("https://www.google.com");
726 contents->controller()->LoadURL(url2, PageTransition::TYPED); 726 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
727 EXPECT_TRUE(contents->state_is_pending()); 727 EXPECT_TRUE(contents->state_is_pending());
728 TestRenderViewHost* pending_rvh = contents->pending_rvh(); 728 TestRenderViewHost* pending_rvh = contents->pending_rvh();
729 729
730 // Show an interstitial 730 // Show an interstitial
731 const GURL interstitial_url("http://interstitial"); 731 const GURL interstitial_url("http://interstitial");
732 InterstitialPage* interstitial = new InterstitialPage(contents, 732 InterstitialPage* interstitial = new InterstitialPage(contents,
733 true, 733 true,
734 interstitial_url); 734 interstitial_url);
735 interstitial->Show(); 735 interstitial->Show();
736 EXPECT_TRUE(contents->state_is_entering_interstitial()); 736 EXPECT_TRUE(contents->state_is_entering_interstitial());
(...skipping 24 matching lines...) Expand all
761 // model, and then choosing Proceed. 761 // model, and then choosing Proceed.
762 TEST_F(WebContentsTest, CrossSiteInterstitialProceed) { 762 TEST_F(WebContentsTest, CrossSiteInterstitialProceed) {
763 contents->transition_cross_site = true; 763 contents->transition_cross_site = true;
764 int orig_rvh_delete_count = 0; 764 int orig_rvh_delete_count = 0;
765 TestRenderViewHost* orig_rvh = contents->rvh(); 765 TestRenderViewHost* orig_rvh = contents->rvh();
766 orig_rvh->set_delete_counter(&orig_rvh_delete_count); 766 orig_rvh->set_delete_counter(&orig_rvh_delete_count);
767 SiteInstance* instance1 = contents->GetSiteInstance(); 767 SiteInstance* instance1 = contents->GetSiteInstance();
768 768
769 // Navigate to URL. First URL should use first RenderViewHost. 769 // Navigate to URL. First URL should use first RenderViewHost.
770 const GURL url("http://www.google.com"); 770 const GURL url("http://www.google.com");
771 contents->controller()->LoadURL(url, PageTransition::TYPED); 771 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
772 ViewHostMsg_FrameNavigate_Params params1; 772 ViewHostMsg_FrameNavigate_Params params1;
773 InitNavigateParams(&params1, 1, url); 773 InitNavigateParams(&params1, 1, url);
774 contents->TestDidNavigate(orig_rvh, params1); 774 contents->TestDidNavigate(orig_rvh, params1);
775 775
776 // Navigate to new site 776 // Navigate to new site
777 const GURL url2("https://www.google.com"); 777 const GURL url2("https://www.google.com");
778 contents->controller()->LoadURL(url2, PageTransition::TYPED); 778 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
779 TestRenderViewHost* pending_rvh = contents->pending_rvh(); 779 TestRenderViewHost* pending_rvh = contents->pending_rvh();
780 int pending_rvh_delete_count = 0; 780 int pending_rvh_delete_count = 0;
781 pending_rvh->set_delete_counter(&pending_rvh_delete_count); 781 pending_rvh->set_delete_counter(&pending_rvh_delete_count);
782 782
783 // Show an interstitial 783 // Show an interstitial
784 const GURL interstitial_url("http://interstitial"); 784 const GURL interstitial_url("http://interstitial");
785 InterstitialPage* interstitial = new InterstitialPage(contents, 785 InterstitialPage* interstitial = new InterstitialPage(contents,
786 true, 786 true,
787 interstitial_url); 787 interstitial_url);
788 interstitial->Show(); 788 interstitial->Show();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 838
839 // Tests that we can transition away from an interstitial page. 839 // Tests that we can transition away from an interstitial page.
840 TEST_F(WebContentsTest, CrossSiteInterstitialThenNavigate) { 840 TEST_F(WebContentsTest, CrossSiteInterstitialThenNavigate) {
841 contents->transition_cross_site = true; 841 contents->transition_cross_site = true;
842 int orig_rvh_delete_count = 0; 842 int orig_rvh_delete_count = 0;
843 TestRenderViewHost* orig_rvh = contents->rvh(); 843 TestRenderViewHost* orig_rvh = contents->rvh();
844 orig_rvh->set_delete_counter(&orig_rvh_delete_count); 844 orig_rvh->set_delete_counter(&orig_rvh_delete_count);
845 845
846 // Navigate to URL. First URL should use first RenderViewHost. 846 // Navigate to URL. First URL should use first RenderViewHost.
847 const GURL url("http://www.google.com"); 847 const GURL url("http://www.google.com");
848 contents->controller()->LoadURL(url, PageTransition::TYPED); 848 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
849 ViewHostMsg_FrameNavigate_Params params1; 849 ViewHostMsg_FrameNavigate_Params params1;
850 InitNavigateParams(&params1, 1, url); 850 InitNavigateParams(&params1, 1, url);
851 contents->TestDidNavigate(orig_rvh, params1); 851 contents->TestDidNavigate(orig_rvh, params1);
852 852
853 // Show an interstitial 853 // Show an interstitial
854 const GURL interstitial_url("http://interstitial"); 854 const GURL interstitial_url("http://interstitial");
855 InterstitialPage* interstitial = new InterstitialPage(contents, 855 InterstitialPage* interstitial = new InterstitialPage(contents,
856 false, 856 false,
857 interstitial_url); 857 interstitial_url);
858 interstitial->Show(); 858 interstitial->Show();
859 TestRenderViewHost* interstitial_rvh = contents->interstitial_rvh(); 859 TestRenderViewHost* interstitial_rvh = contents->interstitial_rvh();
860 860
861 // DidNavigate from the interstitial 861 // DidNavigate from the interstitial
862 ViewHostMsg_FrameNavigate_Params params2; 862 ViewHostMsg_FrameNavigate_Params params2;
863 InitNavigateParams(&params2, 1, url); 863 InitNavigateParams(&params2, 1, url);
864 contents->TestDidNavigate(interstitial_rvh, params2); 864 contents->TestDidNavigate(interstitial_rvh, params2);
865 EXPECT_TRUE(contents->state_is_interstitial()); 865 EXPECT_TRUE(contents->state_is_interstitial());
866 EXPECT_EQ(interstitial_rvh, contents->render_view_host()); 866 EXPECT_EQ(interstitial_rvh, contents->render_view_host());
867 EXPECT_EQ(orig_rvh, contents->original_rvh()); 867 EXPECT_EQ(orig_rvh, contents->original_rvh());
868 EXPECT_TRUE(contents->interstitial_rvh() == NULL); 868 EXPECT_TRUE(contents->interstitial_rvh() == NULL);
869 869
870 // Navigate to a new page. 870 // Navigate to a new page.
871 const GURL url2("http://www.yahoo.com"); 871 const GURL url2("http://www.yahoo.com");
872 contents->controller()->LoadURL(url2, PageTransition::TYPED); 872 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
873 873
874 TestRenderViewHost* new_rvh = contents->pending_rvh(); 874 TestRenderViewHost* new_rvh = contents->pending_rvh();
875 ASSERT_TRUE(new_rvh != NULL); 875 ASSERT_TRUE(new_rvh != NULL);
876 // Make sure the RVH is not suspended (bug #1236441). 876 // Make sure the RVH is not suspended (bug #1236441).
877 EXPECT_FALSE(new_rvh->IsNavigationSuspended()); 877 EXPECT_FALSE(new_rvh->IsNavigationSuspended());
878 EXPECT_TRUE(contents->state_is_leaving_interstitial()); 878 EXPECT_TRUE(contents->state_is_leaving_interstitial());
879 EXPECT_EQ(interstitial_rvh, contents->render_view_host()); 879 EXPECT_EQ(interstitial_rvh, contents->render_view_host());
880 880
881 // DidNavigate from the new page 881 // DidNavigate from the new page
882 ViewHostMsg_FrameNavigate_Params params3; 882 ViewHostMsg_FrameNavigate_Params params3;
883 InitNavigateParams(&params3, 1, url2); 883 InitNavigateParams(&params3, 1, url2);
884 contents->TestDidNavigate(new_rvh, params3); 884 contents->TestDidNavigate(new_rvh, params3);
885 EXPECT_TRUE(contents->state_is_normal()); 885 EXPECT_TRUE(contents->state_is_normal());
886 EXPECT_EQ(new_rvh, contents->render_view_host()); 886 EXPECT_EQ(new_rvh, contents->render_view_host());
887 EXPECT_TRUE(contents->pending_rvh() == NULL); 887 EXPECT_TRUE(contents->pending_rvh() == NULL);
888 EXPECT_EQ(orig_rvh_delete_count, 1); 888 EXPECT_EQ(orig_rvh_delete_count, 1);
889 } 889 }
890 890
891 // Tests that we can transition away from an interstitial page even if the 891 // Tests that we can transition away from an interstitial page even if the
892 // interstitial renderer has crashed. 892 // interstitial renderer has crashed.
893 TEST_F(WebContentsTest, CrossSiteInterstitialCrashThenNavigate) { 893 TEST_F(WebContentsTest, CrossSiteInterstitialCrashThenNavigate) {
894 contents->transition_cross_site = true; 894 contents->transition_cross_site = true;
895 int orig_rvh_delete_count = 0; 895 int orig_rvh_delete_count = 0;
896 TestRenderViewHost* orig_rvh = contents->rvh(); 896 TestRenderViewHost* orig_rvh = contents->rvh();
897 orig_rvh->set_delete_counter(&orig_rvh_delete_count); 897 orig_rvh->set_delete_counter(&orig_rvh_delete_count);
898 898
899 // Navigate to URL. First URL should use first RenderViewHost. 899 // Navigate to URL. First URL should use first RenderViewHost.
900 const GURL url("http://www.google.com"); 900 const GURL url("http://www.google.com");
901 contents->controller()->LoadURL(url, PageTransition::TYPED); 901 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
902 ViewHostMsg_FrameNavigate_Params params1; 902 ViewHostMsg_FrameNavigate_Params params1;
903 InitNavigateParams(&params1, 1, url); 903 InitNavigateParams(&params1, 1, url);
904 contents->TestDidNavigate(orig_rvh, params1); 904 contents->TestDidNavigate(orig_rvh, params1);
905 905
906 // Navigate to new site 906 // Navigate to new site
907 const GURL url2("https://www.google.com"); 907 const GURL url2("https://www.google.com");
908 contents->controller()->LoadURL(url2, PageTransition::TYPED); 908 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
909 TestRenderViewHost* pending_rvh = contents->pending_rvh(); 909 TestRenderViewHost* pending_rvh = contents->pending_rvh();
910 int pending_rvh_delete_count = 0; 910 int pending_rvh_delete_count = 0;
911 pending_rvh->set_delete_counter(&pending_rvh_delete_count); 911 pending_rvh->set_delete_counter(&pending_rvh_delete_count);
912 912
913 // Show an interstitial 913 // Show an interstitial
914 const GURL interstitial_url("http://interstitial"); 914 const GURL interstitial_url("http://interstitial");
915 InterstitialPage* interstitial = new InterstitialPage(contents, 915 InterstitialPage* interstitial = new InterstitialPage(contents,
916 true, 916 true,
917 interstitial_url); 917 interstitial_url);
918 interstitial->Show(); 918 interstitial->Show();
919 TestRenderViewHost* interstitial_rvh = contents->interstitial_rvh(); 919 TestRenderViewHost* interstitial_rvh = contents->interstitial_rvh();
920 920
921 // DidNavigate from the interstitial 921 // DidNavigate from the interstitial
922 ViewHostMsg_FrameNavigate_Params params2; 922 ViewHostMsg_FrameNavigate_Params params2;
923 InitNavigateParams(&params2, 1, url2); 923 InitNavigateParams(&params2, 1, url2);
924 contents->TestDidNavigate(interstitial_rvh, params2); 924 contents->TestDidNavigate(interstitial_rvh, params2);
925 EXPECT_TRUE(contents->state_is_interstitial()); 925 EXPECT_TRUE(contents->state_is_interstitial());
926 EXPECT_EQ(interstitial_rvh, contents->render_view_host()); 926 EXPECT_EQ(interstitial_rvh, contents->render_view_host());
927 EXPECT_EQ(orig_rvh, contents->original_rvh()); 927 EXPECT_EQ(orig_rvh, contents->original_rvh());
928 EXPECT_EQ(pending_rvh, contents->pending_rvh()); 928 EXPECT_EQ(pending_rvh, contents->pending_rvh());
929 EXPECT_TRUE(contents->interstitial_rvh() == NULL); 929 EXPECT_TRUE(contents->interstitial_rvh() == NULL);
930 930
931 // Crash the interstitial RVH 931 // Crash the interstitial RVH
932 // (by making IsRenderViewLive() == false) 932 // (by making IsRenderViewLive() == false)
933 interstitial_rvh->is_created = false; 933 interstitial_rvh->is_created = false;
934 934
935 // Navigate to a new page. Since interstitial RVH is dead, we should clean 935 // Navigate to a new page. Since interstitial RVH is dead, we should clean
936 // it up and go to a new PENDING state, showing the orig_rvh. 936 // it up and go to a new PENDING state, showing the orig_rvh.
937 const GURL url3("http://www.yahoo.com"); 937 const GURL url3("http://www.yahoo.com");
938 contents->controller()->LoadURL(url3, PageTransition::TYPED); 938 contents->controller()->LoadURL(url3, GURL(), PageTransition::TYPED);
939 TestRenderViewHost* new_rvh = contents->pending_rvh(); 939 TestRenderViewHost* new_rvh = contents->pending_rvh();
940 ASSERT_TRUE(new_rvh != NULL); 940 ASSERT_TRUE(new_rvh != NULL);
941 EXPECT_TRUE(contents->state_is_pending()); 941 EXPECT_TRUE(contents->state_is_pending());
942 EXPECT_EQ(orig_rvh, contents->render_view_host()); 942 EXPECT_EQ(orig_rvh, contents->render_view_host());
943 EXPECT_EQ(pending_rvh_delete_count, 1); 943 EXPECT_EQ(pending_rvh_delete_count, 1);
944 EXPECT_NE(interstitial_rvh, new_rvh); 944 EXPECT_NE(interstitial_rvh, new_rvh);
945 EXPECT_TRUE(contents->original_rvh() == NULL); 945 EXPECT_TRUE(contents->original_rvh() == NULL);
946 EXPECT_TRUE(contents->interstitial_rvh() == NULL); 946 EXPECT_TRUE(contents->interstitial_rvh() == NULL);
947 947
948 // DidNavigate from the new page 948 // DidNavigate from the new page
949 ViewHostMsg_FrameNavigate_Params params3; 949 ViewHostMsg_FrameNavigate_Params params3;
950 InitNavigateParams(&params3, 1, url3); 950 InitNavigateParams(&params3, 1, url3);
951 contents->TestDidNavigate(new_rvh, params3); 951 contents->TestDidNavigate(new_rvh, params3);
952 EXPECT_TRUE(contents->state_is_normal()); 952 EXPECT_TRUE(contents->state_is_normal());
953 EXPECT_EQ(new_rvh, contents->render_view_host()); 953 EXPECT_EQ(new_rvh, contents->render_view_host());
954 EXPECT_TRUE(contents->pending_rvh() == NULL); 954 EXPECT_TRUE(contents->pending_rvh() == NULL);
955 EXPECT_EQ(orig_rvh_delete_count, 1); 955 EXPECT_EQ(orig_rvh_delete_count, 1);
956 } 956 }
957 957
958 // Tests that we can transition away from an interstitial page even if both the 958 // Tests that we can transition away from an interstitial page even if both the
959 // original and interstitial renderers have crashed. 959 // original and interstitial renderers have crashed.
960 TEST_F(WebContentsTest, CrossSiteInterstitialCrashesThenNavigate) { 960 TEST_F(WebContentsTest, CrossSiteInterstitialCrashesThenNavigate) {
961 contents->transition_cross_site = true; 961 contents->transition_cross_site = true;
962 int orig_rvh_delete_count = 0; 962 int orig_rvh_delete_count = 0;
963 TestRenderViewHost* orig_rvh = contents->rvh(); 963 TestRenderViewHost* orig_rvh = contents->rvh();
964 orig_rvh->set_delete_counter(&orig_rvh_delete_count); 964 orig_rvh->set_delete_counter(&orig_rvh_delete_count);
965 965
966 // Navigate to URL. First URL should use first RenderViewHost. 966 // Navigate to URL. First URL should use first RenderViewHost.
967 const GURL url("http://www.google.com"); 967 const GURL url("http://www.google.com");
968 contents->controller()->LoadURL(url, PageTransition::TYPED); 968 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
969 ViewHostMsg_FrameNavigate_Params params1; 969 ViewHostMsg_FrameNavigate_Params params1;
970 InitNavigateParams(&params1, 1, url); 970 InitNavigateParams(&params1, 1, url);
971 contents->TestDidNavigate(orig_rvh, params1); 971 contents->TestDidNavigate(orig_rvh, params1);
972 972
973 // Navigate to new site 973 // Navigate to new site
974 const GURL url2("https://www.google.com"); 974 const GURL url2("https://www.google.com");
975 contents->controller()->LoadURL(url2, PageTransition::TYPED); 975 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
976 TestRenderViewHost* pending_rvh = contents->pending_rvh(); 976 TestRenderViewHost* pending_rvh = contents->pending_rvh();
977 int pending_rvh_delete_count = 0; 977 int pending_rvh_delete_count = 0;
978 pending_rvh->set_delete_counter(&pending_rvh_delete_count); 978 pending_rvh->set_delete_counter(&pending_rvh_delete_count);
979 979
980 // Show an interstitial 980 // Show an interstitial
981 const GURL interstitial_url("http://interstitial"); 981 const GURL interstitial_url("http://interstitial");
982 InterstitialPage* interstitial = new InterstitialPage(contents, 982 InterstitialPage* interstitial = new InterstitialPage(contents,
983 true, 983 true,
984 interstitial_url); 984 interstitial_url);
985 interstitial->Show(); 985 interstitial->Show();
(...skipping 10 matching lines...) Expand all
996 EXPECT_TRUE(contents->interstitial_rvh() == NULL); 996 EXPECT_TRUE(contents->interstitial_rvh() == NULL);
997 997
998 // Crash both the original and interstitial RVHs 998 // Crash both the original and interstitial RVHs
999 // (by making IsRenderViewLive() == false) 999 // (by making IsRenderViewLive() == false)
1000 orig_rvh->is_created = false; 1000 orig_rvh->is_created = false;
1001 interstitial_rvh->is_created = false; 1001 interstitial_rvh->is_created = false;
1002 1002
1003 // Navigate to a new page. Since both the interstitial and original RVHs are 1003 // Navigate to a new page. Since both the interstitial and original RVHs are
1004 // dead, we should create a new RVH, jump back to NORMAL, and navigate. 1004 // dead, we should create a new RVH, jump back to NORMAL, and navigate.
1005 const GURL url3("http://www.yahoo.com"); 1005 const GURL url3("http://www.yahoo.com");
1006 contents->controller()->LoadURL(url3, PageTransition::TYPED); 1006 contents->controller()->LoadURL(url3, GURL(), PageTransition::TYPED);
1007 TestRenderViewHost* new_rvh = contents->rvh(); 1007 TestRenderViewHost* new_rvh = contents->rvh();
1008 ASSERT_TRUE(new_rvh != NULL); 1008 ASSERT_TRUE(new_rvh != NULL);
1009 EXPECT_TRUE(contents->state_is_normal()); 1009 EXPECT_TRUE(contents->state_is_normal());
1010 EXPECT_EQ(orig_rvh_delete_count, 1); 1010 EXPECT_EQ(orig_rvh_delete_count, 1);
1011 EXPECT_EQ(pending_rvh_delete_count, 1); 1011 EXPECT_EQ(pending_rvh_delete_count, 1);
1012 EXPECT_NE(interstitial_rvh, new_rvh); 1012 EXPECT_NE(interstitial_rvh, new_rvh);
1013 EXPECT_TRUE(contents->pending_rvh() == NULL); 1013 EXPECT_TRUE(contents->pending_rvh() == NULL);
1014 EXPECT_TRUE(contents->original_rvh() == NULL); 1014 EXPECT_TRUE(contents->original_rvh() == NULL);
1015 EXPECT_TRUE(contents->interstitial_rvh() == NULL); 1015 EXPECT_TRUE(contents->interstitial_rvh() == NULL);
1016 1016
1017 // DidNavigate from the new page 1017 // DidNavigate from the new page
1018 ViewHostMsg_FrameNavigate_Params params3; 1018 ViewHostMsg_FrameNavigate_Params params3;
1019 InitNavigateParams(&params3, 1, url3); 1019 InitNavigateParams(&params3, 1, url3);
1020 contents->TestDidNavigate(new_rvh, params3); 1020 contents->TestDidNavigate(new_rvh, params3);
1021 EXPECT_TRUE(contents->state_is_normal()); 1021 EXPECT_TRUE(contents->state_is_normal());
1022 EXPECT_EQ(new_rvh, contents->render_view_host()); 1022 EXPECT_EQ(new_rvh, contents->render_view_host());
1023 } 1023 }
1024 1024
1025 // Test that opening a new tab in the same SiteInstance and then navigating 1025 // Test that opening a new tab in the same SiteInstance and then navigating
1026 // both tabs to a new site will place both tabs in a single SiteInstance. 1026 // both tabs to a new site will place both tabs in a single SiteInstance.
1027 TEST_F(WebContentsTest, NavigateTwoTabsCrossSite) { 1027 TEST_F(WebContentsTest, NavigateTwoTabsCrossSite) {
1028 contents->transition_cross_site = true; 1028 contents->transition_cross_site = true;
1029 TestRenderViewHost* orig_rvh = contents->rvh(); 1029 TestRenderViewHost* orig_rvh = contents->rvh();
1030 SiteInstance* instance1 = contents->GetSiteInstance(); 1030 SiteInstance* instance1 = contents->GetSiteInstance();
1031 1031
1032 // Navigate to URL. First URL should use first RenderViewHost. 1032 // Navigate to URL. First URL should use first RenderViewHost.
1033 const GURL url("http://www.google.com"); 1033 const GURL url("http://www.google.com");
1034 contents->controller()->LoadURL(url, PageTransition::TYPED); 1034 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
1035 ViewHostMsg_FrameNavigate_Params params1; 1035 ViewHostMsg_FrameNavigate_Params params1;
1036 InitNavigateParams(&params1, 1, url); 1036 InitNavigateParams(&params1, 1, url);
1037 contents->TestDidNavigate(orig_rvh, params1); 1037 contents->TestDidNavigate(orig_rvh, params1);
1038 1038
1039 // Open a new tab with the same SiteInstance, navigated to the same site. 1039 // Open a new tab with the same SiteInstance, navigated to the same site.
1040 TestWebContents* contents2 = new TestWebContents(profile.get(), instance1); 1040 TestWebContents* contents2 = new TestWebContents(profile.get(), instance1);
1041 params1.page_id = 2; // Need this since the site instance is the same (which 1041 params1.page_id = 2; // Need this since the site instance is the same (which
1042 // is the scope of page IDs) and we want to consider 1042 // is the scope of page IDs) and we want to consider
1043 // this a new page. 1043 // this a new page.
1044 contents2->transition_cross_site = true; 1044 contents2->transition_cross_site = true;
1045 contents2->SetupController(profile.get()); 1045 contents2->SetupController(profile.get());
1046 contents2->controller()->LoadURL(url, PageTransition::TYPED); 1046 contents2->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
1047 contents2->TestDidNavigate(contents2->rvh(), params1); 1047 contents2->TestDidNavigate(contents2->rvh(), params1);
1048 1048
1049 // Navigate first tab to a new site 1049 // Navigate first tab to a new site
1050 const GURL url2a("http://www.yahoo.com"); 1050 const GURL url2a("http://www.yahoo.com");
1051 contents->controller()->LoadURL(url2a, PageTransition::TYPED); 1051 contents->controller()->LoadURL(url2a, GURL(), PageTransition::TYPED);
1052 TestRenderViewHost* pending_rvh_a = contents->pending_rvh(); 1052 TestRenderViewHost* pending_rvh_a = contents->pending_rvh();
1053 ViewHostMsg_FrameNavigate_Params params2a; 1053 ViewHostMsg_FrameNavigate_Params params2a;
1054 InitNavigateParams(&params2a, 1, url2a); 1054 InitNavigateParams(&params2a, 1, url2a);
1055 contents->TestDidNavigate(pending_rvh_a, params2a); 1055 contents->TestDidNavigate(pending_rvh_a, params2a);
1056 SiteInstance* instance2a = contents->GetSiteInstance(); 1056 SiteInstance* instance2a = contents->GetSiteInstance();
1057 EXPECT_NE(instance1, instance2a); 1057 EXPECT_NE(instance1, instance2a);
1058 1058
1059 // Navigate second tab to the same site as the first tab 1059 // Navigate second tab to the same site as the first tab
1060 const GURL url2b("http://mail.yahoo.com"); 1060 const GURL url2b("http://mail.yahoo.com");
1061 contents2->controller()->LoadURL(url2b, PageTransition::TYPED); 1061 contents2->controller()->LoadURL(url2b, GURL(), PageTransition::TYPED);
1062 TestRenderViewHost* pending_rvh_b = contents2->pending_rvh(); 1062 TestRenderViewHost* pending_rvh_b = contents2->pending_rvh();
1063 EXPECT_TRUE(pending_rvh_b != NULL); 1063 EXPECT_TRUE(pending_rvh_b != NULL);
1064 EXPECT_TRUE(contents2->state_is_pending()); 1064 EXPECT_TRUE(contents2->state_is_pending());
1065 1065
1066 // NOTE(creis): We used to be in danger of showing a sad tab page here if the 1066 // NOTE(creis): We used to be in danger of showing a sad tab page here if the
1067 // second tab hadn't navigated somewhere first (bug 1145430). That case is 1067 // second tab hadn't navigated somewhere first (bug 1145430). That case is
1068 // now covered by the CrossSiteBoundariesAfterCrash test. 1068 // now covered by the CrossSiteBoundariesAfterCrash test.
1069 1069
1070 ViewHostMsg_FrameNavigate_Params params2b; 1070 ViewHostMsg_FrameNavigate_Params params2b;
1071 InitNavigateParams(&params2b, 2, url2b); 1071 InitNavigateParams(&params2b, 2, url2b);
1072 contents2->TestDidNavigate(pending_rvh_b, params2b); 1072 contents2->TestDidNavigate(pending_rvh_b, params2b);
1073 SiteInstance* instance2b = contents2->GetSiteInstance(); 1073 SiteInstance* instance2b = contents2->GetSiteInstance();
1074 EXPECT_NE(instance1, instance2b); 1074 EXPECT_NE(instance1, instance2b);
1075 1075
1076 // Both tabs should now be in the same SiteInstance. 1076 // Both tabs should now be in the same SiteInstance.
1077 EXPECT_EQ(instance2a, instance2b); 1077 EXPECT_EQ(instance2a, instance2b);
1078 1078
1079 contents2->CloseContents(); 1079 contents2->CloseContents();
1080 } 1080 }
1081 1081
1082 // Tests that WebContents uses the current URL, not the SiteInstance's site, to 1082 // Tests that WebContents uses the current URL, not the SiteInstance's site, to
1083 // determine whether a navigation is cross-site. 1083 // determine whether a navigation is cross-site.
1084 TEST_F(WebContentsTest, CrossSiteComparesAgainstCurrentPage) { 1084 TEST_F(WebContentsTest, CrossSiteComparesAgainstCurrentPage) {
1085 contents->transition_cross_site = true; 1085 contents->transition_cross_site = true;
1086 TestRenderViewHost* orig_rvh = contents->rvh(); 1086 TestRenderViewHost* orig_rvh = contents->rvh();
1087 SiteInstance* instance1 = contents->GetSiteInstance(); 1087 SiteInstance* instance1 = contents->GetSiteInstance();
1088 1088
1089 // Navigate to URL. 1089 // Navigate to URL.
1090 const GURL url("http://www.google.com"); 1090 const GURL url("http://www.google.com");
1091 contents->controller()->LoadURL(url, PageTransition::TYPED); 1091 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
1092 ViewHostMsg_FrameNavigate_Params params1; 1092 ViewHostMsg_FrameNavigate_Params params1;
1093 InitNavigateParams(&params1, 1, url); 1093 InitNavigateParams(&params1, 1, url);
1094 contents->TestDidNavigate(orig_rvh, params1); 1094 contents->TestDidNavigate(orig_rvh, params1);
1095 1095
1096 // Open a related tab to a second site. 1096 // Open a related tab to a second site.
1097 TestWebContents* contents2 = new TestWebContents(profile.get(), instance1); 1097 TestWebContents* contents2 = new TestWebContents(profile.get(), instance1);
1098 contents2->transition_cross_site = true; 1098 contents2->transition_cross_site = true;
1099 contents2->SetupController(profile.get()); 1099 contents2->SetupController(profile.get());
1100 const GURL url2("http://www.yahoo.com"); 1100 const GURL url2("http://www.yahoo.com");
1101 contents2->controller()->LoadURL(url2, PageTransition::TYPED); 1101 contents2->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
1102 // The first RVH in contents2 isn't live yet, so we shortcut the PENDING 1102 // The first RVH in contents2 isn't live yet, so we shortcut the PENDING
1103 // state and go straight to NORMAL. 1103 // state and go straight to NORMAL.
1104 TestRenderViewHost* rvh2 = contents2->rvh(); 1104 TestRenderViewHost* rvh2 = contents2->rvh();
1105 EXPECT_TRUE(contents2->state_is_normal()); 1105 EXPECT_TRUE(contents2->state_is_normal());
1106 ViewHostMsg_FrameNavigate_Params params2; 1106 ViewHostMsg_FrameNavigate_Params params2;
1107 InitNavigateParams(&params2, 2, url2); 1107 InitNavigateParams(&params2, 2, url2);
1108 contents2->TestDidNavigate(rvh2, params2); 1108 contents2->TestDidNavigate(rvh2, params2);
1109 SiteInstance* instance2 = contents2->GetSiteInstance(); 1109 SiteInstance* instance2 = contents2->GetSiteInstance();
1110 EXPECT_NE(instance1, instance2); 1110 EXPECT_NE(instance1, instance2);
1111 EXPECT_TRUE(contents2->state_is_normal()); 1111 EXPECT_TRUE(contents2->state_is_normal());
1112 1112
1113 // Simulate a link click in first tab to second site. Doesn't switch 1113 // Simulate a link click in first tab to second site. Doesn't switch
1114 // SiteInstances, because we don't intercept WebKit navigations. 1114 // SiteInstances, because we don't intercept WebKit navigations.
1115 ViewHostMsg_FrameNavigate_Params params3; 1115 ViewHostMsg_FrameNavigate_Params params3;
1116 InitNavigateParams(&params3, 2, url2); 1116 InitNavigateParams(&params3, 2, url2);
1117 contents->TestDidNavigate(orig_rvh, params3); 1117 contents->TestDidNavigate(orig_rvh, params3);
1118 SiteInstance* instance3 = contents->GetSiteInstance(); 1118 SiteInstance* instance3 = contents->GetSiteInstance();
1119 EXPECT_EQ(instance1, instance3); 1119 EXPECT_EQ(instance1, instance3);
1120 EXPECT_TRUE(contents->state_is_normal()); 1120 EXPECT_TRUE(contents->state_is_normal());
1121 1121
1122 // Navigate to the new site. Doesn't switch SiteInstancees, because we 1122 // Navigate to the new site. Doesn't switch SiteInstancees, because we
1123 // compare against the current URL, not the SiteInstance's site. 1123 // compare against the current URL, not the SiteInstance's site.
1124 const GURL url3("http://mail.yahoo.com"); 1124 const GURL url3("http://mail.yahoo.com");
1125 contents->controller()->LoadURL(url3, PageTransition::TYPED); 1125 contents->controller()->LoadURL(url3, GURL(), PageTransition::TYPED);
1126 EXPECT_TRUE(contents->state_is_normal()); 1126 EXPECT_TRUE(contents->state_is_normal());
1127 ViewHostMsg_FrameNavigate_Params params4; 1127 ViewHostMsg_FrameNavigate_Params params4;
1128 InitNavigateParams(&params4, 3, url3); 1128 InitNavigateParams(&params4, 3, url3);
1129 contents->TestDidNavigate(orig_rvh, params4); 1129 contents->TestDidNavigate(orig_rvh, params4);
1130 SiteInstance* instance4 = contents->GetSiteInstance(); 1130 SiteInstance* instance4 = contents->GetSiteInstance();
1131 EXPECT_EQ(instance1, instance4); 1131 EXPECT_EQ(instance1, instance4);
1132 1132
1133 contents2->CloseContents(); 1133 contents2->CloseContents();
1134 } 1134 }
1135 1135
1136 // Test that the onbeforeunload and onunload handlers run when navigating 1136 // Test that the onbeforeunload and onunload handlers run when navigating
1137 // across site boundaries. 1137 // across site boundaries.
1138 TEST_F(WebContentsTest, CrossSiteUnloadHandlers) { 1138 TEST_F(WebContentsTest, CrossSiteUnloadHandlers) {
1139 contents->transition_cross_site = true; 1139 contents->transition_cross_site = true;
1140 TestRenderViewHost* orig_rvh = contents->rvh(); 1140 TestRenderViewHost* orig_rvh = contents->rvh();
1141 SiteInstance* instance1 = contents->GetSiteInstance(); 1141 SiteInstance* instance1 = contents->GetSiteInstance();
1142 1142
1143 // Navigate to URL. First URL should use first RenderViewHost. 1143 // Navigate to URL. First URL should use first RenderViewHost.
1144 const GURL url("http://www.google.com"); 1144 const GURL url("http://www.google.com");
1145 contents->controller()->LoadURL(url, PageTransition::TYPED); 1145 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
1146 ViewHostMsg_FrameNavigate_Params params1; 1146 ViewHostMsg_FrameNavigate_Params params1;
1147 InitNavigateParams(&params1, 1, url); 1147 InitNavigateParams(&params1, 1, url);
1148 contents->TestDidNavigate(orig_rvh, params1); 1148 contents->TestDidNavigate(orig_rvh, params1);
1149 EXPECT_TRUE(contents->state_is_normal()); 1149 EXPECT_TRUE(contents->state_is_normal());
1150 EXPECT_EQ(orig_rvh, contents->render_view_host()); 1150 EXPECT_EQ(orig_rvh, contents->render_view_host());
1151 1151
1152 // Navigate to new site, but simulate an onbeforeunload denial. 1152 // Navigate to new site, but simulate an onbeforeunload denial.
1153 const GURL url2("http://www.yahoo.com"); 1153 const GURL url2("http://www.yahoo.com");
1154 orig_rvh->immediate_before_unload = false; 1154 orig_rvh->immediate_before_unload = false;
1155 contents->controller()->LoadURL(url2, PageTransition::TYPED); 1155 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
1156 orig_rvh->TestOnMsgShouldClose(false); 1156 orig_rvh->TestOnMsgShouldClose(false);
1157 EXPECT_TRUE(contents->state_is_normal()); 1157 EXPECT_TRUE(contents->state_is_normal());
1158 EXPECT_EQ(orig_rvh, contents->render_view_host()); 1158 EXPECT_EQ(orig_rvh, contents->render_view_host());
1159 1159
1160 // Navigate again, but simulate an onbeforeunload approval. 1160 // Navigate again, but simulate an onbeforeunload approval.
1161 contents->controller()->LoadURL(url2, PageTransition::TYPED); 1161 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
1162 orig_rvh->TestOnMsgShouldClose(true); 1162 orig_rvh->TestOnMsgShouldClose(true);
1163 EXPECT_TRUE(contents->state_is_pending()); 1163 EXPECT_TRUE(contents->state_is_pending());
1164 TestRenderViewHost* pending_rvh = contents->pending_rvh(); 1164 TestRenderViewHost* pending_rvh = contents->pending_rvh();
1165 1165
1166 // We won't hear DidNavigate until the onunload handler has finished running. 1166 // We won't hear DidNavigate until the onunload handler has finished running.
1167 // (No way to simulate that here, but it involves a call from RDH to 1167 // (No way to simulate that here, but it involves a call from RDH to
1168 // WebContents::OnCrossSiteResponse.) 1168 // WebContents::OnCrossSiteResponse.)
1169 1169
1170 // DidNavigate from the pending page 1170 // DidNavigate from the pending page
1171 ViewHostMsg_FrameNavigate_Params params2; 1171 ViewHostMsg_FrameNavigate_Params params2;
1172 InitNavigateParams(&params2, 1, url2); 1172 InitNavigateParams(&params2, 1, url2);
1173 contents->TestDidNavigate(pending_rvh, params2); 1173 contents->TestDidNavigate(pending_rvh, params2);
1174 SiteInstance* instance2 = contents->GetSiteInstance(); 1174 SiteInstance* instance2 = contents->GetSiteInstance();
1175 EXPECT_TRUE(contents->state_is_normal()); 1175 EXPECT_TRUE(contents->state_is_normal());
1176 EXPECT_EQ(pending_rvh, contents->render_view_host()); 1176 EXPECT_EQ(pending_rvh, contents->render_view_host());
1177 EXPECT_NE(instance1, instance2); 1177 EXPECT_NE(instance1, instance2);
1178 EXPECT_TRUE(contents->pending_rvh() == NULL); 1178 EXPECT_TRUE(contents->pending_rvh() == NULL);
1179 EXPECT_TRUE(contents->original_rvh() == NULL); 1179 EXPECT_TRUE(contents->original_rvh() == NULL);
1180 EXPECT_TRUE(contents->interstitial_rvh() == NULL); 1180 EXPECT_TRUE(contents->interstitial_rvh() == NULL);
1181 } 1181 }
1182 1182
1183 // Test that NavigationEntries have the correct content state after going 1183 // Test that NavigationEntries have the correct content state after going
1184 // forward and back. Prevents regression for bug 1116137. 1184 // forward and back. Prevents regression for bug 1116137.
1185 TEST_F(WebContentsTest, NavigationEntryContentState) { 1185 TEST_F(WebContentsTest, NavigationEntryContentState) {
1186 TestRenderViewHost* orig_rvh = contents->rvh(); 1186 TestRenderViewHost* orig_rvh = contents->rvh();
1187 1187
1188 // Navigate to URL. There should be no committed entry yet. 1188 // Navigate to URL. There should be no committed entry yet.
1189 const GURL url("http://www.google.com"); 1189 const GURL url("http://www.google.com");
1190 contents->controller()->LoadURL(url, PageTransition::TYPED); 1190 contents->controller()->LoadURL(url, GURL(), PageTransition::TYPED);
1191 NavigationEntry* entry = contents->controller()->GetLastCommittedEntry(); 1191 NavigationEntry* entry = contents->controller()->GetLastCommittedEntry();
1192 EXPECT_TRUE(entry == NULL); 1192 EXPECT_TRUE(entry == NULL);
1193 1193
1194 // Committed entry should have content state after DidNavigate. 1194 // Committed entry should have content state after DidNavigate.
1195 ViewHostMsg_FrameNavigate_Params params1; 1195 ViewHostMsg_FrameNavigate_Params params1;
1196 InitNavigateParams(&params1, 1, url); 1196 InitNavigateParams(&params1, 1, url);
1197 contents->TestDidNavigate(orig_rvh, params1); 1197 contents->TestDidNavigate(orig_rvh, params1);
1198 entry = contents->controller()->GetLastCommittedEntry(); 1198 entry = contents->controller()->GetLastCommittedEntry();
1199 EXPECT_FALSE(entry->content_state().empty()); 1199 EXPECT_FALSE(entry->content_state().empty());
1200 1200
1201 // Navigate to same site. 1201 // Navigate to same site.
1202 const GURL url2("http://images.google.com"); 1202 const GURL url2("http://images.google.com");
1203 contents->controller()->LoadURL(url2, PageTransition::TYPED); 1203 contents->controller()->LoadURL(url2, GURL(), PageTransition::TYPED);
1204 entry = contents->controller()->GetLastCommittedEntry(); 1204 entry = contents->controller()->GetLastCommittedEntry();
1205 EXPECT_FALSE(entry->content_state().empty()); 1205 EXPECT_FALSE(entry->content_state().empty());
1206 1206
1207 // Committed entry should have content state after DidNavigate. 1207 // Committed entry should have content state after DidNavigate.
1208 ViewHostMsg_FrameNavigate_Params params2; 1208 ViewHostMsg_FrameNavigate_Params params2;
1209 InitNavigateParams(&params2, 2, url2); 1209 InitNavigateParams(&params2, 2, url2);
1210 contents->TestDidNavigate(orig_rvh, params2); 1210 contents->TestDidNavigate(orig_rvh, params2);
1211 entry = contents->controller()->GetLastCommittedEntry(); 1211 entry = contents->controller()->GetLastCommittedEntry();
1212 EXPECT_FALSE(entry->content_state().empty()); 1212 EXPECT_FALSE(entry->content_state().empty());
1213 1213
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 EXPECT_EQ(L"UTF-8", webkit_prefs.default_encoding); 1245 EXPECT_EQ(L"UTF-8", webkit_prefs.default_encoding);
1246 EXPECT_EQ(20, webkit_prefs.default_font_size); 1246 EXPECT_EQ(20, webkit_prefs.default_font_size);
1247 EXPECT_EQ(false, webkit_prefs.text_areas_are_resizable); 1247 EXPECT_EQ(false, webkit_prefs.text_areas_are_resizable);
1248 EXPECT_EQ(true, webkit_prefs.uses_universal_detector); 1248 EXPECT_EQ(true, webkit_prefs.uses_universal_detector);
1249 1249
1250 // These should still be the default values. 1250 // These should still be the default values.
1251 EXPECT_EQ(L"Times New Roman", webkit_prefs.standard_font_family); 1251 EXPECT_EQ(L"Times New Roman", webkit_prefs.standard_font_family);
1252 EXPECT_EQ(true, webkit_prefs.javascript_enabled); 1252 EXPECT_EQ(true, webkit_prefs.javascript_enabled);
1253 } 1253 }
1254 1254
OLDNEW
« no previous file with comments | « chrome/browser/web_contents.cc ('k') | chrome/browser/web_drop_target.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698