Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: mojo/shell/package_manager/content_handler_unittest.cc

Issue 1679573002: Move shell interfaces into the shell.mojom namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@delegate
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const std::string mime_type_; 65 const std::string mime_type_;
66 66
67 DISALLOW_COPY_AND_ASSIGN(TestFetcher); 67 DISALLOW_COPY_AND_ASSIGN(TestFetcher);
68 }; 68 };
69 69
70 void QuitClosure(bool* value) { 70 void QuitClosure(bool* value) {
71 *value = true; 71 *value = true;
72 base::MessageLoop::current()->QuitWhenIdle(); 72 base::MessageLoop::current()->QuitWhenIdle();
73 } 73 }
74 74
75 class TestContentHandler : public ContentHandler, public ApplicationDelegate { 75 class TestContentHandler : public mojom::ContentHandler,
76 public ApplicationDelegate {
76 public: 77 public:
77 TestContentHandler(ApplicationConnection* connection, 78 TestContentHandler(ApplicationConnection* connection,
78 InterfaceRequest<ContentHandler> request) 79 InterfaceRequest<mojom::ContentHandler> request)
79 : binding_(this, std::move(request)) {} 80 : binding_(this, std::move(request)) {}
80 81
81 // ContentHandler: 82 // ContentHandler:
82 void StartApplication( 83 void StartApplication(
83 InterfaceRequest<Application> application_request, 84 InterfaceRequest<mojom::Application> application_request,
84 URLResponsePtr response, 85 URLResponsePtr response,
85 const Callback<void()>& destruct_callback) override { 86 const Callback<void()>& destruct_callback) override {
86 apps_.push_back(new ApplicationImpl(this, std::move(application_request))); 87 apps_.push_back(new ApplicationImpl(this, std::move(application_request)));
87 destruct_callback.Run(); 88 destruct_callback.Run();
88 } 89 }
89 90
90 private: 91 private:
91 StrongBinding<ContentHandler> binding_; 92 StrongBinding<mojom::ContentHandler> binding_;
92 ScopedVector<ApplicationImpl> apps_; 93 ScopedVector<ApplicationImpl> apps_;
93 94
94 DISALLOW_COPY_AND_ASSIGN(TestContentHandler); 95 DISALLOW_COPY_AND_ASSIGN(TestContentHandler);
95 }; 96 };
96 97
97 class TestApplicationLoader : public ApplicationLoader, 98 class TestApplicationLoader : public ApplicationLoader,
98 public ApplicationDelegate, 99 public ApplicationDelegate,
99 public InterfaceFactory<ContentHandler> { 100 public InterfaceFactory<mojom::ContentHandler> {
100 public: 101 public:
101 TestApplicationLoader() : num_loads_(0) {} 102 TestApplicationLoader() : num_loads_(0) {}
102 ~TestApplicationLoader() override {} 103 ~TestApplicationLoader() override {}
103 104
104 int num_loads() const { return num_loads_; } 105 int num_loads() const { return num_loads_; }
105 const GURL& last_requestor_url() const { return last_requestor_url_; } 106 const GURL& last_requestor_url() const { return last_requestor_url_; }
106 107
107 private: 108 private:
108 // ApplicationLoader implementation. 109 // ApplicationLoader implementation.
109 void Load(const GURL& url, 110 void Load(const GURL& url,
110 InterfaceRequest<Application> application_request) override { 111 InterfaceRequest<mojom::Application> application_request) override {
111 ++num_loads_; 112 ++num_loads_;
112 test_app_.reset(new ApplicationImpl(this, std::move(application_request))); 113 test_app_.reset(new ApplicationImpl(this, std::move(application_request)));
113 } 114 }
114 115
115 // ApplicationDelegate implementation. 116 // ApplicationDelegate implementation.
116 bool AcceptConnection(ApplicationConnection* connection) override { 117 bool AcceptConnection(ApplicationConnection* connection) override {
117 connection->AddService<ContentHandler>(this); 118 connection->AddService<mojom::ContentHandler>(this);
118 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL()); 119 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL());
119 return true; 120 return true;
120 } 121 }
121 // InterfaceFactory<ContentHandler> implementation. 122 // InterfaceFactory<mojom::ContentHandler> implementation.
122 void Create(ApplicationConnection* connection, 123 void Create(ApplicationConnection* connection,
123 InterfaceRequest<ContentHandler> request) override { 124 InterfaceRequest<mojom::ContentHandler> request) override {
124 new TestContentHandler(connection, std::move(request)); 125 new TestContentHandler(connection, std::move(request));
125 } 126 }
126 127
127 scoped_ptr<ApplicationImpl> test_app_; 128 scoped_ptr<ApplicationImpl> test_app_;
128 int num_loads_; 129 int num_loads_;
129 GURL last_requestor_url_; 130 GURL last_requestor_url_;
130 131
131 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); 132 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader);
132 }; 133 };
133 134
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 new ConnectToApplicationParams); 226 new ConnectToApplicationParams);
226 params->set_source(Identity(requestor_url_)); 227 params->set_source(Identity(requestor_url_));
227 params->SetTargetURL(GURL("test:test")); 228 params->SetTargetURL(GURL("test:test"));
228 params->set_connect_callback( 229 params->set_connect_callback(
229 [&content_handler_id, &run_loop](uint32_t, uint32_t t) { 230 [&content_handler_id, &run_loop](uint32_t, uint32_t t) {
230 content_handler_id = t; 231 content_handler_id = t;
231 run_loop.Quit(); 232 run_loop.Quit();
232 }); 233 });
233 application_manager_->ConnectToApplication(std::move(params)); 234 application_manager_->ConnectToApplication(std::move(params));
234 run_loop.Run(); 235 run_loop.Run();
235 EXPECT_NE(Shell::kInvalidApplicationID, content_handler_id); 236 EXPECT_NE(mojom::Shell::kInvalidApplicationID, content_handler_id);
236 } 237 }
237 238
238 uint32_t content_handler_id2; 239 uint32_t content_handler_id2;
239 { 240 {
240 base::RunLoop run_loop; 241 base::RunLoop run_loop;
241 scoped_ptr<ConnectToApplicationParams> params( 242 scoped_ptr<ConnectToApplicationParams> params(
242 new ConnectToApplicationParams); 243 new ConnectToApplicationParams);
243 params->set_source(Identity(requestor_url_)); 244 params->set_source(Identity(requestor_url_));
244 params->SetTargetURL(GURL("test:test")); 245 params->SetTargetURL(GURL("test:test"));
245 params->set_connect_callback( 246 params->set_connect_callback(
246 [&content_handler_id2, &run_loop](uint32_t, uint32_t t) { 247 [&content_handler_id2, &run_loop](uint32_t, uint32_t t) {
247 content_handler_id2 = t; 248 content_handler_id2 = t;
248 run_loop.Quit(); 249 run_loop.Quit();
249 }); 250 });
250 application_manager_->ConnectToApplication(std::move(params)); 251 application_manager_->ConnectToApplication(std::move(params));
251 run_loop.Run(); 252 run_loop.Run();
252 EXPECT_NE(Shell::kInvalidApplicationID, content_handler_id2); 253 EXPECT_NE(mojom::Shell::kInvalidApplicationID, content_handler_id2);
253 } 254 }
254 EXPECT_EQ(content_handler_id, content_handler_id2); 255 EXPECT_EQ(content_handler_id, content_handler_id2);
255 } 256 }
256 257
257 TEST_F(ContentHandlerTest, DifferedContentHandlersGetDifferentIDs) { 258 TEST_F(ContentHandlerTest, DifferedContentHandlersGetDifferentIDs) {
258 TestApplicationLoader* content_handler_loader = new TestApplicationLoader; 259 TestApplicationLoader* content_handler_loader = new TestApplicationLoader;
259 application_manager_->SetLoaderForURL( 260 application_manager_->SetLoaderForURL(
260 scoped_ptr<ApplicationLoader>(content_handler_loader), 261 scoped_ptr<ApplicationLoader>(content_handler_loader),
261 content_handler_url_); 262 content_handler_url_);
262 263
263 uint32_t content_handler_id; 264 uint32_t content_handler_id;
264 { 265 {
265 base::RunLoop run_loop; 266 base::RunLoop run_loop;
266 scoped_ptr<ConnectToApplicationParams> params( 267 scoped_ptr<ConnectToApplicationParams> params(
267 new ConnectToApplicationParams); 268 new ConnectToApplicationParams);
268 params->set_source(Identity(requestor_url_)); 269 params->set_source(Identity(requestor_url_));
269 params->SetTargetURL(GURL("test:test")); 270 params->SetTargetURL(GURL("test:test"));
270 params->set_connect_callback( 271 params->set_connect_callback(
271 [&content_handler_id, &run_loop](uint32_t, uint32_t t) { 272 [&content_handler_id, &run_loop](uint32_t, uint32_t t) {
272 content_handler_id = t; 273 content_handler_id = t;
273 run_loop.Quit(); 274 run_loop.Quit();
274 }); 275 });
275 application_manager_->ConnectToApplication(std::move(params)); 276 application_manager_->ConnectToApplication(std::move(params));
276 run_loop.Run(); 277 run_loop.Run();
277 EXPECT_NE(Shell::kInvalidApplicationID, content_handler_id); 278 EXPECT_NE(mojom::Shell::kInvalidApplicationID, content_handler_id);
278 } 279 }
279 280
280 const std::string mime_type2 = "test/mime-type2"; 281 const std::string mime_type2 = "test/mime-type2";
281 const GURL content_handler_url2("http://test.content.handler2"); 282 const GURL content_handler_url2("http://test.content.handler2");
282 test_package_manager_->set_mime_type(mime_type2); 283 test_package_manager_->set_mime_type(mime_type2);
283 test_package_manager_->RegisterContentHandler(mime_type2, 284 test_package_manager_->RegisterContentHandler(mime_type2,
284 content_handler_url2); 285 content_handler_url2);
285 286
286 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader; 287 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader;
287 application_manager_->SetLoaderForURL( 288 application_manager_->SetLoaderForURL(
288 scoped_ptr<ApplicationLoader>(content_handler_loader2), 289 scoped_ptr<ApplicationLoader>(content_handler_loader2),
289 content_handler_url2); 290 content_handler_url2);
290 291
291 uint32_t content_handler_id2; 292 uint32_t content_handler_id2;
292 { 293 {
293 base::RunLoop run_loop; 294 base::RunLoop run_loop;
294 scoped_ptr<ConnectToApplicationParams> params( 295 scoped_ptr<ConnectToApplicationParams> params(
295 new ConnectToApplicationParams); 296 new ConnectToApplicationParams);
296 params->set_source(Identity(requestor_url_)); 297 params->set_source(Identity(requestor_url_));
297 params->SetTargetURL(GURL("test2:test2")); 298 params->SetTargetURL(GURL("test2:test2"));
298 params->set_connect_callback( 299 params->set_connect_callback(
299 [&content_handler_id2, &run_loop](uint32_t, uint32_t t) { 300 [&content_handler_id2, &run_loop](uint32_t, uint32_t t) {
300 content_handler_id2 = t; 301 content_handler_id2 = t;
301 run_loop.Quit(); 302 run_loop.Quit();
302 }); 303 });
303 application_manager_->ConnectToApplication(std::move(params)); 304 application_manager_->ConnectToApplication(std::move(params));
304 run_loop.Run(); 305 run_loop.Run();
305 EXPECT_NE(Shell::kInvalidApplicationID, content_handler_id2); 306 EXPECT_NE(mojom::Shell::kInvalidApplicationID, content_handler_id2);
306 } 307 }
307 EXPECT_NE(content_handler_id, content_handler_id2); 308 EXPECT_NE(content_handler_id, content_handler_id2);
308 } 309 }
309 310
310 TEST_F(ContentHandlerTest, 311 TEST_F(ContentHandlerTest,
311 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) { 312 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) {
312 application_manager_->SetLoaderForURL( 313 application_manager_->SetLoaderForURL(
313 scoped_ptr<ApplicationLoader>(new TestApplicationLoader), 314 scoped_ptr<ApplicationLoader>(new TestApplicationLoader),
314 GURL("test:test")); 315 GURL("test:test"));
315 316
316 uint32_t content_handler_id = 1u; 317 uint32_t content_handler_id = 1u;
317 scoped_ptr<ConnectToApplicationParams> params( 318 scoped_ptr<ConnectToApplicationParams> params(
318 new ConnectToApplicationParams); 319 new ConnectToApplicationParams);
319 params->SetTargetURL(GURL("test:test")); 320 params->SetTargetURL(GURL("test:test"));
320 params->set_connect_callback( 321 params->set_connect_callback(
321 [&content_handler_id](uint32_t, uint32_t t) { content_handler_id = t; }); 322 [&content_handler_id](uint32_t, uint32_t t) { content_handler_id = t; });
322 application_manager_->ConnectToApplication(std::move(params)); 323 application_manager_->ConnectToApplication(std::move(params));
323 EXPECT_EQ(0u, content_handler_id); 324 EXPECT_EQ(0u, content_handler_id);
324 } 325 }
325 326
326 } // namespace test 327 } // namespace test
327 } // namespace package_manager 328 } // namespace package_manager
328 } // namespace mojo 329 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/package_manager/content_handler_connection.cc ('k') | mojo/shell/package_manager/package_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698