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/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 12 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
13 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
14 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
15 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
16 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_ui_controller.h" | 18 #include "content/public/browser/web_ui_controller.h" |
19 #include "content/public/browser/web_ui_data_source.h" | 19 #include "content/public/browser/web_ui_data_source.h" |
20 #include "content/public/common/content_paths.h" | 20 #include "content/public/common/content_paths.h" |
21 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
22 #include "content/public/common/service_registry.h" | 22 #include "content/public/common/service_registry.h" |
23 #include "content/public/common/url_utils.h" | 23 #include "content/public/common/url_utils.h" |
24 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
25 #include "content/public/test/content_browser_test.h" | 25 #include "content/public/test/content_browser_test.h" |
26 #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" | 27 #include "content/shell/browser/shell.h" |
28 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" | 28 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" |
29 #include "mojo/test/test_utils.h" | 29 #include "mojo/test/test_utils.h" |
| 30 #include "net/test/embedded_test_server/embedded_test_server.h" |
30 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | 31 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
31 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" | 32 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" |
32 #include "third_party/mojo/src/mojo/public/js/constants.h" | 33 #include "third_party/mojo/src/mojo/public/js/constants.h" |
33 | 34 |
34 namespace content { | 35 namespace content { |
35 namespace { | 36 namespace { |
36 | 37 |
37 bool got_message = false; | 38 bool got_message = false; |
38 | 39 |
39 // The bindings for the page are generated from a .mojom file. This code looks | 40 // The bindings for the page are generated from a .mojom file. This code looks |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 195 } |
195 | 196 |
196 // Loads a webui page that contains mojo bindings and verifies a message makes | 197 // Loads a webui page that contains mojo bindings and verifies a message makes |
197 // it from the browser to the page and back. | 198 // it from the browser to the page and back. |
198 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, EndToEndPing) { | 199 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, EndToEndPing) { |
199 if (!IsGeneratedResourceAvailable( | 200 if (!IsGeneratedResourceAvailable( |
200 "content/test/data/web_ui_test_mojo_bindings.mojom")) | 201 "content/test/data/web_ui_test_mojo_bindings.mojom")) |
201 return; | 202 return; |
202 | 203 |
203 got_message = false; | 204 got_message = false; |
204 ASSERT_TRUE(test_server()->Start()); | 205 ASSERT_TRUE(embedded_test_server()->Start()); |
205 base::RunLoop run_loop; | 206 base::RunLoop run_loop; |
206 factory()->set_run_loop(&run_loop); | 207 factory()->set_run_loop(&run_loop); |
207 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?ping")); | 208 GURL test_url(embedded_test_server()->GetURL("/web_ui_mojo.html?ping")); |
208 NavigateToURL(shell(), test_url); | 209 NavigateToURL(shell(), test_url); |
209 // RunLoop is quit when message received from page. | 210 // RunLoop is quit when message received from page. |
210 run_loop.Run(); | 211 run_loop.Run(); |
211 EXPECT_TRUE(got_message); | 212 EXPECT_TRUE(got_message); |
212 | 213 |
213 // Check that a second render frame in the same renderer process works | 214 // Check that a second render frame in the same renderer process works |
214 // correctly. | 215 // correctly. |
215 Shell* other_shell = CreateBrowser(); | 216 Shell* other_shell = CreateBrowser(); |
216 got_message = false; | 217 got_message = false; |
217 base::RunLoop other_run_loop; | 218 base::RunLoop other_run_loop; |
218 factory()->set_run_loop(&other_run_loop); | 219 factory()->set_run_loop(&other_run_loop); |
219 NavigateToURL(other_shell, test_url); | 220 NavigateToURL(other_shell, test_url); |
220 // RunLoop is quit when message received from page. | 221 // RunLoop is quit when message received from page. |
221 other_run_loop.Run(); | 222 other_run_loop.Run(); |
222 EXPECT_TRUE(got_message); | 223 EXPECT_TRUE(got_message); |
223 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), | 224 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), |
224 other_shell->web_contents()->GetRenderProcessHost()); | 225 other_shell->web_contents()->GetRenderProcessHost()); |
225 } | 226 } |
226 | 227 |
227 // Loads a webui page that connects to a test Mojo application via the browser's | 228 // Loads a webui page that connects to a test Mojo application via the browser's |
228 // Mojo shell interface. | 229 // Mojo shell interface. |
229 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, ConnectToApplication) { | 230 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, ConnectToApplication) { |
230 if (!IsGeneratedResourceAvailable( | 231 if (!IsGeneratedResourceAvailable( |
231 "content/public/test/test_mojo_service.mojom")) | 232 "content/public/test/test_mojo_service.mojom")) |
232 return; | 233 return; |
233 | 234 |
234 ASSERT_TRUE(test_server()->Start()); | 235 ASSERT_TRUE(embedded_test_server()->Start()); |
235 NavigateToURL(shell(), | 236 NavigateToURL(shell(), |
236 test_server()->GetURL("files/web_ui_mojo_shell_test.html")); | 237 embedded_test_server()->GetURL("/web_ui_mojo_shell_test.html")); |
237 | 238 |
238 DOMMessageQueue message_queue; | 239 DOMMessageQueue message_queue; |
239 std::string message; | 240 std::string message; |
240 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 241 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
241 EXPECT_EQ("true", message); | 242 EXPECT_EQ("true", message); |
242 } | 243 } |
243 | 244 |
244 } // namespace | 245 } // namespace |
245 } // namespace content | 246 } // namespace content |
OLD | NEW |