OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "content/browser/browser_thread_impl.h" | |
7 #include "content/browser/renderer_host/test_render_view_host.h" | 6 #include "content/browser/renderer_host/test_render_view_host.h" |
8 #include "content/browser/site_instance_impl.h" | 7 #include "content/browser/site_instance_impl.h" |
9 #include "content/browser/web_contents/navigation_controller_impl.h" | 8 #include "content/browser/web_contents/navigation_controller_impl.h" |
10 #include "content/browser/web_contents/navigation_entry_impl.h" | 9 #include "content/browser/web_contents/navigation_entry_impl.h" |
11 #include "content/browser/web_contents/render_view_host_manager.h" | 10 #include "content/browser/web_contents/render_view_host_manager.h" |
12 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 11 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
13 #include "content/common/view_messages.h" | 12 #include "content/common/view_messages.h" |
14 #include "content/public/browser/notification_details.h" | 13 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
16 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
17 #include "content/public/browser/web_ui_controller.h" | 16 #include "content/public/browser/web_ui_controller.h" |
18 #include "content/public/common/bindings_policy.h" | 17 #include "content/public/common/bindings_policy.h" |
19 #include "content/public/common/javascript_message_type.h" | 18 #include "content/public/common/javascript_message_type.h" |
20 #include "content/public/common/page_transition_types.h" | 19 #include "content/public/common/page_transition_types.h" |
21 #include "content/public/common/url_constants.h" | 20 #include "content/public/common/url_constants.h" |
22 #include "content/public/common/url_utils.h" | 21 #include "content/public/common/url_utils.h" |
23 #include "content/public/test/mock_render_process_host.h" | 22 #include "content/public/test/mock_render_process_host.h" |
24 #include "content/public/test/test_browser_context.h" | |
25 #include "content/public/test/test_notification_tracker.h" | 23 #include "content/public/test/test_notification_tracker.h" |
26 #include "content/test/test_content_browser_client.h" | 24 #include "content/test/test_content_browser_client.h" |
27 #include "content/test/test_content_client.h" | 25 #include "content/test/test_content_client.h" |
28 #include "content/test/test_web_contents.h" | 26 #include "content/test/test_web_contents.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
30 | 28 |
31 namespace content { | 29 namespace content { |
32 namespace { | 30 namespace { |
33 | 31 |
34 class RenderViewHostManagerTestWebUIControllerFactory | 32 class RenderViewHostManagerTestWebUIControllerFactory |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 private: | 121 private: |
124 RenderViewHostManagerTestWebUIControllerFactory factory_; | 122 RenderViewHostManagerTestWebUIControllerFactory factory_; |
125 }; | 123 }; |
126 | 124 |
127 // Tests that when you navigate from a chrome:// url to another page, and | 125 // Tests that when you navigate from a chrome:// url to another page, and |
128 // then do that same thing in another tab, that the two resulting pages have | 126 // then do that same thing in another tab, that the two resulting pages have |
129 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 127 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
130 // a regression test for bug 9364. | 128 // a regression test for bug 9364. |
131 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { | 129 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { |
132 set_should_create_webui(true); | 130 set_should_create_webui(true); |
133 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); | |
134 const GURL kChromeUrl("chrome://foo"); | 131 const GURL kChromeUrl("chrome://foo"); |
135 const GURL kDestUrl("http://www.google.com/"); | 132 const GURL kDestUrl("http://www.google.com/"); |
136 | 133 |
137 // Navigate our first tab to the chrome url and then to the destination, | 134 // Navigate our first tab to the chrome url and then to the destination, |
138 // ensuring we grant bindings to the chrome URL. | 135 // ensuring we grant bindings to the chrome URL. |
139 NavigateActiveAndCommit(kChromeUrl); | 136 NavigateActiveAndCommit(kChromeUrl); |
140 EXPECT_TRUE(active_rvh()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 137 EXPECT_TRUE(active_rvh()->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
141 NavigateActiveAndCommit(kDestUrl); | 138 NavigateActiveAndCommit(kDestUrl); |
142 | 139 |
143 // Make a second tab. | 140 // Make a second tab. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(), | 185 EXPECT_EQ(active_rvh()->GetSiteInstance()->GetProcess(), |
189 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess()); | 186 contents2->GetRenderViewHost()->GetSiteInstance()->GetProcess()); |
190 } | 187 } |
191 | 188 |
192 // Ensure that the browser ignores most IPC messages that arrive from a | 189 // Ensure that the browser ignores most IPC messages that arrive from a |
193 // RenderViewHost that has been swapped out. We do not want to take | 190 // RenderViewHost that has been swapped out. We do not want to take |
194 // action on requests from a non-active renderer. The main exception is | 191 // action on requests from a non-active renderer. The main exception is |
195 // for synchronous messages, which cannot be ignored without leaving the | 192 // for synchronous messages, which cannot be ignored without leaving the |
196 // renderer in a stuck state. See http://crbug.com/93427. | 193 // renderer in a stuck state. See http://crbug.com/93427. |
197 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) { | 194 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) { |
198 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); | |
199 const GURL kChromeURL("chrome://foo"); | 195 const GURL kChromeURL("chrome://foo"); |
200 const GURL kDestUrl("http://www.google.com/"); | 196 const GURL kDestUrl("http://www.google.com/"); |
201 | 197 |
202 // Navigate our first tab to a chrome url and then to the destination. | 198 // Navigate our first tab to a chrome url and then to the destination. |
203 NavigateActiveAndCommit(kChromeURL); | 199 NavigateActiveAndCommit(kChromeURL); |
204 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>( | 200 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>( |
205 contents()->GetRenderManagerForTesting()->current_host()); | 201 contents()->GetRenderManagerForTesting()->current_host()); |
206 | 202 |
207 // Send an update title message and make sure it works. | 203 // Send an update title message and make sure it works. |
208 const string16 ntp_title = ASCIIToUTF16("NTP Title"); | 204 const string16 ntp_title = ASCIIToUTF16("NTP Title"); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 js_msg.EnableMessagePumping(); | 261 js_msg.EnableMessagePumping(); |
266 EXPECT_TRUE(ntp_rvh->OnMessageReceived(js_msg)); | 262 EXPECT_TRUE(ntp_rvh->OnMessageReceived(js_msg)); |
267 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); | 263 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); |
268 } | 264 } |
269 | 265 |
270 // When there is an error with the specified page, renderer exits view-source | 266 // When there is an error with the specified page, renderer exits view-source |
271 // mode. See WebFrameImpl::DidFail(). We check by this test that | 267 // mode. See WebFrameImpl::DidFail(). We check by this test that |
272 // EnableViewSourceMode message is sent on every navigation regardless | 268 // EnableViewSourceMode message is sent on every navigation regardless |
273 // RenderView is being newly created or reused. | 269 // RenderView is being newly created or reused. |
274 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { | 270 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { |
275 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); | |
276 const GURL kChromeUrl("chrome://foo"); | 271 const GURL kChromeUrl("chrome://foo"); |
277 const GURL kUrl("view-source:http://foo"); | 272 const GURL kUrl("view-source:http://foo"); |
278 | 273 |
279 // We have to navigate to some page at first since without this, the first | 274 // We have to navigate to some page at first since without this, the first |
280 // navigation will reuse the SiteInstance created by Init(), and the second | 275 // navigation will reuse the SiteInstance created by Init(), and the second |
281 // one will create a new SiteInstance. Because current_instance and | 276 // one will create a new SiteInstance. Because current_instance and |
282 // new_instance will be different, a new RenderViewHost will be created for | 277 // new_instance will be different, a new RenderViewHost will be created for |
283 // the second navigation. We have to avoid this in order to exercise the | 278 // the second navigation. We have to avoid this in order to exercise the |
284 // target code patch. | 279 // target code patch. |
285 NavigateActiveAndCommit(kChromeUrl); | 280 NavigateActiveAndCommit(kChromeUrl); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 EXPECT_FALSE(manager.pending_render_view_host()); | 579 EXPECT_FALSE(manager.pending_render_view_host()); |
585 | 580 |
586 // We should observe a notification. | 581 // We should observe a notification. |
587 EXPECT_TRUE(notifications.Check1AndReset( | 582 EXPECT_TRUE(notifications.Check1AndReset( |
588 NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | 583 NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); |
589 } | 584 } |
590 | 585 |
591 // Tests WebUI creation. | 586 // Tests WebUI creation. |
592 TEST_F(RenderViewHostManagerTest, WebUI) { | 587 TEST_F(RenderViewHostManagerTest, WebUI) { |
593 set_should_create_webui(true); | 588 set_should_create_webui(true); |
594 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); | |
595 SiteInstance* instance = SiteInstance::Create(browser_context()); | 589 SiteInstance* instance = SiteInstance::Create(browser_context()); |
596 | 590 |
597 scoped_ptr<TestWebContents> web_contents( | 591 scoped_ptr<TestWebContents> web_contents( |
598 TestWebContents::Create(browser_context(), instance)); | 592 TestWebContents::Create(browser_context(), instance)); |
599 RenderViewHostManager manager(web_contents.get(), web_contents.get(), | 593 RenderViewHostManager manager(web_contents.get(), web_contents.get(), |
600 web_contents.get()); | 594 web_contents.get()); |
601 | 595 |
602 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); | 596 manager.Init(browser_context(), instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE); |
603 EXPECT_FALSE(manager.current_host()->IsRenderViewLive()); | 597 EXPECT_FALSE(manager.current_host()->IsRenderViewLive()); |
604 | 598 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 | 938 |
945 // Commit. | 939 // Commit. |
946 manager.DidNavigateMainFrame(host); | 940 manager.DidNavigateMainFrame(host); |
947 EXPECT_EQ(host, manager.current_host()); | 941 EXPECT_EQ(host, manager.current_host()); |
948 ASSERT_TRUE(host); | 942 ASSERT_TRUE(host); |
949 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), | 943 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), |
950 instance); | 944 instance); |
951 } | 945 } |
952 | 946 |
953 } // namespace content | 947 } // namespace content |
OLD | NEW |