| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/threading/thread_restrictions.h" |
| 16 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 17 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 17 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/browser/web_ui_controller.h" | 23 #include "content/public/browser/web_ui_controller.h" |
| 23 #include "content/public/browser/web_ui_data_source.h" | 24 #include "content/public/browser/web_ui_data_source.h" |
| 24 #include "content/public/common/content_paths.h" | 25 #include "content/public/common/content_paths.h" |
| 25 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 26 #include "content/public/common/url_utils.h" | 27 #include "content/public/common/url_utils.h" |
| 27 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 28 #include "content/public/test/content_browser_test.h" | 29 #include "content/public/test/content_browser_test.h" |
| 29 #include "content/public/test/content_browser_test_utils.h" | 30 #include "content/public/test/content_browser_test_utils.h" |
| 30 #include "content/shell/browser/shell.h" | 31 #include "content/shell/browser/shell.h" |
| 31 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" | 32 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" |
| 32 #include "mojo/public/cpp/bindings/binding.h" | 33 #include "mojo/public/cpp/bindings/binding.h" |
| 33 #include "mojo/public/cpp/bindings/interface_request.h" | 34 #include "mojo/public/cpp/bindings/interface_request.h" |
| 34 #include "net/test/embedded_test_server/embedded_test_server.h" | 35 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 35 #include "services/shell/public/cpp/interface_registry.h" | 36 #include "services/shell/public/cpp/interface_registry.h" |
| 36 | 37 |
| 37 namespace content { | 38 namespace content { |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 base::FilePath GetFilePathForJSResource(const std::string& path) { | 41 base::FilePath GetFilePathForJSResource(const std::string& path) { |
| 42 base::ThreadRestrictions::ScopedAllowIO allow_io_from_test_callbacks; |
| 43 |
| 41 std::string binding_path = "gen/" + path + ".js"; | 44 std::string binding_path = "gen/" + path + ".js"; |
| 42 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
| 43 base::ReplaceChars(binding_path, "//", "\\", &binding_path); | 46 base::ReplaceChars(binding_path, "//", "\\", &binding_path); |
| 44 #endif | 47 #endif |
| 45 base::FilePath exe_dir; | 48 base::FilePath exe_dir; |
| 46 PathService::Get(base::DIR_EXE, &exe_dir); | 49 PathService::Get(base::DIR_EXE, &exe_dir); |
| 47 return exe_dir.AppendASCII(binding_path); | 50 return exe_dir.AppendASCII(binding_path); |
| 48 } | 51 } |
| 49 | 52 |
| 50 bool got_message = false; | 53 bool got_message = false; |
| 51 | 54 |
| 52 // The bindings for the page are generated from a .mojom file. This code looks | 55 // The bindings for the page are generated from a .mojom file. This code looks |
| 53 // up the generated file from disk and returns it. | 56 // up the generated file from disk and returns it. |
| 54 bool GetResource(const std::string& id, | 57 bool GetResource(const std::string& id, |
| 55 const WebUIDataSource::GotDataCallback& callback) { | 58 const WebUIDataSource::GotDataCallback& callback) { |
| 59 base::ThreadRestrictions::ScopedAllowIO allow_io_from_test_callbacks; |
| 60 |
| 56 if (id.find(".mojom") != std::string::npos) { | 61 if (id.find(".mojom") != std::string::npos) { |
| 57 std::string contents; | 62 std::string contents; |
| 58 CHECK(base::ReadFileToString(GetFilePathForJSResource(id), &contents)) | 63 CHECK(base::ReadFileToString(GetFilePathForJSResource(id), &contents)) |
| 59 << id; | 64 << id; |
| 60 base::RefCountedString* ref_contents = new base::RefCountedString; | 65 base::RefCountedString* ref_contents = new base::RefCountedString; |
| 61 ref_contents->data() = contents; | 66 ref_contents->data() = contents; |
| 62 callback.Run(ref_contents); | 67 callback.Run(ref_contents); |
| 63 return true; | 68 return true; |
| 64 } | 69 } |
| 65 | 70 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 TestWebUIControllerFactory factory_; | 196 TestWebUIControllerFactory factory_; |
| 192 | 197 |
| 193 DISALLOW_COPY_AND_ASSIGN(WebUIMojoTest); | 198 DISALLOW_COPY_AND_ASSIGN(WebUIMojoTest); |
| 194 }; | 199 }; |
| 195 | 200 |
| 196 bool IsGeneratedResourceAvailable(const std::string& resource_path) { | 201 bool IsGeneratedResourceAvailable(const std::string& resource_path) { |
| 197 // Currently there is no way to have a generated file included in the isolate | 202 // Currently there is no way to have a generated file included in the isolate |
| 198 // files. If the bindings file doesn't exist assume we're on such a bot and | 203 // files. If the bindings file doesn't exist assume we're on such a bot and |
| 199 // pass. | 204 // pass. |
| 200 // TODO(sky): remove this conditional when isolates support copying from gen. | 205 // TODO(sky): remove this conditional when isolates support copying from gen. |
| 206 base::ThreadRestrictions::ScopedAllowIO allow_io_for_file_existance_check; |
| 201 const base::FilePath test_file_path(GetFilePathForJSResource(resource_path)); | 207 const base::FilePath test_file_path(GetFilePathForJSResource(resource_path)); |
| 202 if (base::PathExists(test_file_path)) | 208 if (base::PathExists(test_file_path)) |
| 203 return true; | 209 return true; |
| 204 LOG(WARNING) << " mojom binding file doesn't exist, assuming on isolate"; | 210 LOG(WARNING) << " mojom binding file doesn't exist, assuming on isolate"; |
| 205 return false; | 211 return false; |
| 206 } | 212 } |
| 207 | 213 |
| 208 // Loads a webui page that contains mojo bindings and verifies a message makes | 214 // Loads a webui page that contains mojo bindings and verifies a message makes |
| 209 // it from the browser to the page and back. | 215 // it from the browser to the page and back. |
| 210 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, EndToEndPing) { | 216 IN_PROC_BROWSER_TEST_F(WebUIMojoTest, EndToEndPing) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 231 NavigateToURL(other_shell, test_url); | 237 NavigateToURL(other_shell, test_url); |
| 232 // RunLoop is quit when message received from page. | 238 // RunLoop is quit when message received from page. |
| 233 other_run_loop.Run(); | 239 other_run_loop.Run(); |
| 234 EXPECT_TRUE(got_message); | 240 EXPECT_TRUE(got_message); |
| 235 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), | 241 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), |
| 236 other_shell->web_contents()->GetRenderProcessHost()); | 242 other_shell->web_contents()->GetRenderProcessHost()); |
| 237 } | 243 } |
| 238 | 244 |
| 239 } // namespace | 245 } // namespace |
| 240 } // namespace content | 246 } // namespace content |
| OLD | NEW |