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/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "mojo/application/public/cpp/application_connection.h" | 10 #include "mojo/application/public/cpp/application_connection.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 TestApplicationLoader() : context_(nullptr), num_loads_(0) {} | 138 TestApplicationLoader() : context_(nullptr), num_loads_(0) {} |
139 | 139 |
140 ~TestApplicationLoader() override { | 140 ~TestApplicationLoader() override { |
141 if (context_) | 141 if (context_) |
142 ++context_->num_loader_deletes; | 142 ++context_->num_loader_deletes; |
143 test_app_.reset(); | 143 test_app_.reset(); |
144 } | 144 } |
145 | 145 |
146 void set_context(TestContext* context) { context_ = context; } | 146 void set_context(TestContext* context) { context_ = context; } |
147 int num_loads() const { return num_loads_; } | 147 int num_loads() const { return num_loads_; } |
148 const std::vector<std::string>& GetArgs() const { return test_app_->args(); } | |
149 const GURL& last_requestor_url() const { return last_requestor_url_; } | 148 const GURL& last_requestor_url() const { return last_requestor_url_; } |
150 | 149 |
151 private: | 150 private: |
152 // ApplicationLoader implementation. | 151 // ApplicationLoader implementation. |
153 void Load(const GURL& url, | 152 void Load(const GURL& url, |
154 InterfaceRequest<Application> application_request) override { | 153 InterfaceRequest<Application> application_request) override { |
155 ++num_loads_; | 154 ++num_loads_; |
156 test_app_.reset(new ApplicationImpl(this, application_request.Pass())); | 155 test_app_.reset(new ApplicationImpl(this, application_request.Pass())); |
157 } | 156 } |
158 | 157 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 scoped_ptr<ApplicationManager> application_manager_; | 513 scoped_ptr<ApplicationManager> application_manager_; |
515 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerTest); | 514 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerTest); |
516 }; | 515 }; |
517 | 516 |
518 TEST_F(ApplicationManagerTest, Basic) { | 517 TEST_F(ApplicationManagerTest, Basic) { |
519 test_client_->Test("test"); | 518 test_client_->Test("test"); |
520 loop_.Run(); | 519 loop_.Run(); |
521 EXPECT_EQ(std::string("test"), context_.last_test_string); | 520 EXPECT_EQ(std::string("test"), context_.last_test_string); |
522 } | 521 } |
523 | 522 |
524 // Confirm that no arguments are sent to an application by default. | |
525 TEST_F(ApplicationManagerTest, NoArgs) { | |
526 ApplicationManager am(&test_delegate_); | |
527 GURL test_url("test:test"); | |
528 TestApplicationLoader* loader = new TestApplicationLoader; | |
529 loader->set_context(&context_); | |
530 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url); | |
531 TestServicePtr test_service; | |
532 am.ConnectToService(test_url, &test_service); | |
533 TestClient test_client(test_service.Pass()); | |
534 test_client.Test("test"); | |
535 loop_.Run(); | |
536 std::vector<std::string> app_args = loader->GetArgs(); | |
537 EXPECT_EQ(0U, app_args.size()); | |
538 } | |
539 | |
540 // Confirm that url mappings are respected. | 523 // Confirm that url mappings are respected. |
541 TEST_F(ApplicationManagerTest, URLMapping) { | 524 TEST_F(ApplicationManagerTest, URLMapping) { |
542 ApplicationManager am(&test_delegate_); | 525 ApplicationManager am(&test_delegate_); |
543 GURL test_url("test:test"); | 526 GURL test_url("test:test"); |
544 GURL test_url2("test:test2"); | 527 GURL test_url2("test:test2"); |
545 test_delegate_.AddMapping(test_url, test_url2); | 528 test_delegate_.AddMapping(test_url, test_url2); |
546 TestApplicationLoader* loader = new TestApplicationLoader; | 529 TestApplicationLoader* loader = new TestApplicationLoader; |
547 loader->set_context(&context_); | 530 loader->set_context(&context_); |
548 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url2); | 531 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url2); |
549 { | 532 { |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 loop.Run(); | 798 loop.Run(); |
816 EXPECT_TRUE(called); | 799 EXPECT_TRUE(called); |
817 | 800 |
818 ASSERT_EQ(1, loader->num_loads()); | 801 ASSERT_EQ(1, loader->num_loads()); |
819 EXPECT_EQ(requestor_url, loader->last_requestor_url()); | 802 EXPECT_EQ(requestor_url, loader->last_requestor_url()); |
820 } | 803 } |
821 | 804 |
822 } // namespace | 805 } // namespace |
823 } // namespace shell | 806 } // namespace shell |
824 } // namespace mojo | 807 } // namespace mojo |
OLD | NEW |