| Index: content/browser/web_contents/render_view_host_manager_unittest.cc
|
| ===================================================================
|
| --- content/browser/web_contents/render_view_host_manager_unittest.cc (revision 163514)
|
| +++ content/browser/web_contents/render_view_host_manager_unittest.cc (working copy)
|
| @@ -30,27 +30,11 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "webkit/glue/glue_serialize.h"
|
|
|
| -using content::BrowserContext;
|
| -using content::BrowserThread;
|
| -using content::BrowserThreadImpl;
|
| -using content::MockRenderProcessHost;
|
| -using content::NavigationController;
|
| -using content::NavigationEntry;
|
| -using content::NavigationEntryImpl;
|
| -using content::RenderViewHost;
|
| -using content::RenderViewHostImpl;
|
| -using content::RenderViewHostImplTestHarness;
|
| -using content::SiteInstance;
|
| -using content::TestRenderViewHost;
|
| -using content::TestWebContents;
|
| -using content::WebContents;
|
| -using content::WebUI;
|
| -using content::WebUIController;
|
| -
|
| +namespace content {
|
| namespace {
|
|
|
| class RenderViewHostManagerTestWebUIControllerFactory
|
| - : public content::WebUIControllerFactory {
|
| + : public WebUIControllerFactory {
|
| public:
|
| RenderViewHostManagerTestWebUIControllerFactory()
|
| : should_create_webui_(false) {
|
| @@ -64,8 +48,7 @@
|
| // WebUIFactory implementation.
|
| virtual WebUIController* CreateWebUIControllerForURL(
|
| WebUI* web_ui, const GURL& url) const OVERRIDE {
|
| - if (!(should_create_webui_ &&
|
| - content::GetContentClient()->HasWebUIScheme(url)))
|
| + if (!(should_create_webui_ && GetContentClient()->HasWebUIScheme(url)))
|
| return NULL;
|
| return new WebUIController(web_ui);
|
| }
|
| @@ -77,19 +60,19 @@
|
|
|
| virtual bool UseWebUIForURL(BrowserContext* browser_context,
|
| const GURL& url) const OVERRIDE {
|
| - return content::GetContentClient()->HasWebUIScheme(url);
|
| + return GetContentClient()->HasWebUIScheme(url);
|
| }
|
|
|
| virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context,
|
| const GURL& url) const OVERRIDE {
|
| - return content::GetContentClient()->HasWebUIScheme(url);
|
| + return GetContentClient()->HasWebUIScheme(url);
|
| }
|
|
|
| virtual bool IsURLAcceptableForWebUI(
|
| BrowserContext* browser_context,
|
| const GURL& url,
|
| bool data_urls_allowed) const OVERRIDE {
|
| - return content::GetContentClient()->HasWebUIScheme(url);
|
| + return GetContentClient()->HasWebUIScheme(url);
|
| }
|
|
|
| private:
|
| @@ -109,7 +92,7 @@
|
| };
|
|
|
| class RenderViewHostManagerTestBrowserClient
|
| - : public content::TestContentBrowserClient {
|
| + : public TestContentBrowserClient {
|
| public:
|
| RenderViewHostManagerTestBrowserClient() {}
|
| virtual ~RenderViewHostManagerTestBrowserClient() {}
|
| @@ -118,8 +101,8 @@
|
| factory_.set_should_create_webui(should_create_webui);
|
| }
|
|
|
| - // content::TestContentBrowserClient implementation.
|
| - virtual content::WebUIControllerFactory*
|
| + // TestContentBrowserClient implementation.
|
| + virtual WebUIControllerFactory*
|
| GetWebUIControllerFactory() OVERRIDE {
|
| return &factory_;
|
| }
|
| @@ -137,17 +120,17 @@
|
| public:
|
| virtual void SetUp() OVERRIDE {
|
| RenderViewHostImplTestHarness::SetUp();
|
| - old_client_ = content::GetContentClient();
|
| - old_browser_client_ = content::GetContentClient()->browser();
|
| - content::SetContentClient(&client_);
|
| - content::GetContentClient()->set_browser_for_testing(&browser_client_);
|
| + old_client_ = GetContentClient();
|
| + old_browser_client_ = GetContentClient()->browser();
|
| + SetContentClient(&client_);
|
| + GetContentClient()->set_browser_for_testing(&browser_client_);
|
| url_util::AddStandardScheme(chrome::kChromeUIScheme);
|
| }
|
|
|
| virtual void TearDown() OVERRIDE {
|
| RenderViewHostImplTestHarness::TearDown();
|
| - content::GetContentClient()->set_browser_for_testing(old_browser_client_);
|
| - content::SetContentClient(old_client_);
|
| + GetContentClient()->set_browser_for_testing(old_browser_client_);
|
| + SetContentClient(old_client_);
|
| }
|
|
|
| void set_should_create_webui(bool should_create_webui) {
|
| @@ -158,8 +141,7 @@
|
| // Note: we navigate the active RenderViewHost because previous navigations
|
| // won't have committed yet, so NavigateAndCommit does the wrong thing
|
| // for us.
|
| - controller().LoadURL(
|
| - url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string());
|
| + controller().LoadURL(url, Referrer(), PAGE_TRANSITION_LINK, std::string());
|
| TestRenderViewHost* old_rvh = test_rvh();
|
|
|
| // Simulate the ShouldClose_ACK that is received from the current renderer
|
| @@ -187,8 +169,8 @@
|
| private:
|
| RenderViewHostManagerTestClient client_;
|
| RenderViewHostManagerTestBrowserClient browser_client_;
|
| - content::ContentClient* old_client_;
|
| - content::ContentBrowserClient* old_browser_client_;
|
| + ContentClient* old_client_;
|
| + ContentBrowserClient* old_browser_client_;
|
| };
|
|
|
| // Tests that when you navigate from the New TabPage to another page, and
|
| @@ -197,7 +179,7 @@
|
| // a regression test for bug 9364.
|
| TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) {
|
| BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current());
|
| - const GURL kNtpUrl(content::kTestNewTabURL);
|
| + const GURL kNtpUrl(kTestNewTabURL);
|
| const GURL kDestUrl("http://www.google.com/");
|
|
|
| // Navigate our first tab to the new tab page and then to the destination.
|
| @@ -212,8 +194,7 @@
|
| // a RVH that's not pending (since there is no cross-site transition), so
|
| // we use the committed one.
|
| contents2->GetController().LoadURL(
|
| - kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK,
|
| - std::string());
|
| + kNtpUrl, Referrer(), PAGE_TRANSITION_LINK, std::string());
|
| TestRenderViewHost* ntp_rvh2 = static_cast<TestRenderViewHost*>(
|
| contents2->GetRenderManagerForTesting()->current_host());
|
| EXPECT_FALSE(contents2->cross_navigation_pending());
|
| @@ -222,8 +203,7 @@
|
| // The second one is the opposite, creating a cross-site transition and
|
| // requiring a beforeunload ack.
|
| contents2->GetController().LoadURL(
|
| - kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK,
|
| - std::string());
|
| + kDestUrl, Referrer(), PAGE_TRANSITION_LINK, std::string());
|
| EXPECT_TRUE(contents2->cross_navigation_pending());
|
| TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>(
|
| contents2->GetRenderManagerForTesting()->pending_render_view_host());
|
| @@ -243,8 +223,7 @@
|
| NavigateActiveAndCommit(kNtpUrl);
|
|
|
| contents2->GetController().LoadURL(
|
| - kNtpUrl, content::Referrer(), content::PAGE_TRANSITION_LINK,
|
| - std::string());
|
| + kNtpUrl, Referrer(), PAGE_TRANSITION_LINK, std::string());
|
| dest_rvh2->SendShouldCloseACK(true);
|
| static_cast<TestRenderViewHost*>(contents2->GetRenderManagerForTesting()->
|
| pending_render_view_host())->SendNavigate(102, kNtpUrl);
|
| @@ -263,7 +242,7 @@
|
| // renderer in a stuck state. See http://crbug.com/93427.
|
| TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) {
|
| BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current());
|
| - const GURL kNtpUrl(content::kTestNewTabURL);
|
| + const GURL kNtpUrl(kTestNewTabURL);
|
| const GURL kDestUrl("http://www.google.com/");
|
|
|
| // Navigate our first tab to the new tab page and then to the destination.
|
| @@ -280,8 +259,7 @@
|
|
|
| // Navigate to a cross-site URL.
|
| contents()->GetController().LoadURL(
|
| - kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK,
|
| - std::string());
|
| + kDestUrl, Referrer(), PAGE_TRANSITION_LINK, std::string());
|
| EXPECT_TRUE(contents()->cross_navigation_pending());
|
| TestRenderViewHost* dest_rvh = static_cast<TestRenderViewHost*>(
|
| contents()->GetRenderManagerForTesting()->pending_render_view_host());
|
| @@ -329,7 +307,7 @@
|
| ntp_process_host->sink().ClearMessages();
|
| ViewHostMsg_RunJavaScriptMessage js_msg(
|
| rvh()->GetRoutingID(), msg, msg, kNtpUrl,
|
| - content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused);
|
| + JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused);
|
| js_msg.EnableMessagePumping();
|
| EXPECT_TRUE(ntp_rvh->OnMessageReceived(js_msg));
|
| EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID));
|
| @@ -341,7 +319,7 @@
|
| // RenderView is being newly created or reused.
|
| TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) {
|
| BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current());
|
| - const GURL kNtpUrl(content::kTestNewTabURL);
|
| + const GURL kNtpUrl(kTestNewTabURL);
|
| const GURL kUrl("view-source:http://foo");
|
|
|
| // We have to navigate to some page at first since without this, the first
|
| @@ -354,7 +332,7 @@
|
|
|
| // Navigate.
|
| controller().LoadURL(
|
| - kUrl, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
|
| + kUrl, Referrer(), PAGE_TRANSITION_TYPED, std::string());
|
| // Simulate response from RenderView for FirePageBeforeUnload.
|
| test_rvh()->OnMessageReceived(ViewHostMsg_ShouldClose_ACK(
|
| rvh()->GetRoutingID(), true, base::TimeTicks(), base::TimeTicks()));
|
| @@ -375,7 +353,7 @@
|
| process()->sink().ClearMessages();
|
| // Navigate, again.
|
| controller().LoadURL(
|
| - kUrl, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
|
| + kUrl, Referrer(), PAGE_TRANSITION_TYPED, std::string());
|
| // The same RenderViewHost should be reused.
|
| EXPECT_FALSE(pending_rvh());
|
| EXPECT_TRUE(last_rvh == rvh());
|
| @@ -412,16 +390,15 @@
|
| // Tests the Navigate function. We navigate three sites consecutively and check
|
| // how the pending/committed RenderViewHost are modified.
|
| TEST_F(RenderViewHostManagerTest, Navigate) {
|
| - content::TestNotificationTracker notifications;
|
| + TestNotificationTracker notifications;
|
|
|
| SiteInstance* instance = SiteInstance::Create(browser_context());
|
|
|
| scoped_ptr<TestWebContents> web_contents(
|
| TestWebContents::Create(browser_context(), instance));
|
| notifications.ListenFor(
|
| - content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
|
| - content::Source<NavigationController>(
|
| - &web_contents->GetController()));
|
| + NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
|
| + Source<NavigationController>(&web_contents->GetController()));
|
|
|
| // Create.
|
| RenderViewHostManager manager(web_contents.get(), web_contents.get(),
|
| @@ -434,8 +411,8 @@
|
| // 1) The first navigation. --------------------------
|
| const GURL kUrl1("http://www.google.com/");
|
| NavigationEntryImpl entry1(
|
| - NULL /* instance */, -1 /* page_id */, kUrl1, content::Referrer(),
|
| - string16() /* title */, content::PAGE_TRANSITION_TYPED,
|
| + NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(),
|
| + string16() /* title */, PAGE_TRANSITION_TYPED,
|
| false /* is_renderer_init */);
|
| host = manager.Navigate(entry1);
|
|
|
| @@ -456,8 +433,8 @@
|
| const GURL kUrl2("http://www.google.com/foo");
|
| NavigationEntryImpl entry2(
|
| NULL /* instance */, -1 /* page_id */, kUrl2,
|
| - content::Referrer(kUrl1, WebKit::WebReferrerPolicyDefault),
|
| - string16() /* title */, content::PAGE_TRANSITION_LINK,
|
| + Referrer(kUrl1, WebKit::WebReferrerPolicyDefault),
|
| + string16() /* title */, PAGE_TRANSITION_LINK,
|
| true /* is_renderer_init */);
|
| host = manager.Navigate(entry2);
|
|
|
| @@ -476,8 +453,8 @@
|
| const GURL kUrl3("http://webkit.org/");
|
| NavigationEntryImpl entry3(
|
| NULL /* instance */, -1 /* page_id */, kUrl3,
|
| - content::Referrer(kUrl2, WebKit::WebReferrerPolicyDefault),
|
| - string16() /* title */, content::PAGE_TRANSITION_LINK,
|
| + Referrer(kUrl2, WebKit::WebReferrerPolicyDefault),
|
| + string16() /* title */, PAGE_TRANSITION_LINK,
|
| false /* is_renderer_init */);
|
| host = manager.Navigate(entry3);
|
|
|
| @@ -498,7 +475,7 @@
|
|
|
| // We should observe a notification.
|
| EXPECT_TRUE(notifications.Check1AndReset(
|
| - content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
|
| + NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
|
| }
|
|
|
| // Tests the Navigate function. In this unit test we verify that the Navigate
|
| @@ -506,16 +483,15 @@
|
| // has been committed. This is also a regression test for
|
| // http://crbug.com/104600.
|
| TEST_F(RenderViewHostManagerTest, NavigateWithEarlyReNavigation) {
|
| - content::TestNotificationTracker notifications;
|
| + TestNotificationTracker notifications;
|
|
|
| SiteInstance* instance = SiteInstance::Create(browser_context());
|
|
|
| scoped_ptr<TestWebContents> web_contents(
|
| TestWebContents::Create(browser_context(), instance));
|
| notifications.ListenFor(
|
| - content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
|
| - content::Source<NavigationController>(
|
| - &web_contents->GetController()));
|
| + NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
|
| + Source<NavigationController>(&web_contents->GetController()));
|
|
|
| // Create.
|
| RenderViewHostManager manager(web_contents.get(), web_contents.get(),
|
| @@ -526,8 +502,8 @@
|
| // 1) The first navigation. --------------------------
|
| const GURL kUrl1("http://www.google.com/");
|
| NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
|
| - content::Referrer(), string16() /* title */,
|
| - content::PAGE_TRANSITION_TYPED,
|
| + Referrer(), string16() /* title */,
|
| + PAGE_TRANSITION_TYPED,
|
| false /* is_renderer_init */);
|
| RenderViewHost* host = manager.Navigate(entry1);
|
|
|
| @@ -537,7 +513,7 @@
|
|
|
| // We should observe a notification.
|
| EXPECT_TRUE(notifications.Check1AndReset(
|
| - content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
|
| + NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
|
| notifications.Reset();
|
|
|
| // Commit.
|
| @@ -553,8 +529,8 @@
|
| // 2) Cross-site navigate to next site. -------------------------
|
| const GURL kUrl2("http://www.example.com");
|
| NavigationEntryImpl entry2(
|
| - NULL /* instance */, -1 /* page_id */, kUrl2, content::Referrer(),
|
| - string16() /* title */, content::PAGE_TRANSITION_TYPED,
|
| + NULL /* instance */, -1 /* page_id */, kUrl2, Referrer(),
|
| + string16() /* title */, PAGE_TRANSITION_TYPED,
|
| false /* is_renderer_init */);
|
| RenderViewHostImpl* host2 = static_cast<RenderViewHostImpl*>(
|
| manager.Navigate(entry2));
|
| @@ -606,8 +582,8 @@
|
| // 3) Cross-site navigate to next site before 2) has committed. --------------
|
| const GURL kUrl3("http://webkit.org/");
|
| NavigationEntryImpl entry3(NULL /* instance */, -1 /* page_id */, kUrl3,
|
| - content::Referrer(), string16() /* title */,
|
| - content::PAGE_TRANSITION_TYPED,
|
| + Referrer(), string16() /* title */,
|
| + PAGE_TRANSITION_TYPED,
|
| false /* is_renderer_init */);
|
| test_process_host->sink().ClearMessages();
|
| RenderViewHost* host3 = manager.Navigate(entry3);
|
| @@ -654,7 +630,7 @@
|
|
|
| // We should observe a notification.
|
| EXPECT_TRUE(notifications.Check1AndReset(
|
| - content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
|
| + NOTIFICATION_RENDER_VIEW_HOST_CHANGED));
|
| }
|
|
|
| // Tests WebUI creation.
|
| @@ -670,10 +646,10 @@
|
|
|
| manager.Init(browser_context(), instance, MSG_ROUTING_NONE);
|
|
|
| - const GURL kUrl(content::kTestNewTabURL);
|
| + const GURL kUrl(kTestNewTabURL);
|
| NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl,
|
| - content::Referrer(), string16() /* title */,
|
| - content::PAGE_TRANSITION_TYPED,
|
| + Referrer(), string16() /* title */,
|
| + PAGE_TRANSITION_TYPED,
|
| false /* is_renderer_init */);
|
| RenderViewHost* host = manager.Navigate(entry);
|
|
|
| @@ -696,7 +672,7 @@
|
|
|
| // Commit.
|
| manager.DidNavigateMainFrame(host);
|
| - EXPECT_TRUE(host->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI);
|
| + EXPECT_TRUE(host->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
|
| }
|
|
|
| // Tests that we don't end up in an inconsistent state if a page does a back and
|
| @@ -725,7 +701,7 @@
|
| ViewHostMsg_FrameNavigate_Params params;
|
| params.page_id = 1;
|
| params.url = kUrl2;
|
| - params.transition = content::PAGE_TRANSITION_CLIENT_REDIRECT;
|
| + params.transition = PAGE_TRANSITION_CLIENT_REDIRECT;
|
| params.should_update_history = false;
|
| params.gesture = NavigationGestureAuto;
|
| params.was_within_same_page = false;
|
| @@ -790,7 +766,7 @@
|
| TEST_F(RenderViewHostManagerTest, CreateSwappedOutOpenerRVHs) {
|
| const GURL kUrl1("http://www.google.com/");
|
| const GURL kUrl2("http://www.chromium.org/");
|
| - const GURL kNtpUrl(content::kTestNewTabURL);
|
| + const GURL kNtpUrl(kTestNewTabURL);
|
|
|
| // Navigate to an initial URL.
|
| contents()->NavigateAndCommit(kUrl1);
|
| @@ -864,7 +840,7 @@
|
|
|
| // Ensure the RVH has WebUI bindings.
|
| TestRenderViewHost* rvh1 = test_rvh();
|
| - EXPECT_TRUE(rvh1->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI);
|
| + EXPECT_TRUE(rvh1->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
|
|
|
| // Create a new tab and simulate it being the opener for the main
|
| // tab. It should be in the same SiteInstance.
|
| @@ -889,12 +865,12 @@
|
| EXPECT_TRUE(opener1_rvh->is_swapped_out());
|
|
|
| // Ensure the new RVH has WebUI bindings.
|
| - EXPECT_TRUE(rvh2->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI);
|
| + EXPECT_TRUE(rvh2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI);
|
| }
|
|
|
| // Test that we reuse the same guest SiteInstance if we navigate across sites.
|
| TEST_F(RenderViewHostManagerTest, NoSwapOnGuestNavigations) {
|
| - content::TestNotificationTracker notifications;
|
| + TestNotificationTracker notifications;
|
|
|
| GURL guest_url("guest://abc123");
|
| SiteInstance* instance =
|
| @@ -913,8 +889,8 @@
|
| // 1) The first navigation. --------------------------
|
| const GURL kUrl1("http://www.google.com/");
|
| NavigationEntryImpl entry1(
|
| - NULL /* instance */, -1 /* page_id */, kUrl1, content::Referrer(),
|
| - string16() /* title */, content::PAGE_TRANSITION_TYPED,
|
| + NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(),
|
| + string16() /* title */, PAGE_TRANSITION_TYPED,
|
| false /* is_renderer_init */);
|
| host = manager.Navigate(entry1);
|
|
|
| @@ -936,8 +912,8 @@
|
| const GURL kUrl2("http://www.chromium.org");
|
| NavigationEntryImpl entry2(
|
| NULL /* instance */, -1 /* page_id */, kUrl2,
|
| - content::Referrer(kUrl1, WebKit::WebReferrerPolicyDefault),
|
| - string16() /* title */, content::PAGE_TRANSITION_LINK,
|
| + Referrer(kUrl1, WebKit::WebReferrerPolicyDefault),
|
| + string16() /* title */, PAGE_TRANSITION_LINK,
|
| true /* is_renderer_init */);
|
| host = manager.Navigate(entry2);
|
|
|
| @@ -951,5 +927,6 @@
|
| ASSERT_TRUE(host);
|
| EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()),
|
| instance);
|
| -
|
| }
|
| +
|
| +} // namespace content
|
|
|