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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "content/browser/frame_host/cross_site_transferring_request.h" | 7 #include "content/browser/frame_host/cross_site_transferring_request.h" |
8 #include "content/browser/frame_host/interstitial_page_impl.h" | 8 #include "content/browser/frame_host/interstitial_page_impl.h" |
9 #include "content/browser/frame_host/navigation_entry_impl.h" | 9 #include "content/browser/frame_host/navigation_entry_impl.h" |
10 #include "content/browser/media/audio_stream_monitor.h" | 10 #include "content/browser/media/audio_stream_monitor.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 return command_received_count_; | 150 return command_received_count_; |
151 } | 151 } |
152 | 152 |
153 void TestDomOperationResponse(const std::string& json_string) { | 153 void TestDomOperationResponse(const std::string& json_string) { |
154 if (enabled()) | 154 if (enabled()) |
155 CommandReceived(); | 155 CommandReceived(); |
156 } | 156 } |
157 | 157 |
158 void TestDidNavigate(int page_id, const GURL& url) { | 158 void TestDidNavigate(int page_id, const GURL& url) { |
159 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 159 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
160 InitNavigateParams(¶ms, page_id, url, PAGE_TRANSITION_TYPED); | 160 InitNavigateParams(¶ms, page_id, url, ui::PAGE_TRANSITION_TYPED); |
161 DidNavigate(GetRenderViewHostForTesting(), params); | 161 DidNavigate(GetRenderViewHostForTesting(), params); |
162 } | 162 } |
163 | 163 |
164 void TestRenderViewTerminated(base::TerminationStatus status, | 164 void TestRenderViewTerminated(base::TerminationStatus status, |
165 int error_code) { | 165 int error_code) { |
166 RenderViewTerminated(GetRenderViewHostForTesting(), status, error_code); | 166 RenderViewTerminated(GetRenderViewHostForTesting(), status, error_code); |
167 } | 167 } |
168 | 168 |
169 bool is_showing() const { | 169 bool is_showing() const { |
170 return static_cast<TestRenderWidgetHostView*>( | 170 return static_cast<TestRenderWidgetHostView*>( |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 }; | 337 }; |
338 | 338 |
339 } // namespace | 339 } // namespace |
340 | 340 |
341 // Test to make sure that title updates get stripped of whitespace. | 341 // Test to make sure that title updates get stripped of whitespace. |
342 TEST_F(WebContentsImplTest, UpdateTitle) { | 342 TEST_F(WebContentsImplTest, UpdateTitle) { |
343 NavigationControllerImpl& cont = | 343 NavigationControllerImpl& cont = |
344 static_cast<NavigationControllerImpl&>(controller()); | 344 static_cast<NavigationControllerImpl&>(controller()); |
345 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 345 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
346 InitNavigateParams( | 346 InitNavigateParams( |
347 ¶ms, 0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED); | 347 ¶ms, 0, GURL(url::kAboutBlankURL), ui::PAGE_TRANSITION_TYPED); |
348 | 348 |
349 LoadCommittedDetails details; | 349 LoadCommittedDetails details; |
350 cont.RendererDidNavigate(contents()->GetMainFrame(), params, &details); | 350 cont.RendererDidNavigate(contents()->GetMainFrame(), params, &details); |
351 | 351 |
352 contents()->UpdateTitle(contents()->GetMainFrame(), 0, | 352 contents()->UpdateTitle(contents()->GetMainFrame(), 0, |
353 base::ASCIIToUTF16(" Lots O' Whitespace\n"), | 353 base::ASCIIToUTF16(" Lots O' Whitespace\n"), |
354 base::i18n::LEFT_TO_RIGHT); | 354 base::i18n::LEFT_TO_RIGHT); |
355 EXPECT_EQ(base::ASCIIToUTF16("Lots O' Whitespace"), contents()->GetTitle()); | 355 EXPECT_EQ(base::ASCIIToUTF16("Lots O' Whitespace"), contents()->GetTitle()); |
356 } | 356 } |
357 | 357 |
358 TEST_F(WebContentsImplTest, DontUseTitleFromPendingEntry) { | 358 TEST_F(WebContentsImplTest, DontUseTitleFromPendingEntry) { |
359 const GURL kGURL("chrome://blah"); | 359 const GURL kGURL("chrome://blah"); |
360 controller().LoadURL( | 360 controller().LoadURL( |
361 kGURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 361 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
362 EXPECT_EQ(base::string16(), contents()->GetTitle()); | 362 EXPECT_EQ(base::string16(), contents()->GetTitle()); |
363 } | 363 } |
364 | 364 |
365 TEST_F(WebContentsImplTest, UseTitleFromPendingEntryIfSet) { | 365 TEST_F(WebContentsImplTest, UseTitleFromPendingEntryIfSet) { |
366 const GURL kGURL("chrome://blah"); | 366 const GURL kGURL("chrome://blah"); |
367 const base::string16 title = base::ASCIIToUTF16("My Title"); | 367 const base::string16 title = base::ASCIIToUTF16("My Title"); |
368 controller().LoadURL( | 368 controller().LoadURL( |
369 kGURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 369 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
370 | 370 |
371 NavigationEntry* entry = controller().GetVisibleEntry(); | 371 NavigationEntry* entry = controller().GetVisibleEntry(); |
372 ASSERT_EQ(kGURL, entry->GetURL()); | 372 ASSERT_EQ(kGURL, entry->GetURL()); |
373 entry->SetTitle(title); | 373 entry->SetTitle(title); |
374 | 374 |
375 EXPECT_EQ(title, contents()->GetTitle()); | 375 EXPECT_EQ(title, contents()->GetTitle()); |
376 } | 376 } |
377 | 377 |
378 // Test view source mode for a webui page. | 378 // Test view source mode for a webui page. |
379 TEST_F(WebContentsImplTest, NTPViewSource) { | 379 TEST_F(WebContentsImplTest, NTPViewSource) { |
380 NavigationControllerImpl& cont = | 380 NavigationControllerImpl& cont = |
381 static_cast<NavigationControllerImpl&>(controller()); | 381 static_cast<NavigationControllerImpl&>(controller()); |
382 const char kUrl[] = "view-source:chrome://blah"; | 382 const char kUrl[] = "view-source:chrome://blah"; |
383 const GURL kGURL(kUrl); | 383 const GURL kGURL(kUrl); |
384 | 384 |
385 process()->sink().ClearMessages(); | 385 process()->sink().ClearMessages(); |
386 | 386 |
387 cont.LoadURL( | 387 cont.LoadURL( |
388 kGURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 388 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
389 rvh()->GetDelegate()->RenderViewCreated(rvh()); | 389 rvh()->GetDelegate()->RenderViewCreated(rvh()); |
390 // Did we get the expected message? | 390 // Did we get the expected message? |
391 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( | 391 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( |
392 ViewMsg_EnableViewSourceMode::ID)); | 392 ViewMsg_EnableViewSourceMode::ID)); |
393 | 393 |
394 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 394 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
395 InitNavigateParams(¶ms, 0, kGURL, PAGE_TRANSITION_TYPED); | 395 InitNavigateParams(¶ms, 0, kGURL, ui::PAGE_TRANSITION_TYPED); |
396 LoadCommittedDetails details; | 396 LoadCommittedDetails details; |
397 cont.RendererDidNavigate(contents()->GetMainFrame(), params, &details); | 397 cont.RendererDidNavigate(contents()->GetMainFrame(), params, &details); |
398 // Also check title and url. | 398 // Also check title and url. |
399 EXPECT_EQ(base::ASCIIToUTF16(kUrl), contents()->GetTitle()); | 399 EXPECT_EQ(base::ASCIIToUTF16(kUrl), contents()->GetTitle()); |
400 } | 400 } |
401 | 401 |
402 // Test to ensure UpdateMaxPageID is working properly. | 402 // Test to ensure UpdateMaxPageID is working properly. |
403 TEST_F(WebContentsImplTest, UpdateMaxPageID) { | 403 TEST_F(WebContentsImplTest, UpdateMaxPageID) { |
404 SiteInstance* instance1 = contents()->GetSiteInstance(); | 404 SiteInstance* instance1 = contents()->GetSiteInstance(); |
405 scoped_refptr<SiteInstance> instance2(SiteInstance::Create(NULL)); | 405 scoped_refptr<SiteInstance> instance2(SiteInstance::Create(NULL)); |
(...skipping 18 matching lines...) Expand all Loading... |
424 | 424 |
425 // Test simple same-SiteInstance navigation. | 425 // Test simple same-SiteInstance navigation. |
426 TEST_F(WebContentsImplTest, SimpleNavigation) { | 426 TEST_F(WebContentsImplTest, SimpleNavigation) { |
427 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 427 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
428 SiteInstance* instance1 = contents()->GetSiteInstance(); | 428 SiteInstance* instance1 = contents()->GetSiteInstance(); |
429 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 429 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
430 | 430 |
431 // Navigate to URL | 431 // Navigate to URL |
432 const GURL url("http://www.google.com"); | 432 const GURL url("http://www.google.com"); |
433 controller().LoadURL( | 433 controller().LoadURL( |
434 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 434 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
435 EXPECT_FALSE(contents()->cross_navigation_pending()); | 435 EXPECT_FALSE(contents()->cross_navigation_pending()); |
436 EXPECT_EQ(instance1, orig_rfh->GetSiteInstance()); | 436 EXPECT_EQ(instance1, orig_rfh->GetSiteInstance()); |
437 // Controller's pending entry will have a NULL site instance until we assign | 437 // Controller's pending entry will have a NULL site instance until we assign |
438 // it in DidNavigate. | 438 // it in DidNavigate. |
439 EXPECT_TRUE( | 439 EXPECT_TRUE( |
440 NavigationEntryImpl::FromNavigationEntry(controller().GetVisibleEntry())-> | 440 NavigationEntryImpl::FromNavigationEntry(controller().GetVisibleEntry())-> |
441 site_instance() == NULL); | 441 site_instance() == NULL); |
442 | 442 |
443 // DidNavigate from the page | 443 // DidNavigate from the page |
444 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 444 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
445 EXPECT_FALSE(contents()->cross_navigation_pending()); | 445 EXPECT_FALSE(contents()->cross_navigation_pending()); |
446 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 446 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
447 EXPECT_EQ(instance1, orig_rfh->GetSiteInstance()); | 447 EXPECT_EQ(instance1, orig_rfh->GetSiteInstance()); |
448 // Controller's entry should now have the SiteInstance, or else we won't be | 448 // Controller's entry should now have the SiteInstance, or else we won't be |
449 // able to find it later. | 449 // able to find it later. |
450 EXPECT_EQ( | 450 EXPECT_EQ( |
451 instance1, | 451 instance1, |
452 NavigationEntryImpl::FromNavigationEntry(controller().GetVisibleEntry())-> | 452 NavigationEntryImpl::FromNavigationEntry(controller().GetVisibleEntry())-> |
453 site_instance()); | 453 site_instance()); |
454 } | 454 } |
455 | 455 |
456 // Test that we reject NavigateToEntry if the url is over kMaxURLChars. | 456 // Test that we reject NavigateToEntry if the url is over kMaxURLChars. |
457 TEST_F(WebContentsImplTest, NavigateToExcessivelyLongURL) { | 457 TEST_F(WebContentsImplTest, NavigateToExcessivelyLongURL) { |
458 // Construct a URL that's kMaxURLChars + 1 long of all 'a's. | 458 // Construct a URL that's kMaxURLChars + 1 long of all 'a's. |
459 const GURL url(std::string("http://example.org/").append( | 459 const GURL url(std::string("http://example.org/").append( |
460 GetMaxURLChars() + 1, 'a')); | 460 GetMaxURLChars() + 1, 'a')); |
461 | 461 |
462 controller().LoadURL( | 462 controller().LoadURL( |
463 url, Referrer(), PAGE_TRANSITION_GENERATED, std::string()); | 463 url, Referrer(), ui::PAGE_TRANSITION_GENERATED, std::string()); |
464 EXPECT_TRUE(controller().GetVisibleEntry() == NULL); | 464 EXPECT_TRUE(controller().GetVisibleEntry() == NULL); |
465 } | 465 } |
466 | 466 |
467 // Test that navigating across a site boundary creates a new RenderViewHost | 467 // Test that navigating across a site boundary creates a new RenderViewHost |
468 // with a new SiteInstance. Going back should do the same. | 468 // with a new SiteInstance. Going back should do the same. |
469 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { | 469 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { |
470 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 470 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
471 int orig_rvh_delete_count = 0; | 471 int orig_rvh_delete_count = 0; |
472 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); | 472 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); |
473 SiteInstance* instance1 = contents()->GetSiteInstance(); | 473 SiteInstance* instance1 = contents()->GetSiteInstance(); |
474 | 474 |
475 // Navigate to URL. First URL should use first RenderViewHost. | 475 // Navigate to URL. First URL should use first RenderViewHost. |
476 const GURL url("http://www.google.com"); | 476 const GURL url("http://www.google.com"); |
477 controller().LoadURL( | 477 controller().LoadURL( |
478 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 478 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
479 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 479 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
480 | 480 |
481 // Keep the number of active views in orig_rfh's SiteInstance non-zero so that | 481 // Keep the number of active views in orig_rfh's SiteInstance non-zero so that |
482 // orig_rfh doesn't get deleted when it gets swapped out. | 482 // orig_rfh doesn't get deleted when it gets swapped out. |
483 static_cast<SiteInstanceImpl*>(orig_rfh->GetSiteInstance())-> | 483 static_cast<SiteInstanceImpl*>(orig_rfh->GetSiteInstance())-> |
484 increment_active_view_count(); | 484 increment_active_view_count(); |
485 | 485 |
486 EXPECT_FALSE(contents()->cross_navigation_pending()); | 486 EXPECT_FALSE(contents()->cross_navigation_pending()); |
487 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); | 487 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); |
488 EXPECT_EQ(url, contents()->GetLastCommittedURL()); | 488 EXPECT_EQ(url, contents()->GetLastCommittedURL()); |
489 EXPECT_EQ(url, contents()->GetVisibleURL()); | 489 EXPECT_EQ(url, contents()->GetVisibleURL()); |
490 | 490 |
491 // Navigate to new site | 491 // Navigate to new site |
492 const GURL url2("http://www.yahoo.com"); | 492 const GURL url2("http://www.yahoo.com"); |
493 controller().LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 493 controller().LoadURL( |
| 494 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
494 EXPECT_TRUE(contents()->cross_navigation_pending()); | 495 EXPECT_TRUE(contents()->cross_navigation_pending()); |
495 EXPECT_EQ(url, contents()->GetLastCommittedURL()); | 496 EXPECT_EQ(url, contents()->GetLastCommittedURL()); |
496 EXPECT_EQ(url2, contents()->GetVisibleURL()); | 497 EXPECT_EQ(url2, contents()->GetVisibleURL()); |
497 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); | 498 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); |
498 int pending_rvh_delete_count = 0; | 499 int pending_rvh_delete_count = 0; |
499 pending_rfh->GetRenderViewHost()->set_delete_counter( | 500 pending_rfh->GetRenderViewHost()->set_delete_counter( |
500 &pending_rvh_delete_count); | 501 &pending_rvh_delete_count); |
501 | 502 |
502 // Navigations should be suspended in pending_rfh until BeforeUnloadACK. | 503 // Navigations should be suspended in pending_rfh until BeforeUnloadACK. |
503 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); | 504 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); |
504 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); | 505 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); |
505 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); | 506 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); |
506 | 507 |
507 // DidNavigate from the pending page | 508 // DidNavigate from the pending page |
508 contents()->TestDidNavigate( | 509 contents()->TestDidNavigate( |
509 pending_rfh, 1, url2, PAGE_TRANSITION_TYPED); | 510 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); |
510 SiteInstance* instance2 = contents()->GetSiteInstance(); | 511 SiteInstance* instance2 = contents()->GetSiteInstance(); |
511 | 512 |
512 // Keep the number of active views in pending_rfh's SiteInstance | 513 // Keep the number of active views in pending_rfh's SiteInstance |
513 // non-zero so that orig_rfh doesn't get deleted when it gets | 514 // non-zero so that orig_rfh doesn't get deleted when it gets |
514 // swapped out. | 515 // swapped out. |
515 static_cast<SiteInstanceImpl*>(pending_rfh->GetSiteInstance())-> | 516 static_cast<SiteInstanceImpl*>(pending_rfh->GetSiteInstance())-> |
516 increment_active_view_count(); | 517 increment_active_view_count(); |
517 | 518 |
518 EXPECT_FALSE(contents()->cross_navigation_pending()); | 519 EXPECT_FALSE(contents()->cross_navigation_pending()); |
519 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); | 520 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); |
(...skipping 13 matching lines...) Expand all Loading... |
533 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame(); | 534 TestRenderFrameHost* goback_rfh = contents()->GetPendingMainFrame(); |
534 EXPECT_EQ(orig_rfh, goback_rfh); | 535 EXPECT_EQ(orig_rfh, goback_rfh); |
535 EXPECT_TRUE(contents()->cross_navigation_pending()); | 536 EXPECT_TRUE(contents()->cross_navigation_pending()); |
536 | 537 |
537 // Navigations should be suspended in goback_rfh until BeforeUnloadACK. | 538 // Navigations should be suspended in goback_rfh until BeforeUnloadACK. |
538 EXPECT_TRUE(goback_rfh->are_navigations_suspended()); | 539 EXPECT_TRUE(goback_rfh->are_navigations_suspended()); |
539 pending_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); | 540 pending_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); |
540 EXPECT_FALSE(goback_rfh->are_navigations_suspended()); | 541 EXPECT_FALSE(goback_rfh->are_navigations_suspended()); |
541 | 542 |
542 // DidNavigate from the back action | 543 // DidNavigate from the back action |
543 contents()->TestDidNavigate(goback_rfh, 1, url2, PAGE_TRANSITION_TYPED); | 544 contents()->TestDidNavigate(goback_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); |
544 EXPECT_FALSE(contents()->cross_navigation_pending()); | 545 EXPECT_FALSE(contents()->cross_navigation_pending()); |
545 EXPECT_EQ(goback_rfh, contents()->GetMainFrame()); | 546 EXPECT_EQ(goback_rfh, contents()->GetMainFrame()); |
546 EXPECT_EQ(instance1, contents()->GetSiteInstance()); | 547 EXPECT_EQ(instance1, contents()->GetSiteInstance()); |
547 // The pending RFH should now be swapped out, not deleted. | 548 // The pending RFH should now be swapped out, not deleted. |
548 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> | 549 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> |
549 IsOnSwappedOutList(pending_rfh)); | 550 IsOnSwappedOutList(pending_rfh)); |
550 EXPECT_EQ(pending_rvh_delete_count, 0); | 551 EXPECT_EQ(pending_rvh_delete_count, 0); |
551 pending_rfh->OnSwappedOut(false); | 552 pending_rfh->OnSwappedOut(false); |
552 | 553 |
553 // Close contents and ensure RVHs are deleted. | 554 // Close contents and ensure RVHs are deleted. |
554 DeleteContents(); | 555 DeleteContents(); |
555 EXPECT_EQ(orig_rvh_delete_count, 1); | 556 EXPECT_EQ(orig_rvh_delete_count, 1); |
556 EXPECT_EQ(pending_rvh_delete_count, 1); | 557 EXPECT_EQ(pending_rvh_delete_count, 1); |
557 } | 558 } |
558 | 559 |
559 // Test that navigating across a site boundary after a crash creates a new | 560 // Test that navigating across a site boundary after a crash creates a new |
560 // RFH without requiring a cross-site transition (i.e., PENDING state). | 561 // RFH without requiring a cross-site transition (i.e., PENDING state). |
561 TEST_F(WebContentsImplTest, CrossSiteBoundariesAfterCrash) { | 562 TEST_F(WebContentsImplTest, CrossSiteBoundariesAfterCrash) { |
562 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 563 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
563 | 564 |
564 int orig_rvh_delete_count = 0; | 565 int orig_rvh_delete_count = 0; |
565 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); | 566 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); |
566 SiteInstance* instance1 = contents()->GetSiteInstance(); | 567 SiteInstance* instance1 = contents()->GetSiteInstance(); |
567 | 568 |
568 // Navigate to URL. First URL should use first RenderViewHost. | 569 // Navigate to URL. First URL should use first RenderViewHost. |
569 const GURL url("http://www.google.com"); | 570 const GURL url("http://www.google.com"); |
570 controller().LoadURL( | 571 controller().LoadURL( |
571 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 572 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
572 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 573 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
573 | 574 |
574 EXPECT_FALSE(contents()->cross_navigation_pending()); | 575 EXPECT_FALSE(contents()->cross_navigation_pending()); |
575 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); | 576 EXPECT_EQ(orig_rfh->GetRenderViewHost(), contents()->GetRenderViewHost()); |
576 | 577 |
577 // Simulate a renderer crash. | 578 // Simulate a renderer crash. |
578 orig_rfh->GetRenderViewHost()->set_render_view_created(false); | 579 orig_rfh->GetRenderViewHost()->set_render_view_created(false); |
579 orig_rfh->set_render_frame_created(false); | 580 orig_rfh->set_render_frame_created(false); |
580 | 581 |
581 // Navigate to new site. We should not go into PENDING. | 582 // Navigate to new site. We should not go into PENDING. |
582 const GURL url2("http://www.yahoo.com"); | 583 const GURL url2("http://www.yahoo.com"); |
583 controller().LoadURL( | 584 controller().LoadURL( |
584 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 585 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
585 TestRenderFrameHost* new_rfh = contents()->GetMainFrame(); | 586 TestRenderFrameHost* new_rfh = contents()->GetMainFrame(); |
586 EXPECT_FALSE(contents()->cross_navigation_pending()); | 587 EXPECT_FALSE(contents()->cross_navigation_pending()); |
587 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 588 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
588 EXPECT_NE(orig_rfh, new_rfh); | 589 EXPECT_NE(orig_rfh, new_rfh); |
589 EXPECT_EQ(orig_rvh_delete_count, 1); | 590 EXPECT_EQ(orig_rvh_delete_count, 1); |
590 | 591 |
591 // DidNavigate from the new page | 592 // DidNavigate from the new page |
592 contents()->TestDidNavigate(new_rfh, 1, url2, PAGE_TRANSITION_TYPED); | 593 contents()->TestDidNavigate(new_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); |
593 SiteInstance* instance2 = contents()->GetSiteInstance(); | 594 SiteInstance* instance2 = contents()->GetSiteInstance(); |
594 | 595 |
595 EXPECT_FALSE(contents()->cross_navigation_pending()); | 596 EXPECT_FALSE(contents()->cross_navigation_pending()); |
596 EXPECT_EQ(new_rfh, main_rfh()); | 597 EXPECT_EQ(new_rfh, main_rfh()); |
597 EXPECT_NE(instance1, instance2); | 598 EXPECT_NE(instance1, instance2); |
598 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 599 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
599 | 600 |
600 // Close contents and ensure RVHs are deleted. | 601 // Close contents and ensure RVHs are deleted. |
601 DeleteContents(); | 602 DeleteContents(); |
602 EXPECT_EQ(orig_rvh_delete_count, 1); | 603 EXPECT_EQ(orig_rvh_delete_count, 1); |
603 } | 604 } |
604 | 605 |
605 // Test that opening a new contents in the same SiteInstance and then navigating | 606 // Test that opening a new contents in the same SiteInstance and then navigating |
606 // both contentses to a new site will place both contentses in a single | 607 // both contentses to a new site will place both contentses in a single |
607 // SiteInstance. | 608 // SiteInstance. |
608 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) { | 609 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) { |
609 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 610 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
610 SiteInstance* instance1 = contents()->GetSiteInstance(); | 611 SiteInstance* instance1 = contents()->GetSiteInstance(); |
611 | 612 |
612 // Navigate to URL. First URL should use first RenderViewHost. | 613 // Navigate to URL. First URL should use first RenderViewHost. |
613 const GURL url("http://www.google.com"); | 614 const GURL url("http://www.google.com"); |
614 controller().LoadURL( | 615 controller().LoadURL( |
615 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 616 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
616 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 617 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
617 | 618 |
618 // Open a new contents with the same SiteInstance, navigated to the same site. | 619 // Open a new contents with the same SiteInstance, navigated to the same site. |
619 scoped_ptr<TestWebContents> contents2( | 620 scoped_ptr<TestWebContents> contents2( |
620 TestWebContents::Create(browser_context(), instance1)); | 621 TestWebContents::Create(browser_context(), instance1)); |
621 contents2->GetController().LoadURL(url, Referrer(), | 622 contents2->GetController().LoadURL(url, Referrer(), |
622 PAGE_TRANSITION_TYPED, | 623 ui::PAGE_TRANSITION_TYPED, |
623 std::string()); | 624 std::string()); |
624 // Need this page id to be 2 since the site instance is the same (which is the | 625 // Need this page id to be 2 since the site instance is the same (which is the |
625 // scope of page IDs) and we want to consider this a new page. | 626 // scope of page IDs) and we want to consider this a new page. |
626 contents2->TestDidNavigate( | 627 contents2->TestDidNavigate( |
627 contents2->GetMainFrame(), 2, url, PAGE_TRANSITION_TYPED); | 628 contents2->GetMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED); |
628 | 629 |
629 // Navigate first contents to a new site. | 630 // Navigate first contents to a new site. |
630 const GURL url2a("http://www.yahoo.com"); | 631 const GURL url2a("http://www.yahoo.com"); |
631 controller().LoadURL( | 632 controller().LoadURL( |
632 url2a, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 633 url2a, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
633 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); | 634 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); |
634 TestRenderFrameHost* pending_rfh_a = contents()->GetPendingMainFrame(); | 635 TestRenderFrameHost* pending_rfh_a = contents()->GetPendingMainFrame(); |
635 contents()->TestDidNavigate( | 636 contents()->TestDidNavigate( |
636 pending_rfh_a, 1, url2a, PAGE_TRANSITION_TYPED); | 637 pending_rfh_a, 1, url2a, ui::PAGE_TRANSITION_TYPED); |
637 SiteInstance* instance2a = contents()->GetSiteInstance(); | 638 SiteInstance* instance2a = contents()->GetSiteInstance(); |
638 EXPECT_NE(instance1, instance2a); | 639 EXPECT_NE(instance1, instance2a); |
639 | 640 |
640 // Navigate second contents to the same site as the first tab. | 641 // Navigate second contents to the same site as the first tab. |
641 const GURL url2b("http://mail.yahoo.com"); | 642 const GURL url2b("http://mail.yahoo.com"); |
642 contents2->GetController().LoadURL(url2b, Referrer(), | 643 contents2->GetController().LoadURL(url2b, Referrer(), |
643 PAGE_TRANSITION_TYPED, | 644 ui::PAGE_TRANSITION_TYPED, |
644 std::string()); | 645 std::string()); |
645 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); | 646 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); |
646 rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); | 647 rfh2->GetRenderViewHost()->SendBeforeUnloadACK(true); |
647 TestRenderFrameHost* pending_rfh_b = contents2->GetPendingMainFrame(); | 648 TestRenderFrameHost* pending_rfh_b = contents2->GetPendingMainFrame(); |
648 EXPECT_TRUE(pending_rfh_b != NULL); | 649 EXPECT_TRUE(pending_rfh_b != NULL); |
649 EXPECT_TRUE(contents2->cross_navigation_pending()); | 650 EXPECT_TRUE(contents2->cross_navigation_pending()); |
650 | 651 |
651 // NOTE(creis): We used to be in danger of showing a crash page here if the | 652 // NOTE(creis): We used to be in danger of showing a crash page here if the |
652 // second contents hadn't navigated somewhere first (bug 1145430). That case | 653 // second contents hadn't navigated somewhere first (bug 1145430). That case |
653 // is now covered by the CrossSiteBoundariesAfterCrash test. | 654 // is now covered by the CrossSiteBoundariesAfterCrash test. |
654 contents2->TestDidNavigate(pending_rfh_b, 2, url2b, PAGE_TRANSITION_TYPED); | 655 contents2->TestDidNavigate( |
| 656 pending_rfh_b, 2, url2b, ui::PAGE_TRANSITION_TYPED); |
655 SiteInstance* instance2b = contents2->GetSiteInstance(); | 657 SiteInstance* instance2b = contents2->GetSiteInstance(); |
656 EXPECT_NE(instance1, instance2b); | 658 EXPECT_NE(instance1, instance2b); |
657 | 659 |
658 // Both contentses should now be in the same SiteInstance. | 660 // Both contentses should now be in the same SiteInstance. |
659 EXPECT_EQ(instance2a, instance2b); | 661 EXPECT_EQ(instance2a, instance2b); |
660 } | 662 } |
661 | 663 |
662 // The embedder can request sites for certain urls not be be assigned to the | 664 // The embedder can request sites for certain urls not be be assigned to the |
663 // SiteInstance through ShouldAssignSiteForURL() in content browser client, | 665 // SiteInstance through ShouldAssignSiteForURL() in content browser client, |
664 // allowing to reuse the renderer backing certain chrome urls for subsequent | 666 // allowing to reuse the renderer backing certain chrome urls for subsequent |
665 // navigation. The test verifies that the override is honored. | 667 // navigation. The test verifies that the override is honored. |
666 TEST_F(WebContentsImplTest, NavigateFromSitelessUrl) { | 668 TEST_F(WebContentsImplTest, NavigateFromSitelessUrl) { |
667 WebContentsImplTestBrowserClient browser_client; | 669 WebContentsImplTestBrowserClient browser_client; |
668 SetBrowserClientForTesting(&browser_client); | 670 SetBrowserClientForTesting(&browser_client); |
669 | 671 |
670 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 672 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
671 int orig_rvh_delete_count = 0; | 673 int orig_rvh_delete_count = 0; |
672 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); | 674 orig_rfh->GetRenderViewHost()->set_delete_counter(&orig_rvh_delete_count); |
673 SiteInstanceImpl* orig_instance = | 675 SiteInstanceImpl* orig_instance = |
674 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); | 676 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); |
675 | 677 |
676 browser_client.set_assign_site_for_url(false); | 678 browser_client.set_assign_site_for_url(false); |
677 // Navigate to an URL that will not assign a new SiteInstance. | 679 // Navigate to an URL that will not assign a new SiteInstance. |
678 const GURL native_url("non-site-url://stuffandthings"); | 680 const GURL native_url("non-site-url://stuffandthings"); |
679 controller().LoadURL( | 681 controller().LoadURL( |
680 native_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 682 native_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
681 contents()->TestDidNavigate(orig_rfh, 1, native_url, PAGE_TRANSITION_TYPED); | 683 contents()->TestDidNavigate( |
| 684 orig_rfh, 1, native_url, ui::PAGE_TRANSITION_TYPED); |
682 | 685 |
683 EXPECT_FALSE(contents()->cross_navigation_pending()); | 686 EXPECT_FALSE(contents()->cross_navigation_pending()); |
684 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 687 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
685 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); | 688 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); |
686 EXPECT_EQ(native_url, contents()->GetVisibleURL()); | 689 EXPECT_EQ(native_url, contents()->GetVisibleURL()); |
687 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); | 690 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); |
688 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL()); | 691 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL()); |
689 EXPECT_FALSE(orig_instance->HasSite()); | 692 EXPECT_FALSE(orig_instance->HasSite()); |
690 | 693 |
691 browser_client.set_assign_site_for_url(true); | 694 browser_client.set_assign_site_for_url(true); |
692 // Navigate to new site (should keep same site instance). | 695 // Navigate to new site (should keep same site instance). |
693 const GURL url("http://www.google.com"); | 696 const GURL url("http://www.google.com"); |
694 controller().LoadURL( | 697 controller().LoadURL( |
695 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 698 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
696 EXPECT_FALSE(contents()->cross_navigation_pending()); | 699 EXPECT_FALSE(contents()->cross_navigation_pending()); |
697 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); | 700 EXPECT_EQ(native_url, contents()->GetLastCommittedURL()); |
698 EXPECT_EQ(url, contents()->GetVisibleURL()); | 701 EXPECT_EQ(url, contents()->GetVisibleURL()); |
699 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 702 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
700 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 703 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
701 | 704 |
702 // Keep the number of active views in orig_rfh's SiteInstance | 705 // Keep the number of active views in orig_rfh's SiteInstance |
703 // non-zero so that orig_rfh doesn't get deleted when it gets | 706 // non-zero so that orig_rfh doesn't get deleted when it gets |
704 // swapped out. | 707 // swapped out. |
705 static_cast<SiteInstanceImpl*>(orig_rfh->GetSiteInstance())-> | 708 static_cast<SiteInstanceImpl*>(orig_rfh->GetSiteInstance())-> |
706 increment_active_view_count(); | 709 increment_active_view_count(); |
707 | 710 |
708 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); | 711 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); |
709 EXPECT_TRUE( | 712 EXPECT_TRUE( |
710 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com")); | 713 contents()->GetSiteInstance()->GetSiteURL().DomainIs("google.com")); |
711 EXPECT_EQ(url, contents()->GetLastCommittedURL()); | 714 EXPECT_EQ(url, contents()->GetLastCommittedURL()); |
712 | 715 |
713 // Navigate to another new site (should create a new site instance). | 716 // Navigate to another new site (should create a new site instance). |
714 const GURL url2("http://www.yahoo.com"); | 717 const GURL url2("http://www.yahoo.com"); |
715 controller().LoadURL( | 718 controller().LoadURL( |
716 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 719 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
717 EXPECT_TRUE(contents()->cross_navigation_pending()); | 720 EXPECT_TRUE(contents()->cross_navigation_pending()); |
718 EXPECT_EQ(url, contents()->GetLastCommittedURL()); | 721 EXPECT_EQ(url, contents()->GetLastCommittedURL()); |
719 EXPECT_EQ(url2, contents()->GetVisibleURL()); | 722 EXPECT_EQ(url2, contents()->GetVisibleURL()); |
720 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); | 723 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); |
721 int pending_rvh_delete_count = 0; | 724 int pending_rvh_delete_count = 0; |
722 pending_rfh->GetRenderViewHost()->set_delete_counter( | 725 pending_rfh->GetRenderViewHost()->set_delete_counter( |
723 &pending_rvh_delete_count); | 726 &pending_rvh_delete_count); |
724 | 727 |
725 // Navigations should be suspended in pending_rvh until BeforeUnloadACK. | 728 // Navigations should be suspended in pending_rvh until BeforeUnloadACK. |
726 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); | 729 EXPECT_TRUE(pending_rfh->are_navigations_suspended()); |
727 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); | 730 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); |
728 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); | 731 EXPECT_FALSE(pending_rfh->are_navigations_suspended()); |
729 | 732 |
730 // DidNavigate from the pending page. | 733 // DidNavigate from the pending page. |
731 contents()->TestDidNavigate( | 734 contents()->TestDidNavigate( |
732 pending_rfh, 1, url2, PAGE_TRANSITION_TYPED); | 735 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); |
733 SiteInstance* new_instance = contents()->GetSiteInstance(); | 736 SiteInstance* new_instance = contents()->GetSiteInstance(); |
734 | 737 |
735 EXPECT_FALSE(contents()->cross_navigation_pending()); | 738 EXPECT_FALSE(contents()->cross_navigation_pending()); |
736 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); | 739 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); |
737 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); | 740 EXPECT_EQ(url2, contents()->GetLastCommittedURL()); |
738 EXPECT_EQ(url2, contents()->GetVisibleURL()); | 741 EXPECT_EQ(url2, contents()->GetVisibleURL()); |
739 EXPECT_NE(new_instance, orig_instance); | 742 EXPECT_NE(new_instance, orig_instance); |
740 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 743 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
741 // We keep the original RFH around, swapped out. | 744 // We keep the original RFH around, swapped out. |
742 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( | 745 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList( |
(...skipping 16 matching lines...) Expand all Loading... |
759 SiteInstanceImpl* orig_instance = | 762 SiteInstanceImpl* orig_instance = |
760 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); | 763 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); |
761 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 764 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
762 | 765 |
763 // Restore a navigation entry for URL that should not assign site to the | 766 // Restore a navigation entry for URL that should not assign site to the |
764 // SiteInstance. | 767 // SiteInstance. |
765 browser_client.set_assign_site_for_url(false); | 768 browser_client.set_assign_site_for_url(false); |
766 const GURL native_url("non-site-url://stuffandthings"); | 769 const GURL native_url("non-site-url://stuffandthings"); |
767 std::vector<NavigationEntry*> entries; | 770 std::vector<NavigationEntry*> entries; |
768 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( | 771 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( |
769 native_url, Referrer(), PAGE_TRANSITION_LINK, false, std::string(), | 772 native_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, std::string(), |
770 browser_context()); | 773 browser_context()); |
771 entry->SetPageID(0); | 774 entry->SetPageID(0); |
772 entries.push_back(entry); | 775 entries.push_back(entry); |
773 controller().Restore( | 776 controller().Restore( |
774 0, | 777 0, |
775 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 778 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
776 &entries); | 779 &entries); |
777 ASSERT_EQ(0u, entries.size()); | 780 ASSERT_EQ(0u, entries.size()); |
778 ASSERT_EQ(1, controller().GetEntryCount()); | 781 ASSERT_EQ(1, controller().GetEntryCount()); |
779 controller().GoToIndex(0); | 782 controller().GoToIndex(0); |
780 contents()->TestDidNavigate(orig_rfh, 0, native_url, PAGE_TRANSITION_RELOAD); | 783 contents()->TestDidNavigate( |
| 784 orig_rfh, 0, native_url, ui::PAGE_TRANSITION_RELOAD); |
781 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); | 785 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); |
782 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL()); | 786 EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL()); |
783 EXPECT_FALSE(orig_instance->HasSite()); | 787 EXPECT_FALSE(orig_instance->HasSite()); |
784 | 788 |
785 // Navigate to a regular site and verify that the SiteInstance was kept. | 789 // Navigate to a regular site and verify that the SiteInstance was kept. |
786 browser_client.set_assign_site_for_url(true); | 790 browser_client.set_assign_site_for_url(true); |
787 const GURL url("http://www.google.com"); | 791 const GURL url("http://www.google.com"); |
788 controller().LoadURL( | 792 controller().LoadURL( |
789 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 793 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
790 contents()->TestDidNavigate(orig_rfh, 2, url, PAGE_TRANSITION_TYPED); | 794 contents()->TestDidNavigate(orig_rfh, 2, url, ui::PAGE_TRANSITION_TYPED); |
791 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); | 795 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); |
792 | 796 |
793 // Cleanup. | 797 // Cleanup. |
794 DeleteContents(); | 798 DeleteContents(); |
795 } | 799 } |
796 | 800 |
797 // Complement for NavigateFromRestoredSitelessUrl, verifying that when a regular | 801 // Complement for NavigateFromRestoredSitelessUrl, verifying that when a regular |
798 // tab is restored, the SiteInstance will change upon navigation. | 802 // tab is restored, the SiteInstance will change upon navigation. |
799 TEST_F(WebContentsImplTest, NavigateFromRestoredRegularUrl) { | 803 TEST_F(WebContentsImplTest, NavigateFromRestoredRegularUrl) { |
800 WebContentsImplTestBrowserClient browser_client; | 804 WebContentsImplTestBrowserClient browser_client; |
801 SetBrowserClientForTesting(&browser_client); | 805 SetBrowserClientForTesting(&browser_client); |
802 SiteInstanceImpl* orig_instance = | 806 SiteInstanceImpl* orig_instance = |
803 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); | 807 static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance()); |
804 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 808 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
805 | 809 |
806 // Restore a navigation entry for a regular URL ensuring that the embedder | 810 // Restore a navigation entry for a regular URL ensuring that the embedder |
807 // ShouldAssignSiteForUrl override is disabled (i.e. returns true). | 811 // ShouldAssignSiteForUrl override is disabled (i.e. returns true). |
808 browser_client.set_assign_site_for_url(true); | 812 browser_client.set_assign_site_for_url(true); |
809 const GURL regular_url("http://www.yahoo.com"); | 813 const GURL regular_url("http://www.yahoo.com"); |
810 std::vector<NavigationEntry*> entries; | 814 std::vector<NavigationEntry*> entries; |
811 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( | 815 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( |
812 regular_url, Referrer(), PAGE_TRANSITION_LINK, false, std::string(), | 816 regular_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, std::string(), |
813 browser_context()); | 817 browser_context()); |
814 entry->SetPageID(0); | 818 entry->SetPageID(0); |
815 entries.push_back(entry); | 819 entries.push_back(entry); |
816 controller().Restore( | 820 controller().Restore( |
817 0, | 821 0, |
818 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 822 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
819 &entries); | 823 &entries); |
820 ASSERT_EQ(0u, entries.size()); | 824 ASSERT_EQ(0u, entries.size()); |
821 ASSERT_EQ(1, controller().GetEntryCount()); | 825 ASSERT_EQ(1, controller().GetEntryCount()); |
822 controller().GoToIndex(0); | 826 controller().GoToIndex(0); |
823 contents()->TestDidNavigate(orig_rfh, 0, regular_url, PAGE_TRANSITION_RELOAD); | 827 contents()->TestDidNavigate( |
| 828 orig_rfh, 0, regular_url, ui::PAGE_TRANSITION_RELOAD); |
824 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); | 829 EXPECT_EQ(orig_instance, contents()->GetSiteInstance()); |
825 EXPECT_TRUE(orig_instance->HasSite()); | 830 EXPECT_TRUE(orig_instance->HasSite()); |
826 | 831 |
827 // Navigate to another site and verify that a new SiteInstance was created. | 832 // Navigate to another site and verify that a new SiteInstance was created. |
828 const GURL url("http://www.google.com"); | 833 const GURL url("http://www.google.com"); |
829 controller().LoadURL( | 834 controller().LoadURL( |
830 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 835 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
831 contents()->TestDidNavigate( | 836 contents()->TestDidNavigate( |
832 contents()->GetPendingMainFrame(), 2, url, PAGE_TRANSITION_TYPED); | 837 contents()->GetPendingMainFrame(), 2, url, ui::PAGE_TRANSITION_TYPED); |
833 EXPECT_NE(orig_instance, contents()->GetSiteInstance()); | 838 EXPECT_NE(orig_instance, contents()->GetSiteInstance()); |
834 | 839 |
835 // Cleanup. | 840 // Cleanup. |
836 DeleteContents(); | 841 DeleteContents(); |
837 } | 842 } |
838 | 843 |
839 // Test that we can find an opener RVH even if it's pending. | 844 // Test that we can find an opener RVH even if it's pending. |
840 // http://crbug.com/176252. | 845 // http://crbug.com/176252. |
841 TEST_F(WebContentsImplTest, FindOpenerRVHWhenPending) { | 846 TEST_F(WebContentsImplTest, FindOpenerRVHWhenPending) { |
842 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 847 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
843 | 848 |
844 // Navigate to a URL. | 849 // Navigate to a URL. |
845 const GURL url("http://www.google.com"); | 850 const GURL url("http://www.google.com"); |
846 controller().LoadURL( | 851 controller().LoadURL( |
847 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 852 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
848 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 853 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
849 | 854 |
850 // Start to navigate first tab to a new site, so that it has a pending RVH. | 855 // Start to navigate first tab to a new site, so that it has a pending RVH. |
851 const GURL url2("http://www.yahoo.com"); | 856 const GURL url2("http://www.yahoo.com"); |
852 controller().LoadURL( | 857 controller().LoadURL( |
853 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 858 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
854 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); | 859 orig_rfh->GetRenderViewHost()->SendBeforeUnloadACK(true); |
855 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); | 860 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); |
856 | 861 |
857 // While it is still pending, simulate opening a new tab with the first tab | 862 // While it is still pending, simulate opening a new tab with the first tab |
858 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews | 863 // as its opener. This will call WebContentsImpl::CreateOpenerRenderViews |
859 // on the opener to ensure that an RVH exists. | 864 // on the opener to ensure that an RVH exists. |
860 int opener_routing_id = | 865 int opener_routing_id = |
861 contents()->CreateOpenerRenderViews(pending_rfh->GetSiteInstance()); | 866 contents()->CreateOpenerRenderViews(pending_rfh->GetSiteInstance()); |
862 | 867 |
863 // We should find the pending RVH and not create a new one. | 868 // We should find the pending RVH and not create a new one. |
864 EXPECT_EQ(pending_rfh->GetRenderViewHost()->GetRoutingID(), | 869 EXPECT_EQ(pending_rfh->GetRenderViewHost()->GetRoutingID(), |
865 opener_routing_id); | 870 opener_routing_id); |
866 } | 871 } |
867 | 872 |
868 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site, | 873 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site, |
869 // to determine whether a navigation is cross-site. | 874 // to determine whether a navigation is cross-site. |
870 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) { | 875 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) { |
871 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 876 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
872 SiteInstance* instance1 = contents()->GetSiteInstance(); | 877 SiteInstance* instance1 = contents()->GetSiteInstance(); |
873 | 878 |
874 // Navigate to URL. | 879 // Navigate to URL. |
875 const GURL url("http://www.google.com"); | 880 const GURL url("http://www.google.com"); |
876 controller().LoadURL( | 881 controller().LoadURL( |
877 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 882 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
878 contents()->TestDidNavigate( | 883 contents()->TestDidNavigate( |
879 orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 884 orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
880 | 885 |
881 // Open a related contents to a second site. | 886 // Open a related contents to a second site. |
882 scoped_ptr<TestWebContents> contents2( | 887 scoped_ptr<TestWebContents> contents2( |
883 TestWebContents::Create(browser_context(), instance1)); | 888 TestWebContents::Create(browser_context(), instance1)); |
884 const GURL url2("http://www.yahoo.com"); | 889 const GURL url2("http://www.yahoo.com"); |
885 contents2->GetController().LoadURL(url2, Referrer(), | 890 contents2->GetController().LoadURL(url2, Referrer(), |
886 PAGE_TRANSITION_TYPED, | 891 ui::PAGE_TRANSITION_TYPED, |
887 std::string()); | 892 std::string()); |
888 // The first RVH in contents2 isn't live yet, so we shortcut the cross site | 893 // The first RVH in contents2 isn't live yet, so we shortcut the cross site |
889 // pending. | 894 // pending. |
890 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); | 895 TestRenderFrameHost* rfh2 = contents2->GetMainFrame(); |
891 EXPECT_FALSE(contents2->cross_navigation_pending()); | 896 EXPECT_FALSE(contents2->cross_navigation_pending()); |
892 contents2->TestDidNavigate(rfh2, 2, url2, PAGE_TRANSITION_TYPED); | 897 contents2->TestDidNavigate(rfh2, 2, url2, ui::PAGE_TRANSITION_TYPED); |
893 SiteInstance* instance2 = contents2->GetSiteInstance(); | 898 SiteInstance* instance2 = contents2->GetSiteInstance(); |
894 EXPECT_NE(instance1, instance2); | 899 EXPECT_NE(instance1, instance2); |
895 EXPECT_FALSE(contents2->cross_navigation_pending()); | 900 EXPECT_FALSE(contents2->cross_navigation_pending()); |
896 | 901 |
897 // Simulate a link click in first contents to second site. Doesn't switch | 902 // Simulate a link click in first contents to second site. Doesn't switch |
898 // SiteInstances, because we don't intercept WebKit navigations. | 903 // SiteInstances, because we don't intercept WebKit navigations. |
899 contents()->TestDidNavigate( | 904 contents()->TestDidNavigate( |
900 orig_rfh, 2, url2, PAGE_TRANSITION_TYPED); | 905 orig_rfh, 2, url2, ui::PAGE_TRANSITION_TYPED); |
901 SiteInstance* instance3 = contents()->GetSiteInstance(); | 906 SiteInstance* instance3 = contents()->GetSiteInstance(); |
902 EXPECT_EQ(instance1, instance3); | 907 EXPECT_EQ(instance1, instance3); |
903 EXPECT_FALSE(contents()->cross_navigation_pending()); | 908 EXPECT_FALSE(contents()->cross_navigation_pending()); |
904 | 909 |
905 // Navigate to the new site. Doesn't switch SiteInstancees, because we | 910 // Navigate to the new site. Doesn't switch SiteInstancees, because we |
906 // compare against the current URL, not the SiteInstance's site. | 911 // compare against the current URL, not the SiteInstance's site. |
907 const GURL url3("http://mail.yahoo.com"); | 912 const GURL url3("http://mail.yahoo.com"); |
908 controller().LoadURL( | 913 controller().LoadURL( |
909 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 914 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
910 EXPECT_FALSE(contents()->cross_navigation_pending()); | 915 EXPECT_FALSE(contents()->cross_navigation_pending()); |
911 contents()->TestDidNavigate( | 916 contents()->TestDidNavigate( |
912 orig_rfh, 3, url3, PAGE_TRANSITION_TYPED); | 917 orig_rfh, 3, url3, ui::PAGE_TRANSITION_TYPED); |
913 SiteInstance* instance4 = contents()->GetSiteInstance(); | 918 SiteInstance* instance4 = contents()->GetSiteInstance(); |
914 EXPECT_EQ(instance1, instance4); | 919 EXPECT_EQ(instance1, instance4); |
915 } | 920 } |
916 | 921 |
917 // Test that the onbeforeunload and onunload handlers run when navigating | 922 // Test that the onbeforeunload and onunload handlers run when navigating |
918 // across site boundaries. | 923 // across site boundaries. |
919 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { | 924 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { |
920 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 925 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
921 SiteInstance* instance1 = contents()->GetSiteInstance(); | 926 SiteInstance* instance1 = contents()->GetSiteInstance(); |
922 | 927 |
923 // Navigate to URL. First URL should use first RenderViewHost. | 928 // Navigate to URL. First URL should use first RenderViewHost. |
924 const GURL url("http://www.google.com"); | 929 const GURL url("http://www.google.com"); |
925 controller().LoadURL( | 930 controller().LoadURL( |
926 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 931 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
927 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 932 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
928 EXPECT_FALSE(contents()->cross_navigation_pending()); | 933 EXPECT_FALSE(contents()->cross_navigation_pending()); |
929 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 934 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
930 | 935 |
931 // Navigate to new site, but simulate an onbeforeunload denial. | 936 // Navigate to new site, but simulate an onbeforeunload denial. |
932 const GURL url2("http://www.yahoo.com"); | 937 const GURL url2("http://www.yahoo.com"); |
933 controller().LoadURL( | 938 controller().LoadURL( |
934 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 939 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
935 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 940 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
936 base::TimeTicks now = base::TimeTicks::Now(); | 941 base::TimeTicks now = base::TimeTicks::Now(); |
937 orig_rfh->OnMessageReceived( | 942 orig_rfh->OnMessageReceived( |
938 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 943 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
939 EXPECT_FALSE( | 944 EXPECT_FALSE( |
940 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 945 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
941 EXPECT_FALSE(contents()->cross_navigation_pending()); | 946 EXPECT_FALSE(contents()->cross_navigation_pending()); |
942 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 947 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
943 | 948 |
944 // Navigate again, but simulate an onbeforeunload approval. | 949 // Navigate again, but simulate an onbeforeunload approval. |
945 controller().LoadURL( | 950 controller().LoadURL( |
946 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 951 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
947 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 952 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
948 now = base::TimeTicks::Now(); | 953 now = base::TimeTicks::Now(); |
949 orig_rfh->OnMessageReceived( | 954 orig_rfh->OnMessageReceived( |
950 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 955 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
951 EXPECT_FALSE( | 956 EXPECT_FALSE( |
952 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 957 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
953 EXPECT_TRUE(contents()->cross_navigation_pending()); | 958 EXPECT_TRUE(contents()->cross_navigation_pending()); |
954 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); | 959 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); |
955 | 960 |
956 // We won't hear DidNavigate until the onunload handler has finished running. | 961 // We won't hear DidNavigate until the onunload handler has finished running. |
957 | 962 |
958 // DidNavigate from the pending page. | 963 // DidNavigate from the pending page. |
959 contents()->TestDidNavigate( | 964 contents()->TestDidNavigate( |
960 pending_rfh, 1, url2, PAGE_TRANSITION_TYPED); | 965 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); |
961 SiteInstance* instance2 = contents()->GetSiteInstance(); | 966 SiteInstance* instance2 = contents()->GetSiteInstance(); |
962 EXPECT_FALSE(contents()->cross_navigation_pending()); | 967 EXPECT_FALSE(contents()->cross_navigation_pending()); |
963 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); | 968 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); |
964 EXPECT_NE(instance1, instance2); | 969 EXPECT_NE(instance1, instance2); |
965 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 970 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
966 } | 971 } |
967 | 972 |
968 // Test that during a slow cross-site navigation, the original renderer can | 973 // Test that during a slow cross-site navigation, the original renderer can |
969 // navigate to a different URL and have it displayed, canceling the slow | 974 // navigate to a different URL and have it displayed, canceling the slow |
970 // navigation. | 975 // navigation. |
971 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) { | 976 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) { |
972 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 977 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
973 SiteInstance* instance1 = contents()->GetSiteInstance(); | 978 SiteInstance* instance1 = contents()->GetSiteInstance(); |
974 | 979 |
975 // Navigate to URL. First URL should use first RenderFrameHost. | 980 // Navigate to URL. First URL should use first RenderFrameHost. |
976 const GURL url("http://www.google.com"); | 981 const GURL url("http://www.google.com"); |
977 controller().LoadURL( | 982 controller().LoadURL( |
978 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 983 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
979 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 984 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
980 EXPECT_FALSE(contents()->cross_navigation_pending()); | 985 EXPECT_FALSE(contents()->cross_navigation_pending()); |
981 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 986 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
982 | 987 |
983 // Navigate to new site, simulating an onbeforeunload approval. | 988 // Navigate to new site, simulating an onbeforeunload approval. |
984 const GURL url2("http://www.yahoo.com"); | 989 const GURL url2("http://www.yahoo.com"); |
985 controller().LoadURL( | 990 controller().LoadURL( |
986 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 991 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
987 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 992 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
988 base::TimeTicks now = base::TimeTicks::Now(); | 993 base::TimeTicks now = base::TimeTicks::Now(); |
989 orig_rfh->OnMessageReceived(FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 994 orig_rfh->OnMessageReceived(FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
990 EXPECT_TRUE(contents()->cross_navigation_pending()); | 995 EXPECT_TRUE(contents()->cross_navigation_pending()); |
991 | 996 |
992 // Suppose the original renderer navigates before the new one is ready. | 997 // Suppose the original renderer navigates before the new one is ready. |
993 orig_rfh->SendNavigate(2, GURL("http://www.google.com/foo")); | 998 orig_rfh->SendNavigate(2, GURL("http://www.google.com/foo")); |
994 | 999 |
995 // Verify that the pending navigation is cancelled. | 1000 // Verify that the pending navigation is cancelled. |
996 EXPECT_FALSE( | 1001 EXPECT_FALSE( |
997 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 1002 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
998 SiteInstance* instance2 = contents()->GetSiteInstance(); | 1003 SiteInstance* instance2 = contents()->GetSiteInstance(); |
999 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1004 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1000 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 1005 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
1001 EXPECT_EQ(instance1, instance2); | 1006 EXPECT_EQ(instance1, instance2); |
1002 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1007 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1003 } | 1008 } |
1004 | 1009 |
1005 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { | 1010 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { |
1006 // Start with a web ui page, which gets a new RVH with WebUI bindings. | 1011 // Start with a web ui page, which gets a new RVH with WebUI bindings. |
1007 const GURL url1("chrome://blah"); | 1012 const GURL url1("chrome://blah"); |
1008 controller().LoadURL( | 1013 controller().LoadURL( |
1009 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1014 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1010 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); | 1015 TestRenderFrameHost* ntp_rfh = contents()->GetMainFrame(); |
1011 contents()->TestDidNavigate(ntp_rfh, 1, url1, PAGE_TRANSITION_TYPED); | 1016 contents()->TestDidNavigate(ntp_rfh, 1, url1, ui::PAGE_TRANSITION_TYPED); |
1012 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); | 1017 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); |
1013 SiteInstance* instance1 = contents()->GetSiteInstance(); | 1018 SiteInstance* instance1 = contents()->GetSiteInstance(); |
1014 | 1019 |
1015 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1020 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1016 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame()); | 1021 EXPECT_EQ(ntp_rfh, contents()->GetMainFrame()); |
1017 EXPECT_EQ(url1, entry1->GetURL()); | 1022 EXPECT_EQ(url1, entry1->GetURL()); |
1018 EXPECT_EQ(instance1, | 1023 EXPECT_EQ(instance1, |
1019 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); | 1024 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); |
1020 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetEnabledBindings() & | 1025 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->GetEnabledBindings() & |
1021 BINDINGS_POLICY_WEB_UI); | 1026 BINDINGS_POLICY_WEB_UI); |
1022 | 1027 |
1023 // Navigate to new site. | 1028 // Navigate to new site. |
1024 const GURL url2("http://www.google.com"); | 1029 const GURL url2("http://www.google.com"); |
1025 controller().LoadURL( | 1030 controller().LoadURL( |
1026 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1031 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1027 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1032 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1028 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); | 1033 TestRenderFrameHost* google_rfh = contents()->GetPendingMainFrame(); |
1029 | 1034 |
1030 // Simulate beforeunload approval. | 1035 // Simulate beforeunload approval. |
1031 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 1036 EXPECT_TRUE(ntp_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
1032 base::TimeTicks now = base::TimeTicks::Now(); | 1037 base::TimeTicks now = base::TimeTicks::Now(); |
1033 ntp_rfh->OnMessageReceived( | 1038 ntp_rfh->OnMessageReceived( |
1034 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1039 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
1035 | 1040 |
1036 // DidNavigate from the pending page. | 1041 // DidNavigate from the pending page. |
1037 contents()->TestDidNavigate( | 1042 contents()->TestDidNavigate( |
1038 google_rfh, 1, url2, PAGE_TRANSITION_TYPED); | 1043 google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); |
1039 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); | 1044 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); |
1040 SiteInstance* instance2 = contents()->GetSiteInstance(); | 1045 SiteInstance* instance2 = contents()->GetSiteInstance(); |
1041 | 1046 |
1042 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1047 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1043 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); | 1048 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); |
1044 EXPECT_NE(instance1, instance2); | 1049 EXPECT_NE(instance1, instance2); |
1045 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 1050 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
1046 EXPECT_EQ(url2, entry2->GetURL()); | 1051 EXPECT_EQ(url2, entry2->GetURL()); |
1047 EXPECT_EQ(instance2, | 1052 EXPECT_EQ(instance2, |
1048 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); | 1053 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); |
1049 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() & | 1054 EXPECT_FALSE(google_rfh->GetRenderViewHost()->GetEnabledBindings() & |
1050 BINDINGS_POLICY_WEB_UI); | 1055 BINDINGS_POLICY_WEB_UI); |
1051 | 1056 |
1052 // Navigate to third page on same site. | 1057 // Navigate to third page on same site. |
1053 const GURL url3("http://news.google.com"); | 1058 const GURL url3("http://news.google.com"); |
1054 controller().LoadURL( | 1059 controller().LoadURL( |
1055 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1060 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1056 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1061 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1057 contents()->TestDidNavigate( | 1062 contents()->TestDidNavigate( |
1058 google_rfh, 2, url3, PAGE_TRANSITION_TYPED); | 1063 google_rfh, 2, url3, ui::PAGE_TRANSITION_TYPED); |
1059 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); | 1064 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); |
1060 SiteInstance* instance3 = contents()->GetSiteInstance(); | 1065 SiteInstance* instance3 = contents()->GetSiteInstance(); |
1061 | 1066 |
1062 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1067 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1063 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); | 1068 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); |
1064 EXPECT_EQ(instance2, instance3); | 1069 EXPECT_EQ(instance2, instance3); |
1065 EXPECT_FALSE(contents()->GetPendingMainFrame()); | 1070 EXPECT_FALSE(contents()->GetPendingMainFrame()); |
1066 EXPECT_EQ(url3, entry3->GetURL()); | 1071 EXPECT_EQ(url3, entry3->GetURL()); |
1067 EXPECT_EQ(instance3, | 1072 EXPECT_EQ(instance3, |
1068 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); | 1073 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); |
(...skipping 10 matching lines...) Expand all Loading... |
1079 EXPECT_EQ(entry1, controller().GetPendingEntry()); | 1084 EXPECT_EQ(entry1, controller().GetPendingEntry()); |
1080 | 1085 |
1081 // Simulate beforeunload approval. | 1086 // Simulate beforeunload approval. |
1082 EXPECT_TRUE( | 1087 EXPECT_TRUE( |
1083 google_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 1088 google_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
1084 now = base::TimeTicks::Now(); | 1089 now = base::TimeTicks::Now(); |
1085 google_rfh->OnMessageReceived( | 1090 google_rfh->OnMessageReceived( |
1086 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1091 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
1087 | 1092 |
1088 // DidNavigate from the first back. This aborts the second back's pending RFH. | 1093 // DidNavigate from the first back. This aborts the second back's pending RFH. |
1089 contents()->TestDidNavigate(google_rfh, 1, url2, PAGE_TRANSITION_TYPED); | 1094 contents()->TestDidNavigate(google_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); |
1090 | 1095 |
1091 // We should commit this page and forget about the second back. | 1096 // We should commit this page and forget about the second back. |
1092 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1097 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1093 EXPECT_FALSE(controller().GetPendingEntry()); | 1098 EXPECT_FALSE(controller().GetPendingEntry()); |
1094 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); | 1099 EXPECT_EQ(google_rfh, contents()->GetMainFrame()); |
1095 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL()); | 1100 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL()); |
1096 | 1101 |
1097 // We should not have corrupted the NTP entry. | 1102 // We should not have corrupted the NTP entry. |
1098 EXPECT_EQ(instance3, | 1103 EXPECT_EQ(instance3, |
1099 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); | 1104 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); |
1100 EXPECT_EQ(instance2, | 1105 EXPECT_EQ(instance2, |
1101 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); | 1106 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); |
1102 EXPECT_EQ(instance1, | 1107 EXPECT_EQ(instance1, |
1103 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); | 1108 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); |
1104 EXPECT_EQ(url1, entry1->GetURL()); | 1109 EXPECT_EQ(url1, entry1->GetURL()); |
1105 } | 1110 } |
1106 | 1111 |
1107 // Test that during a slow cross-site navigation, a sub-frame navigation in the | 1112 // Test that during a slow cross-site navigation, a sub-frame navigation in the |
1108 // original renderer will not cancel the slow navigation (bug 42029). | 1113 // original renderer will not cancel the slow navigation (bug 42029). |
1109 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) { | 1114 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) { |
1110 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1115 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
1111 | 1116 |
1112 // Navigate to URL. First URL should use the original RenderFrameHost. | 1117 // Navigate to URL. First URL should use the original RenderFrameHost. |
1113 const GURL url("http://www.google.com"); | 1118 const GURL url("http://www.google.com"); |
1114 controller().LoadURL( | 1119 controller().LoadURL( |
1115 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1120 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1116 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 1121 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
1117 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1122 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1118 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 1123 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
1119 | 1124 |
1120 // Start navigating to new site. | 1125 // Start navigating to new site. |
1121 const GURL url2("http://www.yahoo.com"); | 1126 const GURL url2("http://www.yahoo.com"); |
1122 controller().LoadURL( | 1127 controller().LoadURL( |
1123 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1128 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1124 | 1129 |
1125 // Simulate a sub-frame navigation arriving and ensure the RVH is still | 1130 // Simulate a sub-frame navigation arriving and ensure the RVH is still |
1126 // waiting for a before unload response. | 1131 // waiting for a before unload response. |
1127 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe"); | 1132 TestRenderFrameHost* child_rfh = orig_rfh->AppendChild("subframe"); |
1128 child_rfh->SendNavigateWithTransition( | 1133 child_rfh->SendNavigateWithTransition( |
1129 1, GURL("http://google.com/frame"), PAGE_TRANSITION_AUTO_SUBFRAME); | 1134 1, GURL("http://google.com/frame"), ui::PAGE_TRANSITION_AUTO_SUBFRAME); |
1130 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 1135 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
1131 | 1136 |
1132 // Now simulate the onbeforeunload approval and verify the navigation is | 1137 // Now simulate the onbeforeunload approval and verify the navigation is |
1133 // not canceled. | 1138 // not canceled. |
1134 base::TimeTicks now = base::TimeTicks::Now(); | 1139 base::TimeTicks now = base::TimeTicks::Now(); |
1135 orig_rfh->OnMessageReceived( | 1140 orig_rfh->OnMessageReceived( |
1136 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1141 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
1137 EXPECT_FALSE( | 1142 EXPECT_FALSE( |
1138 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 1143 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
1139 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1144 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1140 } | 1145 } |
1141 | 1146 |
1142 // Test that a cross-site navigation is not preempted if the previous | 1147 // Test that a cross-site navigation is not preempted if the previous |
1143 // renderer sends a FrameNavigate message just before being told to stop. | 1148 // renderer sends a FrameNavigate message just before being told to stop. |
1144 // We should only preempt the cross-site navigation if the previous renderer | 1149 // We should only preempt the cross-site navigation if the previous renderer |
1145 // has started a new navigation. See http://crbug.com/79176. | 1150 // has started a new navigation. See http://crbug.com/79176. |
1146 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { | 1151 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { |
1147 // Navigate to NTP URL. | 1152 // Navigate to NTP URL. |
1148 const GURL url("chrome://blah"); | 1153 const GURL url("chrome://blah"); |
1149 controller().LoadURL( | 1154 controller().LoadURL( |
1150 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1155 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1151 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1156 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
1152 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1157 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1153 | 1158 |
1154 // Navigate to new site, with the beforeunload request in flight. | 1159 // Navigate to new site, with the beforeunload request in flight. |
1155 const GURL url2("http://www.yahoo.com"); | 1160 const GURL url2("http://www.yahoo.com"); |
1156 controller().LoadURL( | 1161 controller().LoadURL( |
1157 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1162 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1158 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); | 1163 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); |
1159 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1164 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1160 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 1165 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
1161 | 1166 |
1162 // Suppose the first navigation tries to commit now, with a | 1167 // Suppose the first navigation tries to commit now, with a |
1163 // FrameMsg_Stop in flight. This should not cancel the pending navigation, | 1168 // FrameMsg_Stop in flight. This should not cancel the pending navigation, |
1164 // but it should act as if the beforeunload ack arrived. | 1169 // but it should act as if the beforeunload ack arrived. |
1165 orig_rfh->SendNavigate(1, GURL("chrome://blah")); | 1170 orig_rfh->SendNavigate(1, GURL("chrome://blah")); |
1166 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1171 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1167 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 1172 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
1168 EXPECT_FALSE( | 1173 EXPECT_FALSE( |
1169 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 1174 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
1170 | 1175 |
1171 // The pending navigation should be able to commit successfully. | 1176 // The pending navigation should be able to commit successfully. |
1172 contents()->TestDidNavigate(pending_rfh, 1, url2, PAGE_TRANSITION_TYPED); | 1177 contents()->TestDidNavigate(pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); |
1173 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1178 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1174 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); | 1179 EXPECT_EQ(pending_rfh, contents()->GetMainFrame()); |
1175 } | 1180 } |
1176 | 1181 |
1177 // Test that a cross-site navigation that doesn't commit after the unload | 1182 // Test that a cross-site navigation that doesn't commit after the unload |
1178 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562 | 1183 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562 |
1179 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { | 1184 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { |
1180 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1185 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
1181 SiteInstance* instance1 = contents()->GetSiteInstance(); | 1186 SiteInstance* instance1 = contents()->GetSiteInstance(); |
1182 | 1187 |
1183 // Navigate to URL. First URL should use original RenderFrameHost. | 1188 // Navigate to URL. First URL should use original RenderFrameHost. |
1184 const GURL url("http://www.google.com"); | 1189 const GURL url("http://www.google.com"); |
1185 controller().LoadURL( | 1190 controller().LoadURL( |
1186 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1191 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1187 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 1192 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
1188 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1193 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1189 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 1194 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
1190 | 1195 |
1191 // Navigate to new site, simulating an onbeforeunload approval. | 1196 // Navigate to new site, simulating an onbeforeunload approval. |
1192 const GURL url2("http://www.yahoo.com"); | 1197 const GURL url2("http://www.yahoo.com"); |
1193 controller().LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1198 controller().LoadURL( |
| 1199 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1194 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 1200 EXPECT_TRUE(orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
1195 base::TimeTicks now = base::TimeTicks::Now(); | 1201 base::TimeTicks now = base::TimeTicks::Now(); |
1196 orig_rfh->OnMessageReceived( | 1202 orig_rfh->OnMessageReceived( |
1197 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); | 1203 FrameHostMsg_BeforeUnload_ACK(0, true, now, now)); |
1198 EXPECT_TRUE(contents()->cross_navigation_pending()); | 1204 EXPECT_TRUE(contents()->cross_navigation_pending()); |
1199 | 1205 |
1200 // Simulate swap out message when the response arrives. | 1206 // Simulate swap out message when the response arrives. |
1201 orig_rfh->OnSwappedOut(false); | 1207 orig_rfh->OnSwappedOut(false); |
1202 | 1208 |
1203 // Suppose the navigation doesn't get a chance to commit, and the user | 1209 // Suppose the navigation doesn't get a chance to commit, and the user |
1204 // navigates in the current RFH's SiteInstance. | 1210 // navigates in the current RFH's SiteInstance. |
1205 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1211 controller().LoadURL( |
| 1212 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1206 | 1213 |
1207 // Verify that the pending navigation is cancelled and the renderer is no | 1214 // Verify that the pending navigation is cancelled and the renderer is no |
1208 // longer swapped out. | 1215 // longer swapped out. |
1209 EXPECT_FALSE( | 1216 EXPECT_FALSE( |
1210 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); | 1217 orig_rfh->GetRenderViewHost()->is_waiting_for_beforeunload_ack()); |
1211 SiteInstance* instance2 = contents()->GetSiteInstance(); | 1218 SiteInstance* instance2 = contents()->GetSiteInstance(); |
1212 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1219 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1213 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 1220 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
1214 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, | 1221 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, |
1215 orig_rfh->GetRenderViewHost()->rvh_state()); | 1222 orig_rfh->GetRenderViewHost()->rvh_state()); |
1216 EXPECT_EQ(instance1, instance2); | 1223 EXPECT_EQ(instance1, instance2); |
1217 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); | 1224 EXPECT_TRUE(contents()->GetPendingMainFrame() == NULL); |
1218 } | 1225 } |
1219 | 1226 |
1220 // Test that NavigationEntries have the correct page state after going | 1227 // Test that NavigationEntries have the correct page state after going |
1221 // forward and back. Prevents regression for bug 1116137. | 1228 // forward and back. Prevents regression for bug 1116137. |
1222 TEST_F(WebContentsImplTest, NavigationEntryContentState) { | 1229 TEST_F(WebContentsImplTest, NavigationEntryContentState) { |
1223 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1230 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
1224 | 1231 |
1225 // Navigate to URL. There should be no committed entry yet. | 1232 // Navigate to URL. There should be no committed entry yet. |
1226 const GURL url("http://www.google.com"); | 1233 const GURL url("http://www.google.com"); |
1227 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1234 controller().LoadURL( |
| 1235 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1228 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 1236 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
1229 EXPECT_TRUE(entry == NULL); | 1237 EXPECT_TRUE(entry == NULL); |
1230 | 1238 |
1231 // Committed entry should have page state after DidNavigate. | 1239 // Committed entry should have page state after DidNavigate. |
1232 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 1240 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
1233 entry = controller().GetLastCommittedEntry(); | 1241 entry = controller().GetLastCommittedEntry(); |
1234 EXPECT_TRUE(entry->GetPageState().IsValid()); | 1242 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1235 | 1243 |
1236 // Navigate to same site. | 1244 // Navigate to same site. |
1237 const GURL url2("http://images.google.com"); | 1245 const GURL url2("http://images.google.com"); |
1238 controller().LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1246 controller().LoadURL( |
| 1247 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1239 entry = controller().GetLastCommittedEntry(); | 1248 entry = controller().GetLastCommittedEntry(); |
1240 EXPECT_TRUE(entry->GetPageState().IsValid()); | 1249 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1241 | 1250 |
1242 // Committed entry should have page state after DidNavigate. | 1251 // Committed entry should have page state after DidNavigate. |
1243 contents()->TestDidNavigate(orig_rfh, 2, url2, PAGE_TRANSITION_TYPED); | 1252 contents()->TestDidNavigate(orig_rfh, 2, url2, ui::PAGE_TRANSITION_TYPED); |
1244 entry = controller().GetLastCommittedEntry(); | 1253 entry = controller().GetLastCommittedEntry(); |
1245 EXPECT_TRUE(entry->GetPageState().IsValid()); | 1254 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1246 | 1255 |
1247 // Now go back. Committed entry should still have page state. | 1256 // Now go back. Committed entry should still have page state. |
1248 controller().GoBack(); | 1257 controller().GoBack(); |
1249 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 1258 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
1250 entry = controller().GetLastCommittedEntry(); | 1259 entry = controller().GetLastCommittedEntry(); |
1251 EXPECT_TRUE(entry->GetPageState().IsValid()); | 1260 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1252 } | 1261 } |
1253 | 1262 |
1254 // Test that NavigationEntries have the correct page state and SiteInstance | 1263 // Test that NavigationEntries have the correct page state and SiteInstance |
1255 // state after opening a new window to about:blank. Prevents regression for | 1264 // state after opening a new window to about:blank. Prevents regression for |
1256 // bugs b/1116137 and http://crbug.com/111975. | 1265 // bugs b/1116137 and http://crbug.com/111975. |
1257 TEST_F(WebContentsImplTest, NavigationEntryContentStateNewWindow) { | 1266 TEST_F(WebContentsImplTest, NavigationEntryContentStateNewWindow) { |
1258 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1267 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
1259 | 1268 |
1260 // When opening a new window, it is navigated to about:blank internally. | 1269 // When opening a new window, it is navigated to about:blank internally. |
1261 // Currently, this results in two DidNavigate events. | 1270 // Currently, this results in two DidNavigate events. |
1262 const GURL url(url::kAboutBlankURL); | 1271 const GURL url(url::kAboutBlankURL); |
1263 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 1272 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
1264 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 1273 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
1265 | 1274 |
1266 // Should have a page state here. | 1275 // Should have a page state here. |
1267 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 1276 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
1268 EXPECT_TRUE(entry->GetPageState().IsValid()); | 1277 EXPECT_TRUE(entry->GetPageState().IsValid()); |
1269 | 1278 |
1270 // The SiteInstance should be available for other navigations to use. | 1279 // The SiteInstance should be available for other navigations to use. |
1271 NavigationEntryImpl* entry_impl = | 1280 NavigationEntryImpl* entry_impl = |
1272 NavigationEntryImpl::FromNavigationEntry(entry); | 1281 NavigationEntryImpl::FromNavigationEntry(entry); |
1273 EXPECT_FALSE(entry_impl->site_instance()->HasSite()); | 1282 EXPECT_FALSE(entry_impl->site_instance()->HasSite()); |
1274 int32 site_instance_id = entry_impl->site_instance()->GetId(); | 1283 int32 site_instance_id = entry_impl->site_instance()->GetId(); |
1275 | 1284 |
1276 // Navigating to a normal page should not cause a process swap. | 1285 // Navigating to a normal page should not cause a process swap. |
1277 const GURL new_url("http://www.google.com"); | 1286 const GURL new_url("http://www.google.com"); |
1278 controller().LoadURL(new_url, Referrer(), | 1287 controller().LoadURL(new_url, Referrer(), |
1279 PAGE_TRANSITION_TYPED, std::string()); | 1288 ui::PAGE_TRANSITION_TYPED, std::string()); |
1280 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1289 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1281 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 1290 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
1282 contents()->TestDidNavigate(orig_rfh, 1, new_url, PAGE_TRANSITION_TYPED); | 1291 contents()->TestDidNavigate(orig_rfh, 1, new_url, ui::PAGE_TRANSITION_TYPED); |
1283 NavigationEntryImpl* entry_impl2 = NavigationEntryImpl::FromNavigationEntry( | 1292 NavigationEntryImpl* entry_impl2 = NavigationEntryImpl::FromNavigationEntry( |
1284 controller().GetLastCommittedEntry()); | 1293 controller().GetLastCommittedEntry()); |
1285 EXPECT_EQ(site_instance_id, entry_impl2->site_instance()->GetId()); | 1294 EXPECT_EQ(site_instance_id, entry_impl2->site_instance()->GetId()); |
1286 EXPECT_TRUE(entry_impl2->site_instance()->HasSite()); | 1295 EXPECT_TRUE(entry_impl2->site_instance()->HasSite()); |
1287 } | 1296 } |
1288 | 1297 |
1289 // Tests that fullscreen is exited throughout the object hierarchy when | 1298 // Tests that fullscreen is exited throughout the object hierarchy when |
1290 // navigating to a new page. | 1299 // navigating to a new page. |
1291 TEST_F(WebContentsImplTest, NavigationExitsFullscreen) { | 1300 TEST_F(WebContentsImplTest, NavigationExitsFullscreen) { |
1292 FakeFullscreenDelegate fake_delegate; | 1301 FakeFullscreenDelegate fake_delegate; |
1293 contents()->SetDelegate(&fake_delegate); | 1302 contents()->SetDelegate(&fake_delegate); |
1294 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1303 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
1295 TestRenderViewHost* orig_rvh = orig_rfh->GetRenderViewHost(); | 1304 TestRenderViewHost* orig_rvh = orig_rfh->GetRenderViewHost(); |
1296 | 1305 |
1297 // Navigate to a site. | 1306 // Navigate to a site. |
1298 const GURL url("http://www.google.com"); | 1307 const GURL url("http://www.google.com"); |
1299 controller().LoadURL( | 1308 controller().LoadURL( |
1300 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1309 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1301 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 1310 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
1302 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 1311 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
1303 | 1312 |
1304 // Toggle fullscreen mode on (as if initiated via IPC from renderer). | 1313 // Toggle fullscreen mode on (as if initiated via IPC from renderer). |
1305 EXPECT_FALSE(orig_rvh->IsFullscreen()); | 1314 EXPECT_FALSE(orig_rvh->IsFullscreen()); |
1306 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); | 1315 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); |
1307 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); | 1316 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); |
1308 orig_rvh->OnMessageReceived( | 1317 orig_rvh->OnMessageReceived( |
1309 ViewHostMsg_ToggleFullscreen(orig_rvh->GetRoutingID(), true)); | 1318 ViewHostMsg_ToggleFullscreen(orig_rvh->GetRoutingID(), true)); |
1310 EXPECT_TRUE(orig_rvh->IsFullscreen()); | 1319 EXPECT_TRUE(orig_rvh->IsFullscreen()); |
1311 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab()); | 1320 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab()); |
1312 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents())); | 1321 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents())); |
1313 | 1322 |
1314 // Navigate to a new site. | 1323 // Navigate to a new site. |
1315 const GURL url2("http://www.yahoo.com"); | 1324 const GURL url2("http://www.yahoo.com"); |
1316 controller().LoadURL( | 1325 controller().LoadURL( |
1317 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1326 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1318 TestRenderFrameHost* const pending_rfh = contents()->GetPendingMainFrame(); | 1327 TestRenderFrameHost* const pending_rfh = contents()->GetPendingMainFrame(); |
1319 contents()->TestDidNavigate( | 1328 contents()->TestDidNavigate( |
1320 pending_rfh, 1, url2, PAGE_TRANSITION_TYPED); | 1329 pending_rfh, 1, url2, ui::PAGE_TRANSITION_TYPED); |
1321 | 1330 |
1322 // Confirm fullscreen has exited. | 1331 // Confirm fullscreen has exited. |
1323 EXPECT_FALSE(orig_rvh->IsFullscreen()); | 1332 EXPECT_FALSE(orig_rvh->IsFullscreen()); |
1324 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); | 1333 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); |
1325 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); | 1334 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); |
1326 | 1335 |
1327 contents()->SetDelegate(NULL); | 1336 contents()->SetDelegate(NULL); |
1328 } | 1337 } |
1329 | 1338 |
1330 // Tests that fullscreen is exited throughout the object hierarchy when | 1339 // Tests that fullscreen is exited throughout the object hierarchy when |
1331 // instructing NavigationController to GoBack() or GoForward(). | 1340 // instructing NavigationController to GoBack() or GoForward(). |
1332 TEST_F(WebContentsImplTest, HistoryNavigationExitsFullscreen) { | 1341 TEST_F(WebContentsImplTest, HistoryNavigationExitsFullscreen) { |
1333 FakeFullscreenDelegate fake_delegate; | 1342 FakeFullscreenDelegate fake_delegate; |
1334 contents()->SetDelegate(&fake_delegate); | 1343 contents()->SetDelegate(&fake_delegate); |
1335 TestRenderFrameHost* const orig_rfh = contents()->GetMainFrame(); | 1344 TestRenderFrameHost* const orig_rfh = contents()->GetMainFrame(); |
1336 TestRenderViewHost* const orig_rvh = orig_rfh->GetRenderViewHost(); | 1345 TestRenderViewHost* const orig_rvh = orig_rfh->GetRenderViewHost(); |
1337 | 1346 |
1338 // Navigate to a site. | 1347 // Navigate to a site. |
1339 const GURL url("http://www.google.com"); | 1348 const GURL url("http://www.google.com"); |
1340 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1349 controller().LoadURL( |
1341 contents()->TestDidNavigate(orig_rfh, 1, url, PAGE_TRANSITION_TYPED); | 1350 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1351 contents()->TestDidNavigate(orig_rfh, 1, url, ui::PAGE_TRANSITION_TYPED); |
1342 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 1352 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
1343 | 1353 |
1344 // Now, navigate to another page on the same site. | 1354 // Now, navigate to another page on the same site. |
1345 const GURL url2("http://www.google.com/search?q=kittens"); | 1355 const GURL url2("http://www.google.com/search?q=kittens"); |
1346 controller().LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1356 controller().LoadURL( |
| 1357 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1347 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1358 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1348 contents()->TestDidNavigate(orig_rfh, 2, url2, PAGE_TRANSITION_TYPED); | 1359 contents()->TestDidNavigate(orig_rfh, 2, url2, ui::PAGE_TRANSITION_TYPED); |
1349 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 1360 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
1350 | 1361 |
1351 // Sanity-check: Confirm we're not starting out in fullscreen mode. | 1362 // Sanity-check: Confirm we're not starting out in fullscreen mode. |
1352 EXPECT_FALSE(orig_rvh->IsFullscreen()); | 1363 EXPECT_FALSE(orig_rvh->IsFullscreen()); |
1353 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); | 1364 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); |
1354 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); | 1365 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); |
1355 | 1366 |
1356 for (int i = 0; i < 2; ++i) { | 1367 for (int i = 0; i < 2; ++i) { |
1357 // Toggle fullscreen mode on (as if initiated via IPC from renderer). | 1368 // Toggle fullscreen mode on (as if initiated via IPC from renderer). |
1358 orig_rvh->OnMessageReceived( | 1369 orig_rvh->OnMessageReceived( |
1359 ViewHostMsg_ToggleFullscreen(orig_rvh->GetRoutingID(), true)); | 1370 ViewHostMsg_ToggleFullscreen(orig_rvh->GetRoutingID(), true)); |
1360 EXPECT_TRUE(orig_rvh->IsFullscreen()); | 1371 EXPECT_TRUE(orig_rvh->IsFullscreen()); |
1361 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab()); | 1372 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab()); |
1362 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents())); | 1373 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents())); |
1363 | 1374 |
1364 // Navigate backward (or forward). | 1375 // Navigate backward (or forward). |
1365 if (i == 0) | 1376 if (i == 0) |
1366 controller().GoBack(); | 1377 controller().GoBack(); |
1367 else | 1378 else |
1368 controller().GoForward(); | 1379 controller().GoForward(); |
1369 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1380 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1370 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); | 1381 EXPECT_EQ(orig_rfh, contents()->GetMainFrame()); |
1371 contents()->TestDidNavigate( | 1382 contents()->TestDidNavigate( |
1372 orig_rfh, i + 1, url, PAGE_TRANSITION_FORWARD_BACK); | 1383 orig_rfh, i + 1, url, ui::PAGE_TRANSITION_FORWARD_BACK); |
1373 | 1384 |
1374 // Confirm fullscreen has exited. | 1385 // Confirm fullscreen has exited. |
1375 EXPECT_FALSE(orig_rvh->IsFullscreen()); | 1386 EXPECT_FALSE(orig_rvh->IsFullscreen()); |
1376 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); | 1387 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); |
1377 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); | 1388 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); |
1378 } | 1389 } |
1379 | 1390 |
1380 contents()->SetDelegate(NULL); | 1391 contents()->SetDelegate(NULL); |
1381 } | 1392 } |
1382 | 1393 |
(...skipping 15 matching lines...) Expand all Loading... |
1398 | 1409 |
1399 // Tests that fullscreen is exited throughout the object hierarchy on a renderer | 1410 // Tests that fullscreen is exited throughout the object hierarchy on a renderer |
1400 // crash. | 1411 // crash. |
1401 TEST_F(WebContentsImplTest, CrashExitsFullscreen) { | 1412 TEST_F(WebContentsImplTest, CrashExitsFullscreen) { |
1402 FakeFullscreenDelegate fake_delegate; | 1413 FakeFullscreenDelegate fake_delegate; |
1403 contents()->SetDelegate(&fake_delegate); | 1414 contents()->SetDelegate(&fake_delegate); |
1404 | 1415 |
1405 // Navigate to a site. | 1416 // Navigate to a site. |
1406 const GURL url("http://www.google.com"); | 1417 const GURL url("http://www.google.com"); |
1407 controller().LoadURL( | 1418 controller().LoadURL( |
1408 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1419 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1409 contents()->TestDidNavigate( | 1420 contents()->TestDidNavigate( |
1410 contents()->GetMainFrame(), 1, url, PAGE_TRANSITION_TYPED); | 1421 contents()->GetMainFrame(), 1, url, ui::PAGE_TRANSITION_TYPED); |
1411 | 1422 |
1412 // Toggle fullscreen mode on (as if initiated via IPC from renderer). | 1423 // Toggle fullscreen mode on (as if initiated via IPC from renderer). |
1413 EXPECT_FALSE(test_rvh()->IsFullscreen()); | 1424 EXPECT_FALSE(test_rvh()->IsFullscreen()); |
1414 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); | 1425 EXPECT_FALSE(contents()->IsFullscreenForCurrentTab()); |
1415 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); | 1426 EXPECT_FALSE(fake_delegate.IsFullscreenForTabOrPending(contents())); |
1416 test_rvh()->OnMessageReceived( | 1427 test_rvh()->OnMessageReceived( |
1417 ViewHostMsg_ToggleFullscreen(test_rvh()->GetRoutingID(), true)); | 1428 ViewHostMsg_ToggleFullscreen(test_rvh()->GetRoutingID(), true)); |
1418 EXPECT_TRUE(test_rvh()->IsFullscreen()); | 1429 EXPECT_TRUE(test_rvh()->IsFullscreen()); |
1419 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab()); | 1430 EXPECT_TRUE(contents()->IsFullscreenForCurrentTab()); |
1420 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents())); | 1431 EXPECT_TRUE(fake_delegate.IsFullscreenForTabOrPending(contents())); |
(...skipping 20 matching lines...) Expand all Loading... |
1441 // creates a new navigation entry, then hiding it without proceeding. | 1452 // creates a new navigation entry, then hiding it without proceeding. |
1442 TEST_F(WebContentsImplTest, | 1453 TEST_F(WebContentsImplTest, |
1443 ShowInterstitialFromBrowserWithNewNavigationDontProceed) { | 1454 ShowInterstitialFromBrowserWithNewNavigationDontProceed) { |
1444 // Navigate to a page. | 1455 // Navigate to a page. |
1445 GURL url1("http://www.google.com"); | 1456 GURL url1("http://www.google.com"); |
1446 contents()->GetMainFrame()->SendNavigate(1, url1); | 1457 contents()->GetMainFrame()->SendNavigate(1, url1); |
1447 EXPECT_EQ(1, controller().GetEntryCount()); | 1458 EXPECT_EQ(1, controller().GetEntryCount()); |
1448 | 1459 |
1449 // Initiate a browser navigation that will trigger the interstitial | 1460 // Initiate a browser navigation that will trigger the interstitial |
1450 controller().LoadURL(GURL("http://www.evil.com"), Referrer(), | 1461 controller().LoadURL(GURL("http://www.evil.com"), Referrer(), |
1451 PAGE_TRANSITION_TYPED, std::string()); | 1462 ui::PAGE_TRANSITION_TYPED, std::string()); |
1452 | 1463 |
1453 // Show an interstitial. | 1464 // Show an interstitial. |
1454 TestInterstitialPage::InterstitialState state = | 1465 TestInterstitialPage::InterstitialState state = |
1455 TestInterstitialPage::INVALID; | 1466 TestInterstitialPage::INVALID; |
1456 bool deleted = false; | 1467 bool deleted = false; |
1457 GURL url2("http://interstitial"); | 1468 GURL url2("http://interstitial"); |
1458 TestInterstitialPage* interstitial = | 1469 TestInterstitialPage* interstitial = |
1459 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 1470 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
1460 TestInterstitialPageStateGuard state_guard(interstitial); | 1471 TestInterstitialPageStateGuard state_guard(interstitial); |
1461 interstitial->Show(); | 1472 interstitial->Show(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1584 // creates a new navigation entry, then proceeding. | 1595 // creates a new navigation entry, then proceeding. |
1585 TEST_F(WebContentsImplTest, | 1596 TEST_F(WebContentsImplTest, |
1586 ShowInterstitialFromBrowserNewNavigationProceed) { | 1597 ShowInterstitialFromBrowserNewNavigationProceed) { |
1587 // Navigate to a page. | 1598 // Navigate to a page. |
1588 GURL url1("http://www.google.com"); | 1599 GURL url1("http://www.google.com"); |
1589 contents()->GetMainFrame()->SendNavigate(1, url1); | 1600 contents()->GetMainFrame()->SendNavigate(1, url1); |
1590 EXPECT_EQ(1, controller().GetEntryCount()); | 1601 EXPECT_EQ(1, controller().GetEntryCount()); |
1591 | 1602 |
1592 // Initiate a browser navigation that will trigger the interstitial | 1603 // Initiate a browser navigation that will trigger the interstitial |
1593 controller().LoadURL(GURL("http://www.evil.com"), Referrer(), | 1604 controller().LoadURL(GURL("http://www.evil.com"), Referrer(), |
1594 PAGE_TRANSITION_TYPED, std::string()); | 1605 ui::PAGE_TRANSITION_TYPED, std::string()); |
1595 | 1606 |
1596 // Show an interstitial. | 1607 // Show an interstitial. |
1597 TestInterstitialPage::InterstitialState state = | 1608 TestInterstitialPage::InterstitialState state = |
1598 TestInterstitialPage::INVALID; | 1609 TestInterstitialPage::INVALID; |
1599 bool deleted = false; | 1610 bool deleted = false; |
1600 GURL url2("http://interstitial"); | 1611 GURL url2("http://interstitial"); |
1601 TestInterstitialPage* interstitial = | 1612 TestInterstitialPage* interstitial = |
1602 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 1613 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
1603 TestInterstitialPageStateGuard state_guard(interstitial); | 1614 TestInterstitialPageStateGuard state_guard(interstitial); |
1604 interstitial->Show(); | 1615 interstitial->Show(); |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2079 GURL interstitial_url("http://interstitial"); | 2090 GURL interstitial_url("http://interstitial"); |
2080 TestInterstitialPage* interstitial = | 2091 TestInterstitialPage* interstitial = |
2081 new TestInterstitialPage(contents(), true, interstitial_url, | 2092 new TestInterstitialPage(contents(), true, interstitial_url, |
2082 &state, &deleted); | 2093 &state, &deleted); |
2083 TestInterstitialPageStateGuard state_guard(interstitial); | 2094 TestInterstitialPageStateGuard state_guard(interstitial); |
2084 interstitial->Show(); | 2095 interstitial->Show(); |
2085 | 2096 |
2086 // Let's simulate a navigation initiated from the browser before the | 2097 // Let's simulate a navigation initiated from the browser before the |
2087 // interstitial finishes loading. | 2098 // interstitial finishes loading. |
2088 const GURL url("http://www.google.com"); | 2099 const GURL url("http://www.google.com"); |
2089 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2100 controller().LoadURL( |
| 2101 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2090 EXPECT_FALSE(interstitial->is_showing()); | 2102 EXPECT_FALSE(interstitial->is_showing()); |
2091 RunAllPendingInMessageLoop(); | 2103 RunAllPendingInMessageLoop(); |
2092 ASSERT_FALSE(deleted); | 2104 ASSERT_FALSE(deleted); |
2093 | 2105 |
2094 // Now let's make the interstitial navigation commit. | 2106 // Now let's make the interstitial navigation commit. |
2095 interstitial->TestDidNavigate(1, interstitial_url); | 2107 interstitial->TestDidNavigate(1, interstitial_url); |
2096 | 2108 |
2097 // After it loaded the interstitial should be gone. | 2109 // After it loaded the interstitial should be gone. |
2098 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 2110 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
2099 | 2111 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2176 | 2188 |
2177 // Tests that showing an interstitial as a result of a browser initiated | 2189 // Tests that showing an interstitial as a result of a browser initiated |
2178 // navigation while an interstitial is showing does not remove the pending | 2190 // navigation while an interstitial is showing does not remove the pending |
2179 // entry (see http://crbug.com/9791). | 2191 // entry (see http://crbug.com/9791). |
2180 TEST_F(WebContentsImplTest, NewInterstitialDoesNotCancelPendingEntry) { | 2192 TEST_F(WebContentsImplTest, NewInterstitialDoesNotCancelPendingEntry) { |
2181 const char kUrl[] = "http://www.badguys.com/"; | 2193 const char kUrl[] = "http://www.badguys.com/"; |
2182 const GURL kGURL(kUrl); | 2194 const GURL kGURL(kUrl); |
2183 | 2195 |
2184 // Start a navigation to a page | 2196 // Start a navigation to a page |
2185 contents()->GetController().LoadURL( | 2197 contents()->GetController().LoadURL( |
2186 kGURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2198 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2187 | 2199 |
2188 // Simulate that navigation triggering an interstitial. | 2200 // Simulate that navigation triggering an interstitial. |
2189 TestInterstitialPage::InterstitialState state = | 2201 TestInterstitialPage::InterstitialState state = |
2190 TestInterstitialPage::INVALID; | 2202 TestInterstitialPage::INVALID; |
2191 bool deleted = false; | 2203 bool deleted = false; |
2192 TestInterstitialPage* interstitial = | 2204 TestInterstitialPage* interstitial = |
2193 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 2205 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
2194 TestInterstitialPageStateGuard state_guard(interstitial); | 2206 TestInterstitialPageStateGuard state_guard(interstitial); |
2195 interstitial->Show(); | 2207 interstitial->Show(); |
2196 interstitial->TestDidNavigate(1, kGURL); | 2208 interstitial->TestDidNavigate(1, kGURL); |
2197 | 2209 |
2198 // Initiate a new navigation from the browser that also triggers an | 2210 // Initiate a new navigation from the browser that also triggers an |
2199 // interstitial. | 2211 // interstitial. |
2200 contents()->GetController().LoadURL( | 2212 contents()->GetController().LoadURL( |
2201 kGURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2213 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2202 TestInterstitialPage::InterstitialState state2 = | 2214 TestInterstitialPage::InterstitialState state2 = |
2203 TestInterstitialPage::INVALID; | 2215 TestInterstitialPage::INVALID; |
2204 bool deleted2 = false; | 2216 bool deleted2 = false; |
2205 TestInterstitialPage* interstitial2 = | 2217 TestInterstitialPage* interstitial2 = |
2206 new TestInterstitialPage(contents(), true, kGURL, &state2, &deleted2); | 2218 new TestInterstitialPage(contents(), true, kGURL, &state2, &deleted2); |
2207 TestInterstitialPageStateGuard state_guard2(interstitial2); | 2219 TestInterstitialPageStateGuard state_guard2(interstitial2); |
2208 interstitial2->Show(); | 2220 interstitial2->Show(); |
2209 interstitial2->TestDidNavigate(1, kGURL); | 2221 interstitial2->TestDidNavigate(1, kGURL); |
2210 | 2222 |
2211 // Make sure we still have an entry. | 2223 // Make sure we still have an entry. |
(...skipping 10 matching lines...) Expand all Loading... |
2222 } | 2234 } |
2223 | 2235 |
2224 // Tests that Javascript messages are not shown while an interstitial is | 2236 // Tests that Javascript messages are not shown while an interstitial is |
2225 // showing. | 2237 // showing. |
2226 TEST_F(WebContentsImplTest, NoJSMessageOnInterstitials) { | 2238 TEST_F(WebContentsImplTest, NoJSMessageOnInterstitials) { |
2227 const char kUrl[] = "http://www.badguys.com/"; | 2239 const char kUrl[] = "http://www.badguys.com/"; |
2228 const GURL kGURL(kUrl); | 2240 const GURL kGURL(kUrl); |
2229 | 2241 |
2230 // Start a navigation to a page | 2242 // Start a navigation to a page |
2231 contents()->GetController().LoadURL( | 2243 contents()->GetController().LoadURL( |
2232 kGURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2244 kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2233 // DidNavigate from the page | 2245 // DidNavigate from the page |
2234 contents()->TestDidNavigate( | 2246 contents()->TestDidNavigate( |
2235 contents()->GetMainFrame(), 1, kGURL, PAGE_TRANSITION_TYPED); | 2247 contents()->GetMainFrame(), 1, kGURL, ui::PAGE_TRANSITION_TYPED); |
2236 | 2248 |
2237 // Simulate showing an interstitial while the page is showing. | 2249 // Simulate showing an interstitial while the page is showing. |
2238 TestInterstitialPage::InterstitialState state = | 2250 TestInterstitialPage::InterstitialState state = |
2239 TestInterstitialPage::INVALID; | 2251 TestInterstitialPage::INVALID; |
2240 bool deleted = false; | 2252 bool deleted = false; |
2241 TestInterstitialPage* interstitial = | 2253 TestInterstitialPage* interstitial = |
2242 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 2254 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
2243 TestInterstitialPageStateGuard state_guard(interstitial); | 2255 TestInterstitialPageStateGuard state_guard(interstitial); |
2244 interstitial->Show(); | 2256 interstitial->Show(); |
2245 interstitial->TestDidNavigate(1, kGURL); | 2257 interstitial->TestDidNavigate(1, kGURL); |
(...skipping 11 matching lines...) Expand all Loading... |
2257 // Makes sure that if the source passed to CopyStateFromAndPrune has an | 2269 // Makes sure that if the source passed to CopyStateFromAndPrune has an |
2258 // interstitial it isn't copied over to the destination. | 2270 // interstitial it isn't copied over to the destination. |
2259 TEST_F(WebContentsImplTest, CopyStateFromAndPruneSourceInterstitial) { | 2271 TEST_F(WebContentsImplTest, CopyStateFromAndPruneSourceInterstitial) { |
2260 // Navigate to a page. | 2272 // Navigate to a page. |
2261 GURL url1("http://www.google.com"); | 2273 GURL url1("http://www.google.com"); |
2262 contents()->GetMainFrame()->SendNavigate(1, url1); | 2274 contents()->GetMainFrame()->SendNavigate(1, url1); |
2263 EXPECT_EQ(1, controller().GetEntryCount()); | 2275 EXPECT_EQ(1, controller().GetEntryCount()); |
2264 | 2276 |
2265 // Initiate a browser navigation that will trigger the interstitial | 2277 // Initiate a browser navigation that will trigger the interstitial |
2266 controller().LoadURL(GURL("http://www.evil.com"), Referrer(), | 2278 controller().LoadURL(GURL("http://www.evil.com"), Referrer(), |
2267 PAGE_TRANSITION_TYPED, std::string()); | 2279 ui::PAGE_TRANSITION_TYPED, std::string()); |
2268 | 2280 |
2269 // Show an interstitial. | 2281 // Show an interstitial. |
2270 TestInterstitialPage::InterstitialState state = | 2282 TestInterstitialPage::InterstitialState state = |
2271 TestInterstitialPage::INVALID; | 2283 TestInterstitialPage::INVALID; |
2272 bool deleted = false; | 2284 bool deleted = false; |
2273 GURL url2("http://interstitial"); | 2285 GURL url2("http://interstitial"); |
2274 TestInterstitialPage* interstitial = | 2286 TestInterstitialPage* interstitial = |
2275 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 2287 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
2276 TestInterstitialPageStateGuard state_guard(interstitial); | 2288 TestInterstitialPageStateGuard state_guard(interstitial); |
2277 interstitial->Show(); | 2289 interstitial->Show(); |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2617 scoped_refptr<SiteInstance> instance( | 2629 scoped_refptr<SiteInstance> instance( |
2618 SiteInstance::Create(browser_context())); | 2630 SiteInstance::Create(browser_context())); |
2619 | 2631 |
2620 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2632 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2621 | 2633 |
2622 scoped_ptr<TestWebContents> contents( | 2634 scoped_ptr<TestWebContents> contents( |
2623 TestWebContents::Create(browser_context(), instance.get())); | 2635 TestWebContents::Create(browser_context(), instance.get())); |
2624 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2636 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2625 | 2637 |
2626 // Navigate to a URL. | 2638 // Navigate to a URL. |
2627 contents->GetController().LoadURL( | 2639 contents->GetController().LoadURL(GURL("http://a.com/1"), |
2628 GURL("http://a.com/1"), Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2640 Referrer(), |
| 2641 ui::PAGE_TRANSITION_TYPED, |
| 2642 std::string()); |
2629 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2643 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2630 contents->CommitPendingNavigation(); | 2644 contents->CommitPendingNavigation(); |
2631 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2645 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2632 | 2646 |
2633 // Navigate to a URL in the same site. | 2647 // Navigate to a URL in the same site. |
2634 contents->GetController().LoadURL( | 2648 contents->GetController().LoadURL(GURL("http://a.com/2"), |
2635 GURL("http://a.com/2"), Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2649 Referrer(), |
| 2650 ui::PAGE_TRANSITION_TYPED, |
| 2651 std::string()); |
2636 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2652 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2637 contents->CommitPendingNavigation(); | 2653 contents->CommitPendingNavigation(); |
2638 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2654 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2639 | 2655 |
2640 // Navigate to a URL in a different site. | 2656 // Navigate to a URL in a different site. |
2641 contents->GetController().LoadURL( | 2657 contents->GetController().LoadURL(GURL("http://b.com"), |
2642 GURL("http://b.com"), Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2658 Referrer(), |
| 2659 ui::PAGE_TRANSITION_TYPED, |
| 2660 std::string()); |
2643 EXPECT_TRUE(contents->cross_navigation_pending()); | 2661 EXPECT_TRUE(contents->cross_navigation_pending()); |
2644 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2662 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2645 contents->CommitPendingNavigation(); | 2663 contents->CommitPendingNavigation(); |
2646 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2664 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2647 | 2665 |
2648 contents.reset(); | 2666 contents.reset(); |
2649 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2667 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2650 } | 2668 } |
2651 | 2669 |
2652 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes | 2670 // Tests that GetRelatedActiveContentsCount tracks BrowsingInstance changes |
2653 // from WebUI. | 2671 // from WebUI. |
2654 TEST_F(WebContentsImplTest, ActiveContentsCountChangeBrowsingInstance) { | 2672 TEST_F(WebContentsImplTest, ActiveContentsCountChangeBrowsingInstance) { |
2655 scoped_refptr<SiteInstance> instance( | 2673 scoped_refptr<SiteInstance> instance( |
2656 SiteInstance::Create(browser_context())); | 2674 SiteInstance::Create(browser_context())); |
2657 | 2675 |
2658 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); | 2676 EXPECT_EQ(0u, instance->GetRelatedActiveContentsCount()); |
2659 | 2677 |
2660 scoped_ptr<TestWebContents> contents( | 2678 scoped_ptr<TestWebContents> contents( |
2661 TestWebContents::Create(browser_context(), instance.get())); | 2679 TestWebContents::Create(browser_context(), instance.get())); |
2662 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2680 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2663 | 2681 |
2664 // Navigate to a URL. | 2682 // Navigate to a URL. |
2665 contents->NavigateAndCommit(GURL("http://a.com")); | 2683 contents->NavigateAndCommit(GURL("http://a.com")); |
2666 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2684 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2667 | 2685 |
2668 // Navigate to a URL with WebUI. This will change BrowsingInstances. | 2686 // Navigate to a URL with WebUI. This will change BrowsingInstances. |
2669 contents->GetController().LoadURL( | 2687 contents->GetController().LoadURL(GURL(kTestWebUIUrl), |
2670 GURL(kTestWebUIUrl), Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2688 Referrer(), |
| 2689 ui::PAGE_TRANSITION_TYPED, |
| 2690 std::string()); |
2671 EXPECT_TRUE(contents->cross_navigation_pending()); | 2691 EXPECT_TRUE(contents->cross_navigation_pending()); |
2672 scoped_refptr<SiteInstance> instance_webui( | 2692 scoped_refptr<SiteInstance> instance_webui( |
2673 contents->GetPendingMainFrame()->GetSiteInstance()); | 2693 contents->GetPendingMainFrame()->GetSiteInstance()); |
2674 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get())); | 2694 EXPECT_FALSE(instance->IsRelatedSiteInstance(instance_webui.get())); |
2675 | 2695 |
2676 // At this point, contents still counts for the old BrowsingInstance. | 2696 // At this point, contents still counts for the old BrowsingInstance. |
2677 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); | 2697 EXPECT_EQ(1u, instance->GetRelatedActiveContentsCount()); |
2678 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); | 2698 EXPECT_EQ(0u, instance_webui->GetRelatedActiveContentsCount()); |
2679 | 2699 |
2680 // Commit and contents counts for the new one. | 2700 // Commit and contents counts for the new one. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2768 | 2788 |
2769 // Destroy the video only player. No power save blockers should remain. | 2789 // Destroy the video only player. No power save blockers should remain. |
2770 rfh->OnMessageReceived( | 2790 rfh->OnMessageReceived( |
2771 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId)); | 2791 FrameHostMsg_MediaPausedNotification(0, kPlayerVideoOnlyId)); |
2772 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 2792 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); |
2773 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 2793 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); |
2774 } | 2794 } |
2775 #endif | 2795 #endif |
2776 | 2796 |
2777 } // namespace content | 2797 } // namespace content |
OLD | NEW |