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/content_browser_test.h" | 24 #include "content/public/test/content_browser_test.h" |
25 #include "content/public/test/content_browser_test_utils.h" | 25 #include "content/public/test/content_browser_test_utils.h" |
26 #include "content/shell/browser/shell.h" | 26 #include "content/shell/browser/shell.h" |
27 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" | 27 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" |
28 #include "third_party/mojo/src/mojo/edk/test/test_utils.h" | 28 #include "third_party/mojo/src/mojo/edk/test/test_utils.h" |
29 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h" | 29 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
30 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" | 30 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" |
31 #include "third_party/mojo/src/mojo/public/js/constants.h" | 31 #include "third_party/mojo/src/mojo/public/js/constants.h" |
32 | 32 |
33 namespace content { | 33 namespace content { |
34 namespace { | 34 namespace { |
35 | 35 |
36 bool got_message = false; | 36 bool got_message = false; |
37 | 37 |
38 // The bindings for the page are generated from a .mojom file. This code looks | 38 // The bindings for the page are generated from a .mojom file. This code looks |
39 // up the generated file from disk and returns it. | 39 // up the generated file from disk and returns it. |
(...skipping 13 matching lines...) Expand all Loading... |
53 std::string contents; | 53 std::string contents; |
54 CHECK(base::ReadFileToString(mojo::test::GetFilePathForJSResource(id), | 54 CHECK(base::ReadFileToString(mojo::test::GetFilePathForJSResource(id), |
55 &contents, | 55 &contents, |
56 std::string::npos)) << id; | 56 std::string::npos)) << id; |
57 base::RefCountedString* ref_contents = new base::RefCountedString; | 57 base::RefCountedString* ref_contents = new base::RefCountedString; |
58 ref_contents->data() = contents; | 58 ref_contents->data() = contents; |
59 callback.Run(ref_contents); | 59 callback.Run(ref_contents); |
60 return true; | 60 return true; |
61 } | 61 } |
62 | 62 |
63 class BrowserTargetImpl : public mojo::InterfaceImpl<BrowserTarget> { | 63 class BrowserTargetImpl : public BrowserTarget { |
64 public: | 64 public: |
65 explicit BrowserTargetImpl(base::RunLoop* run_loop) : run_loop_(run_loop) {} | 65 BrowserTargetImpl(base::RunLoop* run_loop, |
| 66 mojo::InterfaceRequest<BrowserTarget> request) |
| 67 : run_loop_(run_loop), binding_(this, request.Pass()) {} |
66 | 68 |
67 ~BrowserTargetImpl() override {} | 69 ~BrowserTargetImpl() override {} |
68 | 70 |
69 // mojo::InterfaceImpl<BrowserTarget> overrides: | 71 // BrowserTarget overrides: |
70 void Start(const mojo::Closure& closure) override { | 72 void Start(const mojo::Closure& closure) override { |
71 closure.Run(); | 73 closure.Run(); |
72 } | 74 } |
73 void Stop() override { | 75 void Stop() override { |
74 got_message = true; | 76 got_message = true; |
75 run_loop_->Quit(); | 77 run_loop_->Quit(); |
76 } | 78 } |
77 | 79 |
78 protected: | 80 protected: |
79 base::RunLoop* run_loop_; | 81 base::RunLoop* run_loop_; |
80 | 82 |
81 private: | 83 private: |
| 84 mojo::Binding<BrowserTarget> binding_; |
82 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); | 85 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); |
83 }; | 86 }; |
84 | 87 |
85 // WebUIController that sets up mojo bindings. | 88 // WebUIController that sets up mojo bindings. |
86 class TestWebUIController : public WebUIController { | 89 class TestWebUIController : public WebUIController { |
87 public: | 90 public: |
88 TestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) | 91 TestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) |
89 : WebUIController(web_ui), | 92 : WebUIController(web_ui), |
90 run_loop_(run_loop) { | 93 run_loop_(run_loop) { |
91 content::WebUIDataSource* data_source = | 94 content::WebUIDataSource* data_source = |
(...skipping 20 matching lines...) Expand all Loading... |
112 ~PingTestWebUIController() override {} | 115 ~PingTestWebUIController() override {} |
113 | 116 |
114 // WebUIController overrides: | 117 // WebUIController overrides: |
115 void RenderViewCreated(RenderViewHost* render_view_host) override { | 118 void RenderViewCreated(RenderViewHost* render_view_host) override { |
116 render_view_host->GetMainFrame()->GetServiceRegistry()-> | 119 render_view_host->GetMainFrame()->GetServiceRegistry()-> |
117 AddService<BrowserTarget>(base::Bind( | 120 AddService<BrowserTarget>(base::Bind( |
118 &PingTestWebUIController::CreateHandler, base::Unretained(this))); | 121 &PingTestWebUIController::CreateHandler, base::Unretained(this))); |
119 } | 122 } |
120 | 123 |
121 void CreateHandler(mojo::InterfaceRequest<BrowserTarget> request) { | 124 void CreateHandler(mojo::InterfaceRequest<BrowserTarget> request) { |
122 browser_target_.reset(mojo::WeakBindToRequest( | 125 browser_target_.reset(new BrowserTargetImpl(run_loop_, request.Pass())); |
123 new BrowserTargetImpl(run_loop_), &request)); | |
124 } | 126 } |
125 | 127 |
126 private: | 128 private: |
127 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); | 129 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); |
128 }; | 130 }; |
129 | 131 |
130 // WebUIControllerFactory that creates TestWebUIController. | 132 // WebUIControllerFactory that creates TestWebUIController. |
131 class TestWebUIControllerFactory : public WebUIControllerFactory { | 133 class TestWebUIControllerFactory : public WebUIControllerFactory { |
132 public: | 134 public: |
133 TestWebUIControllerFactory() : run_loop_(NULL) {} | 135 TestWebUIControllerFactory() : run_loop_(NULL) {} |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 NavigateToURL(other_shell, test_url); | 213 NavigateToURL(other_shell, test_url); |
212 // RunLoop is quit when message received from page. | 214 // RunLoop is quit when message received from page. |
213 other_run_loop.Run(); | 215 other_run_loop.Run(); |
214 EXPECT_TRUE(got_message); | 216 EXPECT_TRUE(got_message); |
215 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), | 217 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), |
216 other_shell->web_contents()->GetRenderProcessHost()); | 218 other_shell->web_contents()->GetRenderProcessHost()); |
217 } | 219 } |
218 | 220 |
219 } // namespace | 221 } // namespace |
220 } // namespace content | 222 } // namespace content |
OLD | NEW |