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

Side by Side Diff: content/browser/tab_contents/tab_contents_unittest.cc

Issue 9645003: Introduce abstractions to allow embedders to test RenderViewHost (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "content/browser/mock_content_browser_client.h" 7 #include "content/browser/mock_content_browser_client.h"
8 #include "content/browser/renderer_host/mock_render_process_host.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h" 9 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/renderer_host/test_render_view_host.h" 10 #include "content/browser/renderer_host/test_render_view_host.h"
10 #include "content/browser/site_instance_impl.h" 11 #include "content/browser/site_instance_impl.h"
11 #include "content/browser/tab_contents/interstitial_page_impl.h" 12 #include "content/browser/tab_contents/interstitial_page_impl.h"
12 #include "content/browser/tab_contents/navigation_entry_impl.h" 13 #include "content/browser/tab_contents/navigation_entry_impl.h"
13 #include "content/browser/tab_contents/test_tab_contents.h" 14 #include "content/browser/tab_contents/test_tab_contents.h"
14 #include "content/common/view_messages.h" 15 #include "content/common/view_messages.h"
15 #include "content/public/browser/interstitial_page_delegate.h" 16 #include "content/public/browser/interstitial_page_delegate.h"
16 #include "content/public/browser/navigation_details.h" 17 #include "content/public/browser/navigation_details.h"
17 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
18 #include "content/public/browser/notification_source.h" 19 #include "content/public/browser/notification_source.h"
19 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
20 #include "content/public/browser/render_widget_host_view.h" 21 #include "content/public/browser/render_widget_host_view.h"
21 #include "content/public/browser/web_ui_controller.h" 22 #include "content/public/browser/web_ui_controller.h"
22 #include "content/public/browser/web_ui_controller_factory.h" 23 #include "content/public/browser/web_ui_controller_factory.h"
23 #include "content/public/common/bindings_policy.h" 24 #include "content/public/common/bindings_policy.h"
24 #include "content/public/common/content_constants.h" 25 #include "content/public/common/content_constants.h"
25 #include "content/public/common/url_constants.h" 26 #include "content/public/common/url_constants.h"
26 #include "content/test/test_browser_thread.h" 27 #include "content/test/test_browser_thread.h"
27 #include "googleurl/src/url_util.h" 28 #include "googleurl/src/url_util.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 #include "webkit/glue/webkit_glue.h" 30 #include "webkit/glue/webkit_glue.h"
30 31
31 using content::BrowserContext; 32 using content::BrowserContext;
32 using content::BrowserThread; 33 using content::BrowserThread;
33 using content::InterstitialPage; 34 using content::InterstitialPage;
34 using content::NavigationEntry; 35 using content::NavigationEntry;
35 using content::NavigationEntryImpl; 36 using content::NavigationEntryImpl;
36 using content::SiteInstance; 37 using content::SiteInstance;
38 using content::RenderViewHost;
39 using content::RenderViewHostImplTestHarness;
37 using content::TestRenderViewHost; 40 using content::TestRenderViewHost;
38 using content::WebContents; 41 using content::WebContents;
39 using content::WebUI; 42 using content::WebUI;
40 using content::WebUIController; 43 using content::WebUIController;
41 using webkit::forms::PasswordForm; 44 using webkit::forms::PasswordForm;
42 45
43 namespace { 46 namespace {
44 47
45 class TabContentsTestWebUIControllerFactory 48 class TabContentsTestWebUIControllerFactory
46 : public content::WebUIControllerFactory { 49 : public content::WebUIControllerFactory {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 250
248 virtual void TestInterstitialPageDeleted(TestInterstitialPage* interstitial) { 251 virtual void TestInterstitialPageDeleted(TestInterstitialPage* interstitial) {
249 DCHECK(interstitial_page_ == interstitial); 252 DCHECK(interstitial_page_ == interstitial);
250 interstitial_page_ = NULL; 253 interstitial_page_ = NULL;
251 } 254 }
252 255
253 private: 256 private:
254 TestInterstitialPage* interstitial_page_; 257 TestInterstitialPage* interstitial_page_;
255 }; 258 };
256 259
257 class TabContentsTest : public RenderViewHostTestHarness { 260 class TabContentsTest : public RenderViewHostImplTestHarness {
258 public: 261 public:
259 TabContentsTest() 262 TabContentsTest()
260 : ui_thread_(BrowserThread::UI, &message_loop_), 263 : ui_thread_(BrowserThread::UI, &message_loop_),
261 old_browser_client_(NULL) { 264 old_browser_client_(NULL) {
262 } 265 }
263 266
264 virtual void SetUp() { 267 virtual void SetUp() {
265 // These tests treat tabcontentstest as a privileged WebUI scheme. 268 // These tests treat tabcontentstest as a privileged WebUI scheme.
266 // We must register it similarly to kChromeUIScheme. 269 // We must register it similarly to kChromeUIScheme.
267 url_util::AddStandardScheme("tabcontentstest"); 270 url_util::AddStandardScheme("tabcontentstest");
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 EXPECT_EQ(-1, contents()->GetMaxPageIDForSiteInstance(instance2)); 346 EXPECT_EQ(-1, contents()->GetMaxPageIDForSiteInstance(instance2));
344 347
345 contents()->UpdateMaxPageIDForSiteInstance(instance2, 7); 348 contents()->UpdateMaxPageIDForSiteInstance(instance2, 7);
346 EXPECT_EQ(3, contents()->GetMaxPageID()); 349 EXPECT_EQ(3, contents()->GetMaxPageID());
347 EXPECT_EQ(3, contents()->GetMaxPageIDForSiteInstance(instance1)); 350 EXPECT_EQ(3, contents()->GetMaxPageIDForSiteInstance(instance1));
348 EXPECT_EQ(7, contents()->GetMaxPageIDForSiteInstance(instance2)); 351 EXPECT_EQ(7, contents()->GetMaxPageIDForSiteInstance(instance2));
349 } 352 }
350 353
351 // Test simple same-SiteInstance navigation. 354 // Test simple same-SiteInstance navigation.
352 TEST_F(TabContentsTest, SimpleNavigation) { 355 TEST_F(TabContentsTest, SimpleNavigation) {
353 TestRenderViewHost* orig_rvh = rvh(); 356 TestRenderViewHost* orig_rvh = test_rvh();
354 SiteInstance* instance1 = contents()->GetSiteInstance(); 357 SiteInstance* instance1 = contents()->GetSiteInstance();
355 EXPECT_TRUE(contents()->pending_rvh() == NULL); 358 EXPECT_TRUE(contents()->pending_rvh() == NULL);
356 359
357 // Navigate to URL 360 // Navigate to URL
358 const GURL url("http://www.google.com"); 361 const GURL url("http://www.google.com");
359 controller().LoadURL( 362 controller().LoadURL(
360 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 363 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
361 EXPECT_FALSE(contents()->cross_navigation_pending()); 364 EXPECT_FALSE(contents()->cross_navigation_pending());
362 EXPECT_EQ(instance1, orig_rvh->GetSiteInstance()); 365 EXPECT_EQ(instance1, orig_rvh->GetSiteInstance());
363 // Controller's pending entry will have a NULL site instance until we assign 366 // Controller's pending entry will have a NULL site instance until we assign
(...skipping 24 matching lines...) Expand all
388 controller().LoadURL( 391 controller().LoadURL(
389 url, content::Referrer(), content::PAGE_TRANSITION_GENERATED, 392 url, content::Referrer(), content::PAGE_TRANSITION_GENERATED,
390 std::string()); 393 std::string());
391 EXPECT_TRUE(controller().GetActiveEntry() == NULL); 394 EXPECT_TRUE(controller().GetActiveEntry() == NULL);
392 } 395 }
393 396
394 // Test that navigating across a site boundary creates a new RenderViewHost 397 // Test that navigating across a site boundary creates a new RenderViewHost
395 // with a new SiteInstance. Going back should do the same. 398 // with a new SiteInstance. Going back should do the same.
396 TEST_F(TabContentsTest, CrossSiteBoundaries) { 399 TEST_F(TabContentsTest, CrossSiteBoundaries) {
397 contents()->transition_cross_site = true; 400 contents()->transition_cross_site = true;
398 TestRenderViewHost* orig_rvh = rvh(); 401 TestRenderViewHost* orig_rvh = test_rvh();
399 int orig_rvh_delete_count = 0; 402 int orig_rvh_delete_count = 0;
400 orig_rvh->set_delete_counter(&orig_rvh_delete_count); 403 orig_rvh->set_delete_counter(&orig_rvh_delete_count);
401 SiteInstance* instance1 = contents()->GetSiteInstance(); 404 SiteInstance* instance1 = contents()->GetSiteInstance();
402 405
403 // Navigate to URL. First URL should use first RenderViewHost. 406 // Navigate to URL. First URL should use first RenderViewHost.
404 const GURL url("http://www.google.com"); 407 const GURL url("http://www.google.com");
405 controller().LoadURL( 408 controller().LoadURL(
406 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 409 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
407 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 410 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
408 411
409 EXPECT_FALSE(contents()->cross_navigation_pending()); 412 EXPECT_FALSE(contents()->cross_navigation_pending());
410 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); 413 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost());
411 414
412 // Navigate to new site 415 // Navigate to new site
413 const GURL url2("http://www.yahoo.com"); 416 const GURL url2("http://www.yahoo.com");
414 controller().LoadURL( 417 controller().LoadURL(
415 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 418 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
416 EXPECT_TRUE(contents()->cross_navigation_pending()); 419 EXPECT_TRUE(contents()->cross_navigation_pending());
417 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); 420 TestRenderViewHost* pending_rvh =
421 static_cast<TestRenderViewHost*>(contents()->pending_rvh());
418 int pending_rvh_delete_count = 0; 422 int pending_rvh_delete_count = 0;
419 pending_rvh->set_delete_counter(&pending_rvh_delete_count); 423 pending_rvh->set_delete_counter(&pending_rvh_delete_count);
420 424
421 // Navigations should be suspended in pending_rvh until ShouldCloseACK. 425 // Navigations should be suspended in pending_rvh until ShouldCloseACK.
422 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); 426 EXPECT_TRUE(pending_rvh->are_navigations_suspended());
423 orig_rvh->SendShouldCloseACK(true); 427 orig_rvh->SendShouldCloseACK(true);
424 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); 428 EXPECT_FALSE(pending_rvh->are_navigations_suspended());
425 429
426 // DidNavigate from the pending page 430 // DidNavigate from the pending page
427 contents()->TestDidNavigate( 431 contents()->TestDidNavigate(
428 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); 432 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED);
429 SiteInstance* instance2 = contents()->GetSiteInstance(); 433 SiteInstance* instance2 = contents()->GetSiteInstance();
430 434
431 EXPECT_FALSE(contents()->cross_navigation_pending()); 435 EXPECT_FALSE(contents()->cross_navigation_pending());
432 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); 436 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost());
433 EXPECT_NE(instance1, instance2); 437 EXPECT_NE(instance1, instance2);
434 EXPECT_TRUE(contents()->pending_rvh() == NULL); 438 EXPECT_TRUE(contents()->pending_rvh() == NULL);
435 // We keep the original RVH around, swapped out. 439 // We keep the original RVH around, swapped out.
436 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsSwappedOut(orig_rvh)); 440 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsSwappedOut(orig_rvh));
437 EXPECT_EQ(orig_rvh_delete_count, 0); 441 EXPECT_EQ(orig_rvh_delete_count, 0);
438 442
439 // Going back should switch SiteInstances again. The first SiteInstance is 443 // Going back should switch SiteInstances again. The first SiteInstance is
440 // stored in the NavigationEntry, so it should be the same as at the start. 444 // stored in the NavigationEntry, so it should be the same as at the start.
441 // We should use the same RVH as before, swapping it back in. 445 // We should use the same RVH as before, swapping it back in.
442 controller().GoBack(); 446 controller().GoBack();
443 TestRenderViewHost* goback_rvh = contents()->pending_rvh(); 447 TestRenderViewHost* goback_rvh =
448 static_cast<TestRenderViewHost*>(contents()->pending_rvh());
444 EXPECT_EQ(orig_rvh, goback_rvh); 449 EXPECT_EQ(orig_rvh, goback_rvh);
445 EXPECT_TRUE(contents()->cross_navigation_pending()); 450 EXPECT_TRUE(contents()->cross_navigation_pending());
446 451
447 // Navigations should be suspended in goback_rvh until ShouldCloseACK. 452 // Navigations should be suspended in goback_rvh until ShouldCloseACK.
448 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); 453 EXPECT_TRUE(goback_rvh->are_navigations_suspended());
449 pending_rvh->SendShouldCloseACK(true); 454 pending_rvh->SendShouldCloseACK(true);
450 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); 455 EXPECT_FALSE(goback_rvh->are_navigations_suspended());
451 456
452 // DidNavigate from the back action 457 // DidNavigate from the back action
453 contents()->TestDidNavigate( 458 contents()->TestDidNavigate(
454 goback_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); 459 goback_rvh, 1, url2, content::PAGE_TRANSITION_TYPED);
455 EXPECT_FALSE(contents()->cross_navigation_pending()); 460 EXPECT_FALSE(contents()->cross_navigation_pending());
456 EXPECT_EQ(goback_rvh, contents()->GetRenderViewHost()); 461 EXPECT_EQ(goback_rvh, contents()->GetRenderViewHost());
457 EXPECT_EQ(instance1, contents()->GetSiteInstance()); 462 EXPECT_EQ(instance1, contents()->GetSiteInstance());
458 // The pending RVH should now be swapped out, not deleted. 463 // The pending RVH should now be swapped out, not deleted.
459 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> 464 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->
460 IsSwappedOut(pending_rvh)); 465 IsSwappedOut(pending_rvh));
461 EXPECT_EQ(pending_rvh_delete_count, 0); 466 EXPECT_EQ(pending_rvh_delete_count, 0);
462 467
463 // Close tab and ensure RVHs are deleted. 468 // Close tab and ensure RVHs are deleted.
464 DeleteContents(); 469 DeleteContents();
465 EXPECT_EQ(orig_rvh_delete_count, 1); 470 EXPECT_EQ(orig_rvh_delete_count, 1);
466 EXPECT_EQ(pending_rvh_delete_count, 1); 471 EXPECT_EQ(pending_rvh_delete_count, 1);
467 } 472 }
468 473
469 // Test that navigating across a site boundary after a crash creates a new 474 // Test that navigating across a site boundary after a crash creates a new
470 // RVH without requiring a cross-site transition (i.e., PENDING state). 475 // RVH without requiring a cross-site transition (i.e., PENDING state).
471 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) { 476 TEST_F(TabContentsTest, CrossSiteBoundariesAfterCrash) {
472 contents()->transition_cross_site = true; 477 contents()->transition_cross_site = true;
473 TestRenderViewHost* orig_rvh = rvh(); 478 TestRenderViewHost* orig_rvh = test_rvh();
474 int orig_rvh_delete_count = 0; 479 int orig_rvh_delete_count = 0;
475 orig_rvh->set_delete_counter(&orig_rvh_delete_count); 480 orig_rvh->set_delete_counter(&orig_rvh_delete_count);
476 SiteInstance* instance1 = contents()->GetSiteInstance(); 481 SiteInstance* instance1 = contents()->GetSiteInstance();
477 482
478 // Navigate to URL. First URL should use first RenderViewHost. 483 // Navigate to URL. First URL should use first RenderViewHost.
479 const GURL url("http://www.google.com"); 484 const GURL url("http://www.google.com");
480 controller().LoadURL( 485 controller().LoadURL(
481 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 486 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
482 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 487 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
483 488
484 EXPECT_FALSE(contents()->cross_navigation_pending()); 489 EXPECT_FALSE(contents()->cross_navigation_pending());
485 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); 490 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost());
486 491
487 // Crash the renderer. 492 // Crash the renderer.
488 orig_rvh->set_render_view_created(false); 493 orig_rvh->set_render_view_created(false);
489 494
490 // Navigate to new site. We should not go into PENDING. 495 // Navigate to new site. We should not go into PENDING.
491 const GURL url2("http://www.yahoo.com"); 496 const GURL url2("http://www.yahoo.com");
492 controller().LoadURL( 497 controller().LoadURL(
493 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 498 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
494 TestRenderViewHost* new_rvh = rvh(); 499 RenderViewHost* new_rvh = rvh();
495 EXPECT_FALSE(contents()->cross_navigation_pending()); 500 EXPECT_FALSE(contents()->cross_navigation_pending());
496 EXPECT_TRUE(contents()->pending_rvh() == NULL); 501 EXPECT_TRUE(contents()->pending_rvh() == NULL);
497 EXPECT_NE(orig_rvh, new_rvh); 502 EXPECT_NE(orig_rvh, new_rvh);
498 EXPECT_EQ(orig_rvh_delete_count, 1); 503 EXPECT_EQ(orig_rvh_delete_count, 1);
499 504
500 // DidNavigate from the new page 505 // DidNavigate from the new page
501 contents()->TestDidNavigate(new_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); 506 contents()->TestDidNavigate(new_rvh, 1, url2, content::PAGE_TRANSITION_TYPED);
502 SiteInstance* instance2 = contents()->GetSiteInstance(); 507 SiteInstance* instance2 = contents()->GetSiteInstance();
503 508
504 EXPECT_FALSE(contents()->cross_navigation_pending()); 509 EXPECT_FALSE(contents()->cross_navigation_pending());
505 EXPECT_EQ(new_rvh, rvh()); 510 EXPECT_EQ(new_rvh, rvh());
506 EXPECT_NE(instance1, instance2); 511 EXPECT_NE(instance1, instance2);
507 EXPECT_TRUE(contents()->pending_rvh() == NULL); 512 EXPECT_TRUE(contents()->pending_rvh() == NULL);
508 513
509 // Close tab and ensure RVHs are deleted. 514 // Close tab and ensure RVHs are deleted.
510 DeleteContents(); 515 DeleteContents();
511 EXPECT_EQ(orig_rvh_delete_count, 1); 516 EXPECT_EQ(orig_rvh_delete_count, 1);
512 } 517 }
513 518
514 // Test that opening a new tab in the same SiteInstance and then navigating 519 // Test that opening a new tab in the same SiteInstance and then navigating
515 // both tabs to a new site will place both tabs in a single SiteInstance. 520 // both tabs to a new site will place both tabs in a single SiteInstance.
516 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) { 521 TEST_F(TabContentsTest, NavigateTwoTabsCrossSite) {
517 contents()->transition_cross_site = true; 522 contents()->transition_cross_site = true;
518 TestRenderViewHost* orig_rvh = rvh(); 523 TestRenderViewHost* orig_rvh = test_rvh();
519 SiteInstance* instance1 = contents()->GetSiteInstance(); 524 SiteInstance* instance1 = contents()->GetSiteInstance();
520 525
521 // Navigate to URL. First URL should use first RenderViewHost. 526 // Navigate to URL. First URL should use first RenderViewHost.
522 const GURL url("http://www.google.com"); 527 const GURL url("http://www.google.com");
523 controller().LoadURL( 528 controller().LoadURL(
524 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 529 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
525 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 530 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
526 531
527 // Open a new tab with the same SiteInstance, navigated to the same site. 532 // Open a new tab with the same SiteInstance, navigated to the same site.
528 TestTabContents contents2(browser_context_.get(), instance1); 533 TestTabContents contents2(browser_context_.get(), instance1);
529 contents2.transition_cross_site = true; 534 contents2.transition_cross_site = true;
530 contents2.GetController().LoadURL(url, content::Referrer(), 535 contents2.GetController().LoadURL(url, content::Referrer(),
531 content::PAGE_TRANSITION_TYPED, 536 content::PAGE_TRANSITION_TYPED,
532 std::string()); 537 std::string());
533 // Need this page id to be 2 since the site instance is the same (which is the 538 // Need this page id to be 2 since the site instance is the same (which is the
534 // scope of page IDs) and we want to consider this a new page. 539 // scope of page IDs) and we want to consider this a new page.
535 contents2.TestDidNavigate( 540 contents2.TestDidNavigate(
536 contents2.GetRenderViewHost(), 2, url, content::PAGE_TRANSITION_TYPED); 541 contents2.GetRenderViewHost(), 2, url, content::PAGE_TRANSITION_TYPED);
537 542
538 // Navigate first tab to a new site 543 // Navigate first tab to a new site
539 const GURL url2a("http://www.yahoo.com"); 544 const GURL url2a("http://www.yahoo.com");
540 controller().LoadURL( 545 controller().LoadURL(
541 url2a, content::Referrer(), content::PAGE_TRANSITION_TYPED, 546 url2a, content::Referrer(), content::PAGE_TRANSITION_TYPED,
542 std::string()); 547 std::string());
543 orig_rvh->SendShouldCloseACK(true); 548 orig_rvh->SendShouldCloseACK(true);
544 TestRenderViewHost* pending_rvh_a = contents()->pending_rvh(); 549 TestRenderViewHost* pending_rvh_a =
550 static_cast<TestRenderViewHost*>(contents()->pending_rvh());
545 contents()->TestDidNavigate( 551 contents()->TestDidNavigate(
546 pending_rvh_a, 1, url2a, content::PAGE_TRANSITION_TYPED); 552 pending_rvh_a, 1, url2a, content::PAGE_TRANSITION_TYPED);
547 SiteInstance* instance2a = contents()->GetSiteInstance(); 553 SiteInstance* instance2a = contents()->GetSiteInstance();
548 EXPECT_NE(instance1, instance2a); 554 EXPECT_NE(instance1, instance2a);
549 555
550 // Navigate second tab to the same site as the first tab 556 // Navigate second tab to the same site as the first tab
551 const GURL url2b("http://mail.yahoo.com"); 557 const GURL url2b("http://mail.yahoo.com");
552 contents2.GetController().LoadURL(url2b, content::Referrer(), 558 contents2.GetController().LoadURL(url2b, content::Referrer(),
553 content::PAGE_TRANSITION_TYPED, 559 content::PAGE_TRANSITION_TYPED,
554 std::string()); 560 std::string());
555 TestRenderViewHost* rvh2 = 561 TestRenderViewHost* rvh2 =
556 static_cast<TestRenderViewHost*>(contents2.GetRenderViewHost()); 562 static_cast<TestRenderViewHost*>(contents2.GetRenderViewHost());
557 rvh2->SendShouldCloseACK(true); 563 rvh2->SendShouldCloseACK(true);
558 TestRenderViewHost* pending_rvh_b = contents2.pending_rvh(); 564 TestRenderViewHost* pending_rvh_b =
565 static_cast<TestRenderViewHost*>(contents2.pending_rvh());
559 EXPECT_TRUE(pending_rvh_b != NULL); 566 EXPECT_TRUE(pending_rvh_b != NULL);
560 EXPECT_TRUE(contents2.cross_navigation_pending()); 567 EXPECT_TRUE(contents2.cross_navigation_pending());
561 568
562 // NOTE(creis): We used to be in danger of showing a sad tab page here if the 569 // NOTE(creis): We used to be in danger of showing a sad tab page here if the
563 // second tab hadn't navigated somewhere first (bug 1145430). That case is 570 // second tab hadn't navigated somewhere first (bug 1145430). That case is
564 // now covered by the CrossSiteBoundariesAfterCrash test. 571 // now covered by the CrossSiteBoundariesAfterCrash test.
565 contents2.TestDidNavigate( 572 contents2.TestDidNavigate(
566 pending_rvh_b, 2, url2b, content::PAGE_TRANSITION_TYPED); 573 pending_rvh_b, 2, url2b, content::PAGE_TRANSITION_TYPED);
567 SiteInstance* instance2b = contents2.GetSiteInstance(); 574 SiteInstance* instance2b = contents2.GetSiteInstance();
568 EXPECT_NE(instance1, instance2b); 575 EXPECT_NE(instance1, instance2b);
569 576
570 // Both tabs should now be in the same SiteInstance. 577 // Both tabs should now be in the same SiteInstance.
571 EXPECT_EQ(instance2a, instance2b); 578 EXPECT_EQ(instance2a, instance2b);
572 } 579 }
573 580
574 // Tests that TabContents uses the current URL, not the SiteInstance's site, to 581 // Tests that TabContents uses the current URL, not the SiteInstance's site, to
575 // determine whether a navigation is cross-site. 582 // determine whether a navigation is cross-site.
576 TEST_F(TabContentsTest, CrossSiteComparesAgainstCurrentPage) { 583 TEST_F(TabContentsTest, CrossSiteComparesAgainstCurrentPage) {
577 contents()->transition_cross_site = true; 584 contents()->transition_cross_site = true;
578 TestRenderViewHost* orig_rvh = rvh(); 585 RenderViewHost* orig_rvh = rvh();
579 SiteInstance* instance1 = contents()->GetSiteInstance(); 586 SiteInstance* instance1 = contents()->GetSiteInstance();
580 587
581 // Navigate to URL. 588 // Navigate to URL.
582 const GURL url("http://www.google.com"); 589 const GURL url("http://www.google.com");
583 controller().LoadURL( 590 controller().LoadURL(
584 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 591 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
585 contents()->TestDidNavigate( 592 contents()->TestDidNavigate(
586 orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 593 orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
587 594
588 // Open a related tab to a second site. 595 // Open a related tab to a second site.
(...skipping 30 matching lines...) Expand all
619 contents()->TestDidNavigate( 626 contents()->TestDidNavigate(
620 orig_rvh, 3, url3, content::PAGE_TRANSITION_TYPED); 627 orig_rvh, 3, url3, content::PAGE_TRANSITION_TYPED);
621 SiteInstance* instance4 = contents()->GetSiteInstance(); 628 SiteInstance* instance4 = contents()->GetSiteInstance();
622 EXPECT_EQ(instance1, instance4); 629 EXPECT_EQ(instance1, instance4);
623 } 630 }
624 631
625 // Test that the onbeforeunload and onunload handlers run when navigating 632 // Test that the onbeforeunload and onunload handlers run when navigating
626 // across site boundaries. 633 // across site boundaries.
627 TEST_F(TabContentsTest, CrossSiteUnloadHandlers) { 634 TEST_F(TabContentsTest, CrossSiteUnloadHandlers) {
628 contents()->transition_cross_site = true; 635 contents()->transition_cross_site = true;
629 TestRenderViewHost* orig_rvh = rvh(); 636 TestRenderViewHost* orig_rvh = test_rvh();
630 SiteInstance* instance1 = contents()->GetSiteInstance(); 637 SiteInstance* instance1 = contents()->GetSiteInstance();
631 638
632 // Navigate to URL. First URL should use first RenderViewHost. 639 // Navigate to URL. First URL should use first RenderViewHost.
633 const GURL url("http://www.google.com"); 640 const GURL url("http://www.google.com");
634 controller().LoadURL( 641 controller().LoadURL(
635 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 642 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
636 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 643 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
637 EXPECT_FALSE(contents()->cross_navigation_pending()); 644 EXPECT_FALSE(contents()->cross_navigation_pending());
638 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); 645 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost());
639 646
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 EXPECT_EQ(pending_rvh, rvh()); 678 EXPECT_EQ(pending_rvh, rvh());
672 EXPECT_NE(instance1, instance2); 679 EXPECT_NE(instance1, instance2);
673 EXPECT_TRUE(contents()->pending_rvh() == NULL); 680 EXPECT_TRUE(contents()->pending_rvh() == NULL);
674 } 681 }
675 682
676 // Test that during a slow cross-site navigation, the original renderer can 683 // Test that during a slow cross-site navigation, the original renderer can
677 // navigate to a different URL and have it displayed, canceling the slow 684 // navigate to a different URL and have it displayed, canceling the slow
678 // navigation. 685 // navigation.
679 TEST_F(TabContentsTest, CrossSiteNavigationPreempted) { 686 TEST_F(TabContentsTest, CrossSiteNavigationPreempted) {
680 contents()->transition_cross_site = true; 687 contents()->transition_cross_site = true;
681 TestRenderViewHost* orig_rvh = rvh(); 688 TestRenderViewHost* orig_rvh = test_rvh();
682 SiteInstance* instance1 = contents()->GetSiteInstance(); 689 SiteInstance* instance1 = contents()->GetSiteInstance();
683 690
684 // Navigate to URL. First URL should use first RenderViewHost. 691 // Navigate to URL. First URL should use first RenderViewHost.
685 const GURL url("http://www.google.com"); 692 const GURL url("http://www.google.com");
686 controller().LoadURL( 693 controller().LoadURL(
687 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 694 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
688 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 695 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
689 EXPECT_FALSE(contents()->cross_navigation_pending()); 696 EXPECT_FALSE(contents()->cross_navigation_pending());
690 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); 697 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost());
691 698
(...skipping 18 matching lines...) Expand all
710 EXPECT_TRUE(contents()->pending_rvh() == NULL); 717 EXPECT_TRUE(contents()->pending_rvh() == NULL);
711 } 718 }
712 719
713 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) { 720 TEST_F(TabContentsTest, CrossSiteNavigationBackPreempted) {
714 contents()->transition_cross_site = true; 721 contents()->transition_cross_site = true;
715 722
716 // Start with a web ui page, which gets a new RVH with WebUI bindings. 723 // Start with a web ui page, which gets a new RVH with WebUI bindings.
717 const GURL url1("tabcontentstest://blah"); 724 const GURL url1("tabcontentstest://blah");
718 controller().LoadURL( 725 controller().LoadURL(
719 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 726 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
720 TestRenderViewHost* ntp_rvh = rvh(); 727 TestRenderViewHost* ntp_rvh = test_rvh();
721 contents()->TestDidNavigate(ntp_rvh, 1, url1, content::PAGE_TRANSITION_TYPED); 728 contents()->TestDidNavigate(ntp_rvh, 1, url1, content::PAGE_TRANSITION_TYPED);
722 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); 729 NavigationEntry* entry1 = controller().GetLastCommittedEntry();
723 SiteInstance* instance1 = contents()->GetSiteInstance(); 730 SiteInstance* instance1 = contents()->GetSiteInstance();
724 731
725 EXPECT_FALSE(contents()->cross_navigation_pending()); 732 EXPECT_FALSE(contents()->cross_navigation_pending());
726 EXPECT_EQ(ntp_rvh, contents()->GetRenderViewHost()); 733 EXPECT_EQ(ntp_rvh, contents()->GetRenderViewHost());
727 EXPECT_EQ(url1, entry1->GetURL()); 734 EXPECT_EQ(url1, entry1->GetURL());
728 EXPECT_EQ(instance1, 735 EXPECT_EQ(instance1,
729 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); 736 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance());
730 EXPECT_TRUE(ntp_rvh->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI); 737 EXPECT_TRUE(ntp_rvh->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI);
731 738
732 // Navigate to new site. 739 // Navigate to new site.
733 const GURL url2("http://www.google.com"); 740 const GURL url2("http://www.google.com");
734 controller().LoadURL( 741 controller().LoadURL(
735 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 742 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
736 EXPECT_TRUE(contents()->cross_navigation_pending()); 743 EXPECT_TRUE(contents()->cross_navigation_pending());
737 TestRenderViewHost* google_rvh = contents()->pending_rvh(); 744 TestRenderViewHost* google_rvh =
745 static_cast<TestRenderViewHost*>(contents()->pending_rvh());
738 746
739 // Simulate beforeunload approval. 747 // Simulate beforeunload approval.
740 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); 748 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack());
741 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK( 749 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(
742 0, true, base::TimeTicks(), base::TimeTicks())); 750 0, true, base::TimeTicks(), base::TimeTicks()));
743 751
744 // DidNavigate from the pending page. 752 // DidNavigate from the pending page.
745 contents()->TestDidNavigate( 753 contents()->TestDidNavigate(
746 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); 754 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED);
747 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); 755 NavigationEntry* entry2 = controller().GetLastCommittedEntry();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); 816 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance());
809 EXPECT_EQ(instance1, 817 EXPECT_EQ(instance1,
810 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); 818 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance());
811 EXPECT_EQ(url1, entry1->GetURL()); 819 EXPECT_EQ(url1, entry1->GetURL());
812 } 820 }
813 821
814 // Test that during a slow cross-site navigation, a sub-frame navigation in the 822 // Test that during a slow cross-site navigation, a sub-frame navigation in the
815 // original renderer will not cancel the slow navigation (bug 42029). 823 // original renderer will not cancel the slow navigation (bug 42029).
816 TEST_F(TabContentsTest, CrossSiteNavigationNotPreemptedByFrame) { 824 TEST_F(TabContentsTest, CrossSiteNavigationNotPreemptedByFrame) {
817 contents()->transition_cross_site = true; 825 contents()->transition_cross_site = true;
818 TestRenderViewHost* orig_rvh = rvh(); 826 TestRenderViewHost* orig_rvh = test_rvh();
819 827
820 // Navigate to URL. First URL should use first RenderViewHost. 828 // Navigate to URL. First URL should use first RenderViewHost.
821 const GURL url("http://www.google.com"); 829 const GURL url("http://www.google.com");
822 controller().LoadURL( 830 controller().LoadURL(
823 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 831 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
824 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 832 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
825 EXPECT_FALSE(contents()->cross_navigation_pending()); 833 EXPECT_FALSE(contents()->cross_navigation_pending());
826 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); 834 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost());
827 835
828 // Start navigating to new site. 836 // Start navigating to new site.
(...skipping 19 matching lines...) Expand all
848 // renderer sends a FrameNavigate message just before being told to stop. 856 // renderer sends a FrameNavigate message just before being told to stop.
849 // We should only preempt the cross-site navigation if the previous renderer 857 // We should only preempt the cross-site navigation if the previous renderer
850 // has started a new navigation. See http://crbug.com/79176. 858 // has started a new navigation. See http://crbug.com/79176.
851 TEST_F(TabContentsTest, CrossSiteNotPreemptedDuringBeforeUnload) { 859 TEST_F(TabContentsTest, CrossSiteNotPreemptedDuringBeforeUnload) {
852 contents()->transition_cross_site = true; 860 contents()->transition_cross_site = true;
853 861
854 // Navigate to NTP URL. 862 // Navigate to NTP URL.
855 const GURL url("tabcontentstest://blah"); 863 const GURL url("tabcontentstest://blah");
856 controller().LoadURL( 864 controller().LoadURL(
857 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 865 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
858 TestRenderViewHost* orig_rvh = rvh(); 866 TestRenderViewHost* orig_rvh = test_rvh();
859 EXPECT_FALSE(contents()->cross_navigation_pending()); 867 EXPECT_FALSE(contents()->cross_navigation_pending());
860 868
861 // Navigate to new site, with the beforeunload request in flight. 869 // Navigate to new site, with the beforeunload request in flight.
862 const GURL url2("http://www.yahoo.com"); 870 const GURL url2("http://www.yahoo.com");
863 controller().LoadURL( 871 controller().LoadURL(
864 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 872 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
865 TestRenderViewHost* pending_rvh = contents()->pending_rvh(); 873 TestRenderViewHost* pending_rvh =
874 static_cast<TestRenderViewHost*>(contents()->pending_rvh());
866 EXPECT_TRUE(contents()->cross_navigation_pending()); 875 EXPECT_TRUE(contents()->cross_navigation_pending());
867 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); 876 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack());
868 877
869 // Suppose the first navigation tries to commit now, with a 878 // Suppose the first navigation tries to commit now, with a
870 // ViewMsg_Stop in flight. This should not cancel the pending navigation, 879 // ViewMsg_Stop in flight. This should not cancel the pending navigation,
871 // but it should act as if the beforeunload ack arrived. 880 // but it should act as if the beforeunload ack arrived.
872 orig_rvh->SendNavigate(1, GURL("tabcontentstest://blah")); 881 orig_rvh->SendNavigate(1, GURL("tabcontentstest://blah"));
873 EXPECT_TRUE(contents()->cross_navigation_pending()); 882 EXPECT_TRUE(contents()->cross_navigation_pending());
874 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); 883 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost());
875 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); 884 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack());
876 885
877 // The pending navigation should be able to commit successfully. 886 // The pending navigation should be able to commit successfully.
878 contents()->TestDidNavigate( 887 contents()->TestDidNavigate(
879 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); 888 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED);
880 EXPECT_FALSE(contents()->cross_navigation_pending()); 889 EXPECT_FALSE(contents()->cross_navigation_pending());
881 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); 890 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost());
882 } 891 }
883 892
884 // Test that the original renderer cannot preempt a cross-site navigation once 893 // Test that the original renderer cannot preempt a cross-site navigation once
885 // the unload request has been made. At this point, the cross-site navigation 894 // the unload request has been made. At this point, the cross-site navigation
886 // is almost ready to be displayed, and the original renderer is only given a 895 // is almost ready to be displayed, and the original renderer is only given a
887 // short chance to run an unload handler. Prevents regression of bug 23942. 896 // short chance to run an unload handler. Prevents regression of bug 23942.
888 TEST_F(TabContentsTest, CrossSiteCantPreemptAfterUnload) { 897 TEST_F(TabContentsTest, CrossSiteCantPreemptAfterUnload) {
889 contents()->transition_cross_site = true; 898 contents()->transition_cross_site = true;
890 TestRenderViewHost* orig_rvh = rvh(); 899 TestRenderViewHost* orig_rvh = test_rvh();
891 SiteInstance* instance1 = contents()->GetSiteInstance(); 900 SiteInstance* instance1 = contents()->GetSiteInstance();
892 901
893 // Navigate to URL. First URL should use first RenderViewHost. 902 // Navigate to URL. First URL should use first RenderViewHost.
894 const GURL url("http://www.google.com"); 903 const GURL url("http://www.google.com");
895 controller().LoadURL( 904 controller().LoadURL(
896 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 905 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
897 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 906 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
898 EXPECT_FALSE(contents()->cross_navigation_pending()); 907 EXPECT_FALSE(contents()->cross_navigation_pending());
899 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); 908 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost());
900 909
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 EXPECT_FALSE(contents()->cross_navigation_pending()); 941 EXPECT_FALSE(contents()->cross_navigation_pending());
933 EXPECT_EQ(pending_rvh, rvh()); 942 EXPECT_EQ(pending_rvh, rvh());
934 EXPECT_NE(instance1, instance2); 943 EXPECT_NE(instance1, instance2);
935 EXPECT_TRUE(contents()->pending_rvh() == NULL); 944 EXPECT_TRUE(contents()->pending_rvh() == NULL);
936 } 945 }
937 946
938 // Test that a cross-site navigation that doesn't commit after the unload 947 // Test that a cross-site navigation that doesn't commit after the unload
939 // handler doesn't leave the tab in a stuck state. http://crbug.com/88562. 948 // handler doesn't leave the tab in a stuck state. http://crbug.com/88562.
940 TEST_F(TabContentsTest, CrossSiteNavigationCanceled) { 949 TEST_F(TabContentsTest, CrossSiteNavigationCanceled) {
941 contents()->transition_cross_site = true; 950 contents()->transition_cross_site = true;
942 TestRenderViewHost* orig_rvh = rvh(); 951 TestRenderViewHost* orig_rvh = test_rvh();
943 SiteInstance* instance1 = contents()->GetSiteInstance(); 952 SiteInstance* instance1 = contents()->GetSiteInstance();
944 953
945 // Navigate to URL. First URL should use first RenderViewHost. 954 // Navigate to URL. First URL should use first RenderViewHost.
946 const GURL url("http://www.google.com"); 955 const GURL url("http://www.google.com");
947 controller().LoadURL( 956 controller().LoadURL(
948 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 957 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
949 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 958 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
950 EXPECT_FALSE(contents()->cross_navigation_pending()); 959 EXPECT_FALSE(contents()->cross_navigation_pending());
951 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); 960 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost());
952 961
(...skipping 21 matching lines...) Expand all
974 EXPECT_FALSE(contents()->cross_navigation_pending()); 983 EXPECT_FALSE(contents()->cross_navigation_pending());
975 EXPECT_EQ(orig_rvh, rvh()); 984 EXPECT_EQ(orig_rvh, rvh());
976 EXPECT_FALSE(orig_rvh->is_swapped_out()); 985 EXPECT_FALSE(orig_rvh->is_swapped_out());
977 EXPECT_EQ(instance1, instance2); 986 EXPECT_EQ(instance1, instance2);
978 EXPECT_TRUE(contents()->pending_rvh() == NULL); 987 EXPECT_TRUE(contents()->pending_rvh() == NULL);
979 } 988 }
980 989
981 // Test that NavigationEntries have the correct content state after going 990 // Test that NavigationEntries have the correct content state after going
982 // forward and back. Prevents regression for bug 1116137. 991 // forward and back. Prevents regression for bug 1116137.
983 TEST_F(TabContentsTest, NavigationEntryContentState) { 992 TEST_F(TabContentsTest, NavigationEntryContentState) {
984 TestRenderViewHost* orig_rvh = rvh(); 993 TestRenderViewHost* orig_rvh = test_rvh();
985 994
986 // Navigate to URL. There should be no committed entry yet. 995 // Navigate to URL. There should be no committed entry yet.
987 const GURL url("http://www.google.com"); 996 const GURL url("http://www.google.com");
988 controller().LoadURL( 997 controller().LoadURL(
989 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 998 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
990 NavigationEntry* entry = controller().GetLastCommittedEntry(); 999 NavigationEntry* entry = controller().GetLastCommittedEntry();
991 EXPECT_TRUE(entry == NULL); 1000 EXPECT_TRUE(entry == NULL);
992 1001
993 // Committed entry should have content state after DidNavigate. 1002 // Committed entry should have content state after DidNavigate.
994 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 1003 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
(...skipping 17 matching lines...) Expand all
1012 controller().GoBack(); 1021 controller().GoBack();
1013 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 1022 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
1014 entry = controller().GetLastCommittedEntry(); 1023 entry = controller().GetLastCommittedEntry();
1015 EXPECT_FALSE(entry->GetContentState().empty()); 1024 EXPECT_FALSE(entry->GetContentState().empty());
1016 } 1025 }
1017 1026
1018 // Test that NavigationEntries have the correct content state and SiteInstance 1027 // Test that NavigationEntries have the correct content state and SiteInstance
1019 // state after opening a new window to about:blank. Prevents regression for 1028 // state after opening a new window to about:blank. Prevents regression for
1020 // bugs b/1116137 and http://crbug.com/111975. 1029 // bugs b/1116137 and http://crbug.com/111975.
1021 TEST_F(TabContentsTest, NavigationEntryContentStateNewWindow) { 1030 TEST_F(TabContentsTest, NavigationEntryContentStateNewWindow) {
1022 TestRenderViewHost* orig_rvh = rvh(); 1031 TestRenderViewHost* orig_rvh = test_rvh();
1023 1032
1024 // When opening a new window, it is navigated to about:blank internally. 1033 // When opening a new window, it is navigated to about:blank internally.
1025 // Currently, this results in two DidNavigate events. 1034 // Currently, this results in two DidNavigate events.
1026 const GURL url(chrome::kAboutBlankURL); 1035 const GURL url(chrome::kAboutBlankURL);
1027 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 1036 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
1028 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 1037 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
1029 1038
1030 // Should have a content state here. 1039 // Should have a content state here.
1031 NavigationEntry* entry = controller().GetLastCommittedEntry(); 1040 NavigationEntry* entry = controller().GetLastCommittedEntry();
1032 EXPECT_FALSE(entry->GetContentState().empty()); 1041 EXPECT_FALSE(entry->GetContentState().empty());
(...skipping 22 matching lines...) Expand all
1055 // Interstitial Tests 1064 // Interstitial Tests
1056 //////////////////////////////////////////////////////////////////////////////// 1065 ////////////////////////////////////////////////////////////////////////////////
1057 1066
1058 // Test navigating to a page (with the navigation initiated from the browser, 1067 // Test navigating to a page (with the navigation initiated from the browser,
1059 // as when a URL is typed in the location bar) that shows an interstitial and 1068 // as when a URL is typed in the location bar) that shows an interstitial and
1060 // creates a new navigation entry, then hiding it without proceeding. 1069 // creates a new navigation entry, then hiding it without proceeding.
1061 TEST_F(TabContentsTest, 1070 TEST_F(TabContentsTest,
1062 ShowInterstitialFromBrowserWithNewNavigationDontProceed) { 1071 ShowInterstitialFromBrowserWithNewNavigationDontProceed) {
1063 // Navigate to a page. 1072 // Navigate to a page.
1064 GURL url1("http://www.google.com"); 1073 GURL url1("http://www.google.com");
1065 rvh()->SendNavigate(1, url1); 1074 test_rvh()->SendNavigate(1, url1);
1066 EXPECT_EQ(1, controller().GetEntryCount()); 1075 EXPECT_EQ(1, controller().GetEntryCount());
1067 1076
1068 // Initiate a browser navigation that will trigger the interstitial 1077 // Initiate a browser navigation that will trigger the interstitial
1069 controller().LoadURL(GURL("http://www.evil.com"), content::Referrer(), 1078 controller().LoadURL(GURL("http://www.evil.com"), content::Referrer(),
1070 content::PAGE_TRANSITION_TYPED, std::string()); 1079 content::PAGE_TRANSITION_TYPED, std::string());
1071 1080
1072 // Show an interstitial. 1081 // Show an interstitial.
1073 TestInterstitialPage::InterstitialState state = 1082 TestInterstitialPage::InterstitialState state =
1074 TestInterstitialPage::UNDECIDED; 1083 TestInterstitialPage::UNDECIDED;
1075 bool deleted = false; 1084 bool deleted = false;
(...skipping 27 matching lines...) Expand all
1103 EXPECT_EQ(1, controller().GetEntryCount()); 1112 EXPECT_EQ(1, controller().GetEntryCount());
1104 } 1113 }
1105 1114
1106 // Test navigating to a page (with the navigation initiated from the renderer, 1115 // Test navigating to a page (with the navigation initiated from the renderer,
1107 // as when clicking on a link in the page) that shows an interstitial and 1116 // as when clicking on a link in the page) that shows an interstitial and
1108 // creates a new navigation entry, then hiding it without proceeding. 1117 // creates a new navigation entry, then hiding it without proceeding.
1109 TEST_F(TabContentsTest, 1118 TEST_F(TabContentsTest,
1110 ShowInterstitiaFromRendererlWithNewNavigationDontProceed) { 1119 ShowInterstitiaFromRendererlWithNewNavigationDontProceed) {
1111 // Navigate to a page. 1120 // Navigate to a page.
1112 GURL url1("http://www.google.com"); 1121 GURL url1("http://www.google.com");
1113 rvh()->SendNavigate(1, url1); 1122 test_rvh()->SendNavigate(1, url1);
1114 EXPECT_EQ(1, controller().GetEntryCount()); 1123 EXPECT_EQ(1, controller().GetEntryCount());
1115 1124
1116 // Show an interstitial (no pending entry, the interstitial would have been 1125 // Show an interstitial (no pending entry, the interstitial would have been
1117 // triggered by clicking on a link). 1126 // triggered by clicking on a link).
1118 TestInterstitialPage::InterstitialState state = 1127 TestInterstitialPage::InterstitialState state =
1119 TestInterstitialPage::UNDECIDED; 1128 TestInterstitialPage::UNDECIDED;
1120 bool deleted = false; 1129 bool deleted = false;
1121 GURL url2("http://interstitial"); 1130 GURL url2("http://interstitial");
1122 TestInterstitialPage* interstitial = 1131 TestInterstitialPage* interstitial =
1123 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 1132 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
(...skipping 23 matching lines...) Expand all
1147 EXPECT_TRUE(entry->GetURL() == url1); 1156 EXPECT_TRUE(entry->GetURL() == url1);
1148 EXPECT_EQ(1, controller().GetEntryCount()); 1157 EXPECT_EQ(1, controller().GetEntryCount());
1149 } 1158 }
1150 1159
1151 // Test navigating to a page that shows an interstitial without creating a new 1160 // Test navigating to a page that shows an interstitial without creating a new
1152 // navigation entry (this happens when the interstitial is triggered by a 1161 // navigation entry (this happens when the interstitial is triggered by a
1153 // sub-resource in the page), then hiding it without proceeding. 1162 // sub-resource in the page), then hiding it without proceeding.
1154 TEST_F(TabContentsTest, ShowInterstitialNoNewNavigationDontProceed) { 1163 TEST_F(TabContentsTest, ShowInterstitialNoNewNavigationDontProceed) {
1155 // Navigate to a page. 1164 // Navigate to a page.
1156 GURL url1("http://www.google.com"); 1165 GURL url1("http://www.google.com");
1157 rvh()->SendNavigate(1, url1); 1166 test_rvh()->SendNavigate(1, url1);
1158 EXPECT_EQ(1, controller().GetEntryCount()); 1167 EXPECT_EQ(1, controller().GetEntryCount());
1159 1168
1160 // Show an interstitial. 1169 // Show an interstitial.
1161 TestInterstitialPage::InterstitialState state = 1170 TestInterstitialPage::InterstitialState state =
1162 TestInterstitialPage::UNDECIDED; 1171 TestInterstitialPage::UNDECIDED;
1163 bool deleted = false; 1172 bool deleted = false;
1164 GURL url2("http://interstitial"); 1173 GURL url2("http://interstitial");
1165 TestInterstitialPage* interstitial = 1174 TestInterstitialPage* interstitial =
1166 new TestInterstitialPage(contents(), false, url2, &state, &deleted); 1175 new TestInterstitialPage(contents(), false, url2, &state, &deleted);
1167 TestInterstitialPageStateGuard state_guard(interstitial); 1176 TestInterstitialPageStateGuard state_guard(interstitial);
(...skipping 24 matching lines...) Expand all
1192 EXPECT_EQ(1, controller().GetEntryCount()); 1201 EXPECT_EQ(1, controller().GetEntryCount());
1193 } 1202 }
1194 1203
1195 // Test navigating to a page (with the navigation initiated from the browser, 1204 // Test navigating to a page (with the navigation initiated from the browser,
1196 // as when a URL is typed in the location bar) that shows an interstitial and 1205 // as when a URL is typed in the location bar) that shows an interstitial and
1197 // creates a new navigation entry, then proceeding. 1206 // creates a new navigation entry, then proceeding.
1198 TEST_F(TabContentsTest, 1207 TEST_F(TabContentsTest,
1199 ShowInterstitialFromBrowserNewNavigationProceed) { 1208 ShowInterstitialFromBrowserNewNavigationProceed) {
1200 // Navigate to a page. 1209 // Navigate to a page.
1201 GURL url1("http://www.google.com"); 1210 GURL url1("http://www.google.com");
1202 rvh()->SendNavigate(1, url1); 1211 test_rvh()->SendNavigate(1, url1);
1203 EXPECT_EQ(1, controller().GetEntryCount()); 1212 EXPECT_EQ(1, controller().GetEntryCount());
1204 1213
1205 // Initiate a browser navigation that will trigger the interstitial 1214 // Initiate a browser navigation that will trigger the interstitial
1206 controller().LoadURL(GURL("http://www.evil.com"), content::Referrer(), 1215 controller().LoadURL(GURL("http://www.evil.com"), content::Referrer(),
1207 content::PAGE_TRANSITION_TYPED, std::string()); 1216 content::PAGE_TRANSITION_TYPED, std::string());
1208 1217
1209 // Show an interstitial. 1218 // Show an interstitial.
1210 TestInterstitialPage::InterstitialState state = 1219 TestInterstitialPage::InterstitialState state =
1211 TestInterstitialPage::UNDECIDED; 1220 TestInterstitialPage::UNDECIDED;
1212 bool deleted = false; 1221 bool deleted = false;
(...skipping 19 matching lines...) Expand all
1232 interstitial->Proceed(); 1241 interstitial->Proceed();
1233 // The interstitial should show until the new navigation commits. 1242 // The interstitial should show until the new navigation commits.
1234 ASSERT_FALSE(deleted); 1243 ASSERT_FALSE(deleted);
1235 EXPECT_EQ(TestInterstitialPage::OKED, state); 1244 EXPECT_EQ(TestInterstitialPage::OKED, state);
1236 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1245 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1237 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1246 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1238 1247
1239 // Simulate the navigation to the page, that's when the interstitial gets 1248 // Simulate the navigation to the page, that's when the interstitial gets
1240 // hidden. 1249 // hidden.
1241 GURL url3("http://www.thepage.com"); 1250 GURL url3("http://www.thepage.com");
1242 rvh()->SendNavigate(2, url3); 1251 test_rvh()->SendNavigate(2, url3);
1243 1252
1244 EXPECT_TRUE(deleted); 1253 EXPECT_TRUE(deleted);
1245 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1254 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1246 EXPECT_TRUE(contents()->GetInterstitialPage() == NULL); 1255 EXPECT_TRUE(contents()->GetInterstitialPage() == NULL);
1247 entry = controller().GetActiveEntry(); 1256 entry = controller().GetActiveEntry();
1248 ASSERT_TRUE(entry != NULL); 1257 ASSERT_TRUE(entry != NULL);
1249 EXPECT_TRUE(entry->GetURL() == url3); 1258 EXPECT_TRUE(entry->GetURL() == url3);
1250 1259
1251 EXPECT_EQ(2, controller().GetEntryCount()); 1260 EXPECT_EQ(2, controller().GetEntryCount());
1252 } 1261 }
1253 1262
1254 // Test navigating to a page (with the navigation initiated from the renderer, 1263 // Test navigating to a page (with the navigation initiated from the renderer,
1255 // as when clicking on a link in the page) that shows an interstitial and 1264 // as when clicking on a link in the page) that shows an interstitial and
1256 // creates a new navigation entry, then proceeding. 1265 // creates a new navigation entry, then proceeding.
1257 TEST_F(TabContentsTest, 1266 TEST_F(TabContentsTest,
1258 ShowInterstitialFromRendererNewNavigationProceed) { 1267 ShowInterstitialFromRendererNewNavigationProceed) {
1259 // Navigate to a page. 1268 // Navigate to a page.
1260 GURL url1("http://www.google.com"); 1269 GURL url1("http://www.google.com");
1261 rvh()->SendNavigate(1, url1); 1270 test_rvh()->SendNavigate(1, url1);
1262 EXPECT_EQ(1, controller().GetEntryCount()); 1271 EXPECT_EQ(1, controller().GetEntryCount());
1263 1272
1264 // Show an interstitial. 1273 // Show an interstitial.
1265 TestInterstitialPage::InterstitialState state = 1274 TestInterstitialPage::InterstitialState state =
1266 TestInterstitialPage::UNDECIDED; 1275 TestInterstitialPage::UNDECIDED;
1267 bool deleted = false; 1276 bool deleted = false;
1268 GURL url2("http://interstitial"); 1277 GURL url2("http://interstitial");
1269 TestInterstitialPage* interstitial = 1278 TestInterstitialPage* interstitial =
1270 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 1279 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1271 TestInterstitialPageStateGuard state_guard(interstitial); 1280 TestInterstitialPageStateGuard state_guard(interstitial);
(...skipping 15 matching lines...) Expand all
1287 interstitial->Proceed(); 1296 interstitial->Proceed();
1288 // The interstitial should show until the new navigation commits. 1297 // The interstitial should show until the new navigation commits.
1289 ASSERT_FALSE(deleted); 1298 ASSERT_FALSE(deleted);
1290 EXPECT_EQ(TestInterstitialPage::OKED, state); 1299 EXPECT_EQ(TestInterstitialPage::OKED, state);
1291 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1300 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1292 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1301 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1293 1302
1294 // Simulate the navigation to the page, that's when the interstitial gets 1303 // Simulate the navigation to the page, that's when the interstitial gets
1295 // hidden. 1304 // hidden.
1296 GURL url3("http://www.thepage.com"); 1305 GURL url3("http://www.thepage.com");
1297 rvh()->SendNavigate(2, url3); 1306 test_rvh()->SendNavigate(2, url3);
1298 1307
1299 EXPECT_TRUE(deleted); 1308 EXPECT_TRUE(deleted);
1300 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1309 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1301 EXPECT_TRUE(contents()->GetInterstitialPage() == NULL); 1310 EXPECT_TRUE(contents()->GetInterstitialPage() == NULL);
1302 entry = controller().GetActiveEntry(); 1311 entry = controller().GetActiveEntry();
1303 ASSERT_TRUE(entry != NULL); 1312 ASSERT_TRUE(entry != NULL);
1304 EXPECT_TRUE(entry->GetURL() == url3); 1313 EXPECT_TRUE(entry->GetURL() == url3);
1305 1314
1306 EXPECT_EQ(2, controller().GetEntryCount()); 1315 EXPECT_EQ(2, controller().GetEntryCount());
1307 } 1316 }
1308 1317
1309 // Test navigating to a page that shows an interstitial without creating a new 1318 // Test navigating to a page that shows an interstitial without creating a new
1310 // navigation entry (this happens when the interstitial is triggered by a 1319 // navigation entry (this happens when the interstitial is triggered by a
1311 // sub-resource in the page), then proceeding. 1320 // sub-resource in the page), then proceeding.
1312 TEST_F(TabContentsTest, ShowInterstitialNoNewNavigationProceed) { 1321 TEST_F(TabContentsTest, ShowInterstitialNoNewNavigationProceed) {
1313 // Navigate to a page so we have a navigation entry in the controller. 1322 // Navigate to a page so we have a navigation entry in the controller.
1314 GURL url1("http://www.google.com"); 1323 GURL url1("http://www.google.com");
1315 rvh()->SendNavigate(1, url1); 1324 test_rvh()->SendNavigate(1, url1);
1316 EXPECT_EQ(1, controller().GetEntryCount()); 1325 EXPECT_EQ(1, controller().GetEntryCount());
1317 1326
1318 // Show an interstitial. 1327 // Show an interstitial.
1319 TestInterstitialPage::InterstitialState state = 1328 TestInterstitialPage::InterstitialState state =
1320 TestInterstitialPage::UNDECIDED; 1329 TestInterstitialPage::UNDECIDED;
1321 bool deleted = false; 1330 bool deleted = false;
1322 GURL url2("http://interstitial"); 1331 GURL url2("http://interstitial");
1323 TestInterstitialPage* interstitial = 1332 TestInterstitialPage* interstitial =
1324 new TestInterstitialPage(contents(), false, url2, &state, &deleted); 1333 new TestInterstitialPage(contents(), false, url2, &state, &deleted);
1325 TestInterstitialPageStateGuard state_guard(interstitial); 1334 TestInterstitialPageStateGuard state_guard(interstitial);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 bool deleted = false; 1370 bool deleted = false;
1362 GURL url("http://interstitial"); 1371 GURL url("http://interstitial");
1363 TestInterstitialPage* interstitial = 1372 TestInterstitialPage* interstitial =
1364 new TestInterstitialPage(contents(), true, url, &state, &deleted); 1373 new TestInterstitialPage(contents(), true, url, &state, &deleted);
1365 TestInterstitialPageStateGuard state_guard(interstitial); 1374 TestInterstitialPageStateGuard state_guard(interstitial);
1366 interstitial->Show(); 1375 interstitial->Show();
1367 interstitial->TestDidNavigate(1, url); 1376 interstitial->TestDidNavigate(1, url);
1368 1377
1369 // While interstitial showing, navigate to a new URL. 1378 // While interstitial showing, navigate to a new URL.
1370 const GURL url2("http://www.yahoo.com"); 1379 const GURL url2("http://www.yahoo.com");
1371 rvh()->SendNavigate(1, url2); 1380 test_rvh()->SendNavigate(1, url2);
1372 1381
1373 EXPECT_TRUE(deleted); 1382 EXPECT_TRUE(deleted);
1374 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1383 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1375 } 1384 }
1376 1385
1377 // Test navigating to a page that shows an interstitial, then going back. 1386 // Test navigating to a page that shows an interstitial, then going back.
1378 TEST_F(TabContentsTest, ShowInterstitialThenGoBack) { 1387 TEST_F(TabContentsTest, ShowInterstitialThenGoBack) {
1379 // Navigate to a page so we have a navigation entry in the controller. 1388 // Navigate to a page so we have a navigation entry in the controller.
1380 GURL url1("http://www.google.com"); 1389 GURL url1("http://www.google.com");
1381 rvh()->SendNavigate(1, url1); 1390 test_rvh()->SendNavigate(1, url1);
1382 EXPECT_EQ(1, controller().GetEntryCount()); 1391 EXPECT_EQ(1, controller().GetEntryCount());
1383 1392
1384 // Show interstitial. 1393 // Show interstitial.
1385 TestInterstitialPage::InterstitialState state = 1394 TestInterstitialPage::InterstitialState state =
1386 TestInterstitialPage::UNDECIDED; 1395 TestInterstitialPage::UNDECIDED;
1387 bool deleted = false; 1396 bool deleted = false;
1388 GURL interstitial_url("http://interstitial"); 1397 GURL interstitial_url("http://interstitial");
1389 TestInterstitialPage* interstitial = 1398 TestInterstitialPage* interstitial =
1390 new TestInterstitialPage(contents(), true, interstitial_url, 1399 new TestInterstitialPage(contents(), true, interstitial_url,
1391 &state, &deleted); 1400 &state, &deleted);
1392 TestInterstitialPageStateGuard state_guard(interstitial); 1401 TestInterstitialPageStateGuard state_guard(interstitial);
1393 interstitial->Show(); 1402 interstitial->Show();
1394 interstitial->TestDidNavigate(2, interstitial_url); 1403 interstitial->TestDidNavigate(2, interstitial_url);
1395 1404
1396 // While the interstitial is showing, go back. 1405 // While the interstitial is showing, go back.
1397 controller().GoBack(); 1406 controller().GoBack();
1398 rvh()->SendNavigate(1, url1); 1407 test_rvh()->SendNavigate(1, url1);
1399 1408
1400 // Make sure we are back to the original page and that the interstitial is 1409 // Make sure we are back to the original page and that the interstitial is
1401 // gone. 1410 // gone.
1402 EXPECT_TRUE(deleted); 1411 EXPECT_TRUE(deleted);
1403 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1412 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1404 NavigationEntry* entry = controller().GetActiveEntry(); 1413 NavigationEntry* entry = controller().GetActiveEntry();
1405 ASSERT_TRUE(entry); 1414 ASSERT_TRUE(entry);
1406 EXPECT_EQ(url1.spec(), entry->GetURL().spec()); 1415 EXPECT_EQ(url1.spec(), entry->GetURL().spec());
1407 } 1416 }
1408 1417
1409 // Test navigating to a page that shows an interstitial, has a renderer crash, 1418 // Test navigating to a page that shows an interstitial, has a renderer crash,
1410 // and then goes back. 1419 // and then goes back.
1411 TEST_F(TabContentsTest, ShowInterstitialCrashRendererThenGoBack) { 1420 TEST_F(TabContentsTest, ShowInterstitialCrashRendererThenGoBack) {
1412 // Navigate to a page so we have a navigation entry in the controller. 1421 // Navigate to a page so we have a navigation entry in the controller.
1413 GURL url1("http://www.google.com"); 1422 GURL url1("http://www.google.com");
1414 rvh()->SendNavigate(1, url1); 1423 test_rvh()->SendNavigate(1, url1);
1415 EXPECT_EQ(1, controller().GetEntryCount()); 1424 EXPECT_EQ(1, controller().GetEntryCount());
1416 1425
1417 // Show interstitial. 1426 // Show interstitial.
1418 TestInterstitialPage::InterstitialState state = 1427 TestInterstitialPage::InterstitialState state =
1419 TestInterstitialPage::UNDECIDED; 1428 TestInterstitialPage::UNDECIDED;
1420 bool deleted = false; 1429 bool deleted = false;
1421 GURL interstitial_url("http://interstitial"); 1430 GURL interstitial_url("http://interstitial");
1422 TestInterstitialPage* interstitial = 1431 TestInterstitialPage* interstitial =
1423 new TestInterstitialPage(contents(), true, interstitial_url, 1432 new TestInterstitialPage(contents(), true, interstitial_url,
1424 &state, &deleted); 1433 &state, &deleted);
1425 TestInterstitialPageStateGuard state_guard(interstitial); 1434 TestInterstitialPageStateGuard state_guard(interstitial);
1426 interstitial->Show(); 1435 interstitial->Show();
1427 interstitial->TestDidNavigate(2, interstitial_url); 1436 interstitial->TestDidNavigate(2, interstitial_url);
1428 1437
1429 // Crash the renderer 1438 // Crash the renderer
1430 rvh()->TestOnMessageReceived( 1439 test_rvh()->TestOnMessageReceived(
1431 ViewHostMsg_RenderViewGone( 1440 ViewHostMsg_RenderViewGone(
1432 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1)); 1441 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1));
1433 1442
1434 // While the interstitial is showing, go back. 1443 // While the interstitial is showing, go back.
1435 controller().GoBack(); 1444 controller().GoBack();
1436 rvh()->SendNavigate(1, url1); 1445 test_rvh()->SendNavigate(1, url1);
1437 1446
1438 // Make sure we are back to the original page and that the interstitial is 1447 // Make sure we are back to the original page and that the interstitial is
1439 // gone. 1448 // gone.
1440 EXPECT_TRUE(deleted); 1449 EXPECT_TRUE(deleted);
1441 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1450 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1442 NavigationEntry* entry = controller().GetActiveEntry(); 1451 NavigationEntry* entry = controller().GetActiveEntry();
1443 ASSERT_TRUE(entry); 1452 ASSERT_TRUE(entry);
1444 EXPECT_EQ(url1.spec(), entry->GetURL().spec()); 1453 EXPECT_EQ(url1.spec(), entry->GetURL().spec());
1445 } 1454 }
1446 1455
1447 // Test navigating to a page that shows an interstitial, has the renderer crash, 1456 // Test navigating to a page that shows an interstitial, has the renderer crash,
1448 // and then navigates to the interstitial. 1457 // and then navigates to the interstitial.
1449 TEST_F(TabContentsTest, ShowInterstitialCrashRendererThenNavigate) { 1458 TEST_F(TabContentsTest, ShowInterstitialCrashRendererThenNavigate) {
1450 // Navigate to a page so we have a navigation entry in the controller. 1459 // Navigate to a page so we have a navigation entry in the controller.
1451 GURL url1("http://www.google.com"); 1460 GURL url1("http://www.google.com");
1452 rvh()->SendNavigate(1, url1); 1461 test_rvh()->SendNavigate(1, url1);
1453 EXPECT_EQ(1, controller().GetEntryCount()); 1462 EXPECT_EQ(1, controller().GetEntryCount());
1454 1463
1455 // Show interstitial. 1464 // Show interstitial.
1456 TestInterstitialPage::InterstitialState state = 1465 TestInterstitialPage::InterstitialState state =
1457 TestInterstitialPage::UNDECIDED; 1466 TestInterstitialPage::UNDECIDED;
1458 bool deleted = false; 1467 bool deleted = false;
1459 GURL interstitial_url("http://interstitial"); 1468 GURL interstitial_url("http://interstitial");
1460 TestInterstitialPage* interstitial = 1469 TestInterstitialPage* interstitial =
1461 new TestInterstitialPage(contents(), true, interstitial_url, 1470 new TestInterstitialPage(contents(), true, interstitial_url,
1462 &state, &deleted); 1471 &state, &deleted);
1463 TestInterstitialPageStateGuard state_guard(interstitial); 1472 TestInterstitialPageStateGuard state_guard(interstitial);
1464 interstitial->Show(); 1473 interstitial->Show();
1465 1474
1466 // Crash the renderer 1475 // Crash the renderer
1467 rvh()->TestOnMessageReceived( 1476 test_rvh()->TestOnMessageReceived(
1468 ViewHostMsg_RenderViewGone( 1477 ViewHostMsg_RenderViewGone(
1469 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1)); 1478 0, base::TERMINATION_STATUS_PROCESS_CRASHED, -1));
1470 1479
1471 interstitial->TestDidNavigate(2, interstitial_url); 1480 interstitial->TestDidNavigate(2, interstitial_url);
1472 } 1481 }
1473 1482
1474 // Test navigating to a page that shows an interstitial, then close the tab. 1483 // Test navigating to a page that shows an interstitial, then close the tab.
1475 TEST_F(TabContentsTest, ShowInterstitialThenCloseTab) { 1484 TEST_F(TabContentsTest, ShowInterstitialThenCloseTab) {
1476 // Show interstitial. 1485 // Show interstitial.
1477 TestInterstitialPage::InterstitialState state = 1486 TestInterstitialPage::InterstitialState state =
(...skipping 10 matching lines...) Expand all
1488 DeleteContents(); 1497 DeleteContents();
1489 EXPECT_TRUE(deleted); 1498 EXPECT_TRUE(deleted);
1490 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 1499 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
1491 } 1500 }
1492 1501
1493 // Test that after Proceed is called and an interstitial is still shown, no more 1502 // Test that after Proceed is called and an interstitial is still shown, no more
1494 // commands get executed. 1503 // commands get executed.
1495 TEST_F(TabContentsTest, ShowInterstitialProceedMultipleCommands) { 1504 TEST_F(TabContentsTest, ShowInterstitialProceedMultipleCommands) {
1496 // Navigate to a page so we have a navigation entry in the controller. 1505 // Navigate to a page so we have a navigation entry in the controller.
1497 GURL url1("http://www.google.com"); 1506 GURL url1("http://www.google.com");
1498 rvh()->SendNavigate(1, url1); 1507 test_rvh()->SendNavigate(1, url1);
1499 EXPECT_EQ(1, controller().GetEntryCount()); 1508 EXPECT_EQ(1, controller().GetEntryCount());
1500 1509
1501 // Show an interstitial. 1510 // Show an interstitial.
1502 TestInterstitialPage::InterstitialState state = 1511 TestInterstitialPage::InterstitialState state =
1503 TestInterstitialPage::UNDECIDED; 1512 TestInterstitialPage::UNDECIDED;
1504 bool deleted = false; 1513 bool deleted = false;
1505 GURL url2("http://interstitial"); 1514 GURL url2("http://interstitial");
1506 TestInterstitialPage* interstitial = 1515 TestInterstitialPage* interstitial =
1507 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 1516 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1508 TestInterstitialPageStateGuard state_guard(interstitial); 1517 TestInterstitialPageStateGuard state_guard(interstitial);
(...skipping 13 matching lines...) Expand all
1522 // should be ignored. 1531 // should be ignored.
1523 interstitial->TestDomOperationResponse("hello"); 1532 interstitial->TestDomOperationResponse("hello");
1524 interstitial->TestDomOperationResponse("hi"); 1533 interstitial->TestDomOperationResponse("hi");
1525 EXPECT_EQ(1, interstitial->command_received_count()); 1534 EXPECT_EQ(1, interstitial->command_received_count());
1526 } 1535 }
1527 1536
1528 // Test showing an interstitial while another interstitial is already showing. 1537 // Test showing an interstitial while another interstitial is already showing.
1529 TEST_F(TabContentsTest, ShowInterstitialOnInterstitial) { 1538 TEST_F(TabContentsTest, ShowInterstitialOnInterstitial) {
1530 // Navigate to a page so we have a navigation entry in the controller. 1539 // Navigate to a page so we have a navigation entry in the controller.
1531 GURL start_url("http://www.google.com"); 1540 GURL start_url("http://www.google.com");
1532 rvh()->SendNavigate(1, start_url); 1541 test_rvh()->SendNavigate(1, start_url);
1533 EXPECT_EQ(1, controller().GetEntryCount()); 1542 EXPECT_EQ(1, controller().GetEntryCount());
1534 1543
1535 // Show an interstitial. 1544 // Show an interstitial.
1536 TestInterstitialPage::InterstitialState state1 = 1545 TestInterstitialPage::InterstitialState state1 =
1537 TestInterstitialPage::UNDECIDED; 1546 TestInterstitialPage::UNDECIDED;
1538 bool deleted1 = false; 1547 bool deleted1 = false;
1539 GURL url1("http://interstitial1"); 1548 GURL url1("http://interstitial1");
1540 TestInterstitialPage* interstitial1 = 1549 TestInterstitialPage* interstitial1 =
1541 new TestInterstitialPage(contents(), true, url1, &state1, &deleted1); 1550 new TestInterstitialPage(contents(), true, url1, &state1, &deleted1);
1542 TestInterstitialPageStateGuard state_guard1(interstitial1); 1551 TestInterstitialPageStateGuard state_guard1(interstitial1);
(...skipping 13 matching lines...) Expand all
1556 1565
1557 // Showing interstitial2 should have caused interstitial1 to go away. 1566 // Showing interstitial2 should have caused interstitial1 to go away.
1558 EXPECT_TRUE(deleted1); 1567 EXPECT_TRUE(deleted1);
1559 EXPECT_EQ(TestInterstitialPage::CANCELED, state1); 1568 EXPECT_EQ(TestInterstitialPage::CANCELED, state1);
1560 1569
1561 // Let's make sure interstitial2 is working as intended. 1570 // Let's make sure interstitial2 is working as intended.
1562 ASSERT_FALSE(deleted2); 1571 ASSERT_FALSE(deleted2);
1563 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); 1572 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2);
1564 interstitial2->Proceed(); 1573 interstitial2->Proceed();
1565 GURL landing_url("http://www.thepage.com"); 1574 GURL landing_url("http://www.thepage.com");
1566 rvh()->SendNavigate(2, landing_url); 1575 test_rvh()->SendNavigate(2, landing_url);
1567 1576
1568 EXPECT_TRUE(deleted2); 1577 EXPECT_TRUE(deleted2);
1569 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1578 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1570 EXPECT_TRUE(contents()->GetInterstitialPage() == NULL); 1579 EXPECT_TRUE(contents()->GetInterstitialPage() == NULL);
1571 NavigationEntry* entry = controller().GetActiveEntry(); 1580 NavigationEntry* entry = controller().GetActiveEntry();
1572 ASSERT_TRUE(entry != NULL); 1581 ASSERT_TRUE(entry != NULL);
1573 EXPECT_TRUE(entry->GetURL() == landing_url); 1582 EXPECT_TRUE(entry->GetURL() == landing_url);
1574 EXPECT_EQ(2, controller().GetEntryCount()); 1583 EXPECT_EQ(2, controller().GetEntryCount());
1575 } 1584 }
1576 1585
1577 // Test showing an interstitial, proceeding and then navigating to another 1586 // Test showing an interstitial, proceeding and then navigating to another
1578 // interstitial. 1587 // interstitial.
1579 TEST_F(TabContentsTest, ShowInterstitialProceedShowInterstitial) { 1588 TEST_F(TabContentsTest, ShowInterstitialProceedShowInterstitial) {
1580 // Navigate to a page so we have a navigation entry in the controller. 1589 // Navigate to a page so we have a navigation entry in the controller.
1581 GURL start_url("http://www.google.com"); 1590 GURL start_url("http://www.google.com");
1582 rvh()->SendNavigate(1, start_url); 1591 test_rvh()->SendNavigate(1, start_url);
1583 EXPECT_EQ(1, controller().GetEntryCount()); 1592 EXPECT_EQ(1, controller().GetEntryCount());
1584 1593
1585 // Show an interstitial. 1594 // Show an interstitial.
1586 TestInterstitialPage::InterstitialState state1 = 1595 TestInterstitialPage::InterstitialState state1 =
1587 TestInterstitialPage::UNDECIDED; 1596 TestInterstitialPage::UNDECIDED;
1588 bool deleted1 = false; 1597 bool deleted1 = false;
1589 GURL url1("http://interstitial1"); 1598 GURL url1("http://interstitial1");
1590 TestInterstitialPage* interstitial1 = 1599 TestInterstitialPage* interstitial1 =
1591 new TestInterstitialPage(contents(), true, url1, &state1, &deleted1); 1600 new TestInterstitialPage(contents(), true, url1, &state1, &deleted1);
1592 TestInterstitialPageStateGuard state_guard1(interstitial1); 1601 TestInterstitialPageStateGuard state_guard1(interstitial1);
(...skipping 18 matching lines...) Expand all
1611 interstitial2->TestDidNavigate(1, url2); 1620 interstitial2->TestDidNavigate(1, url2);
1612 1621
1613 // Showing interstitial2 should have caused interstitial1 to go away. 1622 // Showing interstitial2 should have caused interstitial1 to go away.
1614 EXPECT_TRUE(deleted1); 1623 EXPECT_TRUE(deleted1);
1615 1624
1616 // Let's make sure interstitial2 is working as intended. 1625 // Let's make sure interstitial2 is working as intended.
1617 ASSERT_FALSE(deleted2); 1626 ASSERT_FALSE(deleted2);
1618 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); 1627 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2);
1619 interstitial2->Proceed(); 1628 interstitial2->Proceed();
1620 GURL landing_url("http://www.thepage.com"); 1629 GURL landing_url("http://www.thepage.com");
1621 rvh()->SendNavigate(2, landing_url); 1630 test_rvh()->SendNavigate(2, landing_url);
1622 1631
1623 EXPECT_TRUE(deleted2); 1632 EXPECT_TRUE(deleted2);
1624 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1633 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1625 EXPECT_TRUE(contents()->GetInterstitialPage() == NULL); 1634 EXPECT_TRUE(contents()->GetInterstitialPage() == NULL);
1626 NavigationEntry* entry = controller().GetActiveEntry(); 1635 NavigationEntry* entry = controller().GetActiveEntry();
1627 ASSERT_TRUE(entry != NULL); 1636 ASSERT_TRUE(entry != NULL);
1628 EXPECT_TRUE(entry->GetURL() == landing_url); 1637 EXPECT_TRUE(entry->GetURL() == landing_url);
1629 EXPECT_EQ(2, controller().GetEntryCount()); 1638 EXPECT_EQ(2, controller().GetEntryCount());
1630 } 1639 }
1631 1640
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 kGURL, ui::JAVASCRIPT_MESSAGE_TYPE_ALERT, dummy_message, 1818 kGURL, ui::JAVASCRIPT_MESSAGE_TYPE_ALERT, dummy_message,
1810 &did_suppress_message); 1819 &did_suppress_message);
1811 EXPECT_TRUE(did_suppress_message); 1820 EXPECT_TRUE(did_suppress_message);
1812 } 1821 }
1813 1822
1814 // Makes sure that if the source passed to CopyStateFromAndPrune has an 1823 // Makes sure that if the source passed to CopyStateFromAndPrune has an
1815 // interstitial it isn't copied over to the destination. 1824 // interstitial it isn't copied over to the destination.
1816 TEST_F(TabContentsTest, CopyStateFromAndPruneSourceInterstitial) { 1825 TEST_F(TabContentsTest, CopyStateFromAndPruneSourceInterstitial) {
1817 // Navigate to a page. 1826 // Navigate to a page.
1818 GURL url1("http://www.google.com"); 1827 GURL url1("http://www.google.com");
1819 rvh()->SendNavigate(1, url1); 1828 test_rvh()->SendNavigate(1, url1);
1820 EXPECT_EQ(1, controller().GetEntryCount()); 1829 EXPECT_EQ(1, controller().GetEntryCount());
1821 1830
1822 // Initiate a browser navigation that will trigger the interstitial 1831 // Initiate a browser navigation that will trigger the interstitial
1823 controller().LoadURL(GURL("http://www.evil.com"), content::Referrer(), 1832 controller().LoadURL(GURL("http://www.evil.com"), content::Referrer(),
1824 content::PAGE_TRANSITION_TYPED, std::string()); 1833 content::PAGE_TRANSITION_TYPED, std::string());
1825 1834
1826 // Show an interstitial. 1835 // Show an interstitial.
1827 TestInterstitialPage::InterstitialState state = 1836 TestInterstitialPage::InterstitialState state =
1828 TestInterstitialPage::UNDECIDED; 1837 TestInterstitialPage::UNDECIDED;
1829 bool deleted = false; 1838 bool deleted = false;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 // It should have a transient entry. 1911 // It should have a transient entry.
1903 EXPECT_TRUE(other_controller.GetTransientEntry()); 1912 EXPECT_TRUE(other_controller.GetTransientEntry());
1904 1913
1905 // And the interstitial should be showing. 1914 // And the interstitial should be showing.
1906 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); 1915 EXPECT_TRUE(other_contents->ShowingInterstitialPage());
1907 1916
1908 // And the interstitial should do a reload on don't proceed. 1917 // And the interstitial should do a reload on don't proceed.
1909 EXPECT_TRUE(static_cast<InterstitialPageImpl*>( 1918 EXPECT_TRUE(static_cast<InterstitialPageImpl*>(
1910 other_contents->GetInterstitialPage())->reload_on_dont_proceed()); 1919 other_contents->GetInterstitialPage())->reload_on_dont_proceed());
1911 } 1920 }
OLDNEW
« no previous file with comments | « content/browser/tab_contents/render_view_host_manager_unittest.cc ('k') | content/browser/tab_contents/test_tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698