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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "mojo/application_manager/application_loader.h" | 8 #include "mojo/application_manager/application_loader.h" |
9 #include "mojo/application_manager/application_manager.h" | 9 #include "mojo/application_manager/application_manager.h" |
10 #include "mojo/application_manager/background_shell_application_loader.h" | 10 #include "mojo/application_manager/background_shell_application_loader.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 TestApplicationLoader() : context_(NULL), num_loads_(0) {} | 100 TestApplicationLoader() : context_(NULL), num_loads_(0) {} |
101 | 101 |
102 virtual ~TestApplicationLoader() { | 102 virtual ~TestApplicationLoader() { |
103 if (context_) | 103 if (context_) |
104 ++context_->num_loader_deletes; | 104 ++context_->num_loader_deletes; |
105 test_app_.reset(NULL); | 105 test_app_.reset(NULL); |
106 } | 106 } |
107 | 107 |
108 void set_context(TestContext* context) { context_ = context; } | 108 void set_context(TestContext* context) { context_ = context; } |
109 int num_loads() const { return num_loads_; } | 109 int num_loads() const { return num_loads_; } |
| 110 std::vector<std::string> GetArgs() { |
| 111 return test_app_->args().To<std::vector<std::string> >(); |
| 112 } |
110 | 113 |
111 private: | 114 private: |
112 // ApplicationLoader implementation. | 115 // ApplicationLoader implementation. |
113 virtual void Load(ApplicationManager* manager, | 116 virtual void Load(ApplicationManager* manager, |
114 const GURL& url, | 117 const GURL& url, |
115 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE { | 118 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE { |
116 ++num_loads_; | 119 ++num_loads_; |
117 test_app_.reset( | 120 test_app_.reset( |
118 new ApplicationImpl(this, callbacks->RegisterApplication().Pass())); | 121 new ApplicationImpl(this, callbacks->RegisterApplication().Pass())); |
119 } | 122 } |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 scoped_ptr<ApplicationManager> application_manager_; | 462 scoped_ptr<ApplicationManager> application_manager_; |
460 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerTest); | 463 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerTest); |
461 }; | 464 }; |
462 | 465 |
463 TEST_F(ApplicationManagerTest, Basic) { | 466 TEST_F(ApplicationManagerTest, Basic) { |
464 test_client_->Test("test"); | 467 test_client_->Test("test"); |
465 loop_.Run(); | 468 loop_.Run(); |
466 EXPECT_EQ(std::string("test"), context_.last_test_string); | 469 EXPECT_EQ(std::string("test"), context_.last_test_string); |
467 } | 470 } |
468 | 471 |
| 472 // Confirm that arguments are sent to an application. |
| 473 TEST_F(ApplicationManagerTest, Args) { |
| 474 ApplicationManager am; |
| 475 GURL test_url("test:test"); |
| 476 std::vector<std::string> args; |
| 477 args.push_back("test_arg1"); |
| 478 args.push_back("test_arg2"); |
| 479 am.SetArgsForURL(args, test_url); |
| 480 TestContext context; |
| 481 TestApplicationLoader* loader = new TestApplicationLoader; |
| 482 loader->set_context(&context); |
| 483 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url); |
| 484 TestServicePtr test_service; |
| 485 am.ConnectToService(test_url, &test_service); |
| 486 TestClientImpl test_client(test_service.Pass()); |
| 487 test_client.Test("test"); |
| 488 loop_.Run(); |
| 489 std::vector<std::string> app_args = loader->GetArgs(); |
| 490 EXPECT_EQ(args.size(), app_args.size()); |
| 491 } |
| 492 |
469 TEST_F(ApplicationManagerTest, ClientError) { | 493 TEST_F(ApplicationManagerTest, ClientError) { |
470 test_client_->Test("test"); | 494 test_client_->Test("test"); |
471 EXPECT_TRUE(HasFactoryForTestURL()); | 495 EXPECT_TRUE(HasFactoryForTestURL()); |
472 loop_.Run(); | 496 loop_.Run(); |
473 EXPECT_EQ(1, context_.num_impls); | 497 EXPECT_EQ(1, context_.num_impls); |
474 test_client_.reset(NULL); | 498 test_client_.reset(NULL); |
475 loop_.Run(); | 499 loop_.Run(); |
476 EXPECT_EQ(0, context_.num_impls); | 500 EXPECT_EQ(0, context_.num_impls); |
477 EXPECT_TRUE(HasFactoryForTestURL()); | 501 EXPECT_TRUE(HasFactoryForTestURL()); |
478 } | 502 } |
479 | 503 |
480 TEST_F(ApplicationManagerTest, Deletes) { | 504 TEST_F(ApplicationManagerTest, Deletes) { |
481 { | 505 { |
482 ApplicationManager sm; | 506 ApplicationManager am; |
483 TestApplicationLoader* default_loader = new TestApplicationLoader; | 507 TestApplicationLoader* default_loader = new TestApplicationLoader; |
484 default_loader->set_context(&context_); | 508 default_loader->set_context(&context_); |
485 TestApplicationLoader* url_loader1 = new TestApplicationLoader; | 509 TestApplicationLoader* url_loader1 = new TestApplicationLoader; |
486 TestApplicationLoader* url_loader2 = new TestApplicationLoader; | 510 TestApplicationLoader* url_loader2 = new TestApplicationLoader; |
487 url_loader1->set_context(&context_); | 511 url_loader1->set_context(&context_); |
488 url_loader2->set_context(&context_); | 512 url_loader2->set_context(&context_); |
489 TestApplicationLoader* scheme_loader1 = new TestApplicationLoader; | 513 TestApplicationLoader* scheme_loader1 = new TestApplicationLoader; |
490 TestApplicationLoader* scheme_loader2 = new TestApplicationLoader; | 514 TestApplicationLoader* scheme_loader2 = new TestApplicationLoader; |
491 scheme_loader1->set_context(&context_); | 515 scheme_loader1->set_context(&context_); |
492 scheme_loader2->set_context(&context_); | 516 scheme_loader2->set_context(&context_); |
493 sm.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); | 517 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); |
494 sm.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), | 518 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), |
495 GURL("test:test1")); | 519 GURL("test:test1")); |
496 sm.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), | 520 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), |
497 GURL("test:test1")); | 521 GURL("test:test1")); |
498 sm.SetLoaderForScheme(scoped_ptr<ApplicationLoader>(scheme_loader1), | 522 am.SetLoaderForScheme(scoped_ptr<ApplicationLoader>(scheme_loader1), |
499 "test"); | 523 "test"); |
500 sm.SetLoaderForScheme(scoped_ptr<ApplicationLoader>(scheme_loader2), | 524 am.SetLoaderForScheme(scoped_ptr<ApplicationLoader>(scheme_loader2), |
501 "test"); | 525 "test"); |
502 } | 526 } |
503 EXPECT_EQ(5, context_.num_loader_deletes); | 527 EXPECT_EQ(5, context_.num_loader_deletes); |
504 } | 528 } |
505 | 529 |
506 // Confirm that both urls and schemes can have their loaders explicitly set. | 530 // Confirm that both urls and schemes can have their loaders explicitly set. |
507 TEST_F(ApplicationManagerTest, SetLoaders) { | 531 TEST_F(ApplicationManagerTest, SetLoaders) { |
508 ApplicationManager sm; | |
509 TestApplicationLoader* default_loader = new TestApplicationLoader; | 532 TestApplicationLoader* default_loader = new TestApplicationLoader; |
510 TestApplicationLoader* url_loader = new TestApplicationLoader; | 533 TestApplicationLoader* url_loader = new TestApplicationLoader; |
511 TestApplicationLoader* scheme_loader = new TestApplicationLoader; | 534 TestApplicationLoader* scheme_loader = new TestApplicationLoader; |
512 application_manager_->set_default_loader( | 535 application_manager_->set_default_loader( |
513 scoped_ptr<ApplicationLoader>(default_loader)); | 536 scoped_ptr<ApplicationLoader>(default_loader)); |
514 application_manager_->SetLoaderForURL( | 537 application_manager_->SetLoaderForURL( |
515 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); | 538 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); |
516 application_manager_->SetLoaderForScheme( | 539 application_manager_->SetLoaderForScheme( |
517 scoped_ptr<ApplicationLoader>(scheme_loader), "test"); | 540 scoped_ptr<ApplicationLoader>(scheme_loader), "test"); |
518 | 541 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 std::string url("test:test3"); | 657 std::string url("test:test3"); |
635 TestServicePtr test_service; | 658 TestServicePtr test_service; |
636 application_manager_->ConnectToService(GURL(url), &test_service); | 659 application_manager_->ConnectToService(GURL(url), &test_service); |
637 | 660 |
638 EXPECT_EQ(1, interceptor.call_count()); | 661 EXPECT_EQ(1, interceptor.call_count()); |
639 EXPECT_EQ(url, interceptor.url_spec()); | 662 EXPECT_EQ(url, interceptor.url_spec()); |
640 EXPECT_EQ(1, default_loader->num_loads()); | 663 EXPECT_EQ(1, default_loader->num_loads()); |
641 } | 664 } |
642 | 665 |
643 } // namespace mojo | 666 } // namespace mojo |
OLD | NEW |