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/path_service.h" | |
10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
12 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 13 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
13 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
14 #include "content/public/browser/render_frame_host.h" | 15 #include "content/public/browser/render_frame_host.h" |
15 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
16 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_ui_controller.h" | 19 #include "content/public/browser/web_ui_controller.h" |
19 #include "content/public/browser/web_ui_data_source.h" | 20 #include "content/public/browser/web_ui_data_source.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
45 if (id == mojo::kBindingsModuleName || | 46 if (id == mojo::kBindingsModuleName || |
46 id == mojo::kBufferModuleName || | 47 id == mojo::kBufferModuleName || |
47 id == mojo::kCodecModuleName || | 48 id == mojo::kCodecModuleName || |
48 id == mojo::kConnectionModuleName || | 49 id == mojo::kConnectionModuleName || |
49 id == mojo::kConnectorModuleName || | 50 id == mojo::kConnectorModuleName || |
50 id == mojo::kUnicodeModuleName || | 51 id == mojo::kUnicodeModuleName || |
51 id == mojo::kRouterModuleName || | 52 id == mojo::kRouterModuleName || |
52 id == mojo::kValidatorModuleName) | 53 id == mojo::kValidatorModuleName) |
53 return false; | 54 return false; |
54 | 55 |
56 if (id.find(".mojom") != std::string::npos) { | |
57 std::string contents; | |
58 CHECK(base::ReadFileToString(mojo::test::GetFilePathForJSResource(id), | |
59 &contents, std::string::npos)) | |
60 << id; | |
61 base::RefCountedString* ref_contents = new base::RefCountedString; | |
62 ref_contents->data() = contents; | |
63 callback.Run(ref_contents); | |
64 return true; | |
65 } | |
66 | |
67 base::FilePath path; | |
68 DCHECK(base::PathService::Get(content::DIR_TEST_DATA, &path)); | |
69 path = path.AppendASCII(id.substr(0, id.find("?"))); | |
55 std::string contents; | 70 std::string contents; |
56 CHECK(base::ReadFileToString(mojo::test::GetFilePathForJSResource(id), | 71 CHECK(base::ReadFileToString(path, &contents, std::string::npos)) << id; |
magjed_chromium
2015/11/24 08:55:50
After your CL, we are hitting this CHECK on the Ca
| |
57 &contents, | |
58 std::string::npos)) << id; | |
59 base::RefCountedString* ref_contents = new base::RefCountedString; | 72 base::RefCountedString* ref_contents = new base::RefCountedString; |
60 ref_contents->data() = contents; | 73 ref_contents->data() = contents; |
61 callback.Run(ref_contents); | 74 callback.Run(ref_contents); |
62 return true; | 75 return true; |
63 } | 76 } |
64 | 77 |
65 class BrowserTargetImpl : public BrowserTarget { | 78 class BrowserTargetImpl : public BrowserTarget { |
66 public: | 79 public: |
67 BrowserTargetImpl(base::RunLoop* run_loop, | 80 BrowserTargetImpl(base::RunLoop* run_loop, |
68 mojo::InterfaceRequest<BrowserTarget> request) | 81 mojo::InterfaceRequest<BrowserTarget> request) |
(...skipping 14 matching lines...) Expand all Loading... | |
83 base::RunLoop* run_loop_; | 96 base::RunLoop* run_loop_; |
84 | 97 |
85 private: | 98 private: |
86 mojo::Binding<BrowserTarget> binding_; | 99 mojo::Binding<BrowserTarget> binding_; |
87 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); | 100 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); |
88 }; | 101 }; |
89 | 102 |
90 // WebUIController that sets up mojo bindings. | 103 // WebUIController that sets up mojo bindings. |
91 class TestWebUIController : public WebUIController { | 104 class TestWebUIController : public WebUIController { |
92 public: | 105 public: |
93 TestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) | 106 TestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) |
94 : WebUIController(web_ui), | 107 : WebUIController(web_ui), run_loop_(run_loop) { |
95 run_loop_(run_loop) { | |
96 content::WebUIDataSource* data_source = | 108 content::WebUIDataSource* data_source = |
97 WebUIDataSource::AddMojoDataSource( | 109 WebUIDataSource::Create("mojo-web-ui"); |
98 web_ui->GetWebContents()->GetBrowserContext()); | 110 data_source->AddMojoResources(); |
99 data_source->SetRequestFilter(base::Bind(&GetResource)); | 111 data_source->SetRequestFilter(base::Bind(&GetResource)); |
112 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), | |
113 data_source); | |
100 } | 114 } |
101 | 115 |
102 protected: | 116 protected: |
103 base::RunLoop* run_loop_; | 117 base::RunLoop* run_loop_; |
104 scoped_ptr<BrowserTargetImpl> browser_target_; | 118 scoped_ptr<BrowserTargetImpl> browser_target_; |
105 | 119 |
106 private: | 120 private: |
107 DISALLOW_COPY_AND_ASSIGN(TestWebUIController); | 121 DISALLOW_COPY_AND_ASSIGN(TestWebUIController); |
108 }; | 122 }; |
109 | 123 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 // it from the browser to the page and back. | 212 // it from the browser to the page and back. |
199 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, EndToEndPing) { | 213 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, EndToEndPing) { |
200 if (!IsGeneratedResourceAvailable( | 214 if (!IsGeneratedResourceAvailable( |
201 "content/test/data/web_ui_test_mojo_bindings.mojom")) | 215 "content/test/data/web_ui_test_mojo_bindings.mojom")) |
202 return; | 216 return; |
203 | 217 |
204 got_message = false; | 218 got_message = false; |
205 ASSERT_TRUE(embedded_test_server()->Start()); | 219 ASSERT_TRUE(embedded_test_server()->Start()); |
206 base::RunLoop run_loop; | 220 base::RunLoop run_loop; |
207 factory()->set_run_loop(&run_loop); | 221 factory()->set_run_loop(&run_loop); |
208 GURL test_url(embedded_test_server()->GetURL("/web_ui_mojo.html?ping")); | 222 GURL test_url("chrome://mojo-web-ui/web_ui_mojo.html?ping"); |
209 NavigateToURL(shell(), test_url); | 223 NavigateToURL(shell(), test_url); |
210 // RunLoop is quit when message received from page. | 224 // RunLoop is quit when message received from page. |
211 run_loop.Run(); | 225 run_loop.Run(); |
212 EXPECT_TRUE(got_message); | 226 EXPECT_TRUE(got_message); |
213 | 227 |
214 // Check that a second render frame in the same renderer process works | 228 // Check that a second render frame in the same renderer process works |
215 // correctly. | 229 // correctly. |
216 Shell* other_shell = CreateBrowser(); | 230 Shell* other_shell = CreateBrowser(); |
217 got_message = false; | 231 got_message = false; |
218 base::RunLoop other_run_loop; | 232 base::RunLoop other_run_loop; |
219 factory()->set_run_loop(&other_run_loop); | 233 factory()->set_run_loop(&other_run_loop); |
220 NavigateToURL(other_shell, test_url); | 234 NavigateToURL(other_shell, test_url); |
221 // RunLoop is quit when message received from page. | 235 // RunLoop is quit when message received from page. |
222 other_run_loop.Run(); | 236 other_run_loop.Run(); |
223 EXPECT_TRUE(got_message); | 237 EXPECT_TRUE(got_message); |
224 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), | 238 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), |
225 other_shell->web_contents()->GetRenderProcessHost()); | 239 other_shell->web_contents()->GetRenderProcessHost()); |
226 } | 240 } |
227 | 241 |
228 // Loads a webui page that connects to a test Mojo application via the browser's | 242 // Loads a webui page that connects to a test Mojo application via the browser's |
229 // Mojo shell interface. | 243 // Mojo shell interface. |
230 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, ConnectToApplication) { | 244 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, ConnectToApplication) { |
231 if (!IsGeneratedResourceAvailable( | 245 if (!IsGeneratedResourceAvailable( |
232 "content/public/test/test_mojo_service.mojom")) | 246 "content/public/test/test_mojo_service.mojom")) |
233 return; | 247 return; |
234 | 248 |
235 ASSERT_TRUE(embedded_test_server()->Start()); | 249 ASSERT_TRUE(embedded_test_server()->Start()); |
236 NavigateToURL(shell(), | 250 NavigateToURL(shell(), |
237 embedded_test_server()->GetURL("/web_ui_mojo_shell_test.html")); | 251 GURL("chrome://mojo-web-ui/web_ui_mojo_shell_test.html")); |
238 | 252 |
239 DOMMessageQueue message_queue; | 253 DOMMessageQueue message_queue; |
240 std::string message; | 254 std::string message; |
241 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 255 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
242 EXPECT_EQ("true", message); | 256 EXPECT_EQ("true", message); |
243 } | 257 } |
244 | 258 |
245 } // namespace | 259 } // namespace |
246 } // namespace content | 260 } // namespace content |
OLD | NEW |