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

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

Powered by Google App Engine
This is Rietveld 408576698