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

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

Issue 1311353005: Adds a way to determine id of content handler that created app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: separate out declaration/definition Created 5 years, 3 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/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 "mojo/application/public/cpp/application_connection.h" 11 #include "mojo/application/public/cpp/application_connection.h"
11 #include "mojo/application/public/cpp/application_delegate.h" 12 #include "mojo/application/public/cpp/application_delegate.h"
12 #include "mojo/application/public/cpp/application_impl.h" 13 #include "mojo/application/public/cpp/application_impl.h"
13 #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"
14 #include "mojo/application/public/interfaces/service_provider.mojom.h" 16 #include "mojo/application/public/interfaces/service_provider.mojom.h"
15 #include "mojo/public/cpp/bindings/strong_binding.h" 17 #include "mojo/public/cpp/bindings/strong_binding.h"
16 #include "mojo/shell/application_loader.h" 18 #include "mojo/shell/application_loader.h"
17 #include "mojo/shell/application_manager.h" 19 #include "mojo/shell/application_manager.h"
18 #include "mojo/shell/fetcher.h" 20 #include "mojo/shell/fetcher.h"
19 #include "mojo/shell/test.mojom.h" 21 #include "mojo/shell/test.mojom.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 23
22 namespace mojo { 24 namespace mojo {
23 namespace shell { 25 namespace shell {
24 namespace { 26 namespace {
25 27
26 const char kTestURLString[] = "test:testService"; 28 const char kTestURLString[] = "test:testService";
27 const char kTestAURLString[] = "test:TestA"; 29 const char kTestAURLString[] = "test:TestA";
28 const char kTestBURLString[] = "test:TestB"; 30 const char kTestBURLString[] = "test:TestB";
29 31
30 const char kTestMimeType[] = "test/mime-type"; 32 const char kTestMimeType[] = "test/mime-type";
31 33
32 class TestMimeTypeFetcher : public Fetcher { 34 class TestMimeTypeFetcher : public Fetcher {
33 public: 35 public:
34 explicit TestMimeTypeFetcher(const FetchCallback& fetch_callback) 36 TestMimeTypeFetcher(const FetchCallback& fetch_callback,
35 : Fetcher(fetch_callback), url_("xxx") { 37 const GURL& url,
38 const std::string& mime_type)
39 : Fetcher(fetch_callback), url_(url), mime_type_(mime_type) {
36 loader_callback_.Run(make_scoped_ptr(this)); 40 loader_callback_.Run(make_scoped_ptr(this));
37 } 41 }
38 ~TestMimeTypeFetcher() override {} 42 ~TestMimeTypeFetcher() override {}
39 43
40 // Fetcher: 44 // Fetcher:
41 const GURL& GetURL() const override { return url_; } 45 const GURL& GetURL() const override { return url_; }
42 GURL GetRedirectURL() const override { return GURL("yyy"); } 46 GURL GetRedirectURL() const override { return GURL("yyy"); }
43 GURL GetRedirectReferer() const override { return GURL(); } 47 GURL GetRedirectReferer() const override { return GURL(); }
44 URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, 48 URLResponsePtr AsURLResponse(base::TaskRunner* task_runner,
45 uint32_t skip) override { 49 uint32_t skip) override {
46 return URLResponse::New().Pass(); 50 return URLResponse::New().Pass();
47 } 51 }
48 void AsPath( 52 void AsPath(
49 base::TaskRunner* task_runner, 53 base::TaskRunner* task_runner,
50 base::Callback<void(const base::FilePath&, bool)> callback) override {} 54 base::Callback<void(const base::FilePath&, bool)> callback) override {}
51 std::string MimeType() override { return kTestMimeType; } 55 std::string MimeType() override { return mime_type_; }
52 bool HasMojoMagic() override { return false; } 56 bool HasMojoMagic() override { return false; }
53 bool PeekFirstLine(std::string* line) override { return false; } 57 bool PeekFirstLine(std::string* line) override { return false; }
54 58
55 private: 59 private:
56 const GURL url_; 60 const GURL url_;
61 const std::string mime_type_;
57 62
58 DISALLOW_COPY_AND_ASSIGN(TestMimeTypeFetcher); 63 DISALLOW_COPY_AND_ASSIGN(TestMimeTypeFetcher);
59 }; 64 };
60 65
61 struct TestContext { 66 struct TestContext {
62 TestContext() : num_impls(0), num_loader_deletes(0) {} 67 TestContext() : num_impls(0), num_loader_deletes(0) {}
63 std::string last_test_string; 68 std::string last_test_string;
64 int num_impls; 69 int num_impls;
65 int num_loader_deletes; 70 int num_loader_deletes;
66 }; 71 };
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 service_->Test(test_string, 116 service_->Test(test_string,
112 base::Bind(&TestClient::AckTest, base::Unretained(this))); 117 base::Bind(&TestClient::AckTest, base::Unretained(this)));
113 } 118 }
114 119
115 private: 120 private:
116 TestServicePtr service_; 121 TestServicePtr service_;
117 bool quit_after_ack_; 122 bool quit_after_ack_;
118 DISALLOW_COPY_AND_ASSIGN(TestClient); 123 DISALLOW_COPY_AND_ASSIGN(TestClient);
119 }; 124 };
120 125
126 class TestContentHandler : public ContentHandler, public ApplicationDelegate {
127 public:
128 TestContentHandler(ApplicationConnection* connection,
129 InterfaceRequest<ContentHandler> request)
130 : binding_(this, request.Pass()) {}
131
132 // ContentHandler:
133 void StartApplication(InterfaceRequest<Application> application_request,
134 URLResponsePtr response) override {
135 apps_.push_back(new ApplicationImpl(this, application_request.Pass()));
136 }
137
138 private:
139 StrongBinding<ContentHandler> binding_;
140 ScopedVector<ApplicationImpl> apps_;
141
142 DISALLOW_COPY_AND_ASSIGN(TestContentHandler);
143 };
144
121 class TestApplicationLoader : public ApplicationLoader, 145 class TestApplicationLoader : public ApplicationLoader,
122 public ApplicationDelegate, 146 public ApplicationDelegate,
123 public InterfaceFactory<TestService> { 147 public InterfaceFactory<TestService>,
148 public InterfaceFactory<ContentHandler> {
124 public: 149 public:
125 TestApplicationLoader() : context_(nullptr), num_loads_(0) {} 150 TestApplicationLoader()
151 : context_(nullptr), num_loads_(0), create_content_handler_(false) {}
126 152
127 ~TestApplicationLoader() override { 153 ~TestApplicationLoader() override {
128 if (context_) 154 if (context_)
129 ++context_->num_loader_deletes; 155 ++context_->num_loader_deletes;
130 test_app_.reset(); 156 test_app_.reset();
131 } 157 }
132 158
159 void set_create_content_handler(bool value) {
160 create_content_handler_ = true;
161 }
162
133 void set_context(TestContext* context) { context_ = context; } 163 void set_context(TestContext* context) { context_ = context; }
134 int num_loads() const { return num_loads_; } 164 int num_loads() const { return num_loads_; }
135 const GURL& last_requestor_url() const { return last_requestor_url_; } 165 const GURL& last_requestor_url() const { return last_requestor_url_; }
136 166
137 private: 167 private:
138 // ApplicationLoader implementation. 168 // ApplicationLoader implementation.
139 void Load(const GURL& url, 169 void Load(const GURL& url,
140 InterfaceRequest<Application> application_request) override { 170 InterfaceRequest<Application> application_request) override {
141 ++num_loads_; 171 ++num_loads_;
142 test_app_.reset(new ApplicationImpl(this, application_request.Pass())); 172 test_app_.reset(new ApplicationImpl(this, application_request.Pass()));
143 } 173 }
144 174
145 // ApplicationDelegate implementation. 175 // ApplicationDelegate implementation.
146 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 176 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
147 connection->AddService(this); 177 connection->AddService<TestService>(this);
178 if (create_content_handler_)
179 connection->AddService<ContentHandler>(this);
148 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL()); 180 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL());
149 return true; 181 return true;
150 } 182 }
151 183
152 // InterfaceFactory implementation. 184 // InterfaceFactory<TestService> implementation.
153 void Create(ApplicationConnection* connection, 185 void Create(ApplicationConnection* connection,
154 InterfaceRequest<TestService> request) override { 186 InterfaceRequest<TestService> request) override {
155 new TestServiceImpl(context_, request.Pass()); 187 new TestServiceImpl(context_, request.Pass());
156 } 188 }
157 189
190 // InterfaceFactory<ContentHandler> implementation.
191 void Create(ApplicationConnection* connection,
192 InterfaceRequest<ContentHandler> request) override {
193 new TestContentHandler(connection, request.Pass());
194 }
195
158 scoped_ptr<ApplicationImpl> test_app_; 196 scoped_ptr<ApplicationImpl> test_app_;
159 TestContext* context_; 197 TestContext* context_;
160 int num_loads_; 198 int num_loads_;
161 GURL last_requestor_url_; 199 GURL last_requestor_url_;
200 bool create_content_handler_;
162 201
163 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); 202 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader);
164 }; 203 };
165 204
166 class ClosingApplicationLoader : public ApplicationLoader { 205 class ClosingApplicationLoader : public ApplicationLoader {
167 private: 206 private:
168 // ApplicationLoader implementation. 207 // ApplicationLoader implementation.
169 void Load(const GURL& url, 208 void Load(const GURL& url,
170 InterfaceRequest<Application> application_request) override {} 209 InterfaceRequest<Application> application_request) override {}
171 }; 210 };
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 450 }
412 451
413 TesterContext* context_; 452 TesterContext* context_;
414 scoped_ptr<ApplicationImpl> app_; 453 scoped_ptr<ApplicationImpl> app_;
415 std::string requestor_url_; 454 std::string requestor_url_;
416 ScopedVector<TestAImpl> a_bindings_; 455 ScopedVector<TestAImpl> a_bindings_;
417 }; 456 };
418 457
419 class TestDelegate : public ApplicationManager::Delegate { 458 class TestDelegate : public ApplicationManager::Delegate {
420 public: 459 public:
421 TestDelegate() : create_test_fetcher_(false) {} 460 TestDelegate()
461 : create_test_fetcher_(false),
462 fetcher_url_("xxx"),
463 mime_type_(kTestMimeType) {}
422 ~TestDelegate() override {} 464 ~TestDelegate() override {}
423 465
424 void AddMapping(const GURL& from, const GURL& to) { mappings_[from] = to; } 466 void AddMapping(const GURL& from, const GURL& to) { mappings_[from] = to; }
425 467
426 void set_create_test_fetcher(bool create_test_fetcher) { 468 void set_create_test_fetcher(bool create_test_fetcher) {
427 create_test_fetcher_ = create_test_fetcher; 469 create_test_fetcher_ = create_test_fetcher;
428 } 470 }
429 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
430 // ApplicationManager::Delegate 476 // ApplicationManager::Delegate
431 GURL ResolveMappings(const GURL& url) override { 477 GURL ResolveMappings(const GURL& url) override {
432 auto it = mappings_.find(url); 478 auto it = mappings_.find(url);
433 if (it != mappings_.end()) 479 if (it != mappings_.end())
434 return it->second; 480 return it->second;
435 return url; 481 return url;
436 } 482 }
437 GURL ResolveMojoURL(const GURL& url) override { 483 GURL ResolveMojoURL(const GURL& url) override {
438 GURL mapped_url = ResolveMappings(url); 484 GURL mapped_url = ResolveMappings(url);
439 // The shell automatically map mojo URLs. 485 // The shell automatically map mojo URLs.
440 if (mapped_url.scheme() == "mojo") { 486 if (mapped_url.scheme() == "mojo") {
441 url::Replacements<char> replacements; 487 url::Replacements<char> replacements;
442 replacements.SetScheme("file", url::Component(0, 4)); 488 replacements.SetScheme("file", url::Component(0, 4));
443 mapped_url = mapped_url.ReplaceComponents(replacements); 489 mapped_url = mapped_url.ReplaceComponents(replacements);
444 } 490 }
445 return mapped_url; 491 return mapped_url;
446 } 492 }
447 bool CreateFetcher(const GURL& url, 493 bool CreateFetcher(const GURL& url,
448 const Fetcher::FetchCallback& loader_callback) override { 494 const Fetcher::FetchCallback& loader_callback) override {
449 if (!create_test_fetcher_) 495 if (!create_test_fetcher_)
450 return false; 496 return false;
451 new TestMimeTypeFetcher(loader_callback); 497 new TestMimeTypeFetcher(loader_callback, fetcher_url_, mime_type_);
452 return true; 498 return true;
453 } 499 }
454 500
455 private: 501 private:
456 std::map<GURL, GURL> mappings_; 502 std::map<GURL, GURL> mappings_;
457 bool create_test_fetcher_; 503 bool create_test_fetcher_;
504 GURL fetcher_url_;
505 std::string mime_type_;
458 506
459 DISALLOW_COPY_AND_ASSIGN(TestDelegate); 507 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
460 }; 508 };
461 509
462 class ApplicationManagerTest : public testing::Test { 510 class ApplicationManagerTest : public testing::Test {
463 public: 511 public:
464 ApplicationManagerTest() : tester_context_(&loop_) {} 512 ApplicationManagerTest() : tester_context_(&loop_) {}
465 513
466 ~ApplicationManagerTest() override {} 514 ~ApplicationManagerTest() override {}
467 515
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 802
755 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { 803 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) {
756 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); 804 ClosingApplicationLoader* loader = new ClosingApplicationLoader();
757 application_manager_->SetLoaderForScheme( 805 application_manager_->SetLoaderForScheme(
758 scoped_ptr<ApplicationLoader>(loader), "test"); 806 scoped_ptr<ApplicationLoader>(loader), "test");
759 807
760 bool called = false; 808 bool called = false;
761 mojo::URLRequestPtr request(mojo::URLRequest::New()); 809 mojo::URLRequestPtr request(mojo::URLRequest::New());
762 request->url = mojo::String::From("test:test"); 810 request->url = mojo::String::From("test:test");
763 application_manager_->ConnectToApplication( 811 application_manager_->ConnectToApplication(
764 nullptr, request.Pass(), std::string(), GURL(), nullptr, nullptr, 812 nullptr, request.Pass(), std::string(), GURL(),
813 ApplicationManager::kInvalidContentHandlerID, nullptr, nullptr,
765 GetPermissiveCapabilityFilter(), 814 GetPermissiveCapabilityFilter(),
766 base::Bind(&QuitClosure, base::Unretained(&called))); 815 base::Bind(&QuitClosure, base::Unretained(&called)),
816 EmptyConnectCallback());
767 loop_.Run(); 817 loop_.Run();
768 EXPECT_TRUE(called); 818 EXPECT_TRUE(called);
769 } 819 }
770 820
771 TEST(ApplicationManagerTest2, ContentHandlerConnectionGetsRequestorURL) { 821 TEST(ApplicationManagerTest2, ContentHandlerConnectionGetsRequestorURL) {
772 const GURL content_handler_url("http://test.content.handler"); 822 const GURL content_handler_url("http://test.content.handler");
773 const GURL requestor_url("http://requestor.url"); 823 const GURL requestor_url("http://requestor.url");
774 TestContext test_context; 824 TestContext test_context;
775 base::MessageLoop loop; 825 base::MessageLoop loop;
776 TestDelegate test_delegate; 826 TestDelegate test_delegate;
777 test_delegate.set_create_test_fetcher(true); 827 test_delegate.set_create_test_fetcher(true);
778 ApplicationManager application_manager(&test_delegate); 828 ApplicationManager application_manager(&test_delegate);
779 application_manager.set_default_loader(nullptr); 829 application_manager.set_default_loader(nullptr);
780 application_manager.RegisterContentHandler(kTestMimeType, 830 application_manager.RegisterContentHandler(kTestMimeType,
781 content_handler_url); 831 content_handler_url);
782 832
783 TestApplicationLoader* loader = new TestApplicationLoader; 833 TestApplicationLoader* loader = new TestApplicationLoader;
784 loader->set_context(&test_context); 834 loader->set_context(&test_context);
785 application_manager.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), 835 application_manager.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader),
786 content_handler_url); 836 content_handler_url);
787 837
788 bool called = false; 838 bool called = false;
789 mojo::URLRequestPtr request(mojo::URLRequest::New()); 839 mojo::URLRequestPtr request(mojo::URLRequest::New());
790 request->url = mojo::String::From("test:test"); 840 request->url = mojo::String::From("test:test");
791 application_manager.ConnectToApplication( 841 application_manager.ConnectToApplication(
792 nullptr, request.Pass(), std::string(), requestor_url, nullptr, nullptr, 842 nullptr, request.Pass(), std::string(), requestor_url,
843 ApplicationManager::kInvalidContentHandlerID, nullptr, nullptr,
793 GetPermissiveCapabilityFilter(), 844 GetPermissiveCapabilityFilter(),
794 base::Bind(&QuitClosure, base::Unretained(&called))); 845 base::Bind(&QuitClosure, base::Unretained(&called)),
846 EmptyConnectCallback());
795 loop.Run(); 847 loop.Run();
796 EXPECT_TRUE(called); 848 EXPECT_TRUE(called);
797 849
798 ASSERT_EQ(1, loader->num_loads()); 850 ASSERT_EQ(1, loader->num_loads());
799 EXPECT_EQ(requestor_url, loader->last_requestor_url()); 851 EXPECT_EQ(requestor_url, loader->last_requestor_url());
800 } 852 }
801 853
802 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { 854 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) {
803 // 1 because ApplicationManagerTest connects once at startup. 855 // 1 because ApplicationManagerTest connects once at startup.
804 EXPECT_EQ(1, test_loader_->num_loads()); 856 EXPECT_EQ(1, test_loader_->num_loads());
(...skipping 18 matching lines...) Expand all
823 application_manager_->ConnectToService( 875 application_manager_->ConnectToService(
824 GURL("http://www.example.org/another_path"), &test_service); 876 GURL("http://www.example.org/another_path"), &test_service);
825 EXPECT_EQ(3, test_loader_->num_loads()); 877 EXPECT_EQ(3, test_loader_->num_loads());
826 878
827 // A different identity because the domain is different. 879 // A different identity because the domain is different.
828 application_manager_->ConnectToService( 880 application_manager_->ConnectToService(
829 GURL("http://www.another_domain.org/abc"), &test_service); 881 GURL("http://www.another_domain.org/abc"), &test_service);
830 EXPECT_EQ(4, test_loader_->num_loads()); 882 EXPECT_EQ(4, test_loader_->num_loads());
831 } 883 }
832 884
885 TEST(ApplicationManagerTest2,
886 MultipleConnectionsToContentHandlerGetSameTargetId) {
887 base::MessageLoop loop;
888 const GURL content_handler_url("http://test.content.handler");
889 const GURL requestor_url("http://requestor.url");
890 TestContext test_context;
891 TestDelegate test_delegate;
892 test_delegate.set_fetcher_url(GURL("test:test"));
893 test_delegate.set_create_test_fetcher(true);
894 ApplicationManager application_manager(&test_delegate);
895 application_manager.set_default_loader(nullptr);
896 application_manager.RegisterContentHandler(kTestMimeType,
897 content_handler_url);
898
899 TestApplicationLoader* content_handler_loader = new TestApplicationLoader;
900 content_handler_loader->set_create_content_handler(true);
901 content_handler_loader->set_context(&test_context);
902 application_manager.SetLoaderForURL(
903 scoped_ptr<ApplicationLoader>(content_handler_loader),
904 content_handler_url);
905
906 uint32_t content_handler_id;
907 {
908 base::RunLoop run_loop;
909 mojo::URLRequestPtr request(mojo::URLRequest::New());
910 request->url = mojo::String::From("test:test");
911 application_manager.ConnectToApplication(
912 nullptr, request.Pass(), std::string(), requestor_url,
913 ApplicationManager::kInvalidContentHandlerID, nullptr, nullptr,
914 GetPermissiveCapabilityFilter(), base::Closure(),
915 [&content_handler_id, &run_loop](uint32_t t) {
916 content_handler_id = t;
917 run_loop.Quit();
918 });
919 run_loop.Run();
920 EXPECT_NE(ApplicationManager::kInvalidContentHandlerID, content_handler_id);
921 }
922
923 uint32_t content_handler_id2;
924 {
925 base::RunLoop run_loop;
926 mojo::URLRequestPtr request(mojo::URLRequest::New());
927 request->url = mojo::String::From("test:test");
928 application_manager.ConnectToApplication(
929 nullptr, request.Pass(), std::string(), requestor_url,
930 ApplicationManager::kInvalidContentHandlerID, nullptr, nullptr,
931 GetPermissiveCapabilityFilter(), base::Closure(),
932 [&content_handler_id2, &run_loop](uint32_t t) {
933 content_handler_id2 = t;
934 run_loop.Quit();
935 });
936 run_loop.Run();
937 EXPECT_NE(ApplicationManager::kInvalidContentHandlerID,
938 content_handler_id2);
939 }
940 EXPECT_EQ(content_handler_id, content_handler_id2);
941 }
942
943 TEST(ApplicationManagerTest2, DifferedContentHandlersGetDifferentIDs) {
944 base::MessageLoop loop;
945 const GURL content_handler_url("http://test.content.handler");
946 const GURL requestor_url("http://requestor.url");
947 TestContext test_context;
948 TestDelegate test_delegate;
949 test_delegate.set_fetcher_url(GURL("test:test"));
950 test_delegate.set_create_test_fetcher(true);
951 ApplicationManager application_manager(&test_delegate);
952 application_manager.set_default_loader(nullptr);
953 application_manager.RegisterContentHandler(kTestMimeType,
954 content_handler_url);
955
956 TestApplicationLoader* content_handler_loader = new TestApplicationLoader;
957 content_handler_loader->set_create_content_handler(true);
958 content_handler_loader->set_context(&test_context);
959 application_manager.SetLoaderForURL(
960 scoped_ptr<ApplicationLoader>(content_handler_loader),
961 content_handler_url);
962
963 uint32_t content_handler_id;
964 {
965 base::RunLoop run_loop;
966 mojo::URLRequestPtr request(mojo::URLRequest::New());
967 request->url = mojo::String::From("test:test");
968 application_manager.ConnectToApplication(
969 nullptr, request.Pass(), std::string(), requestor_url,
970 ApplicationManager::kInvalidContentHandlerID, nullptr, nullptr,
971 GetPermissiveCapabilityFilter(), base::Closure(),
972 [&content_handler_id, &run_loop](uint32_t t) {
973 content_handler_id = t;
974 run_loop.Quit();
975 });
976 run_loop.Run();
977 EXPECT_NE(ApplicationManager::kInvalidContentHandlerID, content_handler_id);
978 }
979
980 const std::string mime_type2("test/mime-type2");
981 const GURL content_handler_url2("http://test.content2.handler");
982 test_delegate.set_fetcher_url(GURL("test2:test2"));
983 test_delegate.set_mime_type(mime_type2);
984 application_manager.RegisterContentHandler(mime_type2, content_handler_url2);
985
986 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader;
987 content_handler_loader->set_create_content_handler(true);
988 content_handler_loader->set_context(&test_context);
989 application_manager.SetLoaderForURL(
990 scoped_ptr<ApplicationLoader>(content_handler_loader2),
991 content_handler_url2);
992
993 uint32_t content_handler_id2;
994 {
995 base::RunLoop run_loop;
996 mojo::URLRequestPtr request(mojo::URLRequest::New());
997 request->url = mojo::String::From("test2:test2");
998 application_manager.ConnectToApplication(
999 nullptr, request.Pass(), std::string(), requestor_url,
1000 ApplicationManager::kInvalidContentHandlerID, nullptr, nullptr,
1001 GetPermissiveCapabilityFilter(), base::Closure(),
1002 [&content_handler_id2, &run_loop](uint32_t t) {
1003 content_handler_id2 = t;
1004 run_loop.Quit();
1005 });
1006 run_loop.Run();
1007 EXPECT_NE(ApplicationManager::kInvalidContentHandlerID,
1008 content_handler_id2);
1009 }
1010 EXPECT_NE(content_handler_id, content_handler_id2);
1011 }
1012
1013 TEST_F(ApplicationManagerTest,
1014 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) {
1015 application_manager_->SetLoaderForScheme(
1016 scoped_ptr<ApplicationLoader>(new TestApplicationLoader), "test");
1017
1018 uint32_t content_handler_id = 1u;
1019 mojo::URLRequestPtr request(mojo::URLRequest::New());
1020 request->url = mojo::String::From("test:test");
1021 application_manager_->ConnectToApplication(
1022 nullptr, request.Pass(), std::string(), GURL(),
1023 ApplicationManager::kInvalidContentHandlerID, nullptr, nullptr,
1024 GetPermissiveCapabilityFilter(), base::Closure(),
1025 [&content_handler_id](uint32_t t) { content_handler_id = t; });
1026 EXPECT_EQ(0u, content_handler_id);
1027 }
1028
833 } // namespace 1029 } // namespace
834 } // namespace shell 1030 } // namespace shell
835 } // namespace mojo 1031 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698