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/path_service.h" | 10 #include "base/path_service.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 virtual ~BrowserTargetImpl() {} | 67 virtual ~BrowserTargetImpl() {} |
68 | 68 |
69 // mojo::InterfaceImpl<BrowserTarget> overrides: | 69 // mojo::InterfaceImpl<BrowserTarget> overrides: |
70 virtual void PingResponse() OVERRIDE { | 70 virtual void PingResponse() override { |
71 NOTREACHED(); | 71 NOTREACHED(); |
72 } | 72 } |
73 | 73 |
74 protected: | 74 protected: |
75 base::RunLoop* run_loop_; | 75 base::RunLoop* run_loop_; |
76 | 76 |
77 private: | 77 private: |
78 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); | 78 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); |
79 }; | 79 }; |
80 | 80 |
81 class PingBrowserTargetImpl : public BrowserTargetImpl { | 81 class PingBrowserTargetImpl : public BrowserTargetImpl { |
82 public: | 82 public: |
83 explicit PingBrowserTargetImpl(base::RunLoop* run_loop) | 83 explicit PingBrowserTargetImpl(base::RunLoop* run_loop) |
84 : BrowserTargetImpl(run_loop) {} | 84 : BrowserTargetImpl(run_loop) {} |
85 | 85 |
86 virtual ~PingBrowserTargetImpl() {} | 86 virtual ~PingBrowserTargetImpl() {} |
87 | 87 |
88 // mojo::InterfaceImpl<BrowserTarget> overrides: | 88 // mojo::InterfaceImpl<BrowserTarget> overrides: |
89 virtual void OnConnectionEstablished() OVERRIDE { | 89 virtual void OnConnectionEstablished() override { |
90 client()->Ping(); | 90 client()->Ping(); |
91 } | 91 } |
92 | 92 |
93 // Quit the RunLoop when called. | 93 // Quit the RunLoop when called. |
94 virtual void PingResponse() OVERRIDE { | 94 virtual void PingResponse() override { |
95 got_message = true; | 95 got_message = true; |
96 run_loop_->Quit(); | 96 run_loop_->Quit(); |
97 } | 97 } |
98 | 98 |
99 private: | 99 private: |
100 DISALLOW_COPY_AND_ASSIGN(PingBrowserTargetImpl); | 100 DISALLOW_COPY_AND_ASSIGN(PingBrowserTargetImpl); |
101 }; | 101 }; |
102 | 102 |
103 // WebUIController that sets up mojo bindings. | 103 // WebUIController that sets up mojo bindings. |
104 class TestWebUIController : public WebUIController { | 104 class TestWebUIController : public WebUIController { |
(...skipping 18 matching lines...) Expand all Loading... |
123 // TestWebUIController that additionally creates the ping test BrowserTarget | 123 // TestWebUIController that additionally creates the ping test BrowserTarget |
124 // implementation at the right time. | 124 // implementation at the right time. |
125 class PingTestWebUIController : public TestWebUIController { | 125 class PingTestWebUIController : public TestWebUIController { |
126 public: | 126 public: |
127 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) | 127 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) |
128 : TestWebUIController(web_ui, run_loop) { | 128 : TestWebUIController(web_ui, run_loop) { |
129 } | 129 } |
130 virtual ~PingTestWebUIController() {} | 130 virtual ~PingTestWebUIController() {} |
131 | 131 |
132 // WebUIController overrides: | 132 // WebUIController overrides: |
133 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE { | 133 virtual void RenderViewCreated(RenderViewHost* render_view_host) override { |
134 render_view_host->GetMainFrame()->GetServiceRegistry()-> | 134 render_view_host->GetMainFrame()->GetServiceRegistry()-> |
135 AddService<BrowserTarget>(base::Bind( | 135 AddService<BrowserTarget>(base::Bind( |
136 &PingTestWebUIController::CreateHandler, base::Unretained(this))); | 136 &PingTestWebUIController::CreateHandler, base::Unretained(this))); |
137 } | 137 } |
138 | 138 |
139 void CreateHandler(mojo::InterfaceRequest<BrowserTarget> request) { | 139 void CreateHandler(mojo::InterfaceRequest<BrowserTarget> request) { |
140 browser_target_.reset(mojo::WeakBindToRequest( | 140 browser_target_.reset(mojo::WeakBindToRequest( |
141 new PingBrowserTargetImpl(run_loop_), &request)); | 141 new PingBrowserTargetImpl(run_loop_), &request)); |
142 } | 142 } |
143 | 143 |
144 private: | 144 private: |
145 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); | 145 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); |
146 }; | 146 }; |
147 | 147 |
148 // WebUIControllerFactory that creates TestWebUIController. | 148 // WebUIControllerFactory that creates TestWebUIController. |
149 class TestWebUIControllerFactory : public WebUIControllerFactory { | 149 class TestWebUIControllerFactory : public WebUIControllerFactory { |
150 public: | 150 public: |
151 TestWebUIControllerFactory() : run_loop_(NULL) {} | 151 TestWebUIControllerFactory() : run_loop_(NULL) {} |
152 | 152 |
153 void set_run_loop(base::RunLoop* run_loop) { run_loop_ = run_loop; } | 153 void set_run_loop(base::RunLoop* run_loop) { run_loop_ = run_loop; } |
154 | 154 |
155 virtual WebUIController* CreateWebUIControllerForURL( | 155 virtual WebUIController* CreateWebUIControllerForURL( |
156 WebUI* web_ui, const GURL& url) const OVERRIDE { | 156 WebUI* web_ui, const GURL& url) const override { |
157 if (url.query() == "ping") | 157 if (url.query() == "ping") |
158 return new PingTestWebUIController(web_ui, run_loop_); | 158 return new PingTestWebUIController(web_ui, run_loop_); |
159 return NULL; | 159 return NULL; |
160 } | 160 } |
161 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, | 161 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
162 const GURL& url) const OVERRIDE { | 162 const GURL& url) const override { |
163 return reinterpret_cast<WebUI::TypeID>(1); | 163 return reinterpret_cast<WebUI::TypeID>(1); |
164 } | 164 } |
165 virtual bool UseWebUIForURL(BrowserContext* browser_context, | 165 virtual bool UseWebUIForURL(BrowserContext* browser_context, |
166 const GURL& url) const OVERRIDE { | 166 const GURL& url) const override { |
167 return true; | 167 return true; |
168 } | 168 } |
169 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, | 169 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
170 const GURL& url) const OVERRIDE { | 170 const GURL& url) const override { |
171 return true; | 171 return true; |
172 } | 172 } |
173 | 173 |
174 private: | 174 private: |
175 base::RunLoop* run_loop_; | 175 base::RunLoop* run_loop_; |
176 | 176 |
177 DISALLOW_COPY_AND_ASSIGN(TestWebUIControllerFactory); | 177 DISALLOW_COPY_AND_ASSIGN(TestWebUIControllerFactory); |
178 }; | 178 }; |
179 | 179 |
180 class WebUIMojoTest : public ContentBrowserTest { | 180 class WebUIMojoTest : public ContentBrowserTest { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 NavigateToURL(other_shell, test_url); | 235 NavigateToURL(other_shell, test_url); |
236 // RunLoop is quit when message received from page. | 236 // RunLoop is quit when message received from page. |
237 other_run_loop.Run(); | 237 other_run_loop.Run(); |
238 EXPECT_TRUE(got_message); | 238 EXPECT_TRUE(got_message); |
239 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), | 239 EXPECT_EQ(shell()->web_contents()->GetRenderProcessHost(), |
240 other_shell->web_contents()->GetRenderProcessHost()); | 240 other_shell->web_contents()->GetRenderProcessHost()); |
241 } | 241 } |
242 | 242 |
243 } // namespace | 243 } // namespace |
244 } // namespace content | 244 } // namespace content |
OLD | NEW |