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 "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "mojo/application/public/cpp/application_connection.h" | 11 #include "mojo/application/public/cpp/application_connection.h" |
12 #include "mojo/application/public/cpp/application_delegate.h" | 12 #include "mojo/application/public/cpp/application_delegate.h" |
13 #include "mojo/application/public/cpp/application_impl.h" | 13 #include "mojo/application/public/cpp/application_impl.h" |
14 #include "mojo/application/public/cpp/interface_factory.h" | 14 #include "mojo/application/public/cpp/interface_factory.h" |
15 #include "mojo/application/public/interfaces/content_handler.mojom.h" | |
16 #include "mojo/application/public/interfaces/service_provider.mojom.h" | 15 #include "mojo/application/public/interfaces/service_provider.mojom.h" |
17 #include "mojo/public/cpp/bindings/strong_binding.h" | 16 #include "mojo/public/cpp/bindings/strong_binding.h" |
18 #include "mojo/shell/application_loader.h" | 17 #include "mojo/shell/application_loader.h" |
19 #include "mojo/shell/application_manager.h" | 18 #include "mojo/shell/application_manager.h" |
20 #include "mojo/shell/connect_util.h" | 19 #include "mojo/shell/connect_util.h" |
21 #include "mojo/shell/fetcher.h" | 20 #include "mojo/shell/fetcher.h" |
| 21 #include "mojo/shell/package_manager.h" |
22 #include "mojo/shell/test.mojom.h" | 22 #include "mojo/shell/test.mojom.h" |
23 #include "mojo/shell/test_package_manager.h" | 23 #include "mojo/shell/test_package_manager.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
26 namespace mojo { | 26 namespace mojo { |
27 namespace shell { | 27 namespace shell { |
28 namespace { | 28 namespace test { |
29 | 29 |
30 const char kTestURLString[] = "test:testService"; | 30 const char kTestURLString[] = "test:testService"; |
31 const char kTestAURLString[] = "test:TestA"; | 31 const char kTestAURLString[] = "test:TestA"; |
32 const char kTestBURLString[] = "test:TestB"; | 32 const char kTestBURLString[] = "test:TestB"; |
33 | 33 |
34 const char kTestMimeType[] = "test/mime-type"; | |
35 | |
36 class TestMimeTypeFetcher : public Fetcher { | |
37 public: | |
38 TestMimeTypeFetcher(const FetchCallback& fetch_callback, | |
39 const GURL& url, | |
40 const std::string& mime_type) | |
41 : Fetcher(fetch_callback), url_(url), mime_type_(mime_type) { | |
42 loader_callback_.Run(make_scoped_ptr(this)); | |
43 } | |
44 ~TestMimeTypeFetcher() override {} | |
45 | |
46 // Fetcher: | |
47 const GURL& GetURL() const override { return url_; } | |
48 GURL GetRedirectURL() const override { return GURL("yyy"); } | |
49 GURL GetRedirectReferer() const override { return GURL(); } | |
50 URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, | |
51 uint32_t skip) override { | |
52 return URLResponse::New().Pass(); | |
53 } | |
54 void AsPath( | |
55 base::TaskRunner* task_runner, | |
56 base::Callback<void(const base::FilePath&, bool)> callback) override {} | |
57 std::string MimeType() override { return mime_type_; } | |
58 bool HasMojoMagic() override { return false; } | |
59 bool PeekFirstLine(std::string* line) override { return false; } | |
60 | |
61 private: | |
62 const GURL url_; | |
63 const std::string mime_type_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(TestMimeTypeFetcher); | |
66 }; | |
67 | |
68 struct TestContext { | 34 struct TestContext { |
69 TestContext() : num_impls(0), num_loader_deletes(0) {} | 35 TestContext() : num_impls(0), num_loader_deletes(0) {} |
70 std::string last_test_string; | 36 std::string last_test_string; |
71 int num_impls; | 37 int num_impls; |
72 int num_loader_deletes; | 38 int num_loader_deletes; |
73 }; | 39 }; |
74 | 40 |
75 void QuitClosure(bool* value) { | 41 void QuitClosure(bool* value) { |
76 *value = true; | 42 *value = true; |
77 base::MessageLoop::current()->QuitWhenIdle(); | 43 base::MessageLoop::current()->QuitWhenIdle(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 service_->Test(test_string, | 84 service_->Test(test_string, |
119 base::Bind(&TestClient::AckTest, base::Unretained(this))); | 85 base::Bind(&TestClient::AckTest, base::Unretained(this))); |
120 } | 86 } |
121 | 87 |
122 private: | 88 private: |
123 TestServicePtr service_; | 89 TestServicePtr service_; |
124 bool quit_after_ack_; | 90 bool quit_after_ack_; |
125 DISALLOW_COPY_AND_ASSIGN(TestClient); | 91 DISALLOW_COPY_AND_ASSIGN(TestClient); |
126 }; | 92 }; |
127 | 93 |
128 class TestContentHandler : public ContentHandler, public ApplicationDelegate { | |
129 public: | |
130 TestContentHandler(ApplicationConnection* connection, | |
131 InterfaceRequest<ContentHandler> request) | |
132 : binding_(this, request.Pass()) {} | |
133 | |
134 // ContentHandler: | |
135 void StartApplication(InterfaceRequest<Application> application_request, | |
136 URLResponsePtr response) override { | |
137 apps_.push_back(new ApplicationImpl(this, application_request.Pass())); | |
138 } | |
139 | |
140 private: | |
141 StrongBinding<ContentHandler> binding_; | |
142 ScopedVector<ApplicationImpl> apps_; | |
143 | |
144 DISALLOW_COPY_AND_ASSIGN(TestContentHandler); | |
145 }; | |
146 | |
147 class TestApplicationLoader : public ApplicationLoader, | 94 class TestApplicationLoader : public ApplicationLoader, |
148 public ApplicationDelegate, | 95 public ApplicationDelegate, |
149 public InterfaceFactory<TestService>, | 96 public InterfaceFactory<TestService> { |
150 public InterfaceFactory<ContentHandler> { | |
151 public: | 97 public: |
152 TestApplicationLoader() | 98 TestApplicationLoader() |
153 : context_(nullptr), num_loads_(0), create_content_handler_(false) {} | 99 : context_(nullptr), num_loads_(0) {} |
154 | 100 |
155 ~TestApplicationLoader() override { | 101 ~TestApplicationLoader() override { |
156 if (context_) | 102 if (context_) |
157 ++context_->num_loader_deletes; | 103 ++context_->num_loader_deletes; |
158 test_app_.reset(); | 104 test_app_.reset(); |
159 } | 105 } |
160 | 106 |
161 void set_create_content_handler(bool value) { | |
162 create_content_handler_ = true; | |
163 } | |
164 | |
165 void set_context(TestContext* context) { context_ = context; } | 107 void set_context(TestContext* context) { context_ = context; } |
166 int num_loads() const { return num_loads_; } | 108 int num_loads() const { return num_loads_; } |
167 const GURL& last_requestor_url() const { return last_requestor_url_; } | 109 const GURL& last_requestor_url() const { return last_requestor_url_; } |
168 | 110 |
169 private: | 111 private: |
170 // ApplicationLoader implementation. | 112 // ApplicationLoader implementation. |
171 void Load(const GURL& url, | 113 void Load(const GURL& url, |
172 InterfaceRequest<Application> application_request) override { | 114 InterfaceRequest<Application> application_request) override { |
173 ++num_loads_; | 115 ++num_loads_; |
174 test_app_.reset(new ApplicationImpl(this, application_request.Pass())); | 116 test_app_.reset(new ApplicationImpl(this, application_request.Pass())); |
175 } | 117 } |
176 | 118 |
177 // ApplicationDelegate implementation. | 119 // ApplicationDelegate implementation. |
178 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 120 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
179 connection->AddService<TestService>(this); | 121 connection->AddService<TestService>(this); |
180 if (create_content_handler_) | |
181 connection->AddService<ContentHandler>(this); | |
182 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL()); | 122 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL()); |
183 return true; | 123 return true; |
184 } | 124 } |
185 | 125 |
186 // InterfaceFactory<TestService> implementation. | 126 // InterfaceFactory<TestService> implementation. |
187 void Create(ApplicationConnection* connection, | 127 void Create(ApplicationConnection* connection, |
188 InterfaceRequest<TestService> request) override { | 128 InterfaceRequest<TestService> request) override { |
189 new TestServiceImpl(context_, request.Pass()); | 129 new TestServiceImpl(context_, request.Pass()); |
190 } | 130 } |
191 | 131 |
192 // InterfaceFactory<ContentHandler> implementation. | |
193 void Create(ApplicationConnection* connection, | |
194 InterfaceRequest<ContentHandler> request) override { | |
195 new TestContentHandler(connection, request.Pass()); | |
196 } | |
197 | |
198 scoped_ptr<ApplicationImpl> test_app_; | 132 scoped_ptr<ApplicationImpl> test_app_; |
199 TestContext* context_; | 133 TestContext* context_; |
200 int num_loads_; | 134 int num_loads_; |
201 GURL last_requestor_url_; | 135 GURL last_requestor_url_; |
202 bool create_content_handler_; | |
203 | 136 |
204 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); | 137 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); |
205 }; | 138 }; |
206 | 139 |
207 class ClosingApplicationLoader : public ApplicationLoader { | 140 class ClosingApplicationLoader : public ApplicationLoader { |
208 private: | 141 private: |
209 // ApplicationLoader implementation. | 142 // ApplicationLoader implementation. |
210 void Load(const GURL& url, | 143 void Load(const GURL& url, |
211 InterfaceRequest<Application> application_request) override {} | 144 InterfaceRequest<Application> application_request) override {} |
212 }; | 145 }; |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 InterfaceRequest<TestC> request) override { | 383 InterfaceRequest<TestC> request) override { |
451 new TestCImpl(connection, context_, request.Pass()); | 384 new TestCImpl(connection, context_, request.Pass()); |
452 } | 385 } |
453 | 386 |
454 TesterContext* context_; | 387 TesterContext* context_; |
455 scoped_ptr<ApplicationImpl> app_; | 388 scoped_ptr<ApplicationImpl> app_; |
456 std::string requestor_url_; | 389 std::string requestor_url_; |
457 ScopedVector<TestAImpl> a_bindings_; | 390 ScopedVector<TestAImpl> a_bindings_; |
458 }; | 391 }; |
459 | 392 |
460 class AMTestPackageManager : public TestPackageManager { | |
461 public: | |
462 AMTestPackageManager() | |
463 : create_test_fetcher_(false), | |
464 fetcher_url_("xxx"), | |
465 mime_type_(kTestMimeType) {} | |
466 ~AMTestPackageManager() override {} | |
467 | |
468 void set_create_test_fetcher(bool create_test_fetcher) { | |
469 create_test_fetcher_ = create_test_fetcher; | |
470 } | |
471 | |
472 void set_fetcher_url(const GURL& url) { fetcher_url_ = url; } | |
473 | |
474 void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; } | |
475 | |
476 // TestPackageManager: | |
477 void FetchRequest(URLRequestPtr request, | |
478 const Fetcher::FetchCallback& loader_callback) override { | |
479 if (create_test_fetcher_) | |
480 new TestMimeTypeFetcher(loader_callback, fetcher_url_, mime_type_); | |
481 } | |
482 | |
483 private: | |
484 bool create_test_fetcher_; | |
485 GURL fetcher_url_; | |
486 std::string mime_type_; | |
487 | |
488 DISALLOW_COPY_AND_ASSIGN(AMTestPackageManager); | |
489 }; | |
490 | |
491 class ApplicationManagerTest : public testing::Test { | 393 class ApplicationManagerTest : public testing::Test { |
492 public: | 394 public: |
493 ApplicationManagerTest() : tester_context_(&loop_) {} | 395 ApplicationManagerTest() : tester_context_(&loop_) {} |
494 | 396 |
495 ~ApplicationManagerTest() override {} | 397 ~ApplicationManagerTest() override {} |
496 | 398 |
497 void SetUp() override { | 399 void SetUp() override { |
498 application_manager_.reset(new ApplicationManager( | 400 application_manager_.reset(new ApplicationManager( |
499 make_scoped_ptr(new AMTestPackageManager))); | 401 make_scoped_ptr(new TestPackageManager))); |
500 test_loader_ = new TestApplicationLoader; | 402 test_loader_ = new TestApplicationLoader; |
501 test_loader_->set_context(&context_); | 403 test_loader_->set_context(&context_); |
502 application_manager_->set_default_loader( | 404 application_manager_->set_default_loader( |
503 scoped_ptr<ApplicationLoader>(test_loader_)); | 405 scoped_ptr<ApplicationLoader>(test_loader_)); |
504 | 406 |
505 TestServicePtr service_proxy; | 407 TestServicePtr service_proxy; |
506 ConnectToService(application_manager_.get(), GURL(kTestURLString), | 408 ConnectToService(application_manager_.get(), GURL(kTestURLString), |
507 &service_proxy); | 409 &service_proxy); |
508 test_client_.reset(new TestClient(service_proxy.Pass())); | 410 test_client_.reset(new TestClient(service_proxy.Pass())); |
509 } | 411 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 loop_.Run(); | 448 loop_.Run(); |
547 EXPECT_EQ(1, context_.num_impls); | 449 EXPECT_EQ(1, context_.num_impls); |
548 test_client_.reset(); | 450 test_client_.reset(); |
549 loop_.Run(); | 451 loop_.Run(); |
550 EXPECT_EQ(0, context_.num_impls); | 452 EXPECT_EQ(0, context_.num_impls); |
551 EXPECT_TRUE(HasRunningInstanceForURL(GURL(kTestURLString))); | 453 EXPECT_TRUE(HasRunningInstanceForURL(GURL(kTestURLString))); |
552 } | 454 } |
553 | 455 |
554 TEST_F(ApplicationManagerTest, Deletes) { | 456 TEST_F(ApplicationManagerTest, Deletes) { |
555 { | 457 { |
556 ApplicationManager am(make_scoped_ptr(new AMTestPackageManager)); | 458 ApplicationManager am(make_scoped_ptr(new TestPackageManager)); |
557 TestApplicationLoader* default_loader = new TestApplicationLoader; | 459 TestApplicationLoader* default_loader = new TestApplicationLoader; |
558 default_loader->set_context(&context_); | 460 default_loader->set_context(&context_); |
559 TestApplicationLoader* url_loader1 = new TestApplicationLoader; | 461 TestApplicationLoader* url_loader1 = new TestApplicationLoader; |
560 TestApplicationLoader* url_loader2 = new TestApplicationLoader; | 462 TestApplicationLoader* url_loader2 = new TestApplicationLoader; |
561 url_loader1->set_context(&context_); | 463 url_loader1->set_context(&context_); |
562 url_loader2->set_context(&context_); | 464 url_loader2->set_context(&context_); |
563 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); | 465 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); |
564 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), | 466 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), |
565 GURL("test:test1")); | 467 GURL("test:test1")); |
566 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), | 468 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 bool called = false; | 590 bool called = false; |
689 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); | 591 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
690 params->SetTargetURL(GURL("test:test")); | 592 params->SetTargetURL(GURL("test:test")); |
691 params->set_on_application_end( | 593 params->set_on_application_end( |
692 base::Bind(&QuitClosure, base::Unretained(&called))); | 594 base::Bind(&QuitClosure, base::Unretained(&called))); |
693 application_manager_->ConnectToApplication(params.Pass()); | 595 application_manager_->ConnectToApplication(params.Pass()); |
694 loop_.Run(); | 596 loop_.Run(); |
695 EXPECT_TRUE(called); | 597 EXPECT_TRUE(called); |
696 } | 598 } |
697 | 599 |
698 TEST(ApplicationManagerTest2, ContentHandlerConnectionGetsRequestorURL) { | |
699 const GURL content_handler_url("http://test.content.handler"); | |
700 const GURL requestor_url("http://requestor.url"); | |
701 TestContext test_context; | |
702 base::MessageLoop loop; | |
703 scoped_ptr<AMTestPackageManager> test_package_manager( | |
704 new AMTestPackageManager); | |
705 test_package_manager->set_create_test_fetcher(true); | |
706 test_package_manager->RegisterContentHandler(kTestMimeType, | |
707 content_handler_url); | |
708 ApplicationManager application_manager(test_package_manager.Pass()); | |
709 application_manager.set_default_loader(nullptr); | |
710 | |
711 TestApplicationLoader* loader = new TestApplicationLoader; | |
712 loader->set_context(&test_context); | |
713 application_manager.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), | |
714 content_handler_url); | |
715 | |
716 bool called = false; | |
717 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); | |
718 params->set_source(Identity(requestor_url)); | |
719 params->SetTargetURL(GURL("test:test")); | |
720 params->set_on_application_end( | |
721 base::Bind(&QuitClosure, base::Unretained(&called))); | |
722 application_manager.ConnectToApplication(params.Pass()); | |
723 loop.Run(); | |
724 EXPECT_TRUE(called); | |
725 | |
726 ASSERT_EQ(1, loader->num_loads()); | |
727 EXPECT_EQ(requestor_url, loader->last_requestor_url()); | |
728 } | |
729 | |
730 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { | 600 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { |
731 // 1 because ApplicationManagerTest connects once at startup. | 601 // 1 because ApplicationManagerTest connects once at startup. |
732 EXPECT_EQ(1, test_loader_->num_loads()); | 602 EXPECT_EQ(1, test_loader_->num_loads()); |
733 | 603 |
734 TestServicePtr test_service; | 604 TestServicePtr test_service; |
735 ConnectToService(application_manager_.get(), | 605 ConnectToService(application_manager_.get(), |
736 GURL("http://www.example.org/abc?def"), &test_service); | 606 GURL("http://www.example.org/abc?def"), &test_service); |
737 EXPECT_EQ(2, test_loader_->num_loads()); | 607 EXPECT_EQ(2, test_loader_->num_loads()); |
738 | 608 |
739 // Exactly the same URL as above. | 609 // Exactly the same URL as above. |
(...skipping 11 matching lines...) Expand all Loading... |
751 ConnectToService(application_manager_.get(), | 621 ConnectToService(application_manager_.get(), |
752 GURL("http://www.example.org/another_path"), &test_service); | 622 GURL("http://www.example.org/another_path"), &test_service); |
753 EXPECT_EQ(3, test_loader_->num_loads()); | 623 EXPECT_EQ(3, test_loader_->num_loads()); |
754 | 624 |
755 // A different identity because the domain is different. | 625 // A different identity because the domain is different. |
756 ConnectToService(application_manager_.get(), | 626 ConnectToService(application_manager_.get(), |
757 GURL("http://www.another_domain.org/abc"), &test_service); | 627 GURL("http://www.another_domain.org/abc"), &test_service); |
758 EXPECT_EQ(4, test_loader_->num_loads()); | 628 EXPECT_EQ(4, test_loader_->num_loads()); |
759 } | 629 } |
760 | 630 |
761 TEST(ApplicationManagerTest2, | 631 } // namespace test |
762 MultipleConnectionsToContentHandlerGetSameContentHandlerId) { | |
763 base::MessageLoop loop; | |
764 const GURL content_handler_url("http://test.content.handler"); | |
765 const GURL requestor_url("http://requestor.url"); | |
766 TestContext test_context; | |
767 scoped_ptr<AMTestPackageManager> test_package_manager( | |
768 new AMTestPackageManager); | |
769 test_package_manager->set_fetcher_url(GURL("test:test")); | |
770 test_package_manager->set_create_test_fetcher(true); | |
771 test_package_manager->RegisterContentHandler(kTestMimeType, | |
772 content_handler_url); | |
773 ApplicationManager application_manager(test_package_manager.Pass()); | |
774 application_manager.set_default_loader(nullptr); | |
775 | |
776 TestApplicationLoader* content_handler_loader = new TestApplicationLoader; | |
777 content_handler_loader->set_create_content_handler(true); | |
778 content_handler_loader->set_context(&test_context); | |
779 application_manager.SetLoaderForURL( | |
780 scoped_ptr<ApplicationLoader>(content_handler_loader), | |
781 content_handler_url); | |
782 | |
783 uint32_t content_handler_id; | |
784 { | |
785 base::RunLoop run_loop; | |
786 scoped_ptr<ConnectToApplicationParams> params( | |
787 new ConnectToApplicationParams); | |
788 params->set_source(Identity(requestor_url)); | |
789 params->SetTargetURL(GURL("test:test")); | |
790 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) { | |
791 content_handler_id = t; | |
792 run_loop.Quit(); | |
793 }); | |
794 application_manager.ConnectToApplication(params.Pass()); | |
795 run_loop.Run(); | |
796 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); | |
797 } | |
798 | |
799 uint32_t content_handler_id2; | |
800 { | |
801 base::RunLoop run_loop; | |
802 scoped_ptr<ConnectToApplicationParams> params( | |
803 new ConnectToApplicationParams); | |
804 params->set_source(Identity(requestor_url)); | |
805 params->SetTargetURL(GURL("test:test")); | |
806 params->set_connect_callback([&content_handler_id2, &run_loop](uint32_t t) { | |
807 content_handler_id2 = t; | |
808 run_loop.Quit(); | |
809 }); | |
810 application_manager.ConnectToApplication(params.Pass()); | |
811 run_loop.Run(); | |
812 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); | |
813 } | |
814 EXPECT_EQ(content_handler_id, content_handler_id2); | |
815 } | |
816 | |
817 TEST(ApplicationManagerTest2, DifferedContentHandlersGetDifferentIDs) { | |
818 base::MessageLoop loop; | |
819 const GURL content_handler_url("http://test.content.handler"); | |
820 const GURL requestor_url("http://requestor.url"); | |
821 TestContext test_context; | |
822 AMTestPackageManager* test_package_manager = new AMTestPackageManager; | |
823 test_package_manager->set_fetcher_url(GURL("test:test")); | |
824 test_package_manager->set_create_test_fetcher(true); | |
825 test_package_manager->RegisterContentHandler(kTestMimeType, | |
826 content_handler_url); | |
827 ApplicationManager application_manager(make_scoped_ptr(test_package_manager)); | |
828 application_manager.set_default_loader(nullptr); | |
829 | |
830 TestApplicationLoader* content_handler_loader = new TestApplicationLoader; | |
831 content_handler_loader->set_create_content_handler(true); | |
832 content_handler_loader->set_context(&test_context); | |
833 application_manager.SetLoaderForURL( | |
834 scoped_ptr<ApplicationLoader>(content_handler_loader), | |
835 content_handler_url); | |
836 | |
837 uint32_t content_handler_id; | |
838 { | |
839 base::RunLoop run_loop; | |
840 scoped_ptr<ConnectToApplicationParams> params( | |
841 new ConnectToApplicationParams); | |
842 params->set_source(Identity(requestor_url)); | |
843 params->SetTargetURL(GURL("test:test")); | |
844 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) { | |
845 content_handler_id = t; | |
846 run_loop.Quit(); | |
847 }); | |
848 application_manager.ConnectToApplication(params.Pass()); | |
849 run_loop.Run(); | |
850 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); | |
851 } | |
852 | |
853 const std::string mime_type2("test/mime-type2"); | |
854 const GURL content_handler_url2("http://test.content2.handler"); | |
855 test_package_manager->set_fetcher_url(GURL("test2:test2")); | |
856 test_package_manager->set_mime_type(mime_type2); | |
857 test_package_manager->RegisterContentHandler(mime_type2, | |
858 content_handler_url2); | |
859 | |
860 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader; | |
861 content_handler_loader->set_create_content_handler(true); | |
862 content_handler_loader->set_context(&test_context); | |
863 application_manager.SetLoaderForURL( | |
864 scoped_ptr<ApplicationLoader>(content_handler_loader2), | |
865 content_handler_url2); | |
866 | |
867 uint32_t content_handler_id2; | |
868 { | |
869 base::RunLoop run_loop; | |
870 scoped_ptr<ConnectToApplicationParams> params( | |
871 new ConnectToApplicationParams); | |
872 params->set_source(Identity(requestor_url)); | |
873 params->SetTargetURL(GURL("test2:test2")); | |
874 params->set_connect_callback([&content_handler_id2, &run_loop](uint32_t t) { | |
875 content_handler_id2 = t; | |
876 run_loop.Quit(); | |
877 }); | |
878 application_manager.ConnectToApplication(params.Pass()); | |
879 run_loop.Run(); | |
880 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); | |
881 } | |
882 EXPECT_NE(content_handler_id, content_handler_id2); | |
883 } | |
884 | |
885 TEST_F(ApplicationManagerTest, | |
886 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) { | |
887 application_manager_->SetLoaderForURL( | |
888 scoped_ptr<ApplicationLoader>(new TestApplicationLoader), | |
889 GURL("test:test")); | |
890 | |
891 uint32_t content_handler_id = 1u; | |
892 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); | |
893 params->SetTargetURL(GURL("test:test")); | |
894 params->set_connect_callback( | |
895 [&content_handler_id](uint32_t t) { content_handler_id = t; }); | |
896 application_manager_->ConnectToApplication(params.Pass()); | |
897 EXPECT_EQ(0u, content_handler_id); | |
898 } | |
899 | |
900 } // namespace | |
901 } // namespace shell | 632 } // namespace shell |
902 } // namespace mojo | 633 } // namespace mojo |
OLD | NEW |