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" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 return true; | 60 return true; |
61 } | 61 } |
62 | 62 |
63 class BrowserTargetImpl : public mojo::InterfaceImpl<BrowserTarget> { | 63 class BrowserTargetImpl : public mojo::InterfaceImpl<BrowserTarget> { |
64 public: | 64 public: |
65 explicit BrowserTargetImpl(base::RunLoop* run_loop) : run_loop_(run_loop) {} | 65 explicit BrowserTargetImpl(base::RunLoop* run_loop) : run_loop_(run_loop) {} |
66 | 66 |
67 ~BrowserTargetImpl() override {} | 67 ~BrowserTargetImpl() override {} |
68 | 68 |
69 // mojo::InterfaceImpl<BrowserTarget> overrides: | 69 // mojo::InterfaceImpl<BrowserTarget> overrides: |
70 void PingResponse() override { NOTREACHED(); } | 70 void Start(const mojo::Closure& closure) override { |
| 71 closure.Run(); |
| 72 } |
| 73 void Stop() override { |
| 74 got_message = true; |
| 75 run_loop_->Quit(); |
| 76 } |
71 | 77 |
72 protected: | 78 protected: |
73 base::RunLoop* run_loop_; | 79 base::RunLoop* run_loop_; |
74 | 80 |
75 private: | 81 private: |
76 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); | 82 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); |
77 }; | 83 }; |
78 | 84 |
79 class PingBrowserTargetImpl : public BrowserTargetImpl { | |
80 public: | |
81 explicit PingBrowserTargetImpl(base::RunLoop* run_loop) | |
82 : BrowserTargetImpl(run_loop) {} | |
83 | |
84 ~PingBrowserTargetImpl() override {} | |
85 | |
86 // Quit the RunLoop when called. | |
87 void PingResponse() override { | |
88 got_message = true; | |
89 run_loop_->Quit(); | |
90 } | |
91 | |
92 private: | |
93 DISALLOW_COPY_AND_ASSIGN(PingBrowserTargetImpl); | |
94 }; | |
95 | |
96 // WebUIController that sets up mojo bindings. | 85 // WebUIController that sets up mojo bindings. |
97 class TestWebUIController : public WebUIController { | 86 class TestWebUIController : public WebUIController { |
98 public: | 87 public: |
99 TestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) | 88 TestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) |
100 : WebUIController(web_ui), | 89 : WebUIController(web_ui), |
101 run_loop_(run_loop) { | 90 run_loop_(run_loop) { |
102 content::WebUIDataSource* data_source = | 91 content::WebUIDataSource* data_source = |
103 WebUIDataSource::AddMojoDataSource( | 92 WebUIDataSource::AddMojoDataSource( |
104 web_ui->GetWebContents()->GetBrowserContext()); | 93 web_ui->GetWebContents()->GetBrowserContext()); |
105 data_source->SetRequestFilter(base::Bind(&GetResource)); | 94 data_source->SetRequestFilter(base::Bind(&GetResource)); |
(...skipping 10 matching lines...) Expand all Loading... |
116 // TestWebUIController that additionally creates the ping test BrowserTarget | 105 // TestWebUIController that additionally creates the ping test BrowserTarget |
117 // implementation at the right time. | 106 // implementation at the right time. |
118 class PingTestWebUIController : public TestWebUIController { | 107 class PingTestWebUIController : public TestWebUIController { |
119 public: | 108 public: |
120 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) | 109 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) |
121 : TestWebUIController(web_ui, run_loop) { | 110 : TestWebUIController(web_ui, run_loop) { |
122 } | 111 } |
123 ~PingTestWebUIController() override {} | 112 ~PingTestWebUIController() override {} |
124 | 113 |
125 // WebUIController overrides: | 114 // WebUIController overrides: |
126 void RenderViewCreated(RenderViewHost* render_view_host) override { | 115 void RenderViewCreated(RenderViewHost* render_view_host) override { |
127 render_view_host->GetMainFrame()->GetServiceRegistry()-> | 116 render_view_host->GetMainFrame()->GetServiceRegistry()-> |
128 AddService<BrowserTarget>(base::Bind( | 117 AddService<BrowserTarget>(base::Bind( |
129 &PingTestWebUIController::CreateHandler, base::Unretained(this))); | 118 &PingTestWebUIController::CreateHandler, base::Unretained(this))); |
130 } | 119 } |
131 | 120 |
132 void CreateHandler(mojo::InterfaceRequest<BrowserTarget> request) { | 121 void CreateHandler(mojo::InterfaceRequest<BrowserTarget> request) { |
133 browser_target_.reset(mojo::WeakBindToRequest( | 122 browser_target_.reset(mojo::WeakBindToRequest( |
134 new PingBrowserTargetImpl(run_loop_), &request)); | 123 new BrowserTargetImpl(run_loop_), &request)); |
135 browser_target_->client()->Ping(); | |
136 } | 124 } |
137 | 125 |
138 private: | 126 private: |
139 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); | 127 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); |
140 }; | 128 }; |
141 | 129 |
142 // WebUIControllerFactory that creates TestWebUIController. | 130 // WebUIControllerFactory that creates TestWebUIController. |
143 class TestWebUIControllerFactory : public WebUIControllerFactory { | 131 class TestWebUIControllerFactory : public WebUIControllerFactory { |
144 public: | 132 public: |
145 TestWebUIControllerFactory() : run_loop_(NULL) {} | 133 TestWebUIControllerFactory() : run_loop_(NULL) {} |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 NavigateToURL(other_shell, test_url); | 211 NavigateToURL(other_shell, test_url); |
224 // RunLoop is quit when message received from page. | 212 // RunLoop is quit when message received from page. |
225 other_run_loop.Run(); | 213 other_run_loop.Run(); |
226 EXPECT_TRUE(got_message); | 214 EXPECT_TRUE(got_message); |
227 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), | 215 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), |
228 other_shell->web_contents()->GetRenderProcessHost()); | 216 other_shell->web_contents()->GetRenderProcessHost()); |
229 } | 217 } |
230 | 218 |
231 } // namespace | 219 } // namespace |
232 } // namespace content | 220 } // namespace content |
OLD | NEW |