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

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: fix Created 7 years, 2 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 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 577
578 // Tests the Navigate function. We navigate three sites consecutively and check 578 // Tests the Navigate function. We navigate three sites consecutively and check
579 // how the pending/committed RenderViewHost are modified. 579 // how the pending/committed RenderViewHost are modified.
580 TEST_F(RenderViewHostManagerTest, Navigate) { 580 TEST_F(RenderViewHostManagerTest, Navigate) {
581 TestNotificationTracker notifications; 581 TestNotificationTracker notifications;
582 582
583 SiteInstance* instance = SiteInstance::Create(browser_context()); 583 SiteInstance* instance = SiteInstance::Create(browser_context());
584 584
585 scoped_ptr<TestWebContents> web_contents( 585 scoped_ptr<TestWebContents> web_contents(
586 TestWebContents::Create(browser_context(), instance)); 586 TestWebContents::Create(browser_context(), instance));
587 notifications.ListenFor( 587 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
588 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 588 Source<WebContents>(web_contents.get()));
589 Source<NavigationController>(&web_contents->GetController()));
590 589
591 // Create. 590 // Create.
592 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 591 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
593 web_contents.get()); 592 web_contents.get());
594 593
595 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 594 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
596 595
597 RenderViewHost* host; 596 RenderViewHost* host;
598 597
599 // 1) The first navigation. -------------------------- 598 // 1) The first navigation. --------------------------
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 // Commit. 654 // Commit.
656 manager.DidNavigateMainFrame(manager.pending_render_view_host()); 655 manager.DidNavigateMainFrame(manager.pending_render_view_host());
657 EXPECT_TRUE(host == manager.current_host()); 656 EXPECT_TRUE(host == manager.current_host());
658 ASSERT_TRUE(host); 657 ASSERT_TRUE(host);
659 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> 658 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
660 HasSite()); 659 HasSite());
661 // Check the pending RenderViewHost has been committed. 660 // Check the pending RenderViewHost has been committed.
662 EXPECT_FALSE(manager.pending_render_view_host()); 661 EXPECT_FALSE(manager.pending_render_view_host());
663 662
664 // We should observe a notification. 663 // We should observe a notification.
665 EXPECT_TRUE(notifications.Check1AndReset( 664 EXPECT_TRUE(
666 NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 665 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
667 } 666 }
668 667
669 // Tests the Navigate function. In this unit test we verify that the Navigate 668 // Tests the Navigate function. In this unit test we verify that the Navigate
670 // function can handle a new navigation event before the previous navigation 669 // function can handle a new navigation event before the previous navigation
671 // has been committed. This is also a regression test for 670 // has been committed. This is also a regression test for
672 // http://crbug.com/104600. 671 // http://crbug.com/104600.
673 TEST_F(RenderViewHostManagerTest, NavigateWithEarlyReNavigation) { 672 TEST_F(RenderViewHostManagerTest, NavigateWithEarlyReNavigation) {
674 TestNotificationTracker notifications; 673 TestNotificationTracker notifications;
675 674
676 SiteInstance* instance = SiteInstance::Create(browser_context()); 675 SiteInstance* instance = SiteInstance::Create(browser_context());
677 676
678 scoped_ptr<TestWebContents> web_contents( 677 scoped_ptr<TestWebContents> web_contents(
679 TestWebContents::Create(browser_context(), instance)); 678 TestWebContents::Create(browser_context(), instance));
680 notifications.ListenFor( 679 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
681 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 680 Source<WebContents>(web_contents.get()));
682 Source<NavigationController>(&web_contents->GetController()));
683 681
684 // Create. 682 // Create.
685 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 683 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
686 web_contents.get()); 684 web_contents.get());
687 685
688 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 686 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
689 687
690 // 1) The first navigation. -------------------------- 688 // 1) The first navigation. --------------------------
691 const GURL kUrl1("http://www.google.com/"); 689 const GURL kUrl1("http://www.google.com/");
692 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 690 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
693 Referrer(), string16() /* title */, 691 Referrer(), string16() /* title */,
694 PAGE_TRANSITION_TYPED, 692 PAGE_TRANSITION_TYPED,
695 false /* is_renderer_init */); 693 false /* is_renderer_init */);
696 RenderViewHost* host = manager.Navigate(entry1); 694 RenderViewHost* host = manager.Navigate(entry1);
697 695
698 // The RenderViewHost created in Init will be reused. 696 // The RenderViewHost created in Init will be reused.
699 EXPECT_TRUE(host == manager.current_host()); 697 EXPECT_TRUE(host == manager.current_host());
700 EXPECT_FALSE(manager.pending_render_view_host()); 698 EXPECT_FALSE(manager.pending_render_view_host());
701 699
702 // We should observe a notification. 700 // We should observe a notification.
703 EXPECT_TRUE(notifications.Check1AndReset( 701 EXPECT_TRUE(
704 NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 702 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
705 notifications.Reset(); 703 notifications.Reset();
706 704
707 // Commit. 705 // Commit.
708 manager.DidNavigateMainFrame(host); 706 manager.DidNavigateMainFrame(host);
709 707
710 // Commit to SiteInstance should be delayed until RenderView commit. 708 // Commit to SiteInstance should be delayed until RenderView commit.
711 EXPECT_TRUE(host == manager.current_host()); 709 EXPECT_TRUE(host == manager.current_host());
712 ASSERT_TRUE(host); 710 ASSERT_TRUE(host);
713 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> 711 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
714 HasSite()); 712 HasSite());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 // Commit. 805 // Commit.
808 manager.DidNavigateMainFrame(host3); 806 manager.DidNavigateMainFrame(host3);
809 EXPECT_TRUE(host3 == manager.current_host()); 807 EXPECT_TRUE(host3 == manager.current_host());
810 ASSERT_TRUE(host3); 808 ASSERT_TRUE(host3);
811 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())-> 809 EXPECT_TRUE(static_cast<SiteInstanceImpl*>(host3->GetSiteInstance())->
812 HasSite()); 810 HasSite());
813 // Check the pending RenderViewHost has been committed. 811 // Check the pending RenderViewHost has been committed.
814 EXPECT_FALSE(manager.pending_render_view_host()); 812 EXPECT_FALSE(manager.pending_render_view_host());
815 813
816 // We should observe a notification. 814 // We should observe a notification.
817 EXPECT_TRUE(notifications.Check1AndReset( 815 EXPECT_TRUE(
818 NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 816 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
819 } 817 }
820 818
821 // Tests WebUI creation. 819 // Tests WebUI creation.
822 TEST_F(RenderViewHostManagerTest, WebUI) { 820 TEST_F(RenderViewHostManagerTest, WebUI) {
823 set_should_create_webui(true); 821 set_should_create_webui(true);
824 SiteInstance* instance = SiteInstance::Create(browser_context()); 822 SiteInstance* instance = SiteInstance::Create(browser_context());
825 823
826 scoped_ptr<TestWebContents> web_contents( 824 scoped_ptr<TestWebContents> web_contents(
827 TestWebContents::Create(browser_context(), instance)); 825 TestWebContents::Create(browser_context(), instance));
828 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 826 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 // http://crbug.com/294697. 1233 // http://crbug.com/294697.
1236 TEST_F(RenderViewHostManagerTest, NavigateWithEarlyClose) { 1234 TEST_F(RenderViewHostManagerTest, NavigateWithEarlyClose) {
1237 TestNotificationTracker notifications; 1235 TestNotificationTracker notifications;
1238 1236
1239 SiteInstance* instance = SiteInstance::Create(browser_context()); 1237 SiteInstance* instance = SiteInstance::Create(browser_context());
1240 1238
1241 BeforeUnloadFiredWebContentsDelegate delegate; 1239 BeforeUnloadFiredWebContentsDelegate delegate;
1242 scoped_ptr<TestWebContents> web_contents( 1240 scoped_ptr<TestWebContents> web_contents(
1243 TestWebContents::Create(browser_context(), instance)); 1241 TestWebContents::Create(browser_context(), instance));
1244 web_contents->SetDelegate(&delegate); 1242 web_contents->SetDelegate(&delegate);
1245 notifications.ListenFor( 1243 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
1246 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 1244 Source<WebContents>(web_contents.get()));
1247 Source<NavigationController>(&web_contents->GetController()));
1248 1245
1249 // Create. 1246 // Create.
1250 RenderViewHostManager manager(web_contents.get(), web_contents.get(), 1247 RenderViewHostManager manager(web_contents.get(), web_contents.get(),
1251 web_contents.get()); 1248 web_contents.get());
1252 1249
1253 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); 1250 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
1254 1251
1255 // 1) The first navigation. -------------------------- 1252 // 1) The first navigation. --------------------------
1256 const GURL kUrl1("http://www.google.com/"); 1253 const GURL kUrl1("http://www.google.com/");
1257 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 1254 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
1258 Referrer(), string16() /* title */, 1255 Referrer(), string16() /* title */,
1259 PAGE_TRANSITION_TYPED, 1256 PAGE_TRANSITION_TYPED,
1260 false /* is_renderer_init */); 1257 false /* is_renderer_init */);
1261 RenderViewHost* host = manager.Navigate(entry1); 1258 RenderViewHost* host = manager.Navigate(entry1);
1262 1259
1263 // The RenderViewHost created in Init will be reused. 1260 // The RenderViewHost created in Init will be reused.
1264 EXPECT_EQ(host, manager.current_host()); 1261 EXPECT_EQ(host, manager.current_host());
1265 EXPECT_FALSE(manager.pending_render_view_host()); 1262 EXPECT_FALSE(manager.pending_render_view_host());
1266 1263
1267 // We should observe a notification. 1264 // We should observe a notification.
1268 EXPECT_TRUE(notifications.Check1AndReset( 1265 EXPECT_TRUE(
1269 NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); 1266 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
1270 notifications.Reset(); 1267 notifications.Reset();
1271 1268
1272 // Commit. 1269 // Commit.
1273 manager.DidNavigateMainFrame(host); 1270 manager.DidNavigateMainFrame(host);
1274 1271
1275 // Commit to SiteInstance should be delayed until RenderView commit. 1272 // Commit to SiteInstance should be delayed until RenderView commit.
1276 EXPECT_EQ(host, manager.current_host()); 1273 EXPECT_EQ(host, manager.current_host());
1277 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())-> 1274 EXPECT_FALSE(static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->
1278 HasSite()); 1275 HasSite());
1279 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1); 1276 static_cast<SiteInstanceImpl*>(host->GetSiteInstance())->SetSite(kUrl1);
(...skipping 21 matching lines...) Expand all
1301 Source<RenderWidgetHost>(host2)); 1298 Source<RenderWidgetHost>(host2));
1302 manager.ShouldClosePage(false, true, base::TimeTicks()); 1299 manager.ShouldClosePage(false, true, base::TimeTicks());
1303 1300
1304 EXPECT_TRUE( 1301 EXPECT_TRUE(
1305 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED)); 1302 notifications.Check1AndReset(NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED));
1306 EXPECT_FALSE(manager.pending_render_view_host()); 1303 EXPECT_FALSE(manager.pending_render_view_host());
1307 EXPECT_EQ(host, manager.current_host()); 1304 EXPECT_EQ(host, manager.current_host());
1308 } 1305 }
1309 1306
1310 } // namespace content 1307 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/render_view_host_manager.cc ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698