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" | |
17 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
19 #include "content/public/browser/web_ui_controller.h" | 17 #include "content/public/browser/web_ui_controller.h" |
20 #include "content/public/browser/web_ui_data_source.h" | 18 #include "content/public/browser/web_ui_data_source.h" |
21 #include "content/public/common/content_paths.h" | 19 #include "content/public/common/content_paths.h" |
22 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
23 #include "content/public/common/service_registry.h" | |
24 #include "content/public/common/url_utils.h" | 21 #include "content/public/common/url_utils.h" |
25 #include "content/public/test/content_browser_test.h" | 22 #include "content/public/test/content_browser_test.h" |
26 #include "content/public/test/content_browser_test_utils.h" | 23 #include "content/public/test/content_browser_test_utils.h" |
27 #include "content/shell/browser/shell.h" | |
28 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" | 24 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" |
29 #include "grit/content_resources.h" | 25 #include "grit/content_resources.h" |
30 #include "mojo/common/test/test_utils.h" | 26 #include "mojo/common/test/test_utils.h" |
31 #include "mojo/public/js/bindings/constants.h" | 27 #include "mojo/public/js/bindings/constants.h" |
32 | 28 |
33 namespace content { | 29 namespace content { |
34 namespace { | 30 namespace { |
35 | 31 |
36 bool got_message = false; | 32 bool got_message = false; |
37 | 33 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 DISALLOW_COPY_AND_ASSIGN(TestWebUIController); | 118 DISALLOW_COPY_AND_ASSIGN(TestWebUIController); |
123 }; | 119 }; |
124 | 120 |
125 // TestWebUIController that additionally creates the ping test BrowserTarget | 121 // TestWebUIController that additionally creates the ping test BrowserTarget |
126 // implementation at the right time. | 122 // implementation at the right time. |
127 class PingTestWebUIController : public TestWebUIController { | 123 class PingTestWebUIController : public TestWebUIController { |
128 public: | 124 public: |
129 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) | 125 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) |
130 : TestWebUIController(web_ui, run_loop) { | 126 : TestWebUIController(web_ui, run_loop) { |
131 } | 127 } |
132 virtual ~PingTestWebUIController() {} | |
133 | 128 |
134 // WebUIController overrides: | 129 // WebUIController overrides: |
135 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE { | 130 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE { |
136 render_view_host->GetMainFrame()->GetServiceRegistry()->AddService( | 131 mojo::MessagePipe pipe; |
137 "webui_controller", | 132 browser_target_.reset( |
138 base::Bind(&PingTestWebUIController::CreateHandler, | 133 new PingBrowserTargetImpl(pipe.handle0.Pass(), run_loop_)); |
139 base::Unretained(this))); | 134 render_view_host->SetWebUIHandle(pipe.handle1.Pass()); |
140 } | |
141 | |
142 void CreateHandler(mojo::ScopedMessagePipeHandle handle) { | |
143 browser_target_.reset(new PingBrowserTargetImpl(handle.Pass(), run_loop_)); | |
144 } | 135 } |
145 | 136 |
146 private: | 137 private: |
147 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); | 138 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); |
148 }; | 139 }; |
149 | 140 |
150 // WebUIControllerFactory that creates TestWebUIController. | 141 // WebUIControllerFactory that creates TestWebUIController. |
151 class TestWebUIControllerFactory : public WebUIControllerFactory { | 142 class TestWebUIControllerFactory : public WebUIControllerFactory { |
152 public: | 143 public: |
153 TestWebUIControllerFactory() : run_loop_(NULL) {} | 144 TestWebUIControllerFactory() : run_loop_(NULL) {} |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 205 |
215 got_message = false; | 206 got_message = false; |
216 ASSERT_TRUE(test_server()->Start()); | 207 ASSERT_TRUE(test_server()->Start()); |
217 base::RunLoop run_loop; | 208 base::RunLoop run_loop; |
218 factory()->set_run_loop(&run_loop); | 209 factory()->set_run_loop(&run_loop); |
219 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?ping")); | 210 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?ping")); |
220 NavigateToURL(shell(), test_url); | 211 NavigateToURL(shell(), test_url); |
221 // RunLoop is quit when message received from page. | 212 // RunLoop is quit when message received from page. |
222 run_loop.Run(); | 213 run_loop.Run(); |
223 EXPECT_TRUE(got_message); | 214 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()); | |
237 } | 215 } |
238 | 216 |
239 } // namespace | 217 } // namespace |
240 } // namespace content | 218 } // namespace content |
OLD | NEW |