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 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
25 #include "content/public/common/service_registry.h" | 25 #include "content/public/common/service_registry.h" |
26 #include "content/public/common/url_utils.h" | 26 #include "content/public/common/url_utils.h" |
27 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
28 #include "content/public/test/content_browser_test.h" | 28 #include "content/public/test/content_browser_test.h" |
29 #include "content/public/test/content_browser_test_utils.h" | 29 #include "content/public/test/content_browser_test_utils.h" |
30 #include "content/shell/browser/shell.h" | 30 #include "content/shell/browser/shell.h" |
31 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" | 31 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" |
32 #include "mojo/public/cpp/bindings/binding.h" | 32 #include "mojo/public/cpp/bindings/binding.h" |
33 #include "mojo/public/cpp/bindings/interface_request.h" | 33 #include "mojo/public/cpp/bindings/interface_request.h" |
34 #include "mojo/test/test_utils.h" | |
35 #include "net/test/embedded_test_server/embedded_test_server.h" | 34 #include "net/test/embedded_test_server/embedded_test_server.h" |
36 | 35 |
37 namespace content { | 36 namespace content { |
38 namespace { | 37 namespace { |
39 | 38 |
| 39 base::FilePath GetFilePathForJSResource(const std::string& path) { |
| 40 std::string binding_path = "gen/" + path + ".js"; |
| 41 #if defined(OS_WIN) |
| 42 base::ReplaceChars(binding_path, "//", "\\", &binding_path); |
| 43 #endif |
| 44 base::FilePath exe_dir; |
| 45 PathService::Get(base::DIR_EXE, &exe_dir); |
| 46 return exe_dir.AppendASCII(binding_path); |
| 47 } |
| 48 |
40 bool got_message = false; | 49 bool got_message = false; |
41 | 50 |
42 // The bindings for the page are generated from a .mojom file. This code looks | 51 // The bindings for the page are generated from a .mojom file. This code looks |
43 // up the generated file from disk and returns it. | 52 // up the generated file from disk and returns it. |
44 bool GetResource(const std::string& id, | 53 bool GetResource(const std::string& id, |
45 const WebUIDataSource::GotDataCallback& callback) { | 54 const WebUIDataSource::GotDataCallback& callback) { |
46 if (id.find(".mojom") != std::string::npos) { | 55 if (id.find(".mojom") != std::string::npos) { |
47 std::string contents; | 56 std::string contents; |
48 CHECK(base::ReadFileToString(mojo::test::GetFilePathForJSResource(id), | 57 CHECK(base::ReadFileToString(GetFilePathForJSResource(id), &contents)) |
49 &contents)) | |
50 << id; | 58 << id; |
51 base::RefCountedString* ref_contents = new base::RefCountedString; | 59 base::RefCountedString* ref_contents = new base::RefCountedString; |
52 ref_contents->data() = contents; | 60 ref_contents->data() = contents; |
53 callback.Run(ref_contents); | 61 callback.Run(ref_contents); |
54 return true; | 62 return true; |
55 } | 63 } |
56 | 64 |
57 base::FilePath path; | 65 base::FilePath path; |
58 CHECK(base::PathService::Get(content::DIR_TEST_DATA, &path)); | 66 CHECK(base::PathService::Get(content::DIR_TEST_DATA, &path)); |
59 path = path.AppendASCII(id.substr(0, id.find("?"))); | 67 path = path.AppendASCII(id.substr(0, id.find("?"))); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 TestWebUIControllerFactory factory_; | 190 TestWebUIControllerFactory factory_; |
183 | 191 |
184 DISALLOW_COPY_AND_ASSIGN(WebUIMojoTest); | 192 DISALLOW_COPY_AND_ASSIGN(WebUIMojoTest); |
185 }; | 193 }; |
186 | 194 |
187 bool IsGeneratedResourceAvailable(const std::string& resource_path) { | 195 bool IsGeneratedResourceAvailable(const std::string& resource_path) { |
188 // Currently there is no way to have a generated file included in the isolate | 196 // Currently there is no way to have a generated file included in the isolate |
189 // files. If the bindings file doesn't exist assume we're on such a bot and | 197 // files. If the bindings file doesn't exist assume we're on such a bot and |
190 // pass. | 198 // pass. |
191 // TODO(sky): remove this conditional when isolates support copying from gen. | 199 // TODO(sky): remove this conditional when isolates support copying from gen. |
192 const base::FilePath test_file_path( | 200 const base::FilePath test_file_path(GetFilePathForJSResource(resource_path)); |
193 mojo::test::GetFilePathForJSResource(resource_path)); | |
194 if (base::PathExists(test_file_path)) | 201 if (base::PathExists(test_file_path)) |
195 return true; | 202 return true; |
196 LOG(WARNING) << " mojom binding file doesn't exist, assuming on isolate"; | 203 LOG(WARNING) << " mojom binding file doesn't exist, assuming on isolate"; |
197 return false; | 204 return false; |
198 } | 205 } |
199 | 206 |
200 // Loads a webui page that contains mojo bindings and verifies a message makes | 207 // Loads a webui page that contains mojo bindings and verifies a message makes |
201 // it from the browser to the page and back. | 208 // it from the browser to the page and back. |
202 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, EndToEndPing) { | 209 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, EndToEndPing) { |
203 if (!IsGeneratedResourceAvailable( | 210 if (!IsGeneratedResourceAvailable( |
(...skipping 19 matching lines...) Expand all Loading... |
223 NavigateToURL(other_shell, test_url); | 230 NavigateToURL(other_shell, test_url); |
224 // RunLoop is quit when message received from page. | 231 // RunLoop is quit when message received from page. |
225 other_run_loop.Run(); | 232 other_run_loop.Run(); |
226 EXPECT_TRUE(got_message); | 233 EXPECT_TRUE(got_message); |
227 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), | 234 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), |
228 other_shell->web_contents()->GetRenderProcessHost()); | 235 other_shell->web_contents()->GetRenderProcessHost()); |
229 } | 236 } |
230 | 237 |
231 } // namespace | 238 } // namespace |
232 } // namespace content | 239 } // namespace content |
OLD | NEW |