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