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

Side by Side Diff: mojo/application_manager/application_manager_unittest.cc

Issue 619493002: Mojo: Convert OVERRIDE -> override in various subdirectories of mojo/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/macros.h"
7 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
8 #include "mojo/application_manager/application_loader.h" 9 #include "mojo/application_manager/application_loader.h"
9 #include "mojo/application_manager/application_manager.h" 10 #include "mojo/application_manager/application_manager.h"
10 #include "mojo/application_manager/background_shell_application_loader.h" 11 #include "mojo/application_manager/background_shell_application_loader.h"
11 #include "mojo/application_manager/test.mojom.h" 12 #include "mojo/application_manager/test.mojom.h"
12 #include "mojo/public/cpp/application/application_connection.h" 13 #include "mojo/public/cpp/application/application_connection.h"
13 #include "mojo/public/cpp/application/application_delegate.h" 14 #include "mojo/public/cpp/application/application_delegate.h"
14 #include "mojo/public/cpp/application/application_impl.h" 15 #include "mojo/public/cpp/application/application_impl.h"
15 #include "mojo/public/cpp/application/interface_factory.h" 16 #include "mojo/public/cpp/application/interface_factory.h"
16 #include "mojo/public/interfaces/application/service_provider.mojom.h" 17 #include "mojo/public/interfaces/application/service_provider.mojom.h"
(...skipping 12 matching lines...) Expand all
29 int num_impls; 30 int num_impls;
30 int num_loader_deletes; 31 int num_loader_deletes;
31 }; 32 };
32 33
33 class QuitMessageLoopErrorHandler : public ErrorHandler { 34 class QuitMessageLoopErrorHandler : public ErrorHandler {
34 public: 35 public:
35 QuitMessageLoopErrorHandler() {} 36 QuitMessageLoopErrorHandler() {}
36 virtual ~QuitMessageLoopErrorHandler() {} 37 virtual ~QuitMessageLoopErrorHandler() {}
37 38
38 // |ErrorHandler| implementation: 39 // |ErrorHandler| implementation:
39 virtual void OnConnectionError() OVERRIDE { 40 virtual void OnConnectionError() override {
40 base::MessageLoop::current()->QuitWhenIdle(); 41 base::MessageLoop::current()->QuitWhenIdle();
41 } 42 }
42 43
43 private: 44 private:
44 DISALLOW_COPY_AND_ASSIGN(QuitMessageLoopErrorHandler); 45 DISALLOW_COPY_AND_ASSIGN(QuitMessageLoopErrorHandler);
45 }; 46 };
46 47
47 class TestServiceImpl : public InterfaceImpl<TestService> { 48 class TestServiceImpl : public InterfaceImpl<TestService> {
48 public: 49 public:
49 explicit TestServiceImpl(TestContext* context) : context_(context) { 50 explicit TestServiceImpl(TestContext* context) : context_(context) {
50 ++context_->num_impls; 51 ++context_->num_impls;
51 } 52 }
52 53
53 virtual ~TestServiceImpl() { --context_->num_impls; } 54 virtual ~TestServiceImpl() { --context_->num_impls; }
54 55
55 virtual void OnConnectionError() OVERRIDE { 56 virtual void OnConnectionError() override {
56 if (!base::MessageLoop::current()->is_running()) 57 if (!base::MessageLoop::current()->is_running())
57 return; 58 return;
58 base::MessageLoop::current()->Quit(); 59 base::MessageLoop::current()->Quit();
59 } 60 }
60 61
61 // TestService implementation: 62 // TestService implementation:
62 virtual void Test(const String& test_string) OVERRIDE { 63 virtual void Test(const String& test_string) override {
63 context_->last_test_string = test_string; 64 context_->last_test_string = test_string;
64 client()->AckTest(); 65 client()->AckTest();
65 } 66 }
66 67
67 private: 68 private:
68 TestContext* context_; 69 TestContext* context_;
69 }; 70 };
70 71
71 class TestClientImpl : public TestClient { 72 class TestClientImpl : public TestClient {
72 public: 73 public:
73 explicit TestClientImpl(TestServicePtr service) 74 explicit TestClientImpl(TestServicePtr service)
74 : service_(service.Pass()), quit_after_ack_(false) { 75 : service_(service.Pass()), quit_after_ack_(false) {
75 service_.set_client(this); 76 service_.set_client(this);
76 } 77 }
77 78
78 virtual ~TestClientImpl() { service_.reset(); } 79 virtual ~TestClientImpl() { service_.reset(); }
79 80
80 virtual void AckTest() OVERRIDE { 81 virtual void AckTest() override {
81 if (quit_after_ack_) 82 if (quit_after_ack_)
82 base::MessageLoop::current()->Quit(); 83 base::MessageLoop::current()->Quit();
83 } 84 }
84 85
85 void Test(std::string test_string) { 86 void Test(std::string test_string) {
86 quit_after_ack_ = true; 87 quit_after_ack_ = true;
87 service_->Test(test_string); 88 service_->Test(test_string);
88 } 89 }
89 90
90 private: 91 private:
(...skipping 17 matching lines...) Expand all
108 void set_context(TestContext* context) { context_ = context; } 109 void set_context(TestContext* context) { context_ = context; }
109 int num_loads() const { return num_loads_; } 110 int num_loads() const { return num_loads_; }
110 std::vector<std::string> GetArgs() { 111 std::vector<std::string> GetArgs() {
111 return test_app_->args().To<std::vector<std::string> >(); 112 return test_app_->args().To<std::vector<std::string> >();
112 } 113 }
113 114
114 private: 115 private:
115 // ApplicationLoader implementation. 116 // ApplicationLoader implementation.
116 virtual void Load(ApplicationManager* manager, 117 virtual void Load(ApplicationManager* manager,
117 const GURL& url, 118 const GURL& url,
118 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE { 119 scoped_refptr<LoadCallbacks> callbacks) override {
119 ++num_loads_; 120 ++num_loads_;
120 test_app_.reset( 121 test_app_.reset(
121 new ApplicationImpl(this, callbacks->RegisterApplication().Pass())); 122 new ApplicationImpl(this, callbacks->RegisterApplication().Pass()));
122 } 123 }
123 124
124 virtual void OnApplicationError(ApplicationManager* manager, 125 virtual void OnApplicationError(ApplicationManager* manager,
125 const GURL& url) OVERRIDE {} 126 const GURL& url) override {}
126 127
127 // ApplicationDelegate implementation. 128 // ApplicationDelegate implementation.
128 virtual bool ConfigureIncomingConnection( 129 virtual bool ConfigureIncomingConnection(
129 ApplicationConnection* connection) OVERRIDE { 130 ApplicationConnection* connection) override {
130 connection->AddService(this); 131 connection->AddService(this);
131 return true; 132 return true;
132 } 133 }
133 134
134 // InterfaceFactory implementation. 135 // InterfaceFactory implementation.
135 virtual void Create(ApplicationConnection* connection, 136 virtual void Create(ApplicationConnection* connection,
136 InterfaceRequest<TestService> request) OVERRIDE { 137 InterfaceRequest<TestService> request) override {
137 BindToRequest(new TestServiceImpl(context_), &request); 138 BindToRequest(new TestServiceImpl(context_), &request);
138 } 139 }
139 140
140 scoped_ptr<ApplicationImpl> test_app_; 141 scoped_ptr<ApplicationImpl> test_app_;
141 TestContext* context_; 142 TestContext* context_;
142 int num_loads_; 143 int num_loads_;
143 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); 144 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader);
144 }; 145 };
145 146
146 class TesterContext { 147 class TesterContext {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 : test_context_(test_context) { 246 : test_context_(test_context) {
246 connection->ConnectToApplication(kTestBURLString)->ConnectToService(&b_); 247 connection->ConnectToApplication(kTestBURLString)->ConnectToService(&b_);
247 } 248 }
248 virtual ~TestAImpl() { 249 virtual ~TestAImpl() {
249 test_context_->IncrementNumADeletes(); 250 test_context_->IncrementNumADeletes();
250 if (base::MessageLoop::current()->is_running()) 251 if (base::MessageLoop::current()->is_running())
251 Quit(); 252 Quit();
252 } 253 }
253 254
254 private: 255 private:
255 virtual void CallB() OVERRIDE { 256 virtual void CallB() override {
256 b_->B(base::Bind(&TestAImpl::Quit, base::Unretained(this))); 257 b_->B(base::Bind(&TestAImpl::Quit, base::Unretained(this)));
257 } 258 }
258 259
259 virtual void CallCFromB() OVERRIDE { 260 virtual void CallCFromB() override {
260 b_->CallC(base::Bind(&TestAImpl::Quit, base::Unretained(this))); 261 b_->CallC(base::Bind(&TestAImpl::Quit, base::Unretained(this)));
261 } 262 }
262 263
263 void Quit() { 264 void Quit() {
264 base::MessageLoop::current()->Quit(); 265 base::MessageLoop::current()->Quit();
265 test_context_->set_a_called_quit(); 266 test_context_->set_a_called_quit();
266 test_context_->QuitSoon(); 267 test_context_->QuitSoon();
267 } 268 }
268 269
269 TesterContext* test_context_; 270 TesterContext* test_context_;
270 TestBPtr b_; 271 TestBPtr b_;
271 }; 272 };
272 273
273 class TestBImpl : public InterfaceImpl<TestB> { 274 class TestBImpl : public InterfaceImpl<TestB> {
274 public: 275 public:
275 TestBImpl(ApplicationConnection* connection, TesterContext* test_context) 276 TestBImpl(ApplicationConnection* connection, TesterContext* test_context)
276 : test_context_(test_context) { 277 : test_context_(test_context) {
277 connection->ConnectToService(&c_); 278 connection->ConnectToService(&c_);
278 } 279 }
279 280
280 virtual ~TestBImpl() { 281 virtual ~TestBImpl() {
281 test_context_->IncrementNumBDeletes(); 282 test_context_->IncrementNumBDeletes();
282 if (base::MessageLoop::current()->is_running()) 283 if (base::MessageLoop::current()->is_running())
283 base::MessageLoop::current()->Quit(); 284 base::MessageLoop::current()->Quit();
284 test_context_->QuitSoon(); 285 test_context_->QuitSoon();
285 } 286 }
286 287
287 private: 288 private:
288 virtual void B(const mojo::Callback<void()>& callback) OVERRIDE { 289 virtual void B(const mojo::Callback<void()>& callback) override {
289 test_context_->IncrementNumBCalls(); 290 test_context_->IncrementNumBCalls();
290 callback.Run(); 291 callback.Run();
291 } 292 }
292 293
293 virtual void CallC(const mojo::Callback<void()>& callback) OVERRIDE { 294 virtual void CallC(const mojo::Callback<void()>& callback) override {
294 test_context_->IncrementNumBCalls(); 295 test_context_->IncrementNumBCalls();
295 c_->C(callback); 296 c_->C(callback);
296 } 297 }
297 298
298 TesterContext* test_context_; 299 TesterContext* test_context_;
299 TestCPtr c_; 300 TestCPtr c_;
300 }; 301 };
301 302
302 class TestCImpl : public InterfaceImpl<TestC> { 303 class TestCImpl : public InterfaceImpl<TestC> {
303 public: 304 public:
304 TestCImpl(ApplicationConnection* connection, TesterContext* test_context) 305 TestCImpl(ApplicationConnection* connection, TesterContext* test_context)
305 : test_context_(test_context) {} 306 : test_context_(test_context) {}
306 307
307 virtual ~TestCImpl() { test_context_->IncrementNumCDeletes(); } 308 virtual ~TestCImpl() { test_context_->IncrementNumCDeletes(); }
308 309
309 private: 310 private:
310 virtual void C(const mojo::Callback<void()>& callback) OVERRIDE { 311 virtual void C(const mojo::Callback<void()>& callback) override {
311 test_context_->IncrementNumCCalls(); 312 test_context_->IncrementNumCCalls();
312 callback.Run(); 313 callback.Run();
313 } 314 }
314 TesterContext* test_context_; 315 TesterContext* test_context_;
315 }; 316 };
316 317
317 class Tester : public ApplicationDelegate, 318 class Tester : public ApplicationDelegate,
318 public ApplicationLoader, 319 public ApplicationLoader,
319 public InterfaceFactory<TestA>, 320 public InterfaceFactory<TestA>,
320 public InterfaceFactory<TestB>, 321 public InterfaceFactory<TestB>,
321 public InterfaceFactory<TestC> { 322 public InterfaceFactory<TestC> {
322 public: 323 public:
323 Tester(TesterContext* context, const std::string& requestor_url) 324 Tester(TesterContext* context, const std::string& requestor_url)
324 : context_(context), requestor_url_(requestor_url) {} 325 : context_(context), requestor_url_(requestor_url) {}
325 virtual ~Tester() {} 326 virtual ~Tester() {}
326 327
327 private: 328 private:
328 virtual void Load(ApplicationManager* manager, 329 virtual void Load(ApplicationManager* manager,
329 const GURL& url, 330 const GURL& url,
330 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE { 331 scoped_refptr<LoadCallbacks> callbacks) override {
331 app_.reset( 332 app_.reset(
332 new ApplicationImpl(this, callbacks->RegisterApplication().Pass())); 333 new ApplicationImpl(this, callbacks->RegisterApplication().Pass()));
333 } 334 }
334 335
335 virtual void OnApplicationError(ApplicationManager* manager, 336 virtual void OnApplicationError(ApplicationManager* manager,
336 const GURL& url) OVERRIDE {} 337 const GURL& url) override {}
337 338
338 virtual bool ConfigureIncomingConnection( 339 virtual bool ConfigureIncomingConnection(
339 ApplicationConnection* connection) OVERRIDE { 340 ApplicationConnection* connection) override {
340 if (!requestor_url_.empty() && 341 if (!requestor_url_.empty() &&
341 requestor_url_ != connection->GetRemoteApplicationURL()) { 342 requestor_url_ != connection->GetRemoteApplicationURL()) {
342 context_->set_tester_called_quit(); 343 context_->set_tester_called_quit();
343 context_->QuitSoon(); 344 context_->QuitSoon();
344 base::MessageLoop::current()->Quit(); 345 base::MessageLoop::current()->Quit();
345 return false; 346 return false;
346 } 347 }
347 // If we're coming from A, then add B, otherwise A. 348 // If we're coming from A, then add B, otherwise A.
348 if (connection->GetRemoteApplicationURL() == kTestAURLString) 349 if (connection->GetRemoteApplicationURL() == kTestAURLString)
349 connection->AddService<TestB>(this); 350 connection->AddService<TestB>(this);
350 else 351 else
351 connection->AddService<TestA>(this); 352 connection->AddService<TestA>(this);
352 return true; 353 return true;
353 } 354 }
354 355
355 virtual bool ConfigureOutgoingConnection( 356 virtual bool ConfigureOutgoingConnection(
356 ApplicationConnection* connection) OVERRIDE { 357 ApplicationConnection* connection) override {
357 // If we're connecting to B, then add C. 358 // If we're connecting to B, then add C.
358 if (connection->GetRemoteApplicationURL() == kTestBURLString) 359 if (connection->GetRemoteApplicationURL() == kTestBURLString)
359 connection->AddService<TestC>(this); 360 connection->AddService<TestC>(this);
360 return true; 361 return true;
361 } 362 }
362 363
363 virtual void Create(ApplicationConnection* connection, 364 virtual void Create(ApplicationConnection* connection,
364 InterfaceRequest<TestA> request) OVERRIDE { 365 InterfaceRequest<TestA> request) override {
365 BindToRequest(new TestAImpl(connection, context_), &request); 366 BindToRequest(new TestAImpl(connection, context_), &request);
366 } 367 }
367 368
368 virtual void Create(ApplicationConnection* connection, 369 virtual void Create(ApplicationConnection* connection,
369 InterfaceRequest<TestB> request) OVERRIDE { 370 InterfaceRequest<TestB> request) override {
370 BindToRequest(new TestBImpl(connection, context_), &request); 371 BindToRequest(new TestBImpl(connection, context_), &request);
371 } 372 }
372 373
373 virtual void Create(ApplicationConnection* connection, 374 virtual void Create(ApplicationConnection* connection,
374 InterfaceRequest<TestC> request) OVERRIDE { 375 InterfaceRequest<TestC> request) override {
375 BindToRequest(new TestCImpl(connection, context_), &request); 376 BindToRequest(new TestCImpl(connection, context_), &request);
376 } 377 }
377 378
378 TesterContext* context_; 379 TesterContext* context_;
379 scoped_ptr<ApplicationImpl> app_; 380 scoped_ptr<ApplicationImpl> app_;
380 std::string requestor_url_; 381 std::string requestor_url_;
381 }; 382 };
382 383
383 class TestServiceInterceptor : public ApplicationManager::Interceptor { 384 class TestServiceInterceptor : public ApplicationManager::Interceptor {
384 public: 385 public:
385 TestServiceInterceptor() : call_count_(0) {} 386 TestServiceInterceptor() : call_count_(0) {}
386 387
387 virtual ServiceProviderPtr OnConnectToClient( 388 virtual ServiceProviderPtr OnConnectToClient(
388 const GURL& url, 389 const GURL& url,
389 ServiceProviderPtr service_provider) OVERRIDE { 390 ServiceProviderPtr service_provider) override {
390 ++call_count_; 391 ++call_count_;
391 url_ = url; 392 url_ = url;
392 return service_provider.Pass(); 393 return service_provider.Pass();
393 } 394 }
394 395
395 std::string url_spec() const { 396 std::string url_spec() const {
396 if (!url_.is_valid()) 397 if (!url_.is_valid())
397 return "invalid url"; 398 return "invalid url";
398 return url_.spec(); 399 return url_.spec();
399 } 400 }
400 401
401 int call_count() const { return call_count_; } 402 int call_count() const { return call_count_; }
402 403
403 private: 404 private:
404 int call_count_; 405 int call_count_;
405 GURL url_; 406 GURL url_;
406 DISALLOW_COPY_AND_ASSIGN(TestServiceInterceptor); 407 DISALLOW_COPY_AND_ASSIGN(TestServiceInterceptor);
407 }; 408 };
408 409
409 } // namespace 410 } // namespace
410 411
411 class ApplicationManagerTest : public testing::Test { 412 class ApplicationManagerTest : public testing::Test {
412 public: 413 public:
413 ApplicationManagerTest() : tester_context_(&loop_) {} 414 ApplicationManagerTest() : tester_context_(&loop_) {}
414 415
415 virtual ~ApplicationManagerTest() {} 416 virtual ~ApplicationManagerTest() {}
416 417
417 virtual void SetUp() OVERRIDE { 418 virtual void SetUp() override {
418 application_manager_.reset(new ApplicationManager); 419 application_manager_.reset(new ApplicationManager);
419 TestApplicationLoader* default_loader = new TestApplicationLoader; 420 TestApplicationLoader* default_loader = new TestApplicationLoader;
420 default_loader->set_context(&context_); 421 default_loader->set_context(&context_);
421 application_manager_->set_default_loader( 422 application_manager_->set_default_loader(
422 scoped_ptr<ApplicationLoader>(default_loader)); 423 scoped_ptr<ApplicationLoader>(default_loader));
423 424
424 TestServicePtr service_proxy; 425 TestServicePtr service_proxy;
425 application_manager_->ConnectToService(GURL(kTestURLString), 426 application_manager_->ConnectToService(GURL(kTestURLString),
426 &service_proxy); 427 &service_proxy);
427 test_client_.reset(new TestClientImpl(service_proxy.Pass())); 428 test_client_.reset(new TestClientImpl(service_proxy.Pass()));
428 } 429 }
429 430
430 virtual void TearDown() OVERRIDE { 431 virtual void TearDown() override {
431 test_client_.reset(NULL); 432 test_client_.reset(NULL);
432 application_manager_.reset(NULL); 433 application_manager_.reset(NULL);
433 } 434 }
434 435
435 scoped_ptr<BackgroundShellApplicationLoader> MakeLoader( 436 scoped_ptr<BackgroundShellApplicationLoader> MakeLoader(
436 const std::string& requestor_url) { 437 const std::string& requestor_url) {
437 scoped_ptr<ApplicationLoader> real_loader( 438 scoped_ptr<ApplicationLoader> real_loader(
438 new Tester(&tester_context_, requestor_url)); 439 new Tester(&tester_context_, requestor_url));
439 scoped_ptr<BackgroundShellApplicationLoader> loader( 440 scoped_ptr<BackgroundShellApplicationLoader> loader(
440 new BackgroundShellApplicationLoader(real_loader.Pass(), 441 new BackgroundShellApplicationLoader(real_loader.Pass(),
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 std::string url("test:test3"); 677 std::string url("test:test3");
677 TestServicePtr test_service; 678 TestServicePtr test_service;
678 application_manager_->ConnectToService(GURL(url), &test_service); 679 application_manager_->ConnectToService(GURL(url), &test_service);
679 680
680 EXPECT_EQ(1, interceptor.call_count()); 681 EXPECT_EQ(1, interceptor.call_count());
681 EXPECT_EQ(url, interceptor.url_spec()); 682 EXPECT_EQ(url, interceptor.url_spec());
682 EXPECT_EQ(1, default_loader->num_loads()); 683 EXPECT_EQ(1, default_loader->num_loads());
683 } 684 }
684 685
685 } // namespace mojo 686 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698