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

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 1002803002: Classify navigations without page id in parallel to the existing classifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: greeeeeeen Created 5 years, 8 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
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/frame_host/cross_site_transferring_request.h" 8 #include "content/browser/frame_host/cross_site_transferring_request.h"
9 #include "content/browser/frame_host/interstitial_page_impl.h" 9 #include "content/browser/frame_host/interstitial_page_impl.h"
10 #include "content/browser/frame_host/navigation_entry_impl.h" 10 #include "content/browser/frame_host/navigation_entry_impl.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 int command_received_count() const { 153 int command_received_count() const {
154 return command_received_count_; 154 return command_received_count_;
155 } 155 }
156 156
157 void TestDomOperationResponse(const std::string& json_string) { 157 void TestDomOperationResponse(const std::string& json_string) {
158 if (enabled()) 158 if (enabled())
159 CommandReceived(); 159 CommandReceived();
160 } 160 }
161 161
162 void TestDidNavigate(int page_id, const GURL& url) { 162 void TestDidNavigate(int page_id,
163 int nav_entry_id,
164 bool did_create_new_entry,
165 const GURL& url) {
163 FrameHostMsg_DidCommitProvisionalLoad_Params params; 166 FrameHostMsg_DidCommitProvisionalLoad_Params params;
164 InitNavigateParams(&params, page_id, url, ui::PAGE_TRANSITION_TYPED); 167 InitNavigateParams(&params, page_id, nav_entry_id, did_create_new_entry,
168 url, ui::PAGE_TRANSITION_TYPED);
165 DidNavigate(GetMainFrame()->GetRenderViewHost(), params); 169 DidNavigate(GetMainFrame()->GetRenderViewHost(), params);
166 } 170 }
167 171
168 void TestRenderViewTerminated(base::TerminationStatus status, 172 void TestRenderViewTerminated(base::TerminationStatus status,
169 int error_code) { 173 int error_code) {
170 RenderViewTerminated(GetMainFrame()->GetRenderViewHost(), status, 174 RenderViewTerminated(GetMainFrame()->GetRenderViewHost(), status,
171 error_code); 175 error_code);
172 } 176 }
173 177
174 bool is_showing() const { 178 bool is_showing() const {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 DISALLOW_COPY_AND_ASSIGN(FakeValidationMessageDelegate); 347 DISALLOW_COPY_AND_ASSIGN(FakeValidationMessageDelegate);
344 }; 348 };
345 349
346 } // namespace 350 } // namespace
347 351
348 // Test to make sure that title updates get stripped of whitespace. 352 // Test to make sure that title updates get stripped of whitespace.
349 TEST_F(WebContentsImplTest, UpdateTitle) { 353 TEST_F(WebContentsImplTest, UpdateTitle) {
350 NavigationControllerImpl& cont = 354 NavigationControllerImpl& cont =
351 static_cast<NavigationControllerImpl&>(controller()); 355 static_cast<NavigationControllerImpl&>(controller());
352 FrameHostMsg_DidCommitProvisionalLoad_Params params; 356 FrameHostMsg_DidCommitProvisionalLoad_Params params;
353 InitNavigateParams( 357 InitNavigateParams(&params, 0, 0, true, GURL(url::kAboutBlankURL),
354 &params, 0, GURL(url::kAboutBlankURL), ui::PAGE_TRANSITION_TYPED); 358 ui::PAGE_TRANSITION_TYPED);
355 359
356 LoadCommittedDetails details; 360 LoadCommittedDetails details;
357 cont.RendererDidNavigate(contents()->GetMainFrame(), params, &details); 361 cont.RendererDidNavigate(contents()->GetMainFrame(), params, &details);
358 362
359 contents()->UpdateTitle(contents()->GetMainFrame(), 0, 363 contents()->UpdateTitle(contents()->GetMainFrame(), 0,
360 base::ASCIIToUTF16(" Lots O' Whitespace\n"), 364 base::ASCIIToUTF16(" Lots O' Whitespace\n"),
361 base::i18n::LEFT_TO_RIGHT); 365 base::i18n::LEFT_TO_RIGHT);
362 EXPECT_EQ(base::ASCIIToUTF16("Lots O' Whitespace"), contents()->GetTitle()); 366 EXPECT_EQ(base::ASCIIToUTF16("Lots O' Whitespace"), contents()->GetTitle());
363 } 367 }
364 368
(...skipping 21 matching lines...) Expand all
386 TEST_F(WebContentsImplTest, NTPViewSource) { 390 TEST_F(WebContentsImplTest, NTPViewSource) {
387 NavigationControllerImpl& cont = 391 NavigationControllerImpl& cont =
388 static_cast<NavigationControllerImpl&>(controller()); 392 static_cast<NavigationControllerImpl&>(controller());
389 const char kUrl[] = "view-source:chrome://blah"; 393 const char kUrl[] = "view-source:chrome://blah";
390 const GURL kGURL(kUrl); 394 const GURL kGURL(kUrl);
391 395
392 process()->sink().ClearMessages(); 396 process()->sink().ClearMessages();
393 397
394 cont.LoadURL( 398 cont.LoadURL(
395 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 399 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
400 int entry_id = cont.GetPendingEntry()->GetUniqueID();
396 rvh()->GetDelegate()->RenderViewCreated(rvh()); 401 rvh()->GetDelegate()->RenderViewCreated(rvh());
397 // Did we get the expected message? 402 // Did we get the expected message?
398 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( 403 EXPECT_TRUE(process()->sink().GetFirstMessageMatching(
399 ViewMsg_EnableViewSourceMode::ID)); 404 ViewMsg_EnableViewSourceMode::ID));
400 405
401 FrameHostMsg_DidCommitProvisionalLoad_Params params; 406 FrameHostMsg_DidCommitProvisionalLoad_Params params;
402 InitNavigateParams(&params, 0, kGURL, ui::PAGE_TRANSITION_TYPED); 407 InitNavigateParams(&params, 0, entry_id, true, kGURL,
408 ui::PAGE_TRANSITION_TYPED);
403 LoadCommittedDetails details; 409 LoadCommittedDetails details;
404 cont.RendererDidNavigate(contents()->GetMainFrame(), params, &details); 410 cont.RendererDidNavigate(contents()->GetMainFrame(), params, &details);
405 // Also check title and url. 411 // Also check title and url.
406 EXPECT_EQ(base::ASCIIToUTF16(kUrl), contents()->GetTitle()); 412 EXPECT_EQ(base::ASCIIToUTF16(kUrl), contents()->GetTitle());
407 } 413 }
408 414
409 // Test to ensure UpdateMaxPageID is working properly. 415 // Test to ensure UpdateMaxPageID is working properly.
410 TEST_F(WebContentsImplTest, UpdateMaxPageID) { 416 TEST_F(WebContentsImplTest, UpdateMaxPageID) {
411 SiteInstance* instance1 = contents()->GetSiteInstance(); 417 SiteInstance* instance1 = contents()->GetSiteInstance();
412 scoped_refptr<SiteInstance> instance2(SiteInstance::Create(nullptr)); 418 scoped_refptr<SiteInstance> instance2(SiteInstance::Create(nullptr));
(...skipping 19 matching lines...) Expand all
432 // Test simple same-SiteInstance navigation. 438 // Test simple same-SiteInstance navigation.
433 TEST_F(WebContentsImplTest, SimpleNavigation) { 439 TEST_F(WebContentsImplTest, SimpleNavigation) {
434 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 440 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
435 SiteInstance* instance1 = contents()->GetSiteInstance(); 441 SiteInstance* instance1 = contents()->GetSiteInstance();
436 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame()); 442 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame());
437 443
438 // Navigate to URL 444 // Navigate to URL
439 const GURL url("http://www.google.com"); 445 const GURL url("http://www.google.com");
440 controller().LoadURL( 446 controller().LoadURL(
441 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 447 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
448 int entry_id = controller().GetPendingEntry()->GetUniqueID();
442 EXPECT_FALSE(contents()->cross_navigation_pending()); 449 EXPECT_FALSE(contents()->cross_navigation_pending());
443 EXPECT_EQ(instance1, orig_rfh->GetSiteInstance()); 450 EXPECT_EQ(instance1, orig_rfh->GetSiteInstance());
444 // Controller's pending entry will have a null site instance until we assign 451 // Controller's pending entry will have a null site instance until we assign
445 // it in DidNavigate. 452 // it in DidNavigate.
446 EXPECT_EQ( 453 EXPECT_EQ(
447 nullptr, 454 nullptr,
448 NavigationEntryImpl::FromNavigationEntry(controller().GetVisibleEntry())-> 455 NavigationEntryImpl::FromNavigationEntry(controller().GetVisibleEntry())->
449 site_instance()); 456 site_instance());
450 457
451 // DidNavigate from the page 458 // DidNavigate from the page
452 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 459 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url,
460 ui::PAGE_TRANSITION_TYPED);
453 EXPECT_FALSE(contents()->cross_navigation_pending()); 461 EXPECT_FALSE(contents()->cross_navigation_pending());
454 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 462 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
455 EXPECT_EQ(instance1, orig_rfh->GetSiteInstance()); 463 EXPECT_EQ(instance1, orig_rfh->GetSiteInstance());
456 // Controller's entry should now have the SiteInstance, or else we won't be 464 // Controller's entry should now have the SiteInstance, or else we won't be
457 // able to find it later. 465 // able to find it later.
458 EXPECT_EQ( 466 EXPECT_EQ(
459 instance1, 467 instance1,
460 NavigationEntryImpl::FromNavigationEntry(controller().GetVisibleEntry())-> 468 NavigationEntryImpl::FromNavigationEntry(controller().GetVisibleEntry())->
461 site_instance()); 469 site_instance());
462 } 470 }
(...skipping 14 matching lines...) Expand all
477 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { 485 TEST_F(WebContentsImplTest, CrossSiteBoundaries) {
478 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 486 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
479 int orig_rvh_delete_count = 0; 487 int orig_rvh_delete_count = 0;
480 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 488 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
481 SiteInstance* instance1 = contents()->GetSiteInstance(); 489 SiteInstance* instance1 = contents()->GetSiteInstance();
482 490
483 // Navigate to URL. First URL should use first RenderViewHost. 491 // Navigate to URL. First URL should use first RenderViewHost.
484 const GURL url("http://www.google.com"); 492 const GURL url("http://www.google.com");
485 controller().LoadURL( 493 controller().LoadURL(
486 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 494 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
495 int entry_id = controller().GetPendingEntry()->GetUniqueID();
487 orig_rfh->PrepareForCommit(); 496 orig_rfh->PrepareForCommit();
488 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 497 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url,
498 ui::PAGE_TRANSITION_TYPED);
489 499
490 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so 500 // Keep the number of active frames in orig_rfh's SiteInstance non-zero so
491 // that orig_rfh doesn't get deleted when it gets swapped out. 501 // that orig_rfh doesn't get deleted when it gets swapped out.
492 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 502 orig_rfh->GetSiteInstance()->increment_active_frame_count();
493 503
494 EXPECT_FALSE(contents()->cross_navigation_pending()); 504 EXPECT_FALSE(contents()->cross_navigation_pending());
495 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); 505 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost());
496 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 506 EXPECT_EQ(url, contents()->GetLastCommittedURL());
497 EXPECT_EQ(url, contents()->GetVisibleURL()); 507 EXPECT_EQ(url, contents()->GetVisibleURL());
498 508
499 // Navigate to new site 509 // Navigate to new site
500 const GURL url2("http://www.yahoo.com"); 510 const GURL url2("http://www.yahoo.com");
501 controller().LoadURL( 511 controller().LoadURL(
502 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 512 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
513 entry_id = controller().GetPendingEntry()->GetUniqueID();
503 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 514 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
504 switches::kEnableBrowserSideNavigation)) { 515 switches::kEnableBrowserSideNavigation)) {
505 orig_rfh->PrepareForCommit(); 516 orig_rfh->PrepareForCommit();
506 } 517 }
507 EXPECT_TRUE(contents()->cross_navigation_pending()); 518 EXPECT_TRUE(contents()->cross_navigation_pending());
508 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 519 EXPECT_EQ(url, contents()->GetLastCommittedURL());
509 EXPECT_EQ(url2, contents()->GetVisibleURL()); 520 EXPECT_EQ(url2, contents()->GetVisibleURL());
510 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 521 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
511 int pending_rvh_delete_count = 0; 522 int pending_rvh_delete_count = 0;
512 pending_rfh->GetRenderViewHost()->set_delete_counter( 523 pending_rfh->GetRenderViewHost()->set_delete_counter(
513 &pending_rvh_delete_count); 524 &pending_rvh_delete_count);
514 525
515 // Navigations should be suspended in pending_rfh until BeforeUnloadACK. 526 // Navigations should be suspended in pending_rfh until BeforeUnloadACK.
516 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 527 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
517 switches::kEnableBrowserSideNavigation)) { 528 switches::kEnableBrowserSideNavigation)) {
518 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); 529 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
519 orig_rfh->SendBeforeUnloadACK(true); 530 orig_rfh->SendBeforeUnloadACK(true);
520 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); 531 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
521 } 532 }
522 533
523 // DidNavigate from the pending page 534 // DidNavigate from the pending page
524 contents()->TestDidNavigate( 535 contents()->TestDidNavigate(pending_rfh, 1, entry_id, true, url2,
525 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 536 ui::PAGE_TRANSITION_TYPED);
526 SiteInstance* instance2 = contents()->GetSiteInstance(); 537 SiteInstance* instance2 = contents()->GetSiteInstance();
527 538
528 // Keep the number of active frames in pending_rfh's SiteInstance 539 // Keep the number of active frames in pending_rfh's SiteInstance
529 // non-zero so that orig_rfh doesn't get deleted when it gets 540 // non-zero so that orig_rfh doesn't get deleted when it gets
530 // swapped out. 541 // swapped out.
531 pending_rfh->GetSiteInstance()->increment_active_frame_count(); 542 pending_rfh->GetSiteInstance()->increment_active_frame_count();
532 543
533 EXPECT_FALSE(contents()->cross_navigation_pending()); 544 EXPECT_FALSE(contents()->cross_navigation_pending());
534 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 545 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
535 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 546 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
536 EXPECT_EQ(url2, contents()->GetVisibleURL()); 547 EXPECT_EQ(url2, contents()->GetVisibleURL());
537 EXPECT_NE(instance1, instance2); 548 EXPECT_NE(instance1, instance2);
538 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame()); 549 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame());
539 // We keep the original RFH around, swapped out. 550 // We keep the original RFH around, swapped out.
540 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( 551 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList(
541 orig_rfh)); 552 orig_rfh));
542 EXPECT_EQ(orig_rvh_delete_count, 0); 553 EXPECT_EQ(orig_rvh_delete_count, 0);
543 554
544 // Going back should switch SiteInstances again. The first SiteInstance is 555 // Going back should switch SiteInstances again. The first SiteInstance is
545 // stored in the NavigationEntry, so it should be the same as at the start. 556 // stored in the NavigationEntry, so it should be the same as at the start.
546 // We should use the same RFH as before, swapping it back in. 557 // We should use the same RFH as before, swapping it back in.
547 controller().GoBack(); 558 controller().GoBack();
559 entry_id = controller().GetPendingEntry()->GetUniqueID();
548 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 560 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
549 switches::kEnableBrowserSideNavigation)) { 561 switches::kEnableBrowserSideNavigation)) {
550 contents()->GetMainFrame()->PrepareForCommit(); 562 contents()->GetMainFrame()->PrepareForCommit();
551 } 563 }
552 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame(); 564 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame();
553 EXPECT_EQ(orig_rfh, goback_rfh); 565 EXPECT_EQ(orig_rfh, goback_rfh);
554 EXPECT_TRUE(contents()->cross_navigation_pending()); 566 EXPECT_TRUE(contents()->cross_navigation_pending());
555 567
556 // Navigations should be suspended in goback_rfh until BeforeUnloadACK. 568 // Navigations should be suspended in goback_rfh until BeforeUnloadACK.
557 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 569 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
558 switches::kEnableBrowserSideNavigation)) { 570 switches::kEnableBrowserSideNavigation)) {
559 EXPECT_TRUE(goback_rfh->are_navigations_suspended()); 571 EXPECT_TRUE(goback_rfh->are_navigations_suspended());
560 pending_rfh->SendBeforeUnloadACK(true); 572 pending_rfh->SendBeforeUnloadACK(true);
561 EXPECT_FALSE(goback_rfh->are_navigations_suspended()); 573 EXPECT_FALSE(goback_rfh->are_navigations_suspended());
562 } 574 }
563 575
564 // DidNavigate from the back action 576 // DidNavigate from the back action
565 contents()->TestDidNavigate(goback_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 577 contents()->TestDidNavigate(goback_rfh, 1, entry_id, false, url2,
578 ui::PAGE_TRANSITION_TYPED);
566 EXPECT_FALSE(contents()->cross_navigation_pending()); 579 EXPECT_FALSE(contents()->cross_navigation_pending());
567 EXPECT_EQ(goback_rfh, contents()->GetMainFrame()); 580 EXPECT_EQ(goback_rfh, contents()->GetMainFrame());
568 EXPECT_EQ(instance1, contents()->GetSiteInstance()); 581 EXPECT_EQ(instance1, contents()->GetSiteInstance());
569 // The pending RFH should now be swapped out, not deleted. 582 // The pending RFH should now be swapped out, not deleted.
570 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> 583 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->
571 IsOnSwappedOutList(pending_rfh)); 584 IsOnSwappedOutList(pending_rfh));
572 EXPECT_EQ(pending_rvh_delete_count, 0); 585 EXPECT_EQ(pending_rvh_delete_count, 0);
573 pending_rfh->OnSwappedOut(); 586 pending_rfh->OnSwappedOut();
574 587
575 // Close contents and ensure RVHs are deleted. 588 // Close contents and ensure RVHs are deleted.
576 DeleteContents(); 589 DeleteContents();
577 EXPECT_EQ(orig_rvh_delete_count, 1); 590 EXPECT_EQ(orig_rvh_delete_count, 1);
578 EXPECT_EQ(pending_rvh_delete_count, 1); 591 EXPECT_EQ(pending_rvh_delete_count, 1);
579 } 592 }
580 593
581 // Test that navigating across a site boundary after a crash creates a new 594 // Test that navigating across a site boundary after a crash creates a new
582 // RFH without requiring a cross-site transition (i.e., PENDING state). 595 // RFH without requiring a cross-site transition (i.e., PENDING state).
583 TEST_F(WebContentsImplTest, CrossSiteBoundariesAfterCrash) { 596 TEST_F(WebContentsImplTest, CrossSiteBoundariesAfterCrash) {
584 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 597 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
585 598
586 int orig_rvh_delete_count = 0; 599 int orig_rvh_delete_count = 0;
587 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 600 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
588 SiteInstance* instance1 = contents()->GetSiteInstance(); 601 SiteInstance* instance1 = contents()->GetSiteInstance();
589 602
590 // Navigate to URL. First URL should use first RenderViewHost. 603 // Navigate to URL. First URL should use first RenderViewHost.
591 const GURL url("http://www.google.com"); 604 const GURL url("http://www.google.com");
592 controller().LoadURL( 605 controller().LoadURL(
593 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 606 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
607 int entry_id = controller().GetPendingEntry()->GetUniqueID();
594 contents()->GetMainFrame()->PrepareForCommit(); 608 contents()->GetMainFrame()->PrepareForCommit();
595 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 609 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url,
610 ui::PAGE_TRANSITION_TYPED);
596 611
597 EXPECT_FALSE(contents()->cross_navigation_pending()); 612 EXPECT_FALSE(contents()->cross_navigation_pending());
598 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); 613 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost());
599 614
600 // Simulate a renderer crash. 615 // Simulate a renderer crash.
601 orig_rfh->GetRenderViewHost()->set_render_view_created(false); 616 orig_rfh->GetRenderViewHost()->set_render_view_created(false);
602 orig_rfh->SetRenderFrameCreated(false); 617 orig_rfh->SetRenderFrameCreated(false);
603 618
604 // Navigate to new site. We should not go into PENDING. 619 // Navigate to new site. We should not go into PENDING.
605 const GURL url2("http://www.yahoo.com"); 620 const GURL url2("http://www.yahoo.com");
606 controller().LoadURL( 621 controller().LoadURL(
607 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 622 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
623 entry_id = controller().GetPendingEntry()->GetUniqueID();
608 contents()->GetMainFrame()->PrepareForCommit(); 624 contents()->GetMainFrame()->PrepareForCommit();
609 TestRenderFrameHost* new_rfh = contents()->GetMainFrame(); 625 TestRenderFrameHost* new_rfh = contents()->GetMainFrame();
610 EXPECT_FALSE(contents()->cross_navigation_pending()); 626 EXPECT_FALSE(contents()->cross_navigation_pending());
611 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame()); 627 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame());
612 EXPECT_NE(orig_rfh, new_rfh); 628 EXPECT_NE(orig_rfh, new_rfh);
613 EXPECT_EQ(orig_rvh_delete_count, 1); 629 EXPECT_EQ(orig_rvh_delete_count, 1);
614 630
615 // DidNavigate from the new page 631 // DidNavigate from the new page
616 contents()->TestDidNavigate(new_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 632 contents()->TestDidNavigate(new_rfh, 1, entry_id, true, url2,
633 ui::PAGE_TRANSITION_TYPED);
617 SiteInstance* instance2 = contents()->GetSiteInstance(); 634 SiteInstance* instance2 = contents()->GetSiteInstance();
618 635
619 EXPECT_FALSE(contents()->cross_navigation_pending()); 636 EXPECT_FALSE(contents()->cross_navigation_pending());
620 EXPECT_EQ(new_rfh, main_rfh()); 637 EXPECT_EQ(new_rfh, main_rfh());
621 EXPECT_NE(instance1, instance2); 638 EXPECT_NE(instance1, instance2);
622 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame()); 639 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame());
623 640
624 // Close contents and ensure RVHs are deleted. 641 // Close contents and ensure RVHs are deleted.
625 DeleteContents(); 642 DeleteContents();
626 EXPECT_EQ(orig_rvh_delete_count, 1); 643 EXPECT_EQ(orig_rvh_delete_count, 1);
627 } 644 }
628 645
629 // Test that opening a new contents in the same SiteInstance and then navigating 646 // Test that opening a new contents in the same SiteInstance and then navigating
630 // both contentses to a new site will place both contentses in a single 647 // both contentses to a new site will place both contentses in a single
631 // SiteInstance. 648 // SiteInstance.
632 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) { 649 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) {
633 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 650 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
634 SiteInstance* instance1 = contents()->GetSiteInstance(); 651 SiteInstance* instance1 = contents()->GetSiteInstance();
635 652
636 // Navigate to URL. First URL should use first RenderViewHost. 653 // Navigate to URL. First URL should use first RenderViewHost.
637 const GURL url("http://www.google.com"); 654 const GURL url("http://www.google.com");
638 controller().LoadURL( 655 controller().LoadURL(
639 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 656 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
657 int entry_id = controller().GetPendingEntry()->GetUniqueID();
640 contents()->GetMainFrame()->PrepareForCommit(); 658 contents()->GetMainFrame()->PrepareForCommit();
641 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 659 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url,
660 ui::PAGE_TRANSITION_TYPED);
642 661
643 // Open a new contents with the same SiteInstance, navigated to the same site. 662 // Open a new contents with the same SiteInstance, navigated to the same site.
644 scoped_ptr<TestWebContents> contents2( 663 scoped_ptr<TestWebContents> contents2(
645 TestWebContents::Create(browser_context(), instance1)); 664 TestWebContents::Create(browser_context(), instance1));
646 contents2->GetController().LoadURL(url, Referrer(), 665 contents2->GetController().LoadURL(url, Referrer(),
647 ui::PAGE_TRANSITION_TYPED, 666 ui::PAGE_TRANSITION_TYPED,
648 std::string()); 667 std::string());
668 entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID();
649 contents2->GetMainFrame()->PrepareForCommit(); 669 contents2->GetMainFrame()->PrepareForCommit();
650 // Need this page id to be 2 since the site instance is the same (which is the 670 // Need this page id to be 2 since the site instance is the same (which is the
651 // scope of page IDs) and we want to consider this a new page. 671 // scope of page IDs) and we want to consider this a new page.
652 contents2->TestDidNavigate( 672 contents2->TestDidNavigate(contents2->GetMainFrame(), 2, entry_id, true, url,
653 contents2->GetMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED); 673 ui::PAGE_TRANSITION_TYPED);
654 674
655 // Navigate first contents to a new site. 675 // Navigate first contents to a new site.
656 const GURL url2a("http://www.yahoo.com"); 676 const GURL url2a("http://www.yahoo.com");
657 controller().LoadURL( 677 controller().LoadURL(
658 url2a, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 678 url2a, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
679 entry_id = controller().GetPendingEntry()->GetUniqueID();
659 orig_rfh->PrepareForCommit(); 680 orig_rfh->PrepareForCommit();
660 TestRenderFrameHost* pending_rfh_a = contents()->GetPendingMainFrame(); 681 TestRenderFrameHost* pending_rfh_a = contents()->GetPendingMainFrame();
661 contents()->TestDidNavigate( 682 contents()->TestDidNavigate(pending_rfh_a, 1, entry_id, true, url2a,
662 pending_rfh_a, 1, url2a, ui::PAGE_TRANSITION_TYPED); 683 ui::PAGE_TRANSITION_TYPED);
663 SiteInstance* instance2a = contents()->GetSiteInstance(); 684 SiteInstance* instance2a = contents()->GetSiteInstance();
664 EXPECT_NE(instance1, instance2a); 685 EXPECT_NE(instance1, instance2a);
665 686
666 // Navigate second contents to the same site as the first tab. 687 // Navigate second contents to the same site as the first tab.
667 const GURL url2b("http://mail.yahoo.com"); 688 const GURL url2b("http://mail.yahoo.com");
668 contents2->GetController().LoadURL(url2b, Referrer(), 689 contents2->GetController().LoadURL(url2b, Referrer(),
669 ui::PAGE_TRANSITION_TYPED, 690 ui::PAGE_TRANSITION_TYPED,
670 std::string()); 691 std::string());
692 entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID();
671 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); 693 TestRenderFrameHost* rfh2 = contents2->GetMainFrame();
672 rfh2->PrepareForCommit(); 694 rfh2->PrepareForCommit();
673 TestRenderFrameHost* pending_rfh_b = contents2->GetPendingMainFrame(); 695 TestRenderFrameHost* pending_rfh_b = contents2->GetPendingMainFrame();
674 EXPECT_NE(nullptr, pending_rfh_b); 696 EXPECT_NE(nullptr, pending_rfh_b);
675 EXPECT_TRUE(contents2->cross_navigation_pending()); 697 EXPECT_TRUE(contents2->cross_navigation_pending());
676 698
677 // NOTE(creis): We used to be in danger of showing a crash page here if the 699 // NOTE(creis): We used to be in danger of showing a crash page here if the
678 // second contents hadn't navigated somewhere first (bug 1145430). That case 700 // second contents hadn't navigated somewhere first (bug 1145430). That case
679 // is now covered by the CrossSiteBoundariesAfterCrash test. 701 // is now covered by the CrossSiteBoundariesAfterCrash test.
680 contents2->TestDidNavigate( 702 contents2->TestDidNavigate(pending_rfh_b, 2, entry_id, true, url2b,
681 pending_rfh_b, 2, url2b, ui::PAGE_TRANSITION_TYPED); 703 ui::PAGE_TRANSITION_TYPED);
682 SiteInstance* instance2b = contents2->GetSiteInstance(); 704 SiteInstance* instance2b = contents2->GetSiteInstance();
683 EXPECT_NE(instance1, instance2b); 705 EXPECT_NE(instance1, instance2b);
684 706
685 // Both contentses should now be in the same SiteInstance. 707 // Both contentses should now be in the same SiteInstance.
686 EXPECT_EQ(instance2a, instance2b); 708 EXPECT_EQ(instance2a, instance2b);
687 } 709 }
688 710
689 // The embedder can request sites for certain urls not be be assigned to the 711 // The embedder can request sites for certain urls not be be assigned to the
690 // SiteInstance through ShouldAssignSiteForURL() in content browser client, 712 // SiteInstance through ShouldAssignSiteForURL() in content browser client,
691 // allowing to reuse the renderer backing certain chrome urls for subsequent 713 // allowing to reuse the renderer backing certain chrome urls for subsequent
692 // navigation. The test verifies that the override is honored. 714 // navigation. The test verifies that the override is honored.
693 TEST_F(WebContentsImplTest, NavigateFromSitelessUrl) { 715 TEST_F(WebContentsImplTest, NavigateFromSitelessUrl) {
694 WebContentsImplTestBrowserClient browser_client; 716 WebContentsImplTestBrowserClient browser_client;
695 SetBrowserClientForTesting(&browser_client); 717 SetBrowserClientForTesting(&browser_client);
696 718
697 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 719 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
698 int orig_rvh_delete_count = 0; 720 int orig_rvh_delete_count = 0;
699 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); 721 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count);
700 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance(); 722 SiteInstanceImpl* orig_instance = contents()->GetSiteInstance();
701 723
702 browser_client.set_assign_site_for_url(false); 724 browser_client.set_assign_site_for_url(false);
703 // Navigate to an URL that will not assign a new SiteInstance. 725 // Navigate to an URL that will not assign a new SiteInstance.
704 const GURL native_url("non-site-url://stuffandthings"); 726 const GURL native_url("non-site-url://stuffandthings");
705 controller().LoadURL( 727 controller().LoadURL(
706 native_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 728 native_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
729 int entry_id = controller().GetPendingEntry()->GetUniqueID();
707 contents()->GetMainFrame()->PrepareForCommit(); 730 contents()->GetMainFrame()->PrepareForCommit();
708 contents()->TestDidNavigate( 731 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, native_url,
709 orig_rfh, 1, native_url, ui::PAGE_TRANSITION_TYPED); 732 ui::PAGE_TRANSITION_TYPED);
710 733
711 EXPECT_FALSE(contents()->cross_navigation_pending()); 734 EXPECT_FALSE(contents()->cross_navigation_pending());
712 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 735 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
713 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); 736 EXPECT_EQ(native_url, contents()->GetLastCommittedURL());
714 EXPECT_EQ(native_url, contents()->GetVisibleURL()); 737 EXPECT_EQ(native_url, contents()->GetVisibleURL());
715 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 738 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
716 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL()); 739 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL());
717 EXPECT_FALSE(orig_instance->HasSite()); 740 EXPECT_FALSE(orig_instance->HasSite());
718 741
719 browser_client.set_assign_site_for_url(true); 742 browser_client.set_assign_site_for_url(true);
720 // Navigate to new site (should keep same site instance). 743 // Navigate to new site (should keep same site instance).
721 const GURL url("http://www.google.com"); 744 const GURL url("http://www.google.com");
722 controller().LoadURL( 745 controller().LoadURL(
723 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 746 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
747 entry_id = controller().GetPendingEntry()->GetUniqueID();
724 contents()->GetMainFrame()->PrepareForCommit(); 748 contents()->GetMainFrame()->PrepareForCommit();
725 EXPECT_FALSE(contents()->cross_navigation_pending()); 749 EXPECT_FALSE(contents()->cross_navigation_pending());
726 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); 750 EXPECT_EQ(native_url, contents()->GetLastCommittedURL());
727 EXPECT_EQ(url, contents()->GetVisibleURL()); 751 EXPECT_EQ(url, contents()->GetVisibleURL());
728 EXPECT_FALSE(contents()->GetPendingMainFrame()); 752 EXPECT_FALSE(contents()->GetPendingMainFrame());
729 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 753 contents()->TestDidNavigate(orig_rfh, 2, entry_id, true, url,
754 ui::PAGE_TRANSITION_TYPED);
730 755
731 // Keep the number of active frames in orig_rfh's SiteInstance 756 // Keep the number of active frames in orig_rfh's SiteInstance
732 // non-zero so that orig_rfh doesn't get deleted when it gets 757 // non-zero so that orig_rfh doesn't get deleted when it gets
733 // swapped out. 758 // swapped out.
734 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 759 orig_rfh->GetSiteInstance()->increment_active_frame_count();
735 760
736 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 761 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
737 EXPECT_TRUE( 762 EXPECT_TRUE(
738 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com")); 763 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com"));
739 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 764 EXPECT_EQ(url, contents()->GetLastCommittedURL());
740 765
741 // Navigate to another new site (should create a new site instance). 766 // Navigate to another new site (should create a new site instance).
742 const GURL url2("http://www.yahoo.com"); 767 const GURL url2("http://www.yahoo.com");
743 controller().LoadURL( 768 controller().LoadURL(
744 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 769 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
770 entry_id = controller().GetPendingEntry()->GetUniqueID();
745 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 771 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
746 switches::kEnableBrowserSideNavigation)) { 772 switches::kEnableBrowserSideNavigation)) {
747 orig_rfh->PrepareForCommit(); 773 orig_rfh->PrepareForCommit();
748 } 774 }
749 EXPECT_TRUE(contents()->cross_navigation_pending()); 775 EXPECT_TRUE(contents()->cross_navigation_pending());
750 EXPECT_EQ(url, contents()->GetLastCommittedURL()); 776 EXPECT_EQ(url, contents()->GetLastCommittedURL());
751 EXPECT_EQ(url2, contents()->GetVisibleURL()); 777 EXPECT_EQ(url2, contents()->GetVisibleURL());
752 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 778 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
753 int pending_rvh_delete_count = 0; 779 int pending_rvh_delete_count = 0;
754 pending_rfh->GetRenderViewHost()->set_delete_counter( 780 pending_rfh->GetRenderViewHost()->set_delete_counter(
755 &pending_rvh_delete_count); 781 &pending_rvh_delete_count);
756 782
757 // Navigations should be suspended in pending_rvh until BeforeUnloadACK. 783 // Navigations should be suspended in pending_rvh until BeforeUnloadACK.
758 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 784 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
759 switches::kEnableBrowserSideNavigation)) { 785 switches::kEnableBrowserSideNavigation)) {
760 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); 786 EXPECT_TRUE(pending_rfh->are_navigations_suspended());
761 orig_rfh->SendBeforeUnloadACK(true); 787 orig_rfh->SendBeforeUnloadACK(true);
762 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); 788 EXPECT_FALSE(pending_rfh->are_navigations_suspended());
763 } 789 }
764 790
765 // DidNavigate from the pending page. 791 // DidNavigate from the pending page.
766 contents()->TestDidNavigate( 792 contents()->TestDidNavigate(pending_rfh, 1, entry_id, true, url2,
767 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 793 ui::PAGE_TRANSITION_TYPED);
768 SiteInstance* new_instance = contents()->GetSiteInstance(); 794 SiteInstance* new_instance = contents()->GetSiteInstance();
769 795
770 EXPECT_FALSE(contents()->cross_navigation_pending()); 796 EXPECT_FALSE(contents()->cross_navigation_pending());
771 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 797 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
772 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); 798 EXPECT_EQ(url2, contents()->GetLastCommittedURL());
773 EXPECT_EQ(url2, contents()->GetVisibleURL()); 799 EXPECT_EQ(url2, contents()->GetVisibleURL());
774 EXPECT_NE(new_instance, orig_instance); 800 EXPECT_NE(new_instance, orig_instance);
775 EXPECT_FALSE(contents()->GetPendingMainFrame()); 801 EXPECT_FALSE(contents()->GetPendingMainFrame());
776 // We keep the original RFH around, swapped out. 802 // We keep the original RFH around, swapped out.
777 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( 803 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList(
(...skipping 26 matching lines...) Expand all
804 browser_context()); 830 browser_context());
805 entry->SetPageID(0); 831 entry->SetPageID(0);
806 entries.push_back(entry); 832 entries.push_back(entry);
807 controller().Restore( 833 controller().Restore(
808 0, 834 0,
809 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, 835 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY,
810 &entries); 836 &entries);
811 ASSERT_EQ(0u, entries.size()); 837 ASSERT_EQ(0u, entries.size());
812 ASSERT_EQ(1, controller().GetEntryCount()); 838 ASSERT_EQ(1, controller().GetEntryCount());
813 controller().GoToIndex(0); 839 controller().GoToIndex(0);
814 contents()->TestDidNavigate( 840 entry = controller().GetPendingEntry();
815 orig_rfh, 0, native_url, ui::PAGE_TRANSITION_RELOAD); 841 contents()->TestDidNavigate(orig_rfh, 0, entry->GetUniqueID(), false,
842 native_url, ui::PAGE_TRANSITION_RELOAD);
816 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 843 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
817 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL()); 844 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL());
818 EXPECT_FALSE(orig_instance->HasSite()); 845 EXPECT_FALSE(orig_instance->HasSite());
819 846
820 // Navigate to a regular site and verify that the SiteInstance was kept. 847 // Navigate to a regular site and verify that the SiteInstance was kept.
821 browser_client.set_assign_site_for_url(true); 848 browser_client.set_assign_site_for_url(true);
822 const GURL url("http://www.google.com"); 849 const GURL url("http://www.google.com");
823 controller().LoadURL( 850 controller().LoadURL(
824 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 851 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
825 contents()->TestDidNavigate(orig_rfh, 2, url, ui::PAGE_TRANSITION_TYPED); 852 entry = controller().GetPendingEntry();
853 contents()->TestDidNavigate(orig_rfh, 2, entry->GetUniqueID(), true, url,
854 ui::PAGE_TRANSITION_TYPED);
826 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 855 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
827 856
828 // Cleanup. 857 // Cleanup.
829 DeleteContents(); 858 DeleteContents();
830 } 859 }
831 860
832 // Complement for NavigateFromRestoredSitelessUrl, verifying that when a regular 861 // Complement for NavigateFromRestoredSitelessUrl, verifying that when a regular
833 // tab is restored, the SiteInstance will change upon navigation. 862 // tab is restored, the SiteInstance will change upon navigation.
834 TEST_F(WebContentsImplTest, NavigateFromRestoredRegularUrl) { 863 TEST_F(WebContentsImplTest, NavigateFromRestoredRegularUrl) {
835 WebContentsImplTestBrowserClient browser_client; 864 WebContentsImplTestBrowserClient browser_client;
(...skipping 11 matching lines...) Expand all
847 browser_context()); 876 browser_context());
848 entry->SetPageID(0); 877 entry->SetPageID(0);
849 entries.push_back(entry); 878 entries.push_back(entry);
850 controller().Restore( 879 controller().Restore(
851 0, 880 0,
852 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, 881 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY,
853 &entries); 882 &entries);
854 ASSERT_EQ(0u, entries.size()); 883 ASSERT_EQ(0u, entries.size());
855 ASSERT_EQ(1, controller().GetEntryCount()); 884 ASSERT_EQ(1, controller().GetEntryCount());
856 controller().GoToIndex(0); 885 controller().GoToIndex(0);
886 entry = controller().GetPendingEntry();
857 orig_rfh->PrepareForCommit(); 887 orig_rfh->PrepareForCommit();
858 contents()->TestDidNavigate( 888 contents()->TestDidNavigate(orig_rfh, 0, entry->GetUniqueID(), false,
859 orig_rfh, 0, regular_url, ui::PAGE_TRANSITION_RELOAD); 889 regular_url, ui::PAGE_TRANSITION_RELOAD);
860 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); 890 EXPECT_EQ(orig_instance, contents()->GetSiteInstance());
861 EXPECT_TRUE(orig_instance->HasSite()); 891 EXPECT_TRUE(orig_instance->HasSite());
862 892
863 // Navigate to another site and verify that a new SiteInstance was created. 893 // Navigate to another site and verify that a new SiteInstance was created.
864 const GURL url("http://www.google.com"); 894 const GURL url("http://www.google.com");
865 controller().LoadURL( 895 controller().LoadURL(
866 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 896 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
897 entry = controller().GetPendingEntry();
867 orig_rfh->PrepareForCommit(); 898 orig_rfh->PrepareForCommit();
868 contents()->TestDidNavigate( 899 contents()->TestDidNavigate(contents()->GetPendingMainFrame(), 2,
869 contents()->GetPendingMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED); 900 entry->GetUniqueID(), true, url,
901 ui::PAGE_TRANSITION_TYPED);
870 EXPECT_NE(orig_instance, contents()->GetSiteInstance()); 902 EXPECT_NE(orig_instance, contents()->GetSiteInstance());
871 903
872 // Cleanup. 904 // Cleanup.
873 DeleteContents(); 905 DeleteContents();
874 } 906 }
875 907
876 // Test that we can find an opener RVH even if it's pending. 908 // Test that we can find an opener RVH even if it's pending.
877 // http://crbug.com/176252. 909 // http://crbug.com/176252.
878 TEST_F(WebContentsImplTest, FindOpenerRVHWhenPending) { 910 TEST_F(WebContentsImplTest, FindOpenerRVHWhenPending) {
879 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 911 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
880 912
881 // Navigate to a URL. 913 // Navigate to a URL.
882 const GURL url("http://www.google.com"); 914 const GURL url("http://www.google.com");
883 controller().LoadURL( 915 controller().LoadURL(
884 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 916 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
917 int entry_id = controller().GetPendingEntry()->GetUniqueID();
885 orig_rfh->PrepareForCommit(); 918 orig_rfh->PrepareForCommit();
886 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 919 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url,
920 ui::PAGE_TRANSITION_TYPED);
887 921
888 // Start to navigate first tab to a new site, so that it has a pending RVH. 922 // Start to navigate first tab to a new site, so that it has a pending RVH.
889 const GURL url2("http://www.yahoo.com"); 923 const GURL url2("http://www.yahoo.com");
890 controller().LoadURL( 924 controller().LoadURL(
891 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 925 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
892 orig_rfh->PrepareForCommit(); 926 orig_rfh->PrepareForCommit();
893 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 927 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
894 928
895 // While it is still pending, simulate opening a new tab with the first tab 929 // While it is still pending, simulate opening a new tab with the first tab
896 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews 930 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews
897 // on the opener to ensure that an RVH exists. 931 // on the opener to ensure that an RVH exists.
898 int opener_routing_id = 932 int opener_routing_id =
899 contents()->CreateOpenerRenderViews(pending_rfh->GetSiteInstance()); 933 contents()->CreateOpenerRenderViews(pending_rfh->GetSiteInstance());
900 934
901 // We should find the pending RVH and not create a new one. 935 // We should find the pending RVH and not create a new one.
902 EXPECT_EQ(pending_rfh->GetRenderViewHost()->GetRoutingID(), 936 EXPECT_EQ(pending_rfh->GetRenderViewHost()->GetRoutingID(),
903 opener_routing_id); 937 opener_routing_id);
904 } 938 }
905 939
906 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site, 940 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site,
907 // to determine whether a navigation is cross-site. 941 // to determine whether a navigation is cross-site.
908 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) { 942 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) {
909 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 943 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
910 SiteInstance* instance1 = contents()->GetSiteInstance(); 944 SiteInstance* instance1 = contents()->GetSiteInstance();
911 945
912 // Navigate to URL. 946 // Navigate to URL.
913 const GURL url("http://www.google.com"); 947 const GURL url("http://www.google.com");
914 controller().LoadURL( 948 controller().LoadURL(
915 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 949 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
950 int entry_id = controller().GetPendingEntry()->GetUniqueID();
916 contents()->GetMainFrame()->PrepareForCommit(); 951 contents()->GetMainFrame()->PrepareForCommit();
917 contents()->TestDidNavigate( 952 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url,
918 orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 953 ui::PAGE_TRANSITION_TYPED);
919 954
920 // Open a related contents to a second site. 955 // Open a related contents to a second site.
921 scoped_ptr<TestWebContents> contents2( 956 scoped_ptr<TestWebContents> contents2(
922 TestWebContents::Create(browser_context(), instance1)); 957 TestWebContents::Create(browser_context(), instance1));
923 const GURL url2("http://www.yahoo.com"); 958 const GURL url2("http://www.yahoo.com");
924 contents2->GetController().LoadURL(url2, Referrer(), 959 contents2->GetController().LoadURL(url2, Referrer(),
925 ui::PAGE_TRANSITION_TYPED, 960 ui::PAGE_TRANSITION_TYPED,
926 std::string()); 961 std::string());
962 entry_id = contents2->GetController().GetPendingEntry()->GetUniqueID();
927 contents2->GetMainFrame()->PrepareForCommit(); 963 contents2->GetMainFrame()->PrepareForCommit();
964
928 // The first RVH in contents2 isn't live yet, so we shortcut the cross site 965 // The first RVH in contents2 isn't live yet, so we shortcut the cross site
929 // pending. 966 // pending.
930 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); 967 TestRenderFrameHost* rfh2 = contents2->GetMainFrame();
931 EXPECT_FALSE(contents2->cross_navigation_pending()); 968 EXPECT_FALSE(contents2->cross_navigation_pending());
932 contents2->TestDidNavigate(rfh2, 2, url2, ui::PAGE_TRANSITION_TYPED); 969 contents2->TestDidNavigate(rfh2, 2, entry_id, true, url2,
970 ui::PAGE_TRANSITION_TYPED);
933 SiteInstance* instance2 = contents2->GetSiteInstance(); 971 SiteInstance* instance2 = contents2->GetSiteInstance();
934 EXPECT_NE(instance1, instance2); 972 EXPECT_NE(instance1, instance2);
935 EXPECT_FALSE(contents2->cross_navigation_pending()); 973 EXPECT_FALSE(contents2->cross_navigation_pending());
936 974
937 // Simulate a link click in first contents to second site. Doesn't switch 975 // Simulate a link click in first contents to second site. Doesn't switch
938 // SiteInstances, because we don't intercept WebKit navigations. 976 // SiteInstances, because we don't intercept Blink navigations.
939 contents()->TestDidNavigate( 977 contents()->TestDidNavigate(orig_rfh, 2, 0, true, url2,
940 orig_rfh, 2, url2, ui::PAGE_TRANSITION_TYPED); 978 ui::PAGE_TRANSITION_TYPED);
941 SiteInstance* instance3 = contents()->GetSiteInstance(); 979 SiteInstance* instance3 = contents()->GetSiteInstance();
942 EXPECT_EQ(instance1, instance3); 980 EXPECT_EQ(instance1, instance3);
943 EXPECT_FALSE(contents()->cross_navigation_pending()); 981 EXPECT_FALSE(contents()->cross_navigation_pending());
944 982
945 // Navigate to the new site. Doesn't switch SiteInstancees, because we 983 // Navigate to the new site. Doesn't switch SiteInstancees, because we
946 // compare against the current URL, not the SiteInstance's site. 984 // compare against the current URL, not the SiteInstance's site.
947 const GURL url3("http://mail.yahoo.com"); 985 const GURL url3("http://mail.yahoo.com");
948 controller().LoadURL( 986 controller().LoadURL(
949 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 987 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
988 entry_id = controller().GetPendingEntry()->GetUniqueID();
950 EXPECT_FALSE(contents()->cross_navigation_pending()); 989 EXPECT_FALSE(contents()->cross_navigation_pending());
951 contents()->GetMainFrame()->PrepareForCommit(); 990 contents()->GetMainFrame()->PrepareForCommit();
952 contents()->TestDidNavigate( 991 contents()->TestDidNavigate(orig_rfh, 3, entry_id, true, url3,
953 orig_rfh, 3, url3, ui::PAGE_TRANSITION_TYPED); 992 ui::PAGE_TRANSITION_TYPED);
954 SiteInstance* instance4 = contents()->GetSiteInstance(); 993 SiteInstance* instance4 = contents()->GetSiteInstance();
955 EXPECT_EQ(instance1, instance4); 994 EXPECT_EQ(instance1, instance4);
956 } 995 }
957 996
958 // Test that the onbeforeunload and onunload handlers run when navigating 997 // Test that the onbeforeunload and onunload handlers run when navigating
959 // across site boundaries. 998 // across site boundaries.
960 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { 999 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) {
961 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1000 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
962 SiteInstance* instance1 = contents()->GetSiteInstance(); 1001 SiteInstance* instance1 = contents()->GetSiteInstance();
963 1002
964 // Navigate to URL. First URL should use first RenderViewHost. 1003 // Navigate to URL. First URL should use first RenderViewHost.
965 const GURL url("http://www.google.com"); 1004 const GURL url("http://www.google.com");
966 controller().LoadURL( 1005 controller().LoadURL(
967 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1006 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1007 int entry_id = controller().GetPendingEntry()->GetUniqueID();
968 contents()->GetMainFrame()->PrepareForCommit(); 1008 contents()->GetMainFrame()->PrepareForCommit();
969 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1009 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url,
1010 ui::PAGE_TRANSITION_TYPED);
970 EXPECT_FALSE(contents()->cross_navigation_pending()); 1011 EXPECT_FALSE(contents()->cross_navigation_pending());
971 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1012 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
972 1013
973 // Navigate to new site, but simulate an onbeforeunload denial. 1014 // Navigate to new site, but simulate an onbeforeunload denial.
974 const GURL url2("http://www.yahoo.com"); 1015 const GURL url2("http://www.yahoo.com");
975 controller().LoadURL( 1016 controller().LoadURL(
976 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1017 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
977 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1018 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
978 base::TimeTicks now = base::TimeTicks::Now(); 1019 base::TimeTicks now = base::TimeTicks::Now();
979 orig_rfh->OnMessageReceived( 1020 orig_rfh->OnMessageReceived(
980 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 1021 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
981 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1022 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
982 EXPECT_FALSE(contents()->cross_navigation_pending()); 1023 EXPECT_FALSE(contents()->cross_navigation_pending());
983 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1024 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
984 1025
985 // Navigate again, but simulate an onbeforeunload approval. 1026 // Navigate again, but simulate an onbeforeunload approval.
986 controller().LoadURL( 1027 controller().LoadURL(
987 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1028 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1029 entry_id = controller().GetPendingEntry()->GetUniqueID();
988 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1030 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
989 now = base::TimeTicks::Now(); 1031 now = base::TimeTicks::Now();
990 orig_rfh->PrepareForCommit(); 1032 orig_rfh->PrepareForCommit();
991 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1033 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
992 EXPECT_TRUE(contents()->cross_navigation_pending()); 1034 EXPECT_TRUE(contents()->cross_navigation_pending());
993 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 1035 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
994 1036
995 // We won't hear DidNavigate until the onunload handler has finished running. 1037 // We won't hear DidNavigate until the onunload handler has finished running.
996 1038
997 // DidNavigate from the pending page. 1039 // DidNavigate from the pending page.
998 contents()->TestDidNavigate( 1040 contents()->TestDidNavigate(pending_rfh, 1, entry_id, true, url2,
999 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1041 ui::PAGE_TRANSITION_TYPED);
1000 SiteInstance* instance2 = contents()->GetSiteInstance(); 1042 SiteInstance* instance2 = contents()->GetSiteInstance();
1001 EXPECT_FALSE(contents()->cross_navigation_pending()); 1043 EXPECT_FALSE(contents()->cross_navigation_pending());
1002 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 1044 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
1003 EXPECT_NE(instance1, instance2); 1045 EXPECT_NE(instance1, instance2);
1004 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame()); 1046 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame());
1005 } 1047 }
1006 1048
1007 // Test that during a slow cross-site navigation, the original renderer can 1049 // Test that during a slow cross-site navigation, the original renderer can
1008 // navigate to a different URL and have it displayed, canceling the slow 1050 // navigate to a different URL and have it displayed, canceling the slow
1009 // navigation. 1051 // navigation.
1010 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) { 1052 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) {
1011 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1053 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1012 SiteInstance* instance1 = contents()->GetSiteInstance(); 1054 SiteInstance* instance1 = contents()->GetSiteInstance();
1013 1055
1014 // Navigate to URL. First URL should use first RenderFrameHost. 1056 // Navigate to URL. First URL should use first RenderFrameHost.
1015 const GURL url("http://www.google.com"); 1057 const GURL url("http://www.google.com");
1016 controller().LoadURL( 1058 controller().LoadURL(
1017 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1059 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1060 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1018 contents()->GetMainFrame()->PrepareForCommit(); 1061 contents()->GetMainFrame()->PrepareForCommit();
1019 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1062 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url,
1063 ui::PAGE_TRANSITION_TYPED);
1020 EXPECT_FALSE(contents()->cross_navigation_pending()); 1064 EXPECT_FALSE(contents()->cross_navigation_pending());
1021 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1065 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1022 1066
1023 // Navigate to new site, simulating an onbeforeunload approval. 1067 // Navigate to new site, simulating an onbeforeunload approval.
1024 const GURL url2("http://www.yahoo.com"); 1068 const GURL url2("http://www.yahoo.com");
1025 controller().LoadURL( 1069 controller().LoadURL(
1026 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1070 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1027 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1071 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1028 orig_rfh->PrepareForCommit(); 1072 orig_rfh->PrepareForCommit();
1029 EXPECT_TRUE(contents()->cross_navigation_pending()); 1073 EXPECT_TRUE(contents()->cross_navigation_pending());
1030 1074
1031 // Suppose the original renderer navigates before the new one is ready. 1075 // Suppose the original renderer navigates before the new one is ready.
1032 orig_rfh->SendNavigate(2, GURL("http://www.google.com/foo")); 1076 orig_rfh->SendNavigate(2, 0, true, GURL("http://www.google.com/foo"));
1033 1077
1034 // Verify that the pending navigation is cancelled. 1078 // Verify that the pending navigation is cancelled.
1035 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1079 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1036 SiteInstance* instance2 = contents()->GetSiteInstance(); 1080 SiteInstance* instance2 = contents()->GetSiteInstance();
1037 EXPECT_FALSE(contents()->cross_navigation_pending()); 1081 EXPECT_FALSE(contents()->cross_navigation_pending());
1038 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1082 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1039 EXPECT_EQ(instance1, instance2); 1083 EXPECT_EQ(instance1, instance2);
1040 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame()); 1084 EXPECT_EQ(nullptr, contents()->GetPendingMainFrame());
1041 } 1085 }
1042 1086
1043 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { 1087 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) {
1044 // Start with a web ui page, which gets a new RVH with WebUI bindings. 1088 // Start with a web ui page, which gets a new RVH with WebUI bindings.
1045 const GURL url1("chrome://blah"); 1089 const GURL url1("chrome://blah");
1046 controller().LoadURL( 1090 controller().LoadURL(
1047 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1091 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1092 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1048 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); 1093 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame();
1049 ntp_rfh->PrepareForCommit(); 1094 ntp_rfh->PrepareForCommit();
1050 contents()->TestDidNavigate(ntp_rfh, 1, url1, ui::PAGE_TRANSITION_TYPED); 1095 contents()->TestDidNavigate(ntp_rfh, 1, entry_id, true, url1,
1096 ui::PAGE_TRANSITION_TYPED);
1051 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); 1097 NavigationEntry* entry1 = controller().GetLastCommittedEntry();
1052 SiteInstance* instance1 = contents()->GetSiteInstance(); 1098 SiteInstance* instance1 = contents()->GetSiteInstance();
1053 1099
1054 EXPECT_FALSE(contents()->cross_navigation_pending()); 1100 EXPECT_FALSE(contents()->cross_navigation_pending());
1055 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame()); 1101 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame());
1056 EXPECT_EQ(url1, entry1->GetURL()); 1102 EXPECT_EQ(url1, entry1->GetURL());
1057 EXPECT_EQ(instance1, 1103 EXPECT_EQ(instance1,
1058 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); 1104 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance());
1059 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetEnabledBindings() & 1105 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetEnabledBindings() &
1060 BINDINGS_POLICY_WEB_UI); 1106 BINDINGS_POLICY_WEB_UI);
1061 1107
1062 // Navigate to new site. 1108 // Navigate to new site.
1063 const GURL url2("http://www.google.com"); 1109 const GURL url2("http://www.google.com");
1064 controller().LoadURL( 1110 controller().LoadURL(
1065 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1111 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1112 entry_id = controller().GetPendingEntry()->GetUniqueID();
1066 EXPECT_TRUE(contents()->cross_navigation_pending()); 1113 EXPECT_TRUE(contents()->cross_navigation_pending());
1067 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); 1114 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame();
1068 1115
1069 // Simulate beforeunload approval. 1116 // Simulate beforeunload approval.
1070 EXPECT_TRUE(ntp_rfh->IsWaitingForBeforeUnloadACK()); 1117 EXPECT_TRUE(ntp_rfh->IsWaitingForBeforeUnloadACK());
1071 base::TimeTicks now = base::TimeTicks::Now(); 1118 base::TimeTicks now = base::TimeTicks::Now();
1072 ntp_rfh->PrepareForCommit(); 1119 ntp_rfh->PrepareForCommit();
1073 1120
1074 // DidNavigate from the pending page. 1121 // DidNavigate from the pending page.
1075 contents()->TestDidNavigate( 1122 contents()->TestDidNavigate(google_rfh, 1, entry_id, true, url2,
1076 google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1123 ui::PAGE_TRANSITION_TYPED);
1077 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); 1124 NavigationEntry* entry2 = controller().GetLastCommittedEntry();
1078 SiteInstance* instance2 = contents()->GetSiteInstance(); 1125 SiteInstance* instance2 = contents()->GetSiteInstance();
1079 1126
1080 EXPECT_FALSE(contents()->cross_navigation_pending()); 1127 EXPECT_FALSE(contents()->cross_navigation_pending());
1081 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1128 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
1082 EXPECT_NE(instance1, instance2); 1129 EXPECT_NE(instance1, instance2);
1083 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1130 EXPECT_FALSE(contents()->GetPendingMainFrame());
1084 EXPECT_EQ(url2, entry2->GetURL()); 1131 EXPECT_EQ(url2, entry2->GetURL());
1085 EXPECT_EQ(instance2, 1132 EXPECT_EQ(instance2,
1086 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); 1133 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance());
1087 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() & 1134 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() &
1088 BINDINGS_POLICY_WEB_UI); 1135 BINDINGS_POLICY_WEB_UI);
1089 1136
1090 // Navigate to third page on same site. 1137 // Navigate to third page on same site.
1091 const GURL url3("http://news.google.com"); 1138 const GURL url3("http://news.google.com");
1092 controller().LoadURL( 1139 controller().LoadURL(
1093 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1140 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1141 entry_id = controller().GetPendingEntry()->GetUniqueID();
1094 EXPECT_FALSE(contents()->cross_navigation_pending()); 1142 EXPECT_FALSE(contents()->cross_navigation_pending());
1095 contents()->GetMainFrame()->PrepareForCommit(); 1143 contents()->GetMainFrame()->PrepareForCommit();
1096 contents()->TestDidNavigate( 1144 contents()->TestDidNavigate(google_rfh, 2, entry_id, true, url3,
1097 google_rfh, 2, url3, ui::PAGE_TRANSITION_TYPED); 1145 ui::PAGE_TRANSITION_TYPED);
1098 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); 1146 NavigationEntry* entry3 = controller().GetLastCommittedEntry();
1099 SiteInstance* instance3 = contents()->GetSiteInstance(); 1147 SiteInstance* instance3 = contents()->GetSiteInstance();
1100 1148
1101 EXPECT_FALSE(contents()->cross_navigation_pending()); 1149 EXPECT_FALSE(contents()->cross_navigation_pending());
1102 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1150 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
1103 EXPECT_EQ(instance2, instance3); 1151 EXPECT_EQ(instance2, instance3);
1104 EXPECT_FALSE(contents()->GetPendingMainFrame()); 1152 EXPECT_FALSE(contents()->GetPendingMainFrame());
1105 EXPECT_EQ(url3, entry3->GetURL()); 1153 EXPECT_EQ(url3, entry3->GetURL());
1106 EXPECT_EQ(instance3, 1154 EXPECT_EQ(instance3,
1107 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); 1155 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance());
1108 1156
1109 // Go back within the site. 1157 // Go back within the site.
1110 controller().GoBack(); 1158 controller().GoBack();
1159 NavigationEntry* goback_entry = controller().GetPendingEntry();
1111 EXPECT_FALSE(contents()->cross_navigation_pending()); 1160 EXPECT_FALSE(contents()->cross_navigation_pending());
1112 EXPECT_EQ(entry2, controller().GetPendingEntry()); 1161 EXPECT_EQ(entry2, controller().GetPendingEntry());
1113 1162
1114 // Before that commits, go back again. 1163 // Before that commits, go back again.
1115 controller().GoBack(); 1164 controller().GoBack();
1116 EXPECT_TRUE(contents()->cross_navigation_pending()); 1165 EXPECT_TRUE(contents()->cross_navigation_pending());
1117 EXPECT_TRUE(contents()->GetPendingMainFrame()); 1166 EXPECT_TRUE(contents()->GetPendingMainFrame());
1118 EXPECT_EQ(entry1, controller().GetPendingEntry()); 1167 EXPECT_EQ(entry1, controller().GetPendingEntry());
1119 1168
1120 // Simulate beforeunload approval. 1169 // Simulate beforeunload approval.
1121 EXPECT_TRUE(google_rfh->IsWaitingForBeforeUnloadACK()); 1170 EXPECT_TRUE(google_rfh->IsWaitingForBeforeUnloadACK());
1122 now = base::TimeTicks::Now(); 1171 now = base::TimeTicks::Now();
1123 google_rfh->PrepareForCommit(); 1172 google_rfh->PrepareForCommit();
1124 google_rfh->OnMessageReceived( 1173 google_rfh->OnMessageReceived(
1125 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); 1174 FrameHostMsg_BeforeUnload_ACK(0, true, now, now));
1126 1175
1127 // DidNavigate from the first back. This aborts the second back's pending RFH. 1176 // DidNavigate from the first back. This aborts the second back's pending RFH.
1128 contents()->TestDidNavigate(google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1177 contents()->TestDidNavigate(google_rfh, 1, goback_entry->GetUniqueID(), false,
1178 url2, ui::PAGE_TRANSITION_TYPED);
1129 1179
1130 // We should commit this page and forget about the second back. 1180 // We should commit this page and forget about the second back.
1131 EXPECT_FALSE(contents()->cross_navigation_pending()); 1181 EXPECT_FALSE(contents()->cross_navigation_pending());
1132 EXPECT_FALSE(controller().GetPendingEntry()); 1182 EXPECT_FALSE(controller().GetPendingEntry());
1133 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); 1183 EXPECT_EQ(google_rfh, contents()->GetMainFrame());
1134 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL()); 1184 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL());
1135 1185
1136 // We should not have corrupted the NTP entry. 1186 // We should not have corrupted the NTP entry.
1137 EXPECT_EQ(instance3, 1187 EXPECT_EQ(instance3,
1138 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); 1188 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance());
1139 EXPECT_EQ(instance2, 1189 EXPECT_EQ(instance2,
1140 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); 1190 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance());
1141 EXPECT_EQ(instance1, 1191 EXPECT_EQ(instance1,
1142 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); 1192 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance());
1143 EXPECT_EQ(url1, entry1->GetURL()); 1193 EXPECT_EQ(url1, entry1->GetURL());
1144 } 1194 }
1145 1195
1146 // Test that during a slow cross-site navigation, a sub-frame navigation in the 1196 // Test that during a slow cross-site navigation, a sub-frame navigation in the
1147 // original renderer will not cancel the slow navigation (bug 42029). 1197 // original renderer will not cancel the slow navigation (bug 42029).
1148 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) { 1198 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) {
1149 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1199 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1150 1200
1151 // Navigate to URL. First URL should use the original RenderFrameHost. 1201 // Navigate to URL. First URL should use the original RenderFrameHost.
1152 const GURL url("http://www.google.com"); 1202 const GURL url("http://www.google.com");
1153 controller().LoadURL( 1203 controller().LoadURL(
1154 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1204 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1205 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1155 contents()->GetMainFrame()->PrepareForCommit(); 1206 contents()->GetMainFrame()->PrepareForCommit();
1156 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1207 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url,
1208 ui::PAGE_TRANSITION_TYPED);
1157 EXPECT_FALSE(contents()->cross_navigation_pending()); 1209 EXPECT_FALSE(contents()->cross_navigation_pending());
1158 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1210 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1159 1211
1160 // Start navigating to new site. 1212 // Start navigating to new site.
1161 const GURL url2("http://www.yahoo.com"); 1213 const GURL url2("http://www.yahoo.com");
1162 controller().LoadURL( 1214 controller().LoadURL(
1163 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1215 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1164 1216
1165 // Simulate a sub-frame navigation arriving and ensure the RVH is still 1217 // Simulate a sub-frame navigation arriving and ensure the RVH is still
1166 // waiting for a before unload response. 1218 // waiting for a before unload response.
1167 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe"); 1219 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe");
1168 child_rfh->SendNavigateWithTransition( 1220 child_rfh->SendNavigateWithTransition(1, 0, false,
1169 1, GURL("http://google.com/frame"), ui::PAGE_TRANSITION_AUTO_SUBFRAME); 1221 GURL("http://google.com/frame"),
1222 ui::PAGE_TRANSITION_AUTO_SUBFRAME);
1170 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1223 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1171 1224
1172 // Now simulate the onbeforeunload approval and verify the navigation is 1225 // Now simulate the onbeforeunload approval and verify the navigation is
1173 // not canceled. 1226 // not canceled.
1174 orig_rfh->PrepareForCommit(); 1227 orig_rfh->PrepareForCommit();
1175 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1228 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1176 EXPECT_TRUE(contents()->cross_navigation_pending()); 1229 EXPECT_TRUE(contents()->cross_navigation_pending());
1177 } 1230 }
1178 1231
1179 // Test that a cross-site navigation is not preempted if the previous 1232 // Test that a cross-site navigation is not preempted if the previous
1180 // renderer sends a FrameNavigate message just before being told to stop. 1233 // renderer sends a FrameNavigate message just before being told to stop.
1181 // We should only preempt the cross-site navigation if the previous renderer 1234 // We should only preempt the cross-site navigation if the previous renderer
1182 // has started a new navigation. See http://crbug.com/79176. 1235 // has started a new navigation. See http://crbug.com/79176.
1183 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { 1236 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) {
1184 // Navigate to NTP URL. 1237 // Navigate to NTP URL.
1185 const GURL url("chrome://blah"); 1238 const GURL url("chrome://blah");
1186 controller().LoadURL( 1239 controller().LoadURL(
1187 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1240 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1241 int entry1_id = controller().GetPendingEntry()->GetUniqueID();
1188 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1242 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1189 EXPECT_FALSE(contents()->cross_navigation_pending()); 1243 EXPECT_FALSE(contents()->cross_navigation_pending());
1190 1244
1191 // Navigate to new site, with the beforeunload request in flight. 1245 // Navigate to new site, with the beforeunload request in flight.
1192 const GURL url2("http://www.yahoo.com"); 1246 const GURL url2("http://www.yahoo.com");
1193 controller().LoadURL( 1247 controller().LoadURL(
1194 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1248 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1249 int entry2_id = controller().GetPendingEntry()->GetUniqueID();
1195 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 1250 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
1196 EXPECT_TRUE(contents()->cross_navigation_pending()); 1251 EXPECT_TRUE(contents()->cross_navigation_pending());
1197 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1252 EXPECT_TRUE(orig_rfh->IsWaitingForBeforeUnloadACK());
1198 1253
1199 // Suppose the first navigation tries to commit now, with a 1254 // Suppose the first navigation tries to commit now, with a
1200 // FrameMsg_Stop in flight. This should not cancel the pending navigation, 1255 // FrameMsg_Stop in flight. This should not cancel the pending navigation,
1201 // but it should act as if the beforeunload ack arrived. 1256 // but it should act as if the beforeunload ack arrived.
1202 orig_rfh->SendNavigate(1, GURL("chrome://blah")); 1257 orig_rfh->SendNavigate(1, entry1_id, true, GURL("chrome://blah"));
1203 EXPECT_TRUE(contents()->cross_navigation_pending()); 1258 EXPECT_TRUE(contents()->cross_navigation_pending());
1204 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1259 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1205 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK()); 1260 EXPECT_FALSE(orig_rfh->IsWaitingForBeforeUnloadACK());
1206 1261
1207 // The pending navigation should be able to commit successfully. 1262 // The pending navigation should be able to commit successfully.
1208 contents()->TestDidNavigate(pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1263 contents()->TestDidNavigate(pending_rfh, 1, entry2_id, true, url2,
1264 ui::PAGE_TRANSITION_TYPED);
1209 EXPECT_FALSE(contents()->cross_navigation_pending()); 1265 EXPECT_FALSE(contents()->cross_navigation_pending());
1210 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); 1266 EXPECT_EQ(pending_rfh, contents()->GetMainFrame());
1211 } 1267 }
1212 1268
1213 // Test that NavigationEntries have the correct page state after going 1269 // Test that NavigationEntries have the correct page state after going
1214 // forward and back. Prevents regression for bug 1116137. 1270 // forward and back. Prevents regression for bug 1116137.
1215 TEST_F(WebContentsImplTest, NavigationEntryContentState) { 1271 TEST_F(WebContentsImplTest, NavigationEntryContentState) {
1216 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1272 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1217 1273
1218 // Navigate to URL. There should be no committed entry yet. 1274 // Navigate to URL. There should be no committed entry yet.
1219 const GURL url("http://www.google.com"); 1275 const GURL url("http://www.google.com");
1220 controller().LoadURL( 1276 controller().LoadURL(
1221 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1277 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1278 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1222 NavigationEntry* entry = controller().GetLastCommittedEntry(); 1279 NavigationEntry* entry = controller().GetLastCommittedEntry();
1223 EXPECT_EQ(nullptr, entry); 1280 EXPECT_EQ(nullptr, entry);
1224 1281
1225 // Committed entry should have page state after DidNavigate. 1282 // Committed entry should have page state after DidNavigate.
1226 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1283 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url,
1284 ui::PAGE_TRANSITION_TYPED);
1227 entry = controller().GetLastCommittedEntry(); 1285 entry = controller().GetLastCommittedEntry();
1228 EXPECT_TRUE(entry->GetPageState().IsValid()); 1286 EXPECT_TRUE(entry->GetPageState().IsValid());
1229 1287
1230 // Navigate to same site. 1288 // Navigate to same site.
1231 const GURL url2("http://images.google.com"); 1289 const GURL url2("http://images.google.com");
1232 controller().LoadURL( 1290 controller().LoadURL(
1233 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1291 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1292 entry_id = controller().GetPendingEntry()->GetUniqueID();
1234 entry = controller().GetLastCommittedEntry(); 1293 entry = controller().GetLastCommittedEntry();
1235 EXPECT_TRUE(entry->GetPageState().IsValid()); 1294 EXPECT_TRUE(entry->GetPageState().IsValid());
1236 1295
1237 // Committed entry should have page state after DidNavigate. 1296 // Committed entry should have page state after DidNavigate.
1238 contents()->TestDidNavigate(orig_rfh, 2, url2, ui::PAGE_TRANSITION_TYPED); 1297 contents()->TestDidNavigate(orig_rfh, 2, entry_id, true, url2,
1298 ui::PAGE_TRANSITION_TYPED);
1239 entry = controller().GetLastCommittedEntry(); 1299 entry = controller().GetLastCommittedEntry();
1240 EXPECT_TRUE(entry->GetPageState().IsValid()); 1300 EXPECT_TRUE(entry->GetPageState().IsValid());
1241 1301
1242 // Now go back. Committed entry should still have page state. 1302 // Now go back. Committed entry should still have page state.
1243 controller().GoBack(); 1303 controller().GoBack();
1244 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1304 entry_id = controller().GetPendingEntry()->GetUniqueID();
1305 contents()->TestDidNavigate(orig_rfh, 1, entry_id, false, url,
1306 ui::PAGE_TRANSITION_TYPED);
1245 entry = controller().GetLastCommittedEntry(); 1307 entry = controller().GetLastCommittedEntry();
1246 EXPECT_TRUE(entry->GetPageState().IsValid()); 1308 EXPECT_TRUE(entry->GetPageState().IsValid());
1247 } 1309 }
1248 1310
1249 // Test that NavigationEntries have the correct page state and SiteInstance 1311 // Test that NavigationEntries have the correct page state and SiteInstance
1250 // state after opening a new window to about:blank. Prevents regression for 1312 // state after opening a new window to about:blank. Prevents regression for
1251 // bugs b/1116137 and http://crbug.com/111975. 1313 // bugs b/1116137 and http://crbug.com/111975.
1252 TEST_F(WebContentsImplTest, NavigationEntryContentStateNewWindow) { 1314 TEST_F(WebContentsImplTest, NavigationEntryContentStateNewWindow) {
1253 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1315 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1254 1316
1255 // When opening a new window, it is navigated to about:blank internally. 1317 // Navigate to about:blank.
1256 // Currently, this results in two DidNavigate events.
1257 const GURL url(url::kAboutBlankURL); 1318 const GURL url(url::kAboutBlankURL);
1258 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1319 contents()->TestDidNavigate(orig_rfh, 1, 0, true, url,
1259 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1320 ui::PAGE_TRANSITION_TYPED);
1260 1321
1261 // Should have a page state here. 1322 // Should have a page state here.
1262 NavigationEntry* entry = controller().GetLastCommittedEntry(); 1323 NavigationEntry* entry = controller().GetLastCommittedEntry();
1263 EXPECT_TRUE(entry->GetPageState().IsValid()); 1324 EXPECT_TRUE(entry->GetPageState().IsValid());
1264 1325
1265 // The SiteInstance should be available for other navigations to use. 1326 // The SiteInstance should be available for other navigations to use.
1266 NavigationEntryImpl* entry_impl = 1327 NavigationEntryImpl* entry_impl =
1267 NavigationEntryImpl::FromNavigationEntry(entry); 1328 NavigationEntryImpl::FromNavigationEntry(entry);
1268 EXPECT_FALSE(entry_impl->site_instance()->HasSite()); 1329 EXPECT_FALSE(entry_impl->site_instance()->HasSite());
1269 int32 site_instance_id = entry_impl->site_instance()->GetId(); 1330 int32 site_instance_id = entry_impl->site_instance()->GetId();
1270 1331
1271 // Navigating to a normal page should not cause a process swap. 1332 // Navigating to a normal page should not cause a process swap.
1272 const GURL new_url("http://www.google.com"); 1333 const GURL new_url("http://www.google.com");
1273 controller().LoadURL(new_url, Referrer(), 1334 controller().LoadURL(new_url, Referrer(),
1274 ui::PAGE_TRANSITION_TYPED, std::string()); 1335 ui::PAGE_TRANSITION_TYPED, std::string());
1336 entry = controller().GetPendingEntry();
1275 EXPECT_FALSE(contents()->cross_navigation_pending()); 1337 EXPECT_FALSE(contents()->cross_navigation_pending());
1276 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1338 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1277 contents()->TestDidNavigate(orig_rfh, 1, new_url, ui::PAGE_TRANSITION_TYPED); 1339 contents()->TestDidNavigate(orig_rfh, 2, entry->GetUniqueID(), true, new_url,
1340 ui::PAGE_TRANSITION_TYPED);
1278 NavigationEntryImpl* entry_impl2 = NavigationEntryImpl::FromNavigationEntry( 1341 NavigationEntryImpl* entry_impl2 = NavigationEntryImpl::FromNavigationEntry(
1279 controller().GetLastCommittedEntry()); 1342 controller().GetLastCommittedEntry());
1280 EXPECT_EQ(site_instance_id, entry_impl2->site_instance()->GetId()); 1343 EXPECT_EQ(site_instance_id, entry_impl2->site_instance()->GetId());
1281 EXPECT_TRUE(entry_impl2->site_instance()->HasSite()); 1344 EXPECT_TRUE(entry_impl2->site_instance()->HasSite());
1282 } 1345 }
1283 1346
1284 // Tests that fullscreen is exited throughout the object hierarchy when 1347 // Tests that fullscreen is exited throughout the object hierarchy when
1285 // navigating to a new page. 1348 // navigating to a new page.
1286 TEST_F(WebContentsImplTest, NavigationExitsFullscreen) { 1349 TEST_F(WebContentsImplTest, NavigationExitsFullscreen) {
1287 FakeFullscreenDelegate fake_delegate; 1350 FakeFullscreenDelegate fake_delegate;
1288 contents()->SetDelegate(&fake_delegate); 1351 contents()->SetDelegate(&fake_delegate);
1289 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1352 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1290 TestRenderViewHost* orig_rvh = orig_rfh->GetRenderViewHost(); 1353 TestRenderViewHost* orig_rvh = orig_rfh->GetRenderViewHost();
1291 1354
1292 // Navigate to a site. 1355 // Navigate to a site.
1293 const GURL url("http://www.google.com"); 1356 const GURL url("http://www.google.com");
1294 controller().LoadURL( 1357 controller().LoadURL(
1295 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1358 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1359 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1296 contents()->GetMainFrame()->PrepareForCommit(); 1360 contents()->GetMainFrame()->PrepareForCommit();
1297 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1361 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url,
1362 ui::PAGE_TRANSITION_TYPED);
1298 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1363 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1299 1364
1300 // Toggle fullscreen mode on (as if initiated via IPC from renderer). 1365 // Toggle fullscreen mode on (as if initiated via IPC from renderer).
1301 EXPECT_FALSE(orig_rvh->IsFullscreen()); 1366 EXPECT_FALSE(orig_rvh->IsFullscreen());
1302 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); 1367 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab());
1303 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1368 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1304 orig_rfh->OnMessageReceived( 1369 orig_rfh->OnMessageReceived(
1305 FrameHostMsg_ToggleFullscreen(orig_rfh->GetRoutingID(), true)); 1370 FrameHostMsg_ToggleFullscreen(orig_rfh->GetRoutingID(), true));
1306 EXPECT_TRUE(orig_rvh->IsFullscreen()); 1371 EXPECT_TRUE(orig_rvh->IsFullscreen());
1307 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab()); 1372 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab());
1308 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1373 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1309 1374
1310 // Navigate to a new site. 1375 // Navigate to a new site.
1311 const GURL url2("http://www.yahoo.com"); 1376 const GURL url2("http://www.yahoo.com");
1312 controller().LoadURL( 1377 controller().LoadURL(
1313 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1378 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1379 entry_id = controller().GetPendingEntry()->GetUniqueID();
1314 contents()->GetMainFrame()->PrepareForCommit(); 1380 contents()->GetMainFrame()->PrepareForCommit();
1315 TestRenderFrameHost* const pending_rfh = contents()->GetPendingMainFrame(); 1381 TestRenderFrameHost* const pending_rfh = contents()->GetPendingMainFrame();
1316 contents()->TestDidNavigate( 1382 contents()->TestDidNavigate(pending_rfh, 1, entry_id, true, url2,
1317 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); 1383 ui::PAGE_TRANSITION_TYPED);
1318 1384
1319 // Confirm fullscreen has exited. 1385 // Confirm fullscreen has exited.
1320 EXPECT_FALSE(orig_rvh->IsFullscreen()); 1386 EXPECT_FALSE(orig_rvh->IsFullscreen());
1321 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); 1387 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab());
1322 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1388 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1323 1389
1324 contents()->SetDelegate(nullptr); 1390 contents()->SetDelegate(nullptr);
1325 } 1391 }
1326 1392
1327 // Tests that fullscreen is exited throughout the object hierarchy when 1393 // Tests that fullscreen is exited throughout the object hierarchy when
1328 // instructing NavigationController to GoBack() or GoForward(). 1394 // instructing NavigationController to GoBack() or GoForward().
1329 TEST_F(WebContentsImplTest, HistoryNavigationExitsFullscreen) { 1395 TEST_F(WebContentsImplTest, HistoryNavigationExitsFullscreen) {
1330 FakeFullscreenDelegate fake_delegate; 1396 FakeFullscreenDelegate fake_delegate;
1331 contents()->SetDelegate(&fake_delegate); 1397 contents()->SetDelegate(&fake_delegate);
1332 TestRenderFrameHost* const orig_rfh = contents()->GetMainFrame(); 1398 TestRenderFrameHost* const orig_rfh = contents()->GetMainFrame();
1333 TestRenderViewHost* const orig_rvh = orig_rfh->GetRenderViewHost(); 1399 TestRenderViewHost* const orig_rvh = orig_rfh->GetRenderViewHost();
1334 1400
1335 // Navigate to a site. 1401 // Navigate to a site.
1336 const GURL url("http://www.google.com"); 1402 const GURL url("http://www.google.com");
1337 controller().LoadURL( 1403 controller().LoadURL(
1338 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1404 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1339 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); 1405 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1406 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, url,
1407 ui::PAGE_TRANSITION_TYPED);
1340 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1408 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1341 1409
1342 // Now, navigate to another page on the same site. 1410 // Now, navigate to another page on the same site.
1343 const GURL url2("http://www.google.com/search?q=kittens"); 1411 const GURL url2("http://www.google.com/search?q=kittens");
1344 controller().LoadURL( 1412 controller().LoadURL(
1345 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1413 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1414 entry_id = controller().GetPendingEntry()->GetUniqueID();
1346 EXPECT_FALSE(contents()->cross_navigation_pending()); 1415 EXPECT_FALSE(contents()->cross_navigation_pending());
1347 contents()->TestDidNavigate(orig_rfh, 2, url2, ui::PAGE_TRANSITION_TYPED); 1416 contents()->TestDidNavigate(orig_rfh, 2, entry_id, true, url2,
1417 ui::PAGE_TRANSITION_TYPED);
1348 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1418 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1349 1419
1350 // Sanity-check: Confirm we're not starting out in fullscreen mode. 1420 // Sanity-check: Confirm we're not starting out in fullscreen mode.
1351 EXPECT_FALSE(orig_rvh->IsFullscreen()); 1421 EXPECT_FALSE(orig_rvh->IsFullscreen());
1352 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); 1422 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab());
1353 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1423 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1354 1424
1355 for (int i = 0; i < 2; ++i) { 1425 for (int i = 0; i < 2; ++i) {
1356 // Toggle fullscreen mode on (as if initiated via IPC from renderer). 1426 // Toggle fullscreen mode on (as if initiated via IPC from renderer).
1357 orig_rfh->OnMessageReceived( 1427 orig_rfh->OnMessageReceived(
1358 FrameHostMsg_ToggleFullscreen(orig_rfh->GetRoutingID(), true)); 1428 FrameHostMsg_ToggleFullscreen(orig_rfh->GetRoutingID(), true));
1359 EXPECT_TRUE(orig_rvh->IsFullscreen()); 1429 EXPECT_TRUE(orig_rvh->IsFullscreen());
1360 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab()); 1430 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab());
1361 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1431 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1362 1432
1363 // Navigate backward (or forward). 1433 // Navigate backward (or forward).
1364 if (i == 0) 1434 if (i == 0)
1365 controller().GoBack(); 1435 controller().GoBack();
1366 else 1436 else
1367 controller().GoForward(); 1437 controller().GoForward();
1438 entry_id = controller().GetPendingEntry()->GetUniqueID();
1368 EXPECT_FALSE(contents()->cross_navigation_pending()); 1439 EXPECT_FALSE(contents()->cross_navigation_pending());
1369 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 1440 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
1370 contents()->TestDidNavigate( 1441 contents()->TestDidNavigate(orig_rfh, i + 1, entry_id, false, url,
1371 orig_rfh, i + 1, url, ui::PAGE_TRANSITION_FORWARD_BACK); 1442 ui::PAGE_TRANSITION_FORWARD_BACK);
1372 1443
1373 // Confirm fullscreen has exited. 1444 // Confirm fullscreen has exited.
1374 EXPECT_FALSE(orig_rvh->IsFullscreen()); 1445 EXPECT_FALSE(orig_rvh->IsFullscreen());
1375 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); 1446 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab());
1376 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1447 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1377 } 1448 }
1378 1449
1379 contents()->SetDelegate(nullptr); 1450 contents()->SetDelegate(nullptr);
1380 } 1451 }
1381 1452
(...skipping 16 matching lines...) Expand all
1398 // Tests that fullscreen is exited throughout the object hierarchy on a renderer 1469 // Tests that fullscreen is exited throughout the object hierarchy on a renderer
1399 // crash. 1470 // crash.
1400 TEST_F(WebContentsImplTest, CrashExitsFullscreen) { 1471 TEST_F(WebContentsImplTest, CrashExitsFullscreen) {
1401 FakeFullscreenDelegate fake_delegate; 1472 FakeFullscreenDelegate fake_delegate;
1402 contents()->SetDelegate(&fake_delegate); 1473 contents()->SetDelegate(&fake_delegate);
1403 1474
1404 // Navigate to a site. 1475 // Navigate to a site.
1405 const GURL url("http://www.google.com"); 1476 const GURL url("http://www.google.com");
1406 controller().LoadURL( 1477 controller().LoadURL(
1407 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1478 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1408 contents()->TestDidNavigate( 1479 int entry_id = controller().GetPendingEntry()->GetUniqueID();
1409 contents()->GetMainFrame(), 1, url, ui::PAGE_TRANSITION_TYPED); 1480 contents()->TestDidNavigate(contents()->GetMainFrame(), 1, entry_id, true,
1481 url, ui::PAGE_TRANSITION_TYPED);
1410 1482
1411 // Toggle fullscreen mode on (as if initiated via IPC from renderer). 1483 // Toggle fullscreen mode on (as if initiated via IPC from renderer).
1412 EXPECT_FALSE(test_rvh()->IsFullscreen()); 1484 EXPECT_FALSE(test_rvh()->IsFullscreen());
1413 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); 1485 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab());
1414 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1486 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents()));
1415 contents()->GetMainFrame()->OnMessageReceived(FrameHostMsg_ToggleFullscreen( 1487 contents()->GetMainFrame()->OnMessageReceived(FrameHostMsg_ToggleFullscreen(
1416 contents()->GetMainFrame()->GetRoutingID(), true)); 1488 contents()->GetMainFrame()->GetRoutingID(), true));
1417 EXPECT_TRUE(test_rvh()->IsFullscreen()); 1489 EXPECT_TRUE(test_rvh()->IsFullscreen());
1418 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab()); 1490 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab());
1419 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents())); 1491 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents()));
(...skipping 15 matching lines...) Expand all
1435 // Interstitial Tests 1507 // Interstitial Tests
1436 //////////////////////////////////////////////////////////////////////////////// 1508 ////////////////////////////////////////////////////////////////////////////////
1437 1509
1438 // Test navigating to a page (with the navigation initiated from the browser, 1510 // Test navigating to a page (with the navigation initiated from the browser,
1439 // as when a URL is typed in the location bar) that shows an interstitial and 1511 // as when a URL is typed in the location bar) that shows an interstitial and
1440 // creates a new navigation entry, then hiding it without proceeding. 1512 // creates a new navigation entry, then hiding it without proceeding.
1441 TEST_F(WebContentsImplTest, 1513 TEST_F(WebContentsImplTest,
1442 ShowInterstitialFromBrowserWithNewNavigationDontProceed) { 1514 ShowInterstitialFromBrowserWithNewNavigationDontProceed) {
1443 // Navigate to a page. 1515 // Navigate to a page.
1444 GURL url1("http://www.google.com"); 1516 GURL url1("http://www.google.com");
1445 contents()->GetMainFrame()->SendNavigate(1, url1); 1517 contents()->GetMainFrame()->SendNavigate(1, 0, true, url1);
1446 EXPECT_EQ(1, controller().GetEntryCount()); 1518 EXPECT_EQ(1, controller().GetEntryCount());
1447 1519
1448 // Initiate a browser navigation that will trigger the interstitial 1520 // Initiate a browser navigation that will trigger the interstitial.
1449 controller().LoadURL(GURL("http://www.evil.com"), Referrer(), 1521 controller().LoadURL(GURL("http://www.evil.com"), Referrer(),
1450 ui::PAGE_TRANSITION_TYPED, std::string()); 1522 ui::PAGE_TRANSITION_TYPED, std::string());
1523 NavigationEntry* entry = controller().GetPendingEntry();
1451 1524
1452 // Show an interstitial. 1525 // Show an interstitial.
1453 TestInterstitialPage::InterstitialState state = 1526 TestInterstitialPage::InterstitialState state =
1454 TestInterstitialPage::INVALID; 1527 TestInterstitialPage::INVALID;
1455 bool deleted = false; 1528 bool deleted = false;
1456 GURL url2("http://interstitial"); 1529 GURL url2("http://interstitial");
1457 TestInterstitialPage* interstitial = 1530 TestInterstitialPage* interstitial =
1458 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 1531 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1459 TestInterstitialPageStateGuard state_guard(interstitial); 1532 TestInterstitialPageStateGuard state_guard(interstitial);
1460 interstitial->Show(); 1533 interstitial->Show();
1534 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1461 // The interstitial should not show until its navigation has committed. 1535 // The interstitial should not show until its navigation has committed.
1462 EXPECT_FALSE(interstitial->is_showing()); 1536 EXPECT_FALSE(interstitial->is_showing());
1463 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1537 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1464 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1538 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1465 // Let's commit the interstitial navigation. 1539 // Let's commit the interstitial navigation.
1466 interstitial->TestDidNavigate(1, url2); 1540 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url2);
1467 EXPECT_TRUE(interstitial->is_showing()); 1541 EXPECT_TRUE(interstitial->is_showing());
1468 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1542 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1469 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1543 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1470 NavigationEntry* entry = controller().GetVisibleEntry(); 1544 entry = controller().GetVisibleEntry();
1471 ASSERT_NE(nullptr, entry); 1545 ASSERT_NE(nullptr, entry);
1472 EXPECT_TRUE(entry->GetURL() == url2); 1546 EXPECT_TRUE(entry->GetURL() == url2);
1473 1547
1474 // Now don't proceed. 1548 // Now don't proceed.
1475 interstitial->DontProceed(); 1549 interstitial->DontProceed();
1476 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1550 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1477 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1551 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1478 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1552 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1479 entry = controller().GetVisibleEntry(); 1553 entry = controller().GetVisibleEntry();
1480 ASSERT_NE(nullptr, entry); 1554 ASSERT_NE(nullptr, entry);
1481 EXPECT_TRUE(entry->GetURL() == url1); 1555 EXPECT_TRUE(entry->GetURL() == url1);
1482 EXPECT_EQ(1, controller().GetEntryCount()); 1556 EXPECT_EQ(1, controller().GetEntryCount());
1483 1557
1484 RunAllPendingInMessageLoop(); 1558 RunAllPendingInMessageLoop();
1485 EXPECT_TRUE(deleted); 1559 EXPECT_TRUE(deleted);
1486 } 1560 }
1487 1561
1488 // Test navigating to a page (with the navigation initiated from the renderer, 1562 // Test navigating to a page (with the navigation initiated from the renderer,
1489 // as when clicking on a link in the page) that shows an interstitial and 1563 // as when clicking on a link in the page) that shows an interstitial and
1490 // creates a new navigation entry, then hiding it without proceeding. 1564 // creates a new navigation entry, then hiding it without proceeding.
1491 TEST_F(WebContentsImplTest, 1565 TEST_F(WebContentsImplTest,
1492 ShowInterstitiaFromRendererlWithNewNavigationDontProceed) { 1566 ShowInterstitialFromRendererWithNewNavigationDontProceed) {
1493 // Navigate to a page. 1567 // Navigate to a page.
1494 GURL url1("http://www.google.com"); 1568 GURL url1("http://www.google.com");
1495 contents()->GetMainFrame()->SendNavigate(1, url1); 1569 contents()->GetMainFrame()->SendNavigate(1, 0, true, url1);
1496 EXPECT_EQ(1, controller().GetEntryCount()); 1570 EXPECT_EQ(1, controller().GetEntryCount());
1497 1571
1498 // Show an interstitial (no pending entry, the interstitial would have been 1572 // Show an interstitial (no pending entry, the interstitial would have been
1499 // triggered by clicking on a link). 1573 // triggered by clicking on a link).
1500 TestInterstitialPage::InterstitialState state = 1574 TestInterstitialPage::InterstitialState state =
1501 TestInterstitialPage::INVALID; 1575 TestInterstitialPage::INVALID;
1502 bool deleted = false; 1576 bool deleted = false;
1503 GURL url2("http://interstitial"); 1577 GURL url2("http://interstitial");
1504 TestInterstitialPage* interstitial = 1578 TestInterstitialPage* interstitial =
1505 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 1579 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1506 TestInterstitialPageStateGuard state_guard(interstitial); 1580 TestInterstitialPageStateGuard state_guard(interstitial);
1507 interstitial->Show(); 1581 interstitial->Show();
1582 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1508 // The interstitial should not show until its navigation has committed. 1583 // The interstitial should not show until its navigation has committed.
1509 EXPECT_FALSE(interstitial->is_showing()); 1584 EXPECT_FALSE(interstitial->is_showing());
1510 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1585 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1511 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1586 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1512 // Let's commit the interstitial navigation. 1587 // Let's commit the interstitial navigation.
1513 interstitial->TestDidNavigate(1, url2); 1588 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url2);
1514 EXPECT_TRUE(interstitial->is_showing()); 1589 EXPECT_TRUE(interstitial->is_showing());
1515 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1590 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1516 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1591 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1517 NavigationEntry* entry = controller().GetVisibleEntry(); 1592 NavigationEntry* entry = controller().GetVisibleEntry();
1518 ASSERT_NE(nullptr, entry); 1593 ASSERT_NE(nullptr, entry);
1519 EXPECT_TRUE(entry->GetURL() == url2); 1594 EXPECT_TRUE(entry->GetURL() == url2);
1520 1595
1521 // Now don't proceed. 1596 // Now don't proceed.
1522 interstitial->DontProceed(); 1597 interstitial->DontProceed();
1523 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1598 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1524 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1599 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1525 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1600 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1526 entry = controller().GetVisibleEntry(); 1601 entry = controller().GetVisibleEntry();
1527 ASSERT_NE(nullptr, entry); 1602 ASSERT_NE(nullptr, entry);
1528 EXPECT_TRUE(entry->GetURL() == url1); 1603 EXPECT_TRUE(entry->GetURL() == url1);
1529 EXPECT_EQ(1, controller().GetEntryCount()); 1604 EXPECT_EQ(1, controller().GetEntryCount());
1530 1605
1531 RunAllPendingInMessageLoop(); 1606 RunAllPendingInMessageLoop();
1532 EXPECT_TRUE(deleted); 1607 EXPECT_TRUE(deleted);
1533 } 1608 }
1534 1609
1535 // Test navigating to a page that shows an interstitial without creating a new 1610 // Test navigating to a page that shows an interstitial without creating a new
1536 // navigation entry (this happens when the interstitial is triggered by a 1611 // navigation entry (this happens when the interstitial is triggered by a
1537 // sub-resource in the page), then hiding it without proceeding. 1612 // sub-resource in the page), then hiding it without proceeding.
1538 TEST_F(WebContentsImplTest, ShowInterstitialNoNewNavigationDontProceed) { 1613 TEST_F(WebContentsImplTest, ShowInterstitialNoNewNavigationDontProceed) {
1539 // Navigate to a page. 1614 // Navigate to a page.
1540 GURL url1("http://www.google.com"); 1615 GURL url1("http://www.google.com");
1541 contents()->GetMainFrame()->SendNavigate(1, url1); 1616 contents()->GetMainFrame()->SendNavigate(1, 0, true, url1);
1542 EXPECT_EQ(1, controller().GetEntryCount()); 1617 EXPECT_EQ(1, controller().GetEntryCount());
1543 1618
1544 // Show an interstitial. 1619 // Show an interstitial.
1545 TestInterstitialPage::InterstitialState state = 1620 TestInterstitialPage::InterstitialState state =
1546 TestInterstitialPage::INVALID; 1621 TestInterstitialPage::INVALID;
1547 bool deleted = false; 1622 bool deleted = false;
1548 GURL url2("http://interstitial"); 1623 GURL url2("http://interstitial");
1549 TestInterstitialPage* interstitial = 1624 TestInterstitialPage* interstitial =
1550 new TestInterstitialPage(contents(), false, url2, &state, &deleted); 1625 new TestInterstitialPage(contents(), false, url2, &state, &deleted);
1551 TestInterstitialPageStateGuard state_guard(interstitial); 1626 TestInterstitialPageStateGuard state_guard(interstitial);
1552 interstitial->Show(); 1627 interstitial->Show();
1553 // The interstitial should not show until its navigation has committed. 1628 // The interstitial should not show until its navigation has committed.
1554 EXPECT_FALSE(interstitial->is_showing()); 1629 EXPECT_FALSE(interstitial->is_showing());
1555 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1630 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1556 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1631 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1557 // Let's commit the interstitial navigation. 1632 // Let's commit the interstitial navigation.
1558 interstitial->TestDidNavigate(1, url2); 1633 interstitial->TestDidNavigate(1, 0, true, url2);
1559 EXPECT_TRUE(interstitial->is_showing()); 1634 EXPECT_TRUE(interstitial->is_showing());
1560 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1635 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1561 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1636 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1562 NavigationEntry* entry = controller().GetVisibleEntry(); 1637 NavigationEntry* entry = controller().GetVisibleEntry();
1563 ASSERT_NE(nullptr, entry); 1638 ASSERT_NE(nullptr, entry);
1564 // The URL specified to the interstitial should have been ignored. 1639 // The URL specified to the interstitial should have been ignored.
1565 EXPECT_TRUE(entry->GetURL() == url1); 1640 EXPECT_TRUE(entry->GetURL() == url1);
1566 1641
1567 // Now don't proceed. 1642 // Now don't proceed.
1568 interstitial->DontProceed(); 1643 interstitial->DontProceed();
1569 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1644 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1570 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1645 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1571 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1646 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1572 entry = controller().GetVisibleEntry(); 1647 entry = controller().GetVisibleEntry();
1573 ASSERT_NE(nullptr, entry); 1648 ASSERT_NE(nullptr, entry);
1574 EXPECT_TRUE(entry->GetURL() == url1); 1649 EXPECT_TRUE(entry->GetURL() == url1);
1575 EXPECT_EQ(1, controller().GetEntryCount()); 1650 EXPECT_EQ(1, controller().GetEntryCount());
1576 1651
1577 RunAllPendingInMessageLoop(); 1652 RunAllPendingInMessageLoop();
1578 EXPECT_TRUE(deleted); 1653 EXPECT_TRUE(deleted);
1579 } 1654 }
1580 1655
1581 // Test navigating to a page (with the navigation initiated from the browser, 1656 // Test navigating to a page (with the navigation initiated from the browser,
1582 // as when a URL is typed in the location bar) that shows an interstitial and 1657 // as when a URL is typed in the location bar) that shows an interstitial and
1583 // creates a new navigation entry, then proceeding. 1658 // creates a new navigation entry, then proceeding.
1584 TEST_F(WebContentsImplTest, 1659 TEST_F(WebContentsImplTest,
1585 ShowInterstitialFromBrowserNewNavigationProceed) { 1660 ShowInterstitialFromBrowserNewNavigationProceed) {
1586 // Navigate to a page. 1661 // Navigate to a page.
1587 GURL url1("http://www.google.com"); 1662 GURL url1("http://www.google.com");
1588 contents()->GetMainFrame()->SendNavigate(1, url1); 1663 contents()->GetMainFrame()->SendNavigate(1, 0, true, url1);
1589 EXPECT_EQ(1, controller().GetEntryCount()); 1664 EXPECT_EQ(1, controller().GetEntryCount());
1590 1665
1591 // Initiate a browser navigation that will trigger the interstitial 1666 // Initiate a browser navigation that will trigger the interstitial
1592 controller().LoadURL(GURL("http://www.evil.com"), Referrer(), 1667 controller().LoadURL(GURL("http://www.evil.com"), Referrer(),
1593 ui::PAGE_TRANSITION_TYPED, std::string()); 1668 ui::PAGE_TRANSITION_TYPED, std::string());
1594 1669
1595 // Show an interstitial. 1670 // Show an interstitial.
1596 TestInterstitialPage::InterstitialState state = 1671 TestInterstitialPage::InterstitialState state =
1597 TestInterstitialPage::INVALID; 1672 TestInterstitialPage::INVALID;
1598 bool deleted = false; 1673 bool deleted = false;
1599 GURL url2("http://interstitial"); 1674 GURL url2("http://interstitial");
1600 TestInterstitialPage* interstitial = 1675 TestInterstitialPage* interstitial =
1601 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 1676 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1602 TestInterstitialPageStateGuard state_guard(interstitial); 1677 TestInterstitialPageStateGuard state_guard(interstitial);
1603 interstitial->Show(); 1678 interstitial->Show();
1679 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1604 // The interstitial should not show until its navigation has committed. 1680 // The interstitial should not show until its navigation has committed.
1605 EXPECT_FALSE(interstitial->is_showing()); 1681 EXPECT_FALSE(interstitial->is_showing());
1606 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1682 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1607 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1683 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1608 // Let's commit the interstitial navigation. 1684 // Let's commit the interstitial navigation.
1609 interstitial->TestDidNavigate(1, url2); 1685 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url2);
1610 EXPECT_TRUE(interstitial->is_showing()); 1686 EXPECT_TRUE(interstitial->is_showing());
1611 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1687 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1612 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1688 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1613 NavigationEntry* entry = controller().GetVisibleEntry(); 1689 NavigationEntry* entry = controller().GetVisibleEntry();
1614 ASSERT_NE(nullptr, entry); 1690 ASSERT_NE(nullptr, entry);
1615 EXPECT_TRUE(entry->GetURL() == url2); 1691 EXPECT_TRUE(entry->GetURL() == url2);
1616 1692
1617 // Then proceed. 1693 // Then proceed.
1618 interstitial->Proceed(); 1694 interstitial->Proceed();
1619 // The interstitial should show until the new navigation commits. 1695 // The interstitial should show until the new navigation commits.
1620 RunAllPendingInMessageLoop(); 1696 RunAllPendingInMessageLoop();
1621 ASSERT_FALSE(deleted); 1697 ASSERT_FALSE(deleted);
1622 EXPECT_EQ(TestInterstitialPage::OKED, state); 1698 EXPECT_EQ(TestInterstitialPage::OKED, state);
1623 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1699 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1624 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1700 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1625 1701
1626 // Simulate the navigation to the page, that's when the interstitial gets 1702 // Simulate the navigation to the page, that's when the interstitial gets
1627 // hidden. 1703 // hidden.
1628 GURL url3("http://www.thepage.com"); 1704 GURL url3("http://www.thepage.com");
1629 contents()->GetMainFrame()->SendNavigate(2, url3); 1705 contents()->GetMainFrame()->SendNavigate(2, 0, true, url3);
1630 1706
1631 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1707 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1632 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1708 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1633 entry = controller().GetVisibleEntry(); 1709 entry = controller().GetVisibleEntry();
1634 ASSERT_NE(nullptr, entry); 1710 ASSERT_NE(nullptr, entry);
1635 EXPECT_TRUE(entry->GetURL() == url3); 1711 EXPECT_TRUE(entry->GetURL() == url3);
1636 1712
1637 EXPECT_EQ(2, controller().GetEntryCount()); 1713 EXPECT_EQ(2, controller().GetEntryCount());
1638 1714
1639 RunAllPendingInMessageLoop(); 1715 RunAllPendingInMessageLoop();
1640 EXPECT_TRUE(deleted); 1716 EXPECT_TRUE(deleted);
1641 } 1717 }
1642 1718
1643 // Test navigating to a page (with the navigation initiated from the renderer, 1719 // Test navigating to a page (with the navigation initiated from the renderer,
1644 // as when clicking on a link in the page) that shows an interstitial and 1720 // as when clicking on a link in the page) that shows an interstitial and
1645 // creates a new navigation entry, then proceeding. 1721 // creates a new navigation entry, then proceeding.
1646 TEST_F(WebContentsImplTest, 1722 TEST_F(WebContentsImplTest,
1647 ShowInterstitialFromRendererNewNavigationProceed) { 1723 ShowInterstitialFromRendererNewNavigationProceed) {
1648 // Navigate to a page. 1724 // Navigate to a page.
1649 GURL url1("http://www.google.com"); 1725 GURL url1("http://www.google.com");
1650 contents()->GetMainFrame()->SendNavigate(1, url1); 1726 contents()->GetMainFrame()->SendNavigate(1, 0, true, url1);
1651 EXPECT_EQ(1, controller().GetEntryCount()); 1727 EXPECT_EQ(1, controller().GetEntryCount());
1652 1728
1653 // Show an interstitial. 1729 // Show an interstitial.
1654 TestInterstitialPage::InterstitialState state = 1730 TestInterstitialPage::InterstitialState state =
1655 TestInterstitialPage::INVALID; 1731 TestInterstitialPage::INVALID;
1656 bool deleted = false; 1732 bool deleted = false;
1657 GURL url2("http://interstitial"); 1733 GURL url2("http://interstitial");
1658 TestInterstitialPage* interstitial = 1734 TestInterstitialPage* interstitial =
1659 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 1735 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1660 TestInterstitialPageStateGuard state_guard(interstitial); 1736 TestInterstitialPageStateGuard state_guard(interstitial);
1661 interstitial->Show(); 1737 interstitial->Show();
1738 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1662 // The interstitial should not show until its navigation has committed. 1739 // The interstitial should not show until its navigation has committed.
1663 EXPECT_FALSE(interstitial->is_showing()); 1740 EXPECT_FALSE(interstitial->is_showing());
1664 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1741 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1665 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1742 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1666 // Let's commit the interstitial navigation. 1743 // Let's commit the interstitial navigation.
1667 interstitial->TestDidNavigate(1, url2); 1744 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url2);
1668 EXPECT_TRUE(interstitial->is_showing()); 1745 EXPECT_TRUE(interstitial->is_showing());
1669 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1746 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1670 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1747 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1671 NavigationEntry* entry = controller().GetVisibleEntry(); 1748 NavigationEntry* entry = controller().GetVisibleEntry();
1672 ASSERT_NE(nullptr, entry); 1749 ASSERT_NE(nullptr, entry);
1673 EXPECT_TRUE(entry->GetURL() == url2); 1750 EXPECT_TRUE(entry->GetURL() == url2);
1674 1751
1675 // Then proceed. 1752 // Then proceed.
1676 interstitial->Proceed(); 1753 interstitial->Proceed();
1677 // The interstitial should show until the new navigation commits. 1754 // The interstitial should show until the new navigation commits.
1678 RunAllPendingInMessageLoop(); 1755 RunAllPendingInMessageLoop();
1679 ASSERT_FALSE(deleted); 1756 ASSERT_FALSE(deleted);
1680 EXPECT_EQ(TestInterstitialPage::OKED, state); 1757 EXPECT_EQ(TestInterstitialPage::OKED, state);
1681 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1758 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1682 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1759 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1683 1760
1684 // Simulate the navigation to the page, that's when the interstitial gets 1761 // Simulate the navigation to the page, that's when the interstitial gets
1685 // hidden. 1762 // hidden.
1686 GURL url3("http://www.thepage.com"); 1763 GURL url3("http://www.thepage.com");
1687 contents()->GetMainFrame()->SendNavigate(2, url3); 1764 contents()->GetMainFrame()->SendNavigate(2, 0, true, url3);
1688 1765
1689 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1766 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1690 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1767 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1691 entry = controller().GetVisibleEntry(); 1768 entry = controller().GetVisibleEntry();
1692 ASSERT_NE(nullptr, entry); 1769 ASSERT_NE(nullptr, entry);
1693 EXPECT_TRUE(entry->GetURL() == url3); 1770 EXPECT_TRUE(entry->GetURL() == url3);
1694 1771
1695 EXPECT_EQ(2, controller().GetEntryCount()); 1772 EXPECT_EQ(2, controller().GetEntryCount());
1696 1773
1697 RunAllPendingInMessageLoop(); 1774 RunAllPendingInMessageLoop();
1698 EXPECT_TRUE(deleted); 1775 EXPECT_TRUE(deleted);
1699 } 1776 }
1700 1777
1701 // Test navigating to a page that shows an interstitial without creating a new 1778 // Test navigating to a page that shows an interstitial without creating a new
1702 // navigation entry (this happens when the interstitial is triggered by a 1779 // navigation entry (this happens when the interstitial is triggered by a
1703 // sub-resource in the page), then proceeding. 1780 // sub-resource in the page), then proceeding.
1704 TEST_F(WebContentsImplTest, ShowInterstitialNoNewNavigationProceed) { 1781 TEST_F(WebContentsImplTest, ShowInterstitialNoNewNavigationProceed) {
1705 // Navigate to a page so we have a navigation entry in the controller. 1782 // Navigate to a page so we have a navigation entry in the controller.
1706 GURL url1("http://www.google.com"); 1783 GURL url1("http://www.google.com");
1707 contents()->GetMainFrame()->SendNavigate(1, url1); 1784 contents()->GetMainFrame()->SendNavigate(1, 0, true, url1);
1708 EXPECT_EQ(1, controller().GetEntryCount()); 1785 EXPECT_EQ(1, controller().GetEntryCount());
1709 1786
1710 // Show an interstitial. 1787 // Show an interstitial.
1711 TestInterstitialPage::InterstitialState state = 1788 TestInterstitialPage::InterstitialState state =
1712 TestInterstitialPage::INVALID; 1789 TestInterstitialPage::INVALID;
1713 bool deleted = false; 1790 bool deleted = false;
1714 GURL url2("http://interstitial"); 1791 GURL url2("http://interstitial");
1715 TestInterstitialPage* interstitial = 1792 TestInterstitialPage* interstitial =
1716 new TestInterstitialPage(contents(), false, url2, &state, &deleted); 1793 new TestInterstitialPage(contents(), false, url2, &state, &deleted);
1717 TestInterstitialPageStateGuard state_guard(interstitial); 1794 TestInterstitialPageStateGuard state_guard(interstitial);
1718 interstitial->Show(); 1795 interstitial->Show();
1719 // The interstitial should not show until its navigation has committed. 1796 // The interstitial should not show until its navigation has committed.
1720 EXPECT_FALSE(interstitial->is_showing()); 1797 EXPECT_FALSE(interstitial->is_showing());
1721 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1798 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1722 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1799 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1723 // Let's commit the interstitial navigation. 1800 // Let's commit the interstitial navigation.
1724 interstitial->TestDidNavigate(1, url2); 1801 interstitial->TestDidNavigate(1, 0, true, url2);
1725 EXPECT_TRUE(interstitial->is_showing()); 1802 EXPECT_TRUE(interstitial->is_showing());
1726 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1803 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1727 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1804 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1728 NavigationEntry* entry = controller().GetVisibleEntry(); 1805 NavigationEntry* entry = controller().GetVisibleEntry();
1729 ASSERT_NE(nullptr, entry); 1806 ASSERT_NE(nullptr, entry);
1730 // The URL specified to the interstitial should have been ignored. 1807 // The URL specified to the interstitial should have been ignored.
1731 EXPECT_TRUE(entry->GetURL() == url1); 1808 EXPECT_TRUE(entry->GetURL() == url1);
1732 1809
1733 // Then proceed. 1810 // Then proceed.
1734 interstitial->Proceed(); 1811 interstitial->Proceed();
(...skipping 16 matching lines...) Expand all
1751 TEST_F(WebContentsImplTest, ShowInterstitialThenNavigate) { 1828 TEST_F(WebContentsImplTest, ShowInterstitialThenNavigate) {
1752 // Show interstitial. 1829 // Show interstitial.
1753 TestInterstitialPage::InterstitialState state = 1830 TestInterstitialPage::InterstitialState state =
1754 TestInterstitialPage::INVALID; 1831 TestInterstitialPage::INVALID;
1755 bool deleted = false; 1832 bool deleted = false;
1756 GURL url("http://interstitial"); 1833 GURL url("http://interstitial");
1757 TestInterstitialPage* interstitial = 1834 TestInterstitialPage* interstitial =
1758 new TestInterstitialPage(contents(), true, url, &state, &deleted); 1835 new TestInterstitialPage(contents(), true, url, &state, &deleted);
1759 TestInterstitialPageStateGuard state_guard(interstitial); 1836 TestInterstitialPageStateGuard state_guard(interstitial);
1760 interstitial->Show(); 1837 interstitial->Show();
1761 interstitial->TestDidNavigate(1, url); 1838 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1839 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url);
1762 1840
1763 // While interstitial showing, navigate to a new URL. 1841 // While interstitial showing, navigate to a new URL.
1764 const GURL url2("http://www.yahoo.com"); 1842 const GURL url2("http://www.yahoo.com");
1765 contents()->GetMainFrame()->SendNavigate(1, url2); 1843 contents()->GetMainFrame()->SendNavigate(1, 1, true, url2);
1766 1844
1767 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1845 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1768 1846
1769 RunAllPendingInMessageLoop(); 1847 RunAllPendingInMessageLoop();
1770 EXPECT_TRUE(deleted); 1848 EXPECT_TRUE(deleted);
1771 } 1849 }
1772 1850
1773 // Test navigating to a page that shows an interstitial, then going back. 1851 // Test navigating to a page that shows an interstitial, then going back.
1774 TEST_F(WebContentsImplTest, ShowInterstitialThenGoBack) { 1852 TEST_F(WebContentsImplTest, ShowInterstitialThenGoBack) {
1775 // Navigate to a page so we have a navigation entry in the controller. 1853 // Navigate to a page so we have a navigation entry in the controller.
1776 GURL url1("http://www.google.com"); 1854 GURL url1("http://www.google.com");
1777 contents()->GetMainFrame()->SendNavigate(1, url1); 1855 contents()->GetMainFrame()->SendNavigate(1, 0, true, url1);
1778 EXPECT_EQ(1, controller().GetEntryCount()); 1856 EXPECT_EQ(1, controller().GetEntryCount());
1857 NavigationEntry* entry = controller().GetLastCommittedEntry();
1779 1858
1780 // Show interstitial. 1859 // Show interstitial.
1781 TestInterstitialPage::InterstitialState state = 1860 TestInterstitialPage::InterstitialState state =
1782 TestInterstitialPage::INVALID; 1861 TestInterstitialPage::INVALID;
1783 bool deleted = false; 1862 bool deleted = false;
1784 GURL interstitial_url("http://interstitial"); 1863 GURL interstitial_url("http://interstitial");
1785 TestInterstitialPage* interstitial = 1864 TestInterstitialPage* interstitial =
1786 new TestInterstitialPage(contents(), true, interstitial_url, 1865 new TestInterstitialPage(contents(), true, interstitial_url,
1787 &state, &deleted); 1866 &state, &deleted);
1788 TestInterstitialPageStateGuard state_guard(interstitial); 1867 TestInterstitialPageStateGuard state_guard(interstitial);
1789 interstitial->Show(); 1868 interstitial->Show();
1790 interstitial->TestDidNavigate(2, interstitial_url); 1869 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1870 interstitial->TestDidNavigate(2, interstitial_entry_id, true,
1871 interstitial_url);
1791 1872
1792 // While the interstitial is showing, go back. 1873 // While the interstitial is showing, go back.
1793 controller().GoBack(); 1874 controller().GoBack();
1794 contents()->GetMainFrame()->SendNavigate(1, url1); 1875 contents()->GetMainFrame()->SendNavigate(1, entry->GetUniqueID(), false,
1876 url1);
1795 1877
1796 // Make sure we are back to the original page and that the interstitial is 1878 // Make sure we are back to the original page and that the interstitial is
1797 // gone. 1879 // gone.
1798 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1880 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1799 NavigationEntry* entry = controller().GetVisibleEntry(); 1881 entry = controller().GetVisibleEntry();
1800 ASSERT_TRUE(entry); 1882 ASSERT_TRUE(entry);
1801 EXPECT_EQ(url1.spec(), entry->GetURL().spec()); 1883 EXPECT_EQ(url1.spec(), entry->GetURL().spec());
1802 1884
1803 RunAllPendingInMessageLoop(); 1885 RunAllPendingInMessageLoop();
1804 EXPECT_TRUE(deleted); 1886 EXPECT_TRUE(deleted);
1805 } 1887 }
1806 1888
1807 // Test navigating to a page that shows an interstitial, has a renderer crash, 1889 // Test navigating to a page that shows an interstitial, has a renderer crash,
1808 // and then goes back. 1890 // and then goes back.
1809 TEST_F(WebContentsImplTest, ShowInterstitialCrashRendererThenGoBack) { 1891 TEST_F(WebContentsImplTest, ShowInterstitialCrashRendererThenGoBack) {
1810 // Navigate to a page so we have a navigation entry in the controller. 1892 // Navigate to a page so we have a navigation entry in the controller.
1811 GURL url1("http://www.google.com"); 1893 GURL url1("http://www.google.com");
1812 contents()->GetMainFrame()->SendNavigate(1, url1); 1894 contents()->GetMainFrame()->SendNavigate(1, 0, true, url1);
1813 EXPECT_EQ(1, controller().GetEntryCount()); 1895 EXPECT_EQ(1, controller().GetEntryCount());
1896 NavigationEntry* entry = controller().GetLastCommittedEntry();
1814 1897
1815 // Show interstitial. 1898 // Show interstitial.
1816 TestInterstitialPage::InterstitialState state = 1899 TestInterstitialPage::InterstitialState state =
1817 TestInterstitialPage::INVALID; 1900 TestInterstitialPage::INVALID;
1818 bool deleted = false; 1901 bool deleted = false;
1819 GURL interstitial_url("http://interstitial"); 1902 GURL interstitial_url("http://interstitial");
1820 TestInterstitialPage* interstitial = 1903 TestInterstitialPage* interstitial =
1821 new TestInterstitialPage(contents(), true, interstitial_url, 1904 new TestInterstitialPage(contents(), true, interstitial_url,
1822 &state, &deleted); 1905 &state, &deleted);
1823 TestInterstitialPageStateGuard state_guard(interstitial); 1906 TestInterstitialPageStateGuard state_guard(interstitial);
1824 interstitial->Show(); 1907 interstitial->Show();
1825 interstitial->TestDidNavigate(2, interstitial_url); 1908 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1909 interstitial->TestDidNavigate(2, interstitial_entry_id, true,
1910 interstitial_url);
1826 1911
1827 // Crash the renderer 1912 // Crash the renderer
1828 main_rfh()->OnMessageReceived( 1913 main_rfh()->OnMessageReceived(
1829 FrameHostMsg_RenderProcessGone( 1914 FrameHostMsg_RenderProcessGone(
1830 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1)); 1915 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1));
1831 1916
1832 // While the interstitial is showing, go back. 1917 // While the interstitial is showing, go back.
1833 controller().GoBack(); 1918 controller().GoBack();
1834 contents()->GetMainFrame()->SendNavigate(1, url1); 1919 contents()->GetMainFrame()->SendNavigate(1, entry->GetUniqueID(), false,
1920 url1);
1835 1921
1836 // Make sure we are back to the original page and that the interstitial is 1922 // Make sure we are back to the original page and that the interstitial is
1837 // gone. 1923 // gone.
1838 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1924 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1839 NavigationEntry* entry = controller().GetVisibleEntry(); 1925 entry = controller().GetVisibleEntry();
1840 ASSERT_TRUE(entry); 1926 ASSERT_TRUE(entry);
1841 EXPECT_EQ(url1.spec(), entry->GetURL().spec()); 1927 EXPECT_EQ(url1.spec(), entry->GetURL().spec());
1842 1928
1843 RunAllPendingInMessageLoop(); 1929 RunAllPendingInMessageLoop();
1844 EXPECT_TRUE(deleted); 1930 EXPECT_TRUE(deleted);
1845 } 1931 }
1846 1932
1847 // Test navigating to a page that shows an interstitial, has the renderer crash, 1933 // Test navigating to a page that shows an interstitial, has the renderer crash,
1848 // and then navigates to the interstitial. 1934 // and then navigates to the interstitial.
1849 TEST_F(WebContentsImplTest, ShowInterstitialCrashRendererThenNavigate) { 1935 TEST_F(WebContentsImplTest, ShowInterstitialCrashRendererThenNavigate) {
1850 // Navigate to a page so we have a navigation entry in the controller. 1936 // Navigate to a page so we have a navigation entry in the controller.
1851 GURL url1("http://www.google.com"); 1937 GURL url1("http://www.google.com");
1852 contents()->GetMainFrame()->SendNavigate(1, url1); 1938 contents()->GetMainFrame()->SendNavigate(1, 0, true, url1);
1853 EXPECT_EQ(1, controller().GetEntryCount()); 1939 EXPECT_EQ(1, controller().GetEntryCount());
1854 1940
1855 // Show interstitial. 1941 // Show interstitial.
1856 TestInterstitialPage::InterstitialState state = 1942 TestInterstitialPage::InterstitialState state =
1857 TestInterstitialPage::INVALID; 1943 TestInterstitialPage::INVALID;
1858 bool deleted = false; 1944 bool deleted = false;
1859 GURL interstitial_url("http://interstitial"); 1945 GURL interstitial_url("http://interstitial");
1860 TestInterstitialPage* interstitial = 1946 TestInterstitialPage* interstitial =
1861 new TestInterstitialPage(contents(), true, interstitial_url, 1947 new TestInterstitialPage(contents(), true, interstitial_url,
1862 &state, &deleted); 1948 &state, &deleted);
1863 TestInterstitialPageStateGuard state_guard(interstitial); 1949 TestInterstitialPageStateGuard state_guard(interstitial);
1864 interstitial->Show(); 1950 interstitial->Show();
1951 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1865 1952
1866 // Crash the renderer 1953 // Crash the renderer
1867 main_rfh()->OnMessageReceived( 1954 main_rfh()->OnMessageReceived(
1868 FrameHostMsg_RenderProcessGone( 1955 FrameHostMsg_RenderProcessGone(
1869 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1)); 1956 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1));
1870 1957
1871 interstitial->TestDidNavigate(2, interstitial_url); 1958 interstitial->TestDidNavigate(2, interstitial_entry_id, true,
1959 interstitial_url);
1872 } 1960 }
1873 1961
1874 // Test navigating to a page that shows an interstitial, then close the 1962 // Test navigating to a page that shows an interstitial, then close the
1875 // contents. 1963 // contents.
1876 TEST_F(WebContentsImplTest, ShowInterstitialThenCloseTab) { 1964 TEST_F(WebContentsImplTest, ShowInterstitialThenCloseTab) {
1877 // Show interstitial. 1965 // Show interstitial.
1878 TestInterstitialPage::InterstitialState state = 1966 TestInterstitialPage::InterstitialState state =
1879 TestInterstitialPage::INVALID; 1967 TestInterstitialPage::INVALID;
1880 bool deleted = false; 1968 bool deleted = false;
1881 GURL url("http://interstitial"); 1969 GURL url("http://interstitial");
1882 TestInterstitialPage* interstitial = 1970 TestInterstitialPage* interstitial =
1883 new TestInterstitialPage(contents(), true, url, &state, &deleted); 1971 new TestInterstitialPage(contents(), true, url, &state, &deleted);
1884 TestInterstitialPageStateGuard state_guard(interstitial); 1972 TestInterstitialPageStateGuard state_guard(interstitial);
1885 interstitial->Show(); 1973 interstitial->Show();
1886 interstitial->TestDidNavigate(1, url); 1974 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1975 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url);
1887 1976
1888 // Now close the contents. 1977 // Now close the contents.
1889 DeleteContents(); 1978 DeleteContents();
1890 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1979 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1891 1980
1892 RunAllPendingInMessageLoop(); 1981 RunAllPendingInMessageLoop();
1893 EXPECT_TRUE(deleted); 1982 EXPECT_TRUE(deleted);
1894 } 1983 }
1895 1984
1896 // Test navigating to a page that shows an interstitial, then close the 1985 // Test navigating to a page that shows an interstitial, then close the
1897 // contents. 1986 // contents.
1898 TEST_F(WebContentsImplTest, ShowInterstitialThenCloseAndShutdown) { 1987 TEST_F(WebContentsImplTest, ShowInterstitialThenCloseAndShutdown) {
1899 // Show interstitial. 1988 // Show interstitial.
1900 TestInterstitialPage::InterstitialState state = 1989 TestInterstitialPage::InterstitialState state =
1901 TestInterstitialPage::INVALID; 1990 TestInterstitialPage::INVALID;
1902 bool deleted = false; 1991 bool deleted = false;
1903 GURL url("http://interstitial"); 1992 GURL url("http://interstitial");
1904 TestInterstitialPage* interstitial = 1993 TestInterstitialPage* interstitial =
1905 new TestInterstitialPage(contents(), true, url, &state, &deleted); 1994 new TestInterstitialPage(contents(), true, url, &state, &deleted);
1906 TestInterstitialPageStateGuard state_guard(interstitial); 1995 TestInterstitialPageStateGuard state_guard(interstitial);
1907 interstitial->Show(); 1996 interstitial->Show();
1908 interstitial->TestDidNavigate(1, url); 1997 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1998 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url);
1909 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 1999 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
1910 interstitial->GetMainFrame()->GetRenderViewHost()); 2000 interstitial->GetMainFrame()->GetRenderViewHost());
1911 2001
1912 // Now close the contents. 2002 // Now close the contents.
1913 DeleteContents(); 2003 DeleteContents();
1914 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 2004 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1915 2005
1916 // Before the interstitial has a chance to process its shutdown task, 2006 // Before the interstitial has a chance to process its shutdown task,
1917 // simulate quitting the browser. This goes through all processes and 2007 // simulate quitting the browser. This goes through all processes and
1918 // tells them to destruct. 2008 // tells them to destruct.
1919 rvh->GetMainFrame()->OnMessageReceived( 2009 rvh->GetMainFrame()->OnMessageReceived(
1920 FrameHostMsg_RenderProcessGone(0, 0, 0)); 2010 FrameHostMsg_RenderProcessGone(0, 0, 0));
1921 2011
1922 RunAllPendingInMessageLoop(); 2012 RunAllPendingInMessageLoop();
1923 EXPECT_TRUE(deleted); 2013 EXPECT_TRUE(deleted);
1924 } 2014 }
1925 2015
1926 // Test that after Proceed is called and an interstitial is still shown, no more 2016 // Test that after Proceed is called and an interstitial is still shown, no more
1927 // commands get executed. 2017 // commands get executed.
1928 TEST_F(WebContentsImplTest, ShowInterstitialProceedMultipleCommands) { 2018 TEST_F(WebContentsImplTest, ShowInterstitialProceedMultipleCommands) {
1929 // Navigate to a page so we have a navigation entry in the controller. 2019 // Navigate to a page so we have a navigation entry in the controller.
1930 GURL url1("http://www.google.com"); 2020 GURL url1("http://www.google.com");
1931 contents()->GetMainFrame()->SendNavigate(1, url1); 2021 contents()->GetMainFrame()->SendNavigate(1, 0, true, url1);
1932 EXPECT_EQ(1, controller().GetEntryCount()); 2022 EXPECT_EQ(1, controller().GetEntryCount());
1933 2023
1934 // Show an interstitial. 2024 // Show an interstitial.
1935 TestInterstitialPage::InterstitialState state = 2025 TestInterstitialPage::InterstitialState state =
1936 TestInterstitialPage::INVALID; 2026 TestInterstitialPage::INVALID;
1937 bool deleted = false; 2027 bool deleted = false;
1938 GURL url2("http://interstitial"); 2028 GURL url2("http://interstitial");
1939 TestInterstitialPage* interstitial = 2029 TestInterstitialPage* interstitial =
1940 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 2030 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1941 TestInterstitialPageStateGuard state_guard(interstitial); 2031 TestInterstitialPageStateGuard state_guard(interstitial);
1942 interstitial->Show(); 2032 interstitial->Show();
1943 interstitial->TestDidNavigate(1, url2); 2033 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2034 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url2);
1944 2035
1945 // Run a command. 2036 // Run a command.
1946 EXPECT_EQ(0, interstitial->command_received_count()); 2037 EXPECT_EQ(0, interstitial->command_received_count());
1947 interstitial->TestDomOperationResponse("toto"); 2038 interstitial->TestDomOperationResponse("toto");
1948 EXPECT_EQ(1, interstitial->command_received_count()); 2039 EXPECT_EQ(1, interstitial->command_received_count());
1949 2040
1950 // Then proceed. 2041 // Then proceed.
1951 interstitial->Proceed(); 2042 interstitial->Proceed();
1952 RunAllPendingInMessageLoop(); 2043 RunAllPendingInMessageLoop();
1953 ASSERT_FALSE(deleted); 2044 ASSERT_FALSE(deleted);
1954 2045
1955 // While the navigation to the new page is pending, send other commands, they 2046 // While the navigation to the new page is pending, send other commands, they
1956 // should be ignored. 2047 // should be ignored.
1957 interstitial->TestDomOperationResponse("hello"); 2048 interstitial->TestDomOperationResponse("hello");
1958 interstitial->TestDomOperationResponse("hi"); 2049 interstitial->TestDomOperationResponse("hi");
1959 EXPECT_EQ(1, interstitial->command_received_count()); 2050 EXPECT_EQ(1, interstitial->command_received_count());
1960 } 2051 }
1961 2052
1962 // Test showing an interstitial while another interstitial is already showing. 2053 // Test showing an interstitial while another interstitial is already showing.
1963 TEST_F(WebContentsImplTest, ShowInterstitialOnInterstitial) { 2054 TEST_F(WebContentsImplTest, ShowInterstitialOnInterstitial) {
1964 // Navigate to a page so we have a navigation entry in the controller. 2055 // Navigate to a page so we have a navigation entry in the controller.
1965 GURL start_url("http://www.google.com"); 2056 GURL start_url("http://www.google.com");
1966 contents()->GetMainFrame()->SendNavigate(1, start_url); 2057 contents()->GetMainFrame()->SendNavigate(1, 0, true, start_url);
1967 EXPECT_EQ(1, controller().GetEntryCount()); 2058 EXPECT_EQ(1, controller().GetEntryCount());
1968 2059
1969 // Show an interstitial. 2060 // Show an interstitial.
1970 TestInterstitialPage::InterstitialState state1 = 2061 TestInterstitialPage::InterstitialState state1 =
1971 TestInterstitialPage::INVALID; 2062 TestInterstitialPage::INVALID;
1972 bool deleted1 = false; 2063 bool deleted1 = false;
1973 GURL url1("http://interstitial1"); 2064 GURL url1("http://interstitial1");
1974 TestInterstitialPage* interstitial1 = 2065 TestInterstitialPage* interstitial1 =
1975 new TestInterstitialPage(contents(), true, url1, &state1, &deleted1); 2066 new TestInterstitialPage(contents(), true, url1, &state1, &deleted1);
1976 TestInterstitialPageStateGuard state_guard1(interstitial1); 2067 TestInterstitialPageStateGuard state_guard1(interstitial1);
1977 interstitial1->Show(); 2068 interstitial1->Show();
1978 interstitial1->TestDidNavigate(1, url1); 2069 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2070 interstitial1->TestDidNavigate(1, interstitial_entry_id, true, url1);
1979 2071
1980 // Now show another interstitial. 2072 // Now show another interstitial.
1981 TestInterstitialPage::InterstitialState state2 = 2073 TestInterstitialPage::InterstitialState state2 =
1982 TestInterstitialPage::INVALID; 2074 TestInterstitialPage::INVALID;
1983 bool deleted2 = false; 2075 bool deleted2 = false;
1984 GURL url2("http://interstitial2"); 2076 GURL url2("http://interstitial2");
1985 TestInterstitialPage* interstitial2 = 2077 TestInterstitialPage* interstitial2 =
1986 new TestInterstitialPage(contents(), true, url2, &state2, &deleted2); 2078 new TestInterstitialPage(contents(), true, url2, &state2, &deleted2);
1987 TestInterstitialPageStateGuard state_guard2(interstitial2); 2079 TestInterstitialPageStateGuard state_guard2(interstitial2);
1988 interstitial2->Show(); 2080 interstitial2->Show();
1989 interstitial2->TestDidNavigate(1, url2); 2081 interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2082 interstitial2->TestDidNavigate(1, interstitial_entry_id, true, url2);
1990 2083
1991 // Showing interstitial2 should have caused interstitial1 to go away. 2084 // Showing interstitial2 should have caused interstitial1 to go away.
1992 EXPECT_EQ(TestInterstitialPage::CANCELED, state1); 2085 EXPECT_EQ(TestInterstitialPage::CANCELED, state1);
1993 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); 2086 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2);
1994 2087
1995 RunAllPendingInMessageLoop(); 2088 RunAllPendingInMessageLoop();
1996 EXPECT_TRUE(deleted1); 2089 EXPECT_TRUE(deleted1);
1997 ASSERT_FALSE(deleted2); 2090 ASSERT_FALSE(deleted2);
1998 2091
1999 // Let's make sure interstitial2 is working as intended. 2092 // Let's make sure interstitial2 is working as intended.
2000 interstitial2->Proceed(); 2093 interstitial2->Proceed();
2001 GURL landing_url("http://www.thepage.com"); 2094 GURL landing_url("http://www.thepage.com");
2002 contents()->GetMainFrame()->SendNavigate(2, landing_url); 2095 contents()->GetMainFrame()->SendNavigate(2, 0, true, landing_url);
2003 2096
2004 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 2097 EXPECT_FALSE(contents()->ShowingInterstitialPage());
2005 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 2098 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
2006 NavigationEntry* entry = controller().GetVisibleEntry(); 2099 NavigationEntry* entry = controller().GetVisibleEntry();
2007 ASSERT_NE(nullptr, entry); 2100 ASSERT_NE(nullptr, entry);
2008 EXPECT_TRUE(entry->GetURL() == landing_url); 2101 EXPECT_TRUE(entry->GetURL() == landing_url);
2009 EXPECT_EQ(2, controller().GetEntryCount()); 2102 EXPECT_EQ(2, controller().GetEntryCount());
2010 RunAllPendingInMessageLoop(); 2103 RunAllPendingInMessageLoop();
2011 EXPECT_TRUE(deleted2); 2104 EXPECT_TRUE(deleted2);
2012 } 2105 }
2013 2106
2014 // Test showing an interstitial, proceeding and then navigating to another 2107 // Test showing an interstitial, proceeding and then navigating to another
2015 // interstitial. 2108 // interstitial.
2016 TEST_F(WebContentsImplTest, ShowInterstitialProceedShowInterstitial) { 2109 TEST_F(WebContentsImplTest, ShowInterstitialProceedShowInterstitial) {
2017 // Navigate to a page so we have a navigation entry in the controller. 2110 // Navigate to a page so we have a navigation entry in the controller.
2018 GURL start_url("http://www.google.com"); 2111 GURL start_url("http://www.google.com");
2019 contents()->GetMainFrame()->SendNavigate(1, start_url); 2112 contents()->GetMainFrame()->SendNavigate(1, 0, true, start_url);
2020 EXPECT_EQ(1, controller().GetEntryCount()); 2113 EXPECT_EQ(1, controller().GetEntryCount());
2021 2114
2022 // Show an interstitial. 2115 // Show an interstitial.
2023 TestInterstitialPage::InterstitialState state1 = 2116 TestInterstitialPage::InterstitialState state1 =
2024 TestInterstitialPage::INVALID; 2117 TestInterstitialPage::INVALID;
2025 bool deleted1 = false; 2118 bool deleted1 = false;
2026 GURL url1("http://interstitial1"); 2119 GURL url1("http://interstitial1");
2027 TestInterstitialPage* interstitial1 = 2120 TestInterstitialPage* interstitial1 =
2028 new TestInterstitialPage(contents(), true, url1, &state1, &deleted1); 2121 new TestInterstitialPage(contents(), true, url1, &state1, &deleted1);
2029 TestInterstitialPageStateGuard state_guard1(interstitial1); 2122 TestInterstitialPageStateGuard state_guard1(interstitial1);
2030 interstitial1->Show(); 2123 interstitial1->Show();
2031 interstitial1->TestDidNavigate(1, url1); 2124 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2125 interstitial1->TestDidNavigate(1, interstitial_entry_id, true, url1);
2032 2126
2033 // Take action. The interstitial won't be hidden until the navigation is 2127 // Take action. The interstitial won't be hidden until the navigation is
2034 // committed. 2128 // committed.
2035 interstitial1->Proceed(); 2129 interstitial1->Proceed();
2036 EXPECT_EQ(TestInterstitialPage::OKED, state1); 2130 EXPECT_EQ(TestInterstitialPage::OKED, state1);
2037 2131
2038 // Now show another interstitial (simulating the navigation causing another 2132 // Now show another interstitial (simulating the navigation causing another
2039 // interstitial). 2133 // interstitial).
2040 TestInterstitialPage::InterstitialState state2 = 2134 TestInterstitialPage::InterstitialState state2 =
2041 TestInterstitialPage::INVALID; 2135 TestInterstitialPage::INVALID;
2042 bool deleted2 = false; 2136 bool deleted2 = false;
2043 GURL url2("http://interstitial2"); 2137 GURL url2("http://interstitial2");
2044 TestInterstitialPage* interstitial2 = 2138 TestInterstitialPage* interstitial2 =
2045 new TestInterstitialPage(contents(), true, url2, &state2, &deleted2); 2139 new TestInterstitialPage(contents(), true, url2, &state2, &deleted2);
2046 TestInterstitialPageStateGuard state_guard2(interstitial2); 2140 TestInterstitialPageStateGuard state_guard2(interstitial2);
2047 interstitial2->Show(); 2141 interstitial2->Show();
2048 interstitial2->TestDidNavigate(1, url2); 2142 interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2143 interstitial2->TestDidNavigate(1, interstitial_entry_id, true, url2);
2049 2144
2050 // Showing interstitial2 should have caused interstitial1 to go away. 2145 // Showing interstitial2 should have caused interstitial1 to go away.
2051 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); 2146 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2);
2052 RunAllPendingInMessageLoop(); 2147 RunAllPendingInMessageLoop();
2053 EXPECT_TRUE(deleted1); 2148 EXPECT_TRUE(deleted1);
2054 ASSERT_FALSE(deleted2); 2149 ASSERT_FALSE(deleted2);
2055 2150
2056 // Let's make sure interstitial2 is working as intended. 2151 // Let's make sure interstitial2 is working as intended.
2057 interstitial2->Proceed(); 2152 interstitial2->Proceed();
2058 GURL landing_url("http://www.thepage.com"); 2153 GURL landing_url("http://www.thepage.com");
2059 contents()->GetMainFrame()->SendNavigate(2, landing_url); 2154 contents()->GetMainFrame()->SendNavigate(2, 0, true, landing_url);
2060 2155
2061 RunAllPendingInMessageLoop(); 2156 RunAllPendingInMessageLoop();
2062 EXPECT_TRUE(deleted2); 2157 EXPECT_TRUE(deleted2);
2063 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 2158 EXPECT_FALSE(contents()->ShowingInterstitialPage());
2064 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 2159 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
2065 NavigationEntry* entry = controller().GetVisibleEntry(); 2160 NavigationEntry* entry = controller().GetVisibleEntry();
2066 ASSERT_NE(nullptr, entry); 2161 ASSERT_NE(nullptr, entry);
2067 EXPECT_TRUE(entry->GetURL() == landing_url); 2162 EXPECT_TRUE(entry->GetURL() == landing_url);
2068 EXPECT_EQ(2, controller().GetEntryCount()); 2163 EXPECT_EQ(2, controller().GetEntryCount());
2069 } 2164 }
2070 2165
2071 // Test that navigating away from an interstitial while it's loading cause it 2166 // Test that navigating away from an interstitial while it's loading cause it
2072 // not to show. 2167 // not to show.
2073 TEST_F(WebContentsImplTest, NavigateBeforeInterstitialShows) { 2168 TEST_F(WebContentsImplTest, NavigateBeforeInterstitialShows) {
2074 // Show an interstitial. 2169 // Show an interstitial.
2075 TestInterstitialPage::InterstitialState state = 2170 TestInterstitialPage::InterstitialState state =
2076 TestInterstitialPage::INVALID; 2171 TestInterstitialPage::INVALID;
2077 bool deleted = false; 2172 bool deleted = false;
2078 GURL interstitial_url("http://interstitial"); 2173 GURL interstitial_url("http://interstitial");
2079 TestInterstitialPage* interstitial = 2174 TestInterstitialPage* interstitial =
2080 new TestInterstitialPage(contents(), true, interstitial_url, 2175 new TestInterstitialPage(contents(), true, interstitial_url,
2081 &state, &deleted); 2176 &state, &deleted);
2082 TestInterstitialPageStateGuard state_guard(interstitial); 2177 TestInterstitialPageStateGuard state_guard(interstitial);
2083 interstitial->Show(); 2178 interstitial->Show();
2179 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2084 2180
2085 // Let's simulate a navigation initiated from the browser before the 2181 // Let's simulate a navigation initiated from the browser before the
2086 // interstitial finishes loading. 2182 // interstitial finishes loading.
2087 const GURL url("http://www.google.com"); 2183 const GURL url("http://www.google.com");
2088 controller().LoadURL( 2184 controller().LoadURL(
2089 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2185 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2090 EXPECT_FALSE(interstitial->is_showing()); 2186 EXPECT_FALSE(interstitial->is_showing());
2091 RunAllPendingInMessageLoop(); 2187 RunAllPendingInMessageLoop();
2092 ASSERT_FALSE(deleted); 2188 ASSERT_FALSE(deleted);
2093 2189
2094 // Now let's make the interstitial navigation commit. 2190 // Now let's make the interstitial navigation commit.
2095 interstitial->TestDidNavigate(1, interstitial_url); 2191 interstitial->TestDidNavigate(1, interstitial_entry_id, true,
2192 interstitial_url);
2096 2193
2097 // After it loaded the interstitial should be gone. 2194 // After it loaded the interstitial should be gone.
2098 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 2195 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
2099 2196
2100 RunAllPendingInMessageLoop(); 2197 RunAllPendingInMessageLoop();
2101 EXPECT_TRUE(deleted); 2198 EXPECT_TRUE(deleted);
2102 } 2199 }
2103 2200
2104 // Test that a new request to show an interstitial while an interstitial is 2201 // Test that a new request to show an interstitial while an interstitial is
2105 // pending does not cause problems. htp://crbug/29655 and htp://crbug/9442. 2202 // pending does not cause problems. htp://crbug/29655 and htp://crbug/9442.
(...skipping 13 matching lines...) Expand all
2119 // Show another interstitial on that same contents before the first one had 2216 // Show another interstitial on that same contents before the first one had
2120 // time to load. 2217 // time to load.
2121 TestInterstitialPage::InterstitialState state2 = 2218 TestInterstitialPage::InterstitialState state2 =
2122 TestInterstitialPage::INVALID; 2219 TestInterstitialPage::INVALID;
2123 bool deleted2 = false; 2220 bool deleted2 = false;
2124 TestInterstitialPage* interstitial2 = 2221 TestInterstitialPage* interstitial2 =
2125 new TestInterstitialPage(contents(), true, interstitial_url, 2222 new TestInterstitialPage(contents(), true, interstitial_url,
2126 &state2, &deleted2); 2223 &state2, &deleted2);
2127 TestInterstitialPageStateGuard state_guard2(interstitial2); 2224 TestInterstitialPageStateGuard state_guard2(interstitial2);
2128 interstitial2->Show(); 2225 interstitial2->Show();
2226 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2129 2227
2130 // The first interstitial should have been closed and deleted. 2228 // The first interstitial should have been closed and deleted.
2131 EXPECT_EQ(TestInterstitialPage::CANCELED, state1); 2229 EXPECT_EQ(TestInterstitialPage::CANCELED, state1);
2132 // The 2nd one should still be OK. 2230 // The 2nd one should still be OK.
2133 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); 2231 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2);
2134 2232
2135 RunAllPendingInMessageLoop(); 2233 RunAllPendingInMessageLoop();
2136 EXPECT_TRUE(deleted1); 2234 EXPECT_TRUE(deleted1);
2137 ASSERT_FALSE(deleted2); 2235 ASSERT_FALSE(deleted2);
2138 2236
2139 // Make the interstitial navigation commit it should be showing. 2237 // Make the interstitial navigation commit it should be showing.
2140 interstitial2->TestDidNavigate(1, interstitial_url); 2238 interstitial2->TestDidNavigate(1, interstitial_entry_id, true,
2239 interstitial_url);
2141 EXPECT_EQ(interstitial2, contents()->GetInterstitialPage()); 2240 EXPECT_EQ(interstitial2, contents()->GetInterstitialPage());
2142 } 2241 }
2143 2242
2144 // Test showing an interstitial and have its renderer crash. 2243 // Test showing an interstitial and have its renderer crash.
2145 TEST_F(WebContentsImplTest, InterstitialCrasher) { 2244 TEST_F(WebContentsImplTest, InterstitialCrasher) {
2146 // Show an interstitial. 2245 // Show an interstitial.
2147 TestInterstitialPage::InterstitialState state = 2246 TestInterstitialPage::InterstitialState state =
2148 TestInterstitialPage::INVALID; 2247 TestInterstitialPage::INVALID;
2149 bool deleted = false; 2248 bool deleted = false;
2150 GURL url("http://interstitial"); 2249 GURL url("http://interstitial");
2151 TestInterstitialPage* interstitial = 2250 TestInterstitialPage* interstitial =
2152 new TestInterstitialPage(contents(), true, url, &state, &deleted); 2251 new TestInterstitialPage(contents(), true, url, &state, &deleted);
2153 TestInterstitialPageStateGuard state_guard(interstitial); 2252 TestInterstitialPageStateGuard state_guard(interstitial);
2154 interstitial->Show(); 2253 interstitial->Show();
2155 // Simulate a renderer crash before the interstitial is shown. 2254 // Simulate a renderer crash before the interstitial is shown.
2156 interstitial->TestRenderViewTerminated( 2255 interstitial->TestRenderViewTerminated(
2157 base::TERMINATION_STATUS_PROCESS_CRASHED, -1); 2256 base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
2158 // The interstitial should have been dismissed. 2257 // The interstitial should have been dismissed.
2159 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 2258 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
2160 RunAllPendingInMessageLoop(); 2259 RunAllPendingInMessageLoop();
2161 EXPECT_TRUE(deleted); 2260 EXPECT_TRUE(deleted);
2162 2261
2163 // Now try again but this time crash the intersitial after it was shown. 2262 // Now try again but this time crash the intersitial after it was shown.
2164 interstitial = 2263 interstitial =
2165 new TestInterstitialPage(contents(), true, url, &state, &deleted); 2264 new TestInterstitialPage(contents(), true, url, &state, &deleted);
2166 interstitial->Show(); 2265 interstitial->Show();
2167 interstitial->TestDidNavigate(1, url); 2266 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2267 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url);
2168 // Simulate a renderer crash. 2268 // Simulate a renderer crash.
2169 interstitial->TestRenderViewTerminated( 2269 interstitial->TestRenderViewTerminated(
2170 base::TERMINATION_STATUS_PROCESS_CRASHED, -1); 2270 base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
2171 // The interstitial should have been dismissed. 2271 // The interstitial should have been dismissed.
2172 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 2272 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
2173 RunAllPendingInMessageLoop(); 2273 RunAllPendingInMessageLoop();
2174 EXPECT_TRUE(deleted); 2274 EXPECT_TRUE(deleted);
2175 } 2275 }
2176 2276
2177 // Tests that showing an interstitial as a result of a browser initiated 2277 // Tests that showing an interstitial as a result of a browser initiated
2178 // navigation while an interstitial is showing does not remove the pending 2278 // navigation while an interstitial is showing does not remove the pending
2179 // entry (see http://crbug.com/9791). 2279 // entry (see http://crbug.com/9791).
2180 TEST_F(WebContentsImplTest, NewInterstitialDoesNotCancelPendingEntry) { 2280 TEST_F(WebContentsImplTest, NewInterstitialDoesNotCancelPendingEntry) {
2181 const char kUrl[] = "http://www.badguys.com/"; 2281 const char kUrl[] = "http://www.badguys.com/";
2182 const GURL kGURL(kUrl); 2282 const GURL kGURL(kUrl);
2183 2283
2184 // Start a navigation to a page 2284 // Start a navigation to a page
2185 contents()->GetController().LoadURL( 2285 contents()->GetController().LoadURL(
2186 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2286 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2187 2287
2188 // Simulate that navigation triggering an interstitial. 2288 // Simulate that navigation triggering an interstitial.
2189 TestInterstitialPage::InterstitialState state = 2289 TestInterstitialPage::InterstitialState state =
2190 TestInterstitialPage::INVALID; 2290 TestInterstitialPage::INVALID;
2191 bool deleted = false; 2291 bool deleted = false;
2192 TestInterstitialPage* interstitial = 2292 TestInterstitialPage* interstitial =
2193 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); 2293 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted);
2194 TestInterstitialPageStateGuard state_guard(interstitial); 2294 TestInterstitialPageStateGuard state_guard(interstitial);
2195 interstitial->Show(); 2295 interstitial->Show();
2196 interstitial->TestDidNavigate(1, kGURL); 2296 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2297 interstitial->TestDidNavigate(1, interstitial_entry_id, true, kGURL);
2197 2298
2198 // Initiate a new navigation from the browser that also triggers an 2299 // Initiate a new navigation from the browser that also triggers an
2199 // interstitial. 2300 // interstitial.
2200 contents()->GetController().LoadURL( 2301 contents()->GetController().LoadURL(
2201 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2302 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2202 TestInterstitialPage::InterstitialState state2 = 2303 TestInterstitialPage::InterstitialState state2 =
2203 TestInterstitialPage::INVALID; 2304 TestInterstitialPage::INVALID;
2204 bool deleted2 = false; 2305 bool deleted2 = false;
2205 TestInterstitialPage* interstitial2 = 2306 TestInterstitialPage* interstitial2 =
2206 new TestInterstitialPage(contents(), true, kGURL, &state2, &deleted2); 2307 new TestInterstitialPage(contents(), true, kGURL, &state2, &deleted2);
2207 TestInterstitialPageStateGuard state_guard2(interstitial2); 2308 TestInterstitialPageStateGuard state_guard2(interstitial2);
2208 interstitial2->Show(); 2309 interstitial2->Show();
2209 interstitial2->TestDidNavigate(1, kGURL); 2310 interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2311 interstitial2->TestDidNavigate(1, interstitial_entry_id, true, kGURL);
2210 2312
2211 // Make sure we still have an entry. 2313 // Make sure we still have an entry.
2212 NavigationEntry* entry = contents()->GetController().GetPendingEntry(); 2314 NavigationEntry* entry = contents()->GetController().GetPendingEntry();
2213 ASSERT_TRUE(entry); 2315 ASSERT_TRUE(entry);
2214 EXPECT_EQ(kUrl, entry->GetURL().spec()); 2316 EXPECT_EQ(kUrl, entry->GetURL().spec());
2215 2317
2216 // And that the first interstitial is gone, but not the second. 2318 // And that the first interstitial is gone, but not the second.
2217 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 2319 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
2218 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); 2320 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2);
2219 RunAllPendingInMessageLoop(); 2321 RunAllPendingInMessageLoop();
2220 EXPECT_TRUE(deleted); 2322 EXPECT_TRUE(deleted);
2221 EXPECT_FALSE(deleted2); 2323 EXPECT_FALSE(deleted2);
2222 } 2324 }
2223 2325
2224 // Tests that Javascript messages are not shown while an interstitial is 2326 // Tests that Javascript messages are not shown while an interstitial is
2225 // showing. 2327 // showing.
2226 TEST_F(WebContentsImplTest, NoJSMessageOnInterstitials) { 2328 TEST_F(WebContentsImplTest, NoJSMessageOnInterstitials) {
2227 const char kUrl[] = "http://www.badguys.com/"; 2329 const char kUrl[] = "http://www.badguys.com/";
2228 const GURL kGURL(kUrl); 2330 const GURL kGURL(kUrl);
2229 2331
2230 // Start a navigation to a page 2332 // Start a navigation to a page
2231 contents()->GetController().LoadURL( 2333 contents()->GetController().LoadURL(
2232 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2334 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2335 int entry_id = controller().GetPendingEntry()->GetUniqueID();
2233 // DidNavigate from the page 2336 // DidNavigate from the page
2234 contents()->TestDidNavigate( 2337 contents()->TestDidNavigate(contents()->GetMainFrame(), 1, entry_id, true,
2235 contents()->GetMainFrame(), 1, kGURL, ui::PAGE_TRANSITION_TYPED); 2338 kGURL, ui::PAGE_TRANSITION_TYPED);
2236 2339
2237 // Simulate showing an interstitial while the page is showing. 2340 // Simulate showing an interstitial while the page is showing.
2238 TestInterstitialPage::InterstitialState state = 2341 TestInterstitialPage::InterstitialState state =
2239 TestInterstitialPage::INVALID; 2342 TestInterstitialPage::INVALID;
2240 bool deleted = false; 2343 bool deleted = false;
2241 TestInterstitialPage* interstitial = 2344 TestInterstitialPage* interstitial =
2242 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); 2345 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted);
2243 TestInterstitialPageStateGuard state_guard(interstitial); 2346 TestInterstitialPageStateGuard state_guard(interstitial);
2244 interstitial->Show(); 2347 interstitial->Show();
2245 interstitial->TestDidNavigate(1, kGURL); 2348 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2349 interstitial->TestDidNavigate(1, interstitial_entry_id, true, kGURL);
2246 2350
2247 // While the interstitial is showing, let's simulate the hidden page 2351 // While the interstitial is showing, let's simulate the hidden page
2248 // attempting to show a JS message. 2352 // attempting to show a JS message.
2249 IPC::Message* dummy_message = new IPC::Message; 2353 IPC::Message* dummy_message = new IPC::Message;
2250 contents()->RunJavaScriptMessage(contents()->GetMainFrame(), 2354 contents()->RunJavaScriptMessage(contents()->GetMainFrame(),
2251 base::ASCIIToUTF16("This is an informative message"), 2355 base::ASCIIToUTF16("This is an informative message"),
2252 base::ASCIIToUTF16("OK"), 2356 base::ASCIIToUTF16("OK"),
2253 kGURL, JAVASCRIPT_MESSAGE_TYPE_ALERT, dummy_message); 2357 kGURL, JAVASCRIPT_MESSAGE_TYPE_ALERT, dummy_message);
2254 EXPECT_TRUE(contents()->last_dialog_suppressed_); 2358 EXPECT_TRUE(contents()->last_dialog_suppressed_);
2255 } 2359 }
2256 2360
2257 // Makes sure that if the source passed to CopyStateFromAndPrune has an 2361 // Makes sure that if the source passed to CopyStateFromAndPrune has an
2258 // interstitial it isn't copied over to the destination. 2362 // interstitial it isn't copied over to the destination.
2259 TEST_F(WebContentsImplTest, CopyStateFromAndPruneSourceInterstitial) { 2363 TEST_F(WebContentsImplTest, CopyStateFromAndPruneSourceInterstitial) {
2260 // Navigate to a page. 2364 // Navigate to a page.
2261 GURL url1("http://www.google.com"); 2365 GURL url1("http://www.google.com");
2262 contents()->GetMainFrame()->SendNavigate(1, url1); 2366 contents()->GetMainFrame()->SendNavigate(1, 0, true, url1);
2263 EXPECT_EQ(1, controller().GetEntryCount()); 2367 EXPECT_EQ(1, controller().GetEntryCount());
2264 2368
2265 // Initiate a browser navigation that will trigger the interstitial 2369 // Initiate a browser navigation that will trigger the interstitial
2266 controller().LoadURL(GURL("http://www.evil.com"), Referrer(), 2370 controller().LoadURL(GURL("http://www.evil.com"), Referrer(),
2267 ui::PAGE_TRANSITION_TYPED, std::string()); 2371 ui::PAGE_TRANSITION_TYPED, std::string());
2268 2372
2269 // Show an interstitial. 2373 // Show an interstitial.
2270 TestInterstitialPage::InterstitialState state = 2374 TestInterstitialPage::InterstitialState state =
2271 TestInterstitialPage::INVALID; 2375 TestInterstitialPage::INVALID;
2272 bool deleted = false; 2376 bool deleted = false;
2273 GURL url2("http://interstitial"); 2377 GURL url2("http://interstitial");
2274 TestInterstitialPage* interstitial = 2378 TestInterstitialPage* interstitial =
2275 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 2379 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
2276 TestInterstitialPageStateGuard state_guard(interstitial); 2380 TestInterstitialPageStateGuard state_guard(interstitial);
2277 interstitial->Show(); 2381 interstitial->Show();
2278 interstitial->TestDidNavigate(1, url2); 2382 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2383 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url2);
2279 EXPECT_TRUE(interstitial->is_showing()); 2384 EXPECT_TRUE(interstitial->is_showing());
2280 EXPECT_EQ(2, controller().GetEntryCount()); 2385 EXPECT_EQ(2, controller().GetEntryCount());
2281 2386
2282 // Create another NavigationController. 2387 // Create another NavigationController.
2283 GURL url3("http://foo2"); 2388 GURL url3("http://foo2");
2284 scoped_ptr<TestWebContents> other_contents( 2389 scoped_ptr<TestWebContents> other_contents(
2285 static_cast<TestWebContents*>(CreateTestWebContents())); 2390 static_cast<TestWebContents*>(CreateTestWebContents()));
2286 NavigationControllerImpl& other_controller = other_contents->GetController(); 2391 NavigationControllerImpl& other_controller = other_contents->GetController();
2287 other_contents->NavigateAndCommit(url3); 2392 other_contents->NavigateAndCommit(url3);
2288 other_contents->ExpectSetHistoryOffsetAndLength(1, 2); 2393 other_contents->ExpectSetHistoryOffsetAndLength(1, 2);
(...skipping 28 matching lines...) Expand all
2317 // Show an interstitial. 2422 // Show an interstitial.
2318 TestInterstitialPage::InterstitialState state = 2423 TestInterstitialPage::InterstitialState state =
2319 TestInterstitialPage::INVALID; 2424 TestInterstitialPage::INVALID;
2320 bool deleted = false; 2425 bool deleted = false;
2321 GURL url3("http://interstitial"); 2426 GURL url3("http://interstitial");
2322 TestInterstitialPage* interstitial = 2427 TestInterstitialPage* interstitial =
2323 new TestInterstitialPage(other_contents.get(), true, url3, &state, 2428 new TestInterstitialPage(other_contents.get(), true, url3, &state,
2324 &deleted); 2429 &deleted);
2325 TestInterstitialPageStateGuard state_guard(interstitial); 2430 TestInterstitialPageStateGuard state_guard(interstitial);
2326 interstitial->Show(); 2431 interstitial->Show();
2327 interstitial->TestDidNavigate(1, url3); 2432 int interstitial_entry_id =
2433 other_controller.GetTransientEntry()->GetUniqueID();
2434 interstitial->TestDidNavigate(1, interstitial_entry_id, true, url3);
2328 EXPECT_TRUE(interstitial->is_showing()); 2435 EXPECT_TRUE(interstitial->is_showing());
2329 EXPECT_EQ(2, other_controller.GetEntryCount()); 2436 EXPECT_EQ(2, other_controller.GetEntryCount());
2330 2437
2331 // Ensure that we do not allow calling CopyStateFromAndPrune when an 2438 // Ensure that we do not allow calling CopyStateFromAndPrune when an
2332 // interstitial is showing in the target. 2439 // interstitial is showing in the target.
2333 EXPECT_FALSE(other_controller.CanPruneAllButLastCommitted()); 2440 EXPECT_FALSE(other_controller.CanPruneAllButLastCommitted());
2334 } 2441 }
2335 2442
2336 // Regression test for http://crbug.com/168611 - the URLs passed by the 2443 // Regression test for http://crbug.com/168611 - the URLs passed by the
2337 // DidFinishLoad and DidFailLoadWithError IPCs should get filtered. 2444 // DidFinishLoad and DidFailLoadWithError IPCs should get filtered.
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
2754 const GURL bar_url("http://bar.chromium.org"); 2861 const GURL bar_url("http://bar.chromium.org");
2755 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 2862 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
2756 2863
2757 // Use a WebContentsObserver to approximate the behavior of the tab's spinner. 2864 // Use a WebContentsObserver to approximate the behavior of the tab's spinner.
2758 LoadingWebContentsObserver observer(contents()); 2865 LoadingWebContentsObserver observer(contents());
2759 2866
2760 // Navigate the main RenderFrame, simulate the DidStartLoading, and commit. 2867 // Navigate the main RenderFrame, simulate the DidStartLoading, and commit.
2761 // The frame should still be loading. 2868 // The frame should still be loading.
2762 controller().LoadURL( 2869 controller().LoadURL(
2763 main_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2870 main_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2871 int entry_id = controller().GetPendingEntry()->GetUniqueID();
2764 orig_rfh->OnMessageReceived( 2872 orig_rfh->OnMessageReceived(
2765 FrameHostMsg_DidStartLoading(orig_rfh->GetRoutingID(), false)); 2873 FrameHostMsg_DidStartLoading(orig_rfh->GetRoutingID(), false));
2766 contents()->TestDidNavigate(orig_rfh, 1, main_url, ui::PAGE_TRANSITION_TYPED); 2874 contents()->TestDidNavigate(orig_rfh, 1, entry_id, true, main_url,
2875 ui::PAGE_TRANSITION_TYPED);
2767 EXPECT_FALSE(contents()->cross_navigation_pending()); 2876 EXPECT_FALSE(contents()->cross_navigation_pending());
2768 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); 2877 EXPECT_EQ(orig_rfh, contents()->GetMainFrame());
2769 EXPECT_TRUE(contents()->IsLoading()); 2878 EXPECT_TRUE(contents()->IsLoading());
2770 EXPECT_TRUE(observer.is_loading()); 2879 EXPECT_TRUE(observer.is_loading());
2771 2880
2772 // Create a child frame to navigate multiple times. 2881 // Create a child frame to navigate multiple times.
2773 TestRenderFrameHost* subframe = orig_rfh->AppendChild("subframe"); 2882 TestRenderFrameHost* subframe = orig_rfh->AppendChild("subframe");
2774 2883
2775 // Navigate the child frame to about:blank, which will send both 2884 // Navigate the child frame to about:blank, which will send both
2776 // DidStartLoading and DidStopLoading messages. 2885 // DidStartLoading and DidStopLoading messages.
2777 { 2886 {
2778 subframe->OnMessageReceived( 2887 subframe->OnMessageReceived(
2779 FrameHostMsg_DidStartLoading(subframe->GetRoutingID(), true)); 2888 FrameHostMsg_DidStartLoading(subframe->GetRoutingID(), true));
2780 subframe->SendNavigateWithTransition( 2889 subframe->SendNavigateWithTransition(1, 0, false, GURL("about:blank"),
2781 1, GURL("about:blank"), ui::PAGE_TRANSITION_AUTO_SUBFRAME); 2890 ui::PAGE_TRANSITION_AUTO_SUBFRAME);
2782 subframe->OnMessageReceived( 2891 subframe->OnMessageReceived(
2783 FrameHostMsg_DidStopLoading(subframe->GetRoutingID())); 2892 FrameHostMsg_DidStopLoading(subframe->GetRoutingID()));
2784 } 2893 }
2785 2894
2786 // Navigate the frame to another URL, which will send again 2895 // Navigate the frame to another URL, which will send again
2787 // DidStartLoading and DidStopLoading messages. 2896 // DidStartLoading and DidStopLoading messages.
2788 { 2897 {
2789 subframe->OnMessageReceived( 2898 subframe->OnMessageReceived(
2790 FrameHostMsg_DidStartLoading(subframe->GetRoutingID(), true)); 2899 FrameHostMsg_DidStartLoading(subframe->GetRoutingID(), true));
2791 subframe->SendNavigateWithTransition( 2900 subframe->SendNavigateWithTransition(1, 0, false, foo_url,
2792 1, foo_url, ui::PAGE_TRANSITION_AUTO_SUBFRAME); 2901 ui::PAGE_TRANSITION_AUTO_SUBFRAME);
2793 subframe->OnMessageReceived( 2902 subframe->OnMessageReceived(
2794 FrameHostMsg_DidStopLoading(subframe->GetRoutingID())); 2903 FrameHostMsg_DidStopLoading(subframe->GetRoutingID()));
2795 } 2904 }
2796 2905
2797 // Since the main frame hasn't sent any DidStopLoading messages, it is 2906 // Since the main frame hasn't sent any DidStopLoading messages, it is
2798 // expected that the WebContents is still in loading state. 2907 // expected that the WebContents is still in loading state.
2799 EXPECT_TRUE(contents()->IsLoading()); 2908 EXPECT_TRUE(contents()->IsLoading());
2800 EXPECT_TRUE(observer.is_loading()); 2909 EXPECT_TRUE(observer.is_loading());
2801 2910
2802 // Navigate the frame again, this time using LoadURLWithParams. This causes 2911 // Navigate the frame again, this time using LoadURLWithParams. This causes
2803 // RenderFrameHost to call into WebContents::DidStartLoading, which starts 2912 // RenderFrameHost to call into WebContents::DidStartLoading, which starts
2804 // the spinner. 2913 // the spinner.
2805 { 2914 {
2806 NavigationController::LoadURLParams load_params(bar_url); 2915 NavigationController::LoadURLParams load_params(bar_url);
2807 load_params.referrer = 2916 load_params.referrer =
2808 Referrer(GURL("http://referrer"), blink::WebReferrerPolicyDefault); 2917 Referrer(GURL("http://referrer"), blink::WebReferrerPolicyDefault);
2809 load_params.transition_type = ui::PAGE_TRANSITION_GENERATED; 2918 load_params.transition_type = ui::PAGE_TRANSITION_GENERATED;
2810 load_params.extra_headers = "content-type: text/plain"; 2919 load_params.extra_headers = "content-type: text/plain";
2811 load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT; 2920 load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT;
2812 load_params.is_renderer_initiated = false; 2921 load_params.is_renderer_initiated = false;
2813 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; 2922 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE;
2814 load_params.frame_tree_node_id = 2923 load_params.frame_tree_node_id =
2815 subframe->frame_tree_node()->frame_tree_node_id(); 2924 subframe->frame_tree_node()->frame_tree_node_id();
2816 controller().LoadURLWithParams(load_params); 2925 controller().LoadURLWithParams(load_params);
2926 entry_id = controller().GetPendingEntry()->GetUniqueID();
2817 2927
2818 subframe->OnMessageReceived( 2928 subframe->OnMessageReceived(
2819 FrameHostMsg_DidStartLoading(subframe->GetRoutingID(), true)); 2929 FrameHostMsg_DidStartLoading(subframe->GetRoutingID(), true));
2820 2930
2821 // Commit the navigation in the child frame and send the DidStopLoading 2931 // Commit the navigation in the child frame and send the DidStopLoading
2822 // message. 2932 // message.
2823 contents()->TestDidNavigate( 2933 contents()->TestDidNavigate(subframe, 3, entry_id, true, bar_url,
2824 subframe, 3, bar_url, ui::PAGE_TRANSITION_MANUAL_SUBFRAME); 2934 ui::PAGE_TRANSITION_MANUAL_SUBFRAME);
2825 subframe->OnMessageReceived( 2935 subframe->OnMessageReceived(
2826 FrameHostMsg_DidStopLoading(subframe->GetRoutingID())); 2936 FrameHostMsg_DidStopLoading(subframe->GetRoutingID()));
2827 } 2937 }
2828 2938
2829 // At this point the status should still be loading, since the main frame 2939 // At this point the status should still be loading, since the main frame
2830 // hasn't sent the DidstopLoading message yet. 2940 // hasn't sent the DidstopLoading message yet.
2831 EXPECT_TRUE(contents()->IsLoading()); 2941 EXPECT_TRUE(contents()->IsLoading());
2832 EXPECT_TRUE(observer.is_loading()); 2942 EXPECT_TRUE(observer.is_loading());
2833 2943
2834 // Send the DidStopLoading for the main frame and ensure it isn't loading 2944 // Send the DidStopLoading for the main frame and ensure it isn't loading
(...skipping 15 matching lines...) Expand all
2850 const GURL kUrl3("http://www.wikipedia.org"); 2960 const GURL kUrl3("http://www.wikipedia.org");
2851 2961
2852 contents()->NavigateAndCommit(kUrl1); 2962 contents()->NavigateAndCommit(kUrl1);
2853 2963
2854 TestRenderFrameHost* current_rfh = contents()->GetMainFrame(); 2964 TestRenderFrameHost* current_rfh = contents()->GetMainFrame();
2855 2965
2856 // Start a browser-initiated cross-process navigation to |kUrl2|. There should 2966 // Start a browser-initiated cross-process navigation to |kUrl2|. There should
2857 // be a pending RenderFrameHost and the WebContents should be loading. 2967 // be a pending RenderFrameHost and the WebContents should be loading.
2858 controller().LoadURL( 2968 controller().LoadURL(
2859 kUrl2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2969 kUrl2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2970 int entry_id = controller().GetPendingEntry()->GetUniqueID();
2860 EXPECT_TRUE(contents()->cross_navigation_pending()); 2971 EXPECT_TRUE(contents()->cross_navigation_pending());
2861 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); 2972 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
2862 ASSERT_TRUE(pending_rfh); 2973 ASSERT_TRUE(pending_rfh);
2863 EXPECT_TRUE(contents()->IsLoading()); 2974 EXPECT_TRUE(contents()->IsLoading());
2864 2975
2865 // The current RenderFrameHost starts a non user-initiated render-initiated 2976 // The current RenderFrameHost starts a non user-initiated render-initiated
2866 // navigation and sends a DidStartLoading IPC. The WebContents should still be 2977 // navigation and sends a DidStartLoading IPC. The WebContents should still be
2867 // loading. 2978 // loading.
2868 current_rfh->OnMessageReceived( 2979 current_rfh->OnMessageReceived(
2869 FrameHostMsg_DidStartLoading(current_rfh->GetRoutingID(), false)); 2980 FrameHostMsg_DidStartLoading(current_rfh->GetRoutingID(), false));
2870 EXPECT_TRUE(contents()->IsLoading()); 2981 EXPECT_TRUE(contents()->IsLoading());
2871 2982
2872 // Simulate the pending RenderFrameHost DidStartLoading. There should still be 2983 // Simulate the pending RenderFrameHost DidStartLoading. There should still be
2873 // a pending RenderFrameHost and the WebContents should still be loading. 2984 // a pending RenderFrameHost and the WebContents should still be loading.
2874 pending_rfh->PrepareForCommit(); 2985 pending_rfh->PrepareForCommit();
2875 pending_rfh->OnMessageReceived( 2986 pending_rfh->OnMessageReceived(
2876 FrameHostMsg_DidStartLoading(pending_rfh->GetRoutingID(), false)); 2987 FrameHostMsg_DidStartLoading(pending_rfh->GetRoutingID(), false));
2877 EXPECT_EQ(contents()->GetPendingMainFrame(), pending_rfh); 2988 EXPECT_EQ(contents()->GetPendingMainFrame(), pending_rfh);
2878 EXPECT_TRUE(contents()->IsLoading()); 2989 EXPECT_TRUE(contents()->IsLoading());
2879 2990
2880 // Simulate the commit and DidStopLoading from the renderer-initiated 2991 // Simulate the commit and DidStopLoading from the renderer-initiated
2881 // navigation in the current RenderFrameHost. There should still be a pending 2992 // navigation in the current RenderFrameHost. There should still be a pending
2882 // RenderFrameHost and the WebContents should still be loading. 2993 // RenderFrameHost and the WebContents should still be loading.
2883 current_rfh->SendNavigate(1, kUrl3); 2994 current_rfh->SendNavigate(1, 0, true, kUrl3);
2884 current_rfh->OnMessageReceived( 2995 current_rfh->OnMessageReceived(
2885 FrameHostMsg_DidStopLoading(current_rfh->GetRoutingID())); 2996 FrameHostMsg_DidStopLoading(current_rfh->GetRoutingID()));
2886 EXPECT_EQ(contents()->GetPendingMainFrame(), pending_rfh); 2997 EXPECT_EQ(contents()->GetPendingMainFrame(), pending_rfh);
2887 EXPECT_TRUE(contents()->IsLoading()); 2998 EXPECT_TRUE(contents()->IsLoading());
2888 2999
2889 // Commit the navigation. The formerly pending RenderFrameHost should now be 3000 // Commit the navigation. The formerly pending RenderFrameHost should now be
2890 // the current RenderFrameHost and the WebContents should still be loading. 3001 // the current RenderFrameHost and the WebContents should still be loading.
2891 contents()->TestDidNavigate(pending_rfh, 1, kUrl2, 3002 contents()->TestDidNavigate(pending_rfh, 1, entry_id, true, kUrl2,
2892 ui::PAGE_TRANSITION_TYPED); 3003 ui::PAGE_TRANSITION_TYPED);
2893 EXPECT_FALSE(contents()->GetPendingMainFrame()); 3004 EXPECT_FALSE(contents()->GetPendingMainFrame());
2894 TestRenderFrameHost* new_current_rfh = contents()->GetMainFrame(); 3005 TestRenderFrameHost* new_current_rfh = contents()->GetMainFrame();
2895 EXPECT_EQ(new_current_rfh, pending_rfh); 3006 EXPECT_EQ(new_current_rfh, pending_rfh);
2896 EXPECT_TRUE(contents()->IsLoading()); 3007 EXPECT_TRUE(contents()->IsLoading());
2897 3008
2898 // Simulate the new current RenderFrameHost DidStopLoading. The WebContents 3009 // Simulate the new current RenderFrameHost DidStopLoading. The WebContents
2899 // should now have stopped loading. 3010 // should now have stopped loading.
2900 new_current_rfh->OnMessageReceived( 3011 new_current_rfh->OnMessageReceived(
2901 FrameHostMsg_DidStopLoading(new_current_rfh->GetRoutingID())); 3012 FrameHostMsg_DidStopLoading(new_current_rfh->GetRoutingID()));
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
3014 contents()->GetMainFrame()->OnMessageReceived( 3125 contents()->GetMainFrame()->OnMessageReceived(
3015 FrameHostMsg_RenderProcessGone( 3126 FrameHostMsg_RenderProcessGone(
3016 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1)); 3127 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1));
3017 3128
3018 // Verify that all the power save blockers have been released. 3129 // Verify that all the power save blockers have been released.
3019 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 3130 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
3020 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 3131 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
3021 } 3132 }
3022 3133
3023 } // namespace content 3134 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698