OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 13 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/render_frame_host.h" |
| 16 #include "content/public/browser/render_process_host.h" |
15 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
16 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_ui_controller.h" | 19 #include "content/public/browser/web_ui_controller.h" |
18 #include "content/public/browser/web_ui_data_source.h" | 20 #include "content/public/browser/web_ui_data_source.h" |
19 #include "content/public/common/content_paths.h" | 21 #include "content/public/common/content_paths.h" |
20 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 23 #include "content/public/common/service_registry.h" |
21 #include "content/public/common/url_utils.h" | 24 #include "content/public/common/url_utils.h" |
22 #include "content/public/test/content_browser_test.h" | 25 #include "content/public/test/content_browser_test.h" |
23 #include "content/public/test/content_browser_test_utils.h" | 26 #include "content/public/test/content_browser_test_utils.h" |
| 27 #include "content/shell/browser/shell.h" |
24 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" | 28 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" |
25 #include "grit/content_resources.h" | 29 #include "grit/content_resources.h" |
26 #include "mojo/common/test/test_utils.h" | 30 #include "mojo/common/test/test_utils.h" |
27 #include "mojo/public/js/bindings/constants.h" | 31 #include "mojo/public/js/bindings/constants.h" |
28 | 32 |
29 namespace content { | 33 namespace content { |
30 namespace { | 34 namespace { |
31 | 35 |
32 bool got_message = false; | 36 bool got_message = false; |
33 | 37 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 DISALLOW_COPY_AND_ASSIGN(TestWebUIController); | 122 DISALLOW_COPY_AND_ASSIGN(TestWebUIController); |
119 }; | 123 }; |
120 | 124 |
121 // TestWebUIController that additionally creates the ping test BrowserTarget | 125 // TestWebUIController that additionally creates the ping test BrowserTarget |
122 // implementation at the right time. | 126 // implementation at the right time. |
123 class PingTestWebUIController : public TestWebUIController { | 127 class PingTestWebUIController : public TestWebUIController { |
124 public: | 128 public: |
125 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) | 129 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) |
126 : TestWebUIController(web_ui, run_loop) { | 130 : TestWebUIController(web_ui, run_loop) { |
127 } | 131 } |
| 132 virtual ~PingTestWebUIController() {} |
128 | 133 |
129 // WebUIController overrides: | 134 // WebUIController overrides: |
130 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE { | 135 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE { |
131 mojo::MessagePipe pipe; | 136 render_view_host->GetMainFrame()->GetServiceRegistry()->AddService( |
132 browser_target_.reset( | 137 "webui_controller", |
133 new PingBrowserTargetImpl(pipe.handle0.Pass(), run_loop_)); | 138 base::Bind(&PingTestWebUIController::CreateHandler, |
134 render_view_host->SetWebUIHandle(pipe.handle1.Pass()); | 139 base::Unretained(this))); |
| 140 } |
| 141 |
| 142 void CreateHandler(mojo::ScopedMessagePipeHandle handle) { |
| 143 browser_target_.reset(new PingBrowserTargetImpl(handle.Pass(), run_loop_)); |
135 } | 144 } |
136 | 145 |
137 private: | 146 private: |
138 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); | 147 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); |
139 }; | 148 }; |
140 | 149 |
141 // WebUIControllerFactory that creates TestWebUIController. | 150 // WebUIControllerFactory that creates TestWebUIController. |
142 class TestWebUIControllerFactory : public WebUIControllerFactory { | 151 class TestWebUIControllerFactory : public WebUIControllerFactory { |
143 public: | 152 public: |
144 TestWebUIControllerFactory() : run_loop_(NULL) {} | 153 TestWebUIControllerFactory() : run_loop_(NULL) {} |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 214 |
206 got_message = false; | 215 got_message = false; |
207 ASSERT_TRUE(test_server()->Start()); | 216 ASSERT_TRUE(test_server()->Start()); |
208 base::RunLoop run_loop; | 217 base::RunLoop run_loop; |
209 factory()->set_run_loop(&run_loop); | 218 factory()->set_run_loop(&run_loop); |
210 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?ping")); | 219 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?ping")); |
211 NavigateToURL(shell(), test_url); | 220 NavigateToURL(shell(), test_url); |
212 // RunLoop is quit when message received from page. | 221 // RunLoop is quit when message received from page. |
213 run_loop.Run(); | 222 run_loop.Run(); |
214 EXPECT_TRUE(got_message); | 223 EXPECT_TRUE(got_message); |
| 224 |
| 225 // Check that a second render frame in the same renderer process works |
| 226 // correctly. |
| 227 Shell* other_shell = CreateBrowser(); |
| 228 got_message = false; |
| 229 base::RunLoop other_run_loop; |
| 230 factory()->set_run_loop(&other_run_loop); |
| 231 NavigateToURL(other_shell, test_url); |
| 232 // RunLoop is quit when message received from page. |
| 233 other_run_loop.Run(); |
| 234 EXPECT_TRUE(got_message); |
| 235 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), |
| 236 other_shell->web_contents()->GetRenderProcessHost()); |
215 } | 237 } |
216 | 238 |
217 } // namespace | 239 } // namespace |
218 } // namespace content | 240 } // namespace content |
OLD | NEW |