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

Side by Side Diff: content/browser/web_contents/render_view_host_manager_unittest.cc

Issue 23618036: Merge NOTIFICATION_RENDER_VIEW_HOST_CHANGED into NOTIFICATION_WEB_CONTENTS_SWAPPED. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "content/browser/renderer_host/test_render_view_host.h" 6 #include "content/browser/renderer_host/test_render_view_host.h"
7 #include "content/browser/site_instance_impl.h" 7 #include "content/browser/site_instance_impl.h"
8 #include "content/browser/web_contents/navigation_controller_impl.h" 8 #include "content/browser/web_contents/navigation_controller_impl.h"
9 #include "content/browser/web_contents/navigation_entry_impl.h" 9 #include "content/browser/web_contents/navigation_entry_impl.h"
10 #include "content/browser/web_contents/render_view_host_manager.h" 10 #include "content/browser/web_contents/render_view_host_manager.h"
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 557
558 // Tests the Navigate function. We navigate three sites consecutively and check 558 // Tests the Navigate function. We navigate three sites consecutively and check
559 // how the pending/committed RenderViewHost are modified. 559 // how the pending/committed RenderViewHost are modified.
560 TEST_F(RenderViewHostManagerTest, Navigate) { 560 TEST_F(RenderViewHostManagerTest, Navigate) {
561 TestNotificationTracker notifications; 561 TestNotificationTracker notifications;
562 562
563 SiteInstance* instance = SiteInstance::Create(browser_context()); 563 SiteInstance* instance = SiteInstance::Create(browser_context());
564 564
565 scoped_ptr<TestWebContents> web_contents( 565 scoped_ptr<TestWebContents> web_contents(
566 TestWebContents::Create(browser_context(), instance)); 566 TestWebContents::Create(browser_context(), instance));
567 notifications.ListenFor( 567 notifications.ListenFor(NOTIFICATION_WEB_CONTENTS_SWAPPED,
568 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 568 Source<WebContents>(web_contents.get()));
569 Source<NavigationController>(&web_contents->GetController()));
570 569
571 // Create. 570 // Create.
572 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 571 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
573 web_contents.get()); 572 web_contents.get());
574 573
575 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 574 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
576 575
577 RenderViewHost* host; 576 RenderViewHost* host;
578 577
579 // 1) The first navigation. -------------------------- 578 // 1) The first navigation. --------------------------
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 // Commit. 634 // Commit.
636 manager.DidNavigateMainFrame(manager.pending_render_view_host()); 635 manager.DidNavigateMainFrame(manager.pending_render_view_host());
637 EXPECT_TRUE(host == manager.current_host()); 636 EXPECT_TRUE(host == manager.current_host());
638 ASSERT_TRUE(host); 637 ASSERT_TRUE(host);
639 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> 638 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
640 HasSite()); 639 HasSite());
641 // Check the pending RenderViewHost has been committed. 640 // Check the pending RenderViewHost has been committed.
642 EXPECT_FALSE(manager.pending_render_view_host()); 641 EXPECT_FALSE(manager.pending_render_view_host());
643 642
644 // We should observe a notification. 643 // We should observe a notification.
645 EXPECT_TRUE(notifications.Check1AndReset( 644 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_WEB_CONTENTS_SWAPPED));
646 NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
647 } 645 }
648 646
649 // Tests the Navigate function. In this unit test we verify that the Navigate 647 // Tests the Navigate function. In this unit test we verify that the Navigate
650 // function can handle a new navigation event before the previous navigation 648 // function can handle a new navigation event before the previous navigation
651 // has been committed. This is also a regression test for 649 // has been committed. This is also a regression test for
652 // http://crbug.com/104600. 650 // http://crbug.com/104600.
653 TEST_F(RenderViewHostManagerTest, NavigateWithEarlyReNavigation) { 651 TEST_F(RenderViewHostManagerTest, NavigateWithEarlyReNavigation) {
654 TestNotificationTracker notifications; 652 TestNotificationTracker notifications;
655 653
656 SiteInstance* instance = SiteInstance::Create(browser_context()); 654 SiteInstance* instance = SiteInstance::Create(browser_context());
657 655
658 scoped_ptr<TestWebContents> web_contents( 656 scoped_ptr<TestWebContents> web_contents(
659 TestWebContents::Create(browser_context(), instance)); 657 TestWebContents::Create(browser_context(), instance));
660 notifications.ListenFor( 658 notifications.ListenFor(NOTIFICATION_WEB_CONTENTS_SWAPPED,
661 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 659 Source<WebContents>(web_contents.get()));
662 Source<NavigationController>(&web_contents->GetController()));
663 660
664 // Create. 661 // Create.
665 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 662 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
666 web_contents.get()); 663 web_contents.get());
667 664
668 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 665 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
669 666
670 // 1) The first navigation. -------------------------- 667 // 1) The first navigation. --------------------------
671 const GURL kUrl1("http://www.google.com/"); 668 const GURL kUrl1("http://www.google.com/");
672 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 669 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
673 Referrer(), string16() /* title */, 670 Referrer(), string16() /* title */,
674 PAGE_TRANSITION_TYPED, 671 PAGE_TRANSITION_TYPED,
675 false /* is_renderer_init */); 672 false /* is_renderer_init */);
676 RenderViewHost* host = manager.Navigate(entry1); 673 RenderViewHost* host = manager.Navigate(entry1);
677 674
678 // The RenderViewHost created in Init will be reused. 675 // The RenderViewHost created in Init will be reused.
679 EXPECT_TRUE(host == manager.current_host()); 676 EXPECT_TRUE(host == manager.current_host());
680 EXPECT_FALSE(manager.pending_render_view_host()); 677 EXPECT_FALSE(manager.pending_render_view_host());
681 678
682 // We should observe a notification. 679 // We should observe a notification.
683 EXPECT_TRUE(notifications.Check1AndReset( 680 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_WEB_CONTENTS_SWAPPED));
684 NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
685 notifications.Reset(); 681 notifications.Reset();
686 682
687 // Commit. 683 // Commit.
688 manager.DidNavigateMainFrame(host); 684 manager.DidNavigateMainFrame(host);
689 685
690 // Commit to SiteInstance should be delayed until RenderView commit. 686 // Commit to SiteInstance should be delayed until RenderView commit.
691 EXPECT_TRUE(host == manager.current_host()); 687 EXPECT_TRUE(host == manager.current_host());
692 ASSERT_TRUE(host); 688 ASSERT_TRUE(host);
693 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> 689 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
694 HasSite()); 690 HasSite());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 // Commit. 783 // Commit.
788 manager.DidNavigateMainFrame(host3); 784 manager.DidNavigateMainFrame(host3);
789 EXPECT_TRUE(host3 == manager.current_host()); 785 EXPECT_TRUE(host3 == manager.current_host());
790 ASSERT_TRUE(host3); 786 ASSERT_TRUE(host3);
791 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())-> 787 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())->
792 HasSite()); 788 HasSite());
793 // Check the pending RenderViewHost has been committed. 789 // Check the pending RenderViewHost has been committed.
794 EXPECT_FALSE(manager.pending_render_view_host()); 790 EXPECT_FALSE(manager.pending_render_view_host());
795 791
796 // We should observe a notification. 792 // We should observe a notification.
797 EXPECT_TRUE(notifications.Check1AndReset( 793 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_WEB_CONTENTS_SWAPPED));
798 NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
799 } 794 }
800 795
801 // Tests WebUI creation. 796 // Tests WebUI creation.
802 TEST_F(RenderViewHostManagerTest, WebUI) { 797 TEST_F(RenderViewHostManagerTest, WebUI) {
803 set_should_create_webui(true); 798 set_should_create_webui(true);
804 SiteInstance* instance = SiteInstance::Create(browser_context()); 799 SiteInstance* instance = SiteInstance::Create(browser_context());
805 800
806 scoped_ptr<TestWebContents> web_contents( 801 scoped_ptr<TestWebContents> web_contents(
807 TestWebContents::Create(browser_context(), instance)); 802 TestWebContents::Create(browser_context(), instance));
808 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 803 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 1200
1206 // Commit. 1201 // Commit.
1207 manager.DidNavigateMainFrame(host); 1202 manager.DidNavigateMainFrame(host);
1208 EXPECT_EQ(host, manager.current_host()); 1203 EXPECT_EQ(host, manager.current_host());
1209 ASSERT_TRUE(host); 1204 ASSERT_TRUE(host);
1210 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), 1205 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()),
1211 instance); 1206 instance);
1212 } 1207 }
1213 1208
1214 } // namespace content 1209 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698