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