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 no arguments are sent to an application by default. |
| 473 TEST_F(ApplicationManagerTest, NoArgs) { |
| 474 ApplicationManager am; |
| 475 GURL test_url("test:test"); |
| 476 TestContext context; |
| 477 TestApplicationLoader* loader = new TestApplicationLoader; |
| 478 loader->set_context(&context); |
| 479 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url); |
| 480 TestServicePtr test_service; |
| 481 am.ConnectToService(test_url, &test_service); |
| 482 TestClientImpl test_client(test_service.Pass()); |
| 483 test_client.Test("test"); |
| 484 loop_.Run(); |
| 485 std::vector<std::string> app_args = loader->GetArgs(); |
| 486 EXPECT_EQ(0U, app_args.size()); |
| 487 } |
| 488 |
| 489 // Confirm that arguments are sent to an application. |
| 490 TEST_F(ApplicationManagerTest, Args) { |
| 491 ApplicationManager am; |
| 492 GURL test_url("test:test"); |
| 493 std::vector<std::string> args; |
| 494 args.push_back("test_arg1"); |
| 495 args.push_back("test_arg2"); |
| 496 am.SetArgsForURL(args, test_url); |
| 497 TestContext context; |
| 498 TestApplicationLoader* loader = new TestApplicationLoader; |
| 499 loader->set_context(&context); |
| 500 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url); |
| 501 TestServicePtr test_service; |
| 502 am.ConnectToService(test_url, &test_service); |
| 503 TestClientImpl test_client(test_service.Pass()); |
| 504 test_client.Test("test"); |
| 505 loop_.Run(); |
| 506 std::vector<std::string> app_args = loader->GetArgs(); |
| 507 ASSERT_EQ(args.size(), app_args.size()); |
| 508 EXPECT_EQ(args[0], app_args[0]); |
| 509 EXPECT_EQ(args[1], app_args[1]); |
| 510 } |
| 511 |
469 TEST_F(ApplicationManagerTest, ClientError) { | 512 TEST_F(ApplicationManagerTest, ClientError) { |
470 test_client_->Test("test"); | 513 test_client_->Test("test"); |
471 EXPECT_TRUE(HasFactoryForTestURL()); | 514 EXPECT_TRUE(HasFactoryForTestURL()); |
472 loop_.Run(); | 515 loop_.Run(); |
473 EXPECT_EQ(1, context_.num_impls); | 516 EXPECT_EQ(1, context_.num_impls); |
474 test_client_.reset(NULL); | 517 test_client_.reset(NULL); |
475 loop_.Run(); | 518 loop_.Run(); |
476 EXPECT_EQ(0, context_.num_impls); | 519 EXPECT_EQ(0, context_.num_impls); |
477 EXPECT_TRUE(HasFactoryForTestURL()); | 520 EXPECT_TRUE(HasFactoryForTestURL()); |
478 } | 521 } |
479 | 522 |
480 TEST_F(ApplicationManagerTest, Deletes) { | 523 TEST_F(ApplicationManagerTest, Deletes) { |
481 { | 524 { |
482 ApplicationManager sm; | 525 ApplicationManager am; |
483 TestApplicationLoader* default_loader = new TestApplicationLoader; | 526 TestApplicationLoader* default_loader = new TestApplicationLoader; |
484 default_loader->set_context(&context_); | 527 default_loader->set_context(&context_); |
485 TestApplicationLoader* url_loader1 = new TestApplicationLoader; | 528 TestApplicationLoader* url_loader1 = new TestApplicationLoader; |
486 TestApplicationLoader* url_loader2 = new TestApplicationLoader; | 529 TestApplicationLoader* url_loader2 = new TestApplicationLoader; |
487 url_loader1->set_context(&context_); | 530 url_loader1->set_context(&context_); |
488 url_loader2->set_context(&context_); | 531 url_loader2->set_context(&context_); |
489 TestApplicationLoader* scheme_loader1 = new TestApplicationLoader; | 532 TestApplicationLoader* scheme_loader1 = new TestApplicationLoader; |
490 TestApplicationLoader* scheme_loader2 = new TestApplicationLoader; | 533 TestApplicationLoader* scheme_loader2 = new TestApplicationLoader; |
491 scheme_loader1->set_context(&context_); | 534 scheme_loader1->set_context(&context_); |
492 scheme_loader2->set_context(&context_); | 535 scheme_loader2->set_context(&context_); |
493 sm.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); | 536 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); |
494 sm.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), | 537 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), |
495 GURL("test:test1")); | 538 GURL("test:test1")); |
496 sm.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), | 539 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), |
497 GURL("test:test1")); | 540 GURL("test:test1")); |
498 sm.SetLoaderForScheme(scoped_ptr<ApplicationLoader>(scheme_loader1), | 541 am.SetLoaderForScheme(scoped_ptr<ApplicationLoader>(scheme_loader1), |
499 "test"); | 542 "test"); |
500 sm.SetLoaderForScheme(scoped_ptr<ApplicationLoader>(scheme_loader2), | 543 am.SetLoaderForScheme(scoped_ptr<ApplicationLoader>(scheme_loader2), |
501 "test"); | 544 "test"); |
502 } | 545 } |
503 EXPECT_EQ(5, context_.num_loader_deletes); | 546 EXPECT_EQ(5, context_.num_loader_deletes); |
504 } | 547 } |
505 | 548 |
506 // Confirm that both urls and schemes can have their loaders explicitly set. | 549 // Confirm that both urls and schemes can have their loaders explicitly set. |
507 TEST_F(ApplicationManagerTest, SetLoaders) { | 550 TEST_F(ApplicationManagerTest, SetLoaders) { |
508 ApplicationManager sm; | |
509 TestApplicationLoader* default_loader = new TestApplicationLoader; | 551 TestApplicationLoader* default_loader = new TestApplicationLoader; |
510 TestApplicationLoader* url_loader = new TestApplicationLoader; | 552 TestApplicationLoader* url_loader = new TestApplicationLoader; |
511 TestApplicationLoader* scheme_loader = new TestApplicationLoader; | 553 TestApplicationLoader* scheme_loader = new TestApplicationLoader; |
512 application_manager_->set_default_loader( | 554 application_manager_->set_default_loader( |
513 scoped_ptr<ApplicationLoader>(default_loader)); | 555 scoped_ptr<ApplicationLoader>(default_loader)); |
514 application_manager_->SetLoaderForURL( | 556 application_manager_->SetLoaderForURL( |
515 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); | 557 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); |
516 application_manager_->SetLoaderForScheme( | 558 application_manager_->SetLoaderForScheme( |
517 scoped_ptr<ApplicationLoader>(scheme_loader), "test"); | 559 scoped_ptr<ApplicationLoader>(scheme_loader), "test"); |
518 | 560 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 std::string url("test:test3"); | 676 std::string url("test:test3"); |
635 TestServicePtr test_service; | 677 TestServicePtr test_service; |
636 application_manager_->ConnectToService(GURL(url), &test_service); | 678 application_manager_->ConnectToService(GURL(url), &test_service); |
637 | 679 |
638 EXPECT_EQ(1, interceptor.call_count()); | 680 EXPECT_EQ(1, interceptor.call_count()); |
639 EXPECT_EQ(url, interceptor.url_spec()); | 681 EXPECT_EQ(url, interceptor.url_spec()); |
640 EXPECT_EQ(1, default_loader->num_loads()); | 682 EXPECT_EQ(1, default_loader->num_loads()); |
641 } | 683 } |
642 | 684 |
643 } // namespace mojo | 685 } // namespace mojo |
OLD | NEW |