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_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_ui_controller.h" | 17 #include "content/public/browser/web_ui_controller.h" |
18 #include "content/public/browser/web_ui_data_source.h" | 18 #include "content/public/browser/web_ui_data_source.h" |
19 #include "content/public/common/content_paths.h" | 19 #include "content/public/common/content_paths.h" |
20 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
21 #include "content/public/common/url_utils.h" | 21 #include "content/public/common/url_utils.h" |
22 #include "content/public/test/content_browser_test.h" | 22 #include "content/public/test/content_browser_test.h" |
23 #include "content/public/test/content_browser_test_utils.h" | 23 #include "content/public/test/content_browser_test_utils.h" |
24 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" | 24 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" |
25 #include "grit/content_resources.h" | 25 #include "grit/content_resources.h" |
| 26 #include "mojo/common/test/test_utils.h" |
26 #include "mojo/public/cpp/bindings/allocation_scope.h" | 27 #include "mojo/public/cpp/bindings/allocation_scope.h" |
27 #include "mojo/public/cpp/bindings/remote_ptr.h" | 28 #include "mojo/public/cpp/bindings/remote_ptr.h" |
28 #include "mojo/public/js/bindings/constants.h" | 29 #include "mojo/public/js/bindings/constants.h" |
29 | 30 |
30 namespace content { | 31 namespace content { |
31 namespace { | 32 namespace { |
32 | 33 |
33 bool got_message = false; | 34 bool got_message = false; |
34 int message_count = 0; | 35 int message_count = 0; |
35 | 36 |
(...skipping 17 matching lines...) Expand all Loading... |
53 const double kExpectedDoubleVal = 3.14159265358979323846; | 54 const double kExpectedDoubleVal = 3.14159265358979323846; |
54 const double kExpectedDoubleInf = std::numeric_limits<double>::infinity(); | 55 const double kExpectedDoubleInf = std::numeric_limits<double>::infinity(); |
55 const double kExpectedDoubleNan = std::numeric_limits<double>::quiet_NaN(); | 56 const double kExpectedDoubleNan = std::numeric_limits<double>::quiet_NaN(); |
56 const float kExpectedFloatVal = static_cast<float>(kExpectedDoubleVal); | 57 const float kExpectedFloatVal = static_cast<float>(kExpectedDoubleVal); |
57 const float kExpectedFloatInf = std::numeric_limits<float>::infinity(); | 58 const float kExpectedFloatInf = std::numeric_limits<float>::infinity(); |
58 const float kExpectedFloatNan = std::numeric_limits<float>::quiet_NaN(); | 59 const float kExpectedFloatNan = std::numeric_limits<float>::quiet_NaN(); |
59 | 60 |
60 // NaN has the property that it is not equal to itself. | 61 // NaN has the property that it is not equal to itself. |
61 #define EXPECT_NAN(x) EXPECT_NE(x, x) | 62 #define EXPECT_NAN(x) EXPECT_NE(x, x) |
62 | 63 |
63 // Returns the path to the mojom js bindings file. | |
64 base::FilePath GetFilePathForJSResource(const std::string& path) { | |
65 std::string binding_path = "gen/" + path + ".js"; | |
66 #if defined(OS_WIN) | |
67 std::string tmp; | |
68 base::ReplaceChars(binding_path, "//", "\\", &tmp); | |
69 binding_path.swap(tmp); | |
70 #endif | |
71 base::FilePath file_path; | |
72 PathService::Get(CHILD_PROCESS_EXE, &file_path); | |
73 return file_path.DirName().AppendASCII(binding_path); | |
74 } | |
75 | |
76 // The bindings for the page are generated from a .mojom file. This code looks | 64 // The bindings for the page are generated from a .mojom file. This code looks |
77 // up the generated file from disk and returns it. | 65 // up the generated file from disk and returns it. |
78 bool GetResource(const std::string& id, | 66 bool GetResource(const std::string& id, |
79 const WebUIDataSource::GotDataCallback& callback) { | 67 const WebUIDataSource::GotDataCallback& callback) { |
80 // These are handled by the WebUIDataSource that AddMojoDataSource() creates. | 68 // These are handled by the WebUIDataSource that AddMojoDataSource() creates. |
81 if (id == mojo::kCodecModuleName || | 69 if (id == mojo::kCodecModuleName || |
82 id == mojo::kConnectionModuleName || | 70 id == mojo::kConnectionModuleName || |
83 id == mojo::kConnectorModuleName || | 71 id == mojo::kConnectorModuleName || |
84 id == mojo::kRouterModuleName) | 72 id == mojo::kRouterModuleName) |
85 return false; | 73 return false; |
86 | 74 |
87 std::string contents; | 75 std::string contents; |
88 CHECK(base::ReadFileToString(GetFilePathForJSResource(id), &contents, | 76 CHECK(base::ReadFileToString(mojo::test::GetFilePathForJSResource(id), |
| 77 &contents, |
89 std::string::npos)) << id; | 78 std::string::npos)) << id; |
90 base::RefCountedString* ref_contents = new base::RefCountedString; | 79 base::RefCountedString* ref_contents = new base::RefCountedString; |
91 ref_contents->data() = contents; | 80 ref_contents->data() = contents; |
92 callback.Run(ref_contents); | 81 callback.Run(ref_contents); |
93 return true; | 82 return true; |
94 } | 83 } |
95 | 84 |
96 class BrowserTargetImpl : public mojo::BrowserTarget { | 85 class BrowserTargetImpl : public mojo::BrowserTarget { |
97 public: | 86 public: |
98 BrowserTargetImpl(mojo::ScopedRendererTargetHandle& handle, | 87 BrowserTargetImpl(mojo::ScopedRendererTargetHandle& handle, |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 #endif | 317 #endif |
329 | 318 |
330 // Loads a webui page that contains mojo bindings and verifies a message makes | 319 // Loads a webui page that contains mojo bindings and verifies a message makes |
331 // it from the browser to the page and back. | 320 // it from the browser to the page and back. |
332 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, MAYBE_EndToEndPing) { | 321 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, MAYBE_EndToEndPing) { |
333 // Currently there is no way to have a generated file included in the isolate | 322 // Currently there is no way to have a generated file included in the isolate |
334 // files. If the bindings file doesn't exist assume we're on such a bot and | 323 // files. If the bindings file doesn't exist assume we're on such a bot and |
335 // pass. | 324 // pass. |
336 // TODO(sky): remove this conditional when isolates support copying from gen. | 325 // TODO(sky): remove this conditional when isolates support copying from gen. |
337 const base::FilePath test_file_path( | 326 const base::FilePath test_file_path( |
338 GetFilePathForJSResource( | 327 mojo::test::GetFilePathForJSResource( |
339 "content/test/data/web_ui_test_mojo_bindings.mojom")); | 328 "content/test/data/web_ui_test_mojo_bindings.mojom")); |
340 if (!base::PathExists(test_file_path)) { | 329 if (!base::PathExists(test_file_path)) { |
341 LOG(WARNING) << " mojom binding file doesn't exist, assuming on isolate"; | 330 LOG(WARNING) << " mojom binding file doesn't exist, assuming on isolate"; |
342 return; | 331 return; |
343 } | 332 } |
344 | 333 |
345 got_message = false; | 334 got_message = false; |
346 ASSERT_TRUE(test_server()->Start()); | 335 ASSERT_TRUE(test_server()->Start()); |
347 base::RunLoop run_loop; | 336 base::RunLoop run_loop; |
348 factory()->set_run_loop(&run_loop); | 337 factory()->set_run_loop(&run_loop); |
349 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?ping")); | 338 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?ping")); |
350 NavigateToURL(shell(), test_url); | 339 NavigateToURL(shell(), test_url); |
351 // RunLoop is quit when message received from page. | 340 // RunLoop is quit when message received from page. |
352 run_loop.Run(); | 341 run_loop.Run(); |
353 EXPECT_TRUE(got_message); | 342 EXPECT_TRUE(got_message); |
354 } | 343 } |
355 | 344 |
356 // Loads a webui page that contains mojo bindings and verifies that | 345 // Loads a webui page that contains mojo bindings and verifies that |
357 // parameters are passed back correctly from JavaScript. | 346 // parameters are passed back correctly from JavaScript. |
358 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, MAYBE_EndToEndEcho) { | 347 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, MAYBE_EndToEndEcho) { |
359 // Currently there is no way to have a generated file included in the isolate | 348 // Currently there is no way to have a generated file included in the isolate |
360 // files. If the bindings file doesn't exist assume we're on such a bot and | 349 // files. If the bindings file doesn't exist assume we're on such a bot and |
361 // pass. | 350 // pass. |
362 // TODO(sky): remove this conditional when isolates support copying from gen. | 351 // TODO(sky): remove this conditional when isolates support copying from gen. |
363 const base::FilePath test_file_path( | 352 const base::FilePath test_file_path( |
364 GetFilePathForJSResource( | 353 mojo::test::GetFilePathForJSResource( |
365 "content/test/data/web_ui_test_mojo_bindings.mojom")); | 354 "content/test/data/web_ui_test_mojo_bindings.mojom")); |
366 if (!base::PathExists(test_file_path)) { | 355 if (!base::PathExists(test_file_path)) { |
367 LOG(WARNING) << " mojom binding file doesn't exist, assuming on isolate"; | 356 LOG(WARNING) << " mojom binding file doesn't exist, assuming on isolate"; |
368 return; | 357 return; |
369 } | 358 } |
370 | 359 |
371 message_count = 0; | 360 message_count = 0; |
372 ASSERT_TRUE(test_server()->Start()); | 361 ASSERT_TRUE(test_server()->Start()); |
373 base::RunLoop run_loop; | 362 base::RunLoop run_loop; |
374 factory()->set_run_loop(&run_loop); | 363 factory()->set_run_loop(&run_loop); |
375 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?echo")); | 364 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?echo")); |
376 NavigateToURL(shell(), test_url); | 365 NavigateToURL(shell(), test_url); |
377 // RunLoop is quit when response received from page. | 366 // RunLoop is quit when response received from page. |
378 run_loop.Run(); | 367 run_loop.Run(); |
379 EXPECT_EQ(kExpectedMessageCount, message_count); | 368 EXPECT_EQ(kExpectedMessageCount, message_count); |
380 } | 369 } |
381 | 370 |
382 } // namespace | 371 } // namespace |
383 } // namespace content | 372 } // namespace content |
OLD | NEW |