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" | 6 #include "content/browser/browser_thread_impl.h" |
7 #include "content/browser/mock_content_browser_client.h" | |
8 #include "content/browser/renderer_host/test_render_view_host.h" | 7 #include "content/browser/renderer_host/test_render_view_host.h" |
9 #include "content/browser/site_instance_impl.h" | 8 #include "content/browser/site_instance_impl.h" |
10 #include "content/browser/web_contents/navigation_controller_impl.h" | 9 #include "content/browser/web_contents/navigation_controller_impl.h" |
11 #include "content/browser/web_contents/navigation_entry_impl.h" | 10 #include "content/browser/web_contents/navigation_entry_impl.h" |
12 #include "content/browser/web_contents/render_view_host_manager.h" | 11 #include "content/browser/web_contents/render_view_host_manager.h" |
13 #include "content/browser/web_contents/test_web_contents.h" | 12 #include "content/browser/web_contents/test_web_contents.h" |
14 #include "content/common/test_url_constants.h" | 13 #include "content/common/test_url_constants.h" |
15 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
16 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
17 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
18 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
19 #include "content/public/browser/web_ui_controller.h" | 18 #include "content/public/browser/web_ui_controller.h" |
20 #include "content/public/browser/web_ui_controller_factory.h" | 19 #include "content/public/browser/web_ui_controller_factory.h" |
21 #include "content/public/common/javascript_message_type.h" | 20 #include "content/public/common/javascript_message_type.h" |
22 #include "content/public/common/page_transition_types.h" | 21 #include "content/public/common/page_transition_types.h" |
23 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
24 #include "content/public/test/mock_render_process_host.h" | 23 #include "content/public/test/mock_render_process_host.h" |
25 #include "content/public/test/test_browser_context.h" | 24 #include "content/public/test/test_browser_context.h" |
26 #include "content/public/test/test_notification_tracker.h" | 25 #include "content/public/test/test_notification_tracker.h" |
| 26 #include "content/test/test_content_browser_client.h" |
27 #include "content/test/test_content_client.h" | 27 #include "content/test/test_content_client.h" |
28 #include "googleurl/src/url_util.h" | 28 #include "googleurl/src/url_util.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "webkit/glue/webkit_glue.h" | 30 #include "webkit/glue/webkit_glue.h" |
31 | 31 |
32 using content::BrowserContext; | 32 using content::BrowserContext; |
33 using content::BrowserThread; | 33 using content::BrowserThread; |
34 using content::BrowserThreadImpl; | 34 using content::BrowserThreadImpl; |
35 using content::MockRenderProcessHost; | 35 using content::MockRenderProcessHost; |
36 using content::NavigationController; | 36 using content::NavigationController; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 public: | 101 public: |
102 RenderViewHostManagerTestClient() { | 102 RenderViewHostManagerTestClient() { |
103 } | 103 } |
104 | 104 |
105 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE { | 105 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE { |
106 return url.SchemeIs(chrome::kChromeUIScheme); | 106 return url.SchemeIs(chrome::kChromeUIScheme); |
107 } | 107 } |
108 }; | 108 }; |
109 | 109 |
110 class RenderViewHostManagerTestBrowserClient | 110 class RenderViewHostManagerTestBrowserClient |
111 : public content::MockContentBrowserClient { | 111 : public content::TestContentBrowserClient { |
112 public: | 112 public: |
113 RenderViewHostManagerTestBrowserClient() {} | 113 RenderViewHostManagerTestBrowserClient() {} |
114 virtual ~RenderViewHostManagerTestBrowserClient() {} | 114 virtual ~RenderViewHostManagerTestBrowserClient() {} |
115 | 115 |
116 void set_should_create_webui(bool should_create_webui) { | 116 void set_should_create_webui(bool should_create_webui) { |
117 factory_.set_should_create_webui(should_create_webui); | 117 factory_.set_should_create_webui(should_create_webui); |
118 } | 118 } |
119 | 119 |
120 // content::MockContentBrowserClient implementation. | 120 // content::TestContentBrowserClient implementation. |
121 virtual content::WebUIControllerFactory* | 121 virtual content::WebUIControllerFactory* |
122 GetWebUIControllerFactory() OVERRIDE { | 122 GetWebUIControllerFactory() OVERRIDE { |
123 return &factory_; | 123 return &factory_; |
124 } | 124 } |
125 | 125 |
126 private: | 126 private: |
127 RenderViewHostManagerTestWebUIControllerFactory factory_; | 127 RenderViewHostManagerTestWebUIControllerFactory factory_; |
128 | 128 |
129 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManagerTestBrowserClient); | 129 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManagerTestBrowserClient); |
130 }; | 130 }; |
131 | 131 |
132 } // namespace | 132 } // namespace |
133 | 133 |
134 class RenderViewHostManagerTest | 134 class RenderViewHostManagerTest |
135 : public RenderViewHostImplTestHarness { | 135 : public RenderViewHostImplTestHarness { |
136 public: | 136 public: |
137 virtual void SetUp() OVERRIDE { | 137 virtual void SetUp() OVERRIDE { |
138 RenderViewHostImplTestHarness::SetUp(); | 138 RenderViewHostImplTestHarness::SetUp(); |
139 old_client_ = content::GetContentClient(); | 139 old_client_ = content::GetContentClient(); |
140 old_browser_client_ = content::GetContentClient()->browser(); | 140 old_browser_client_ = content::GetContentClient()->browser(); |
141 content::SetContentClient(&client_); | 141 content::SetContentClient(&client_); |
142 content::GetContentClient()->set_browser(&browser_client_); | 142 content::GetContentClient()->set_browser_for_testing(&browser_client_); |
143 url_util::AddStandardScheme(chrome::kChromeUIScheme); | 143 url_util::AddStandardScheme(chrome::kChromeUIScheme); |
144 } | 144 } |
145 | 145 |
146 virtual void TearDown() OVERRIDE { | 146 virtual void TearDown() OVERRIDE { |
147 RenderViewHostImplTestHarness::TearDown(); | 147 RenderViewHostImplTestHarness::TearDown(); |
148 content::GetContentClient()->set_browser(old_browser_client_); | 148 content::GetContentClient()->set_browser_for_testing(old_browser_client_); |
149 content::SetContentClient(old_client_); | 149 content::SetContentClient(old_client_); |
150 } | 150 } |
151 | 151 |
152 void set_should_create_webui(bool should_create_webui) { | 152 void set_should_create_webui(bool should_create_webui) { |
153 browser_client_.set_should_create_webui(should_create_webui); | 153 browser_client_.set_should_create_webui(should_create_webui); |
154 } | 154 } |
155 | 155 |
156 void NavigateActiveAndCommit(const GURL& url) { | 156 void NavigateActiveAndCommit(const GURL& url) { |
157 // Note: we navigate the active RenderViewHost because previous navigations | 157 // Note: we navigate the active RenderViewHost because previous navigations |
158 // won't have committed yet, so NavigateAndCommit does the wrong thing | 158 // won't have committed yet, so NavigateAndCommit does the wrong thing |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 EXPECT_FALSE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( | 829 EXPECT_FALSE(rvh1->GetSiteInstance()->IsRelatedSiteInstance( |
830 rvh3->GetSiteInstance())); | 830 rvh3->GetSiteInstance())); |
831 | 831 |
832 // No scripting is allowed across BrowsingInstances, so we should not create | 832 // No scripting is allowed across BrowsingInstances, so we should not create |
833 // swapped out RVHs for the opener chain in this case. | 833 // swapped out RVHs for the opener chain in this case. |
834 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( | 834 EXPECT_FALSE(opener1_manager->GetSwappedOutRenderViewHost( |
835 rvh3->GetSiteInstance())); | 835 rvh3->GetSiteInstance())); |
836 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost( | 836 EXPECT_FALSE(opener2_manager->GetSwappedOutRenderViewHost( |
837 rvh3->GetSiteInstance())); | 837 rvh3->GetSiteInstance())); |
838 } | 838 } |
OLD | NEW |