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

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: nuke comment 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
« no previous file with comments | « mojo/shell/application_manager.cc ('k') | mojo/shell/capability_filter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(), nullptr, nullptr,
765 GetPermissiveCapabilityFilter(), 813 GetPermissiveCapabilityFilter(),
766 base::Bind(&QuitClosure, base::Unretained(&called))); 814 base::Bind(&QuitClosure, base::Unretained(&called)),
815 EmptyConnectCallback());
767 loop_.Run(); 816 loop_.Run();
768 EXPECT_TRUE(called); 817 EXPECT_TRUE(called);
769 } 818 }
770 819
771 TEST(ApplicationManagerTest2, ContentHandlerConnectionGetsRequestorURL) { 820 TEST(ApplicationManagerTest2, ContentHandlerConnectionGetsRequestorURL) {
772 const GURL content_handler_url("http://test.content.handler"); 821 const GURL content_handler_url("http://test.content.handler");
773 const GURL requestor_url("http://requestor.url"); 822 const GURL requestor_url("http://requestor.url");
774 TestContext test_context; 823 TestContext test_context;
775 base::MessageLoop loop; 824 base::MessageLoop loop;
776 TestDelegate test_delegate; 825 TestDelegate test_delegate;
777 test_delegate.set_create_test_fetcher(true); 826 test_delegate.set_create_test_fetcher(true);
778 ApplicationManager application_manager(&test_delegate); 827 ApplicationManager application_manager(&test_delegate);
779 application_manager.set_default_loader(nullptr); 828 application_manager.set_default_loader(nullptr);
780 application_manager.RegisterContentHandler(kTestMimeType, 829 application_manager.RegisterContentHandler(kTestMimeType,
781 content_handler_url); 830 content_handler_url);
782 831
783 TestApplicationLoader* loader = new TestApplicationLoader; 832 TestApplicationLoader* loader = new TestApplicationLoader;
784 loader->set_context(&test_context); 833 loader->set_context(&test_context);
785 application_manager.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), 834 application_manager.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader),
786 content_handler_url); 835 content_handler_url);
787 836
788 bool called = false; 837 bool called = false;
789 mojo::URLRequestPtr request(mojo::URLRequest::New()); 838 mojo::URLRequestPtr request(mojo::URLRequest::New());
790 request->url = mojo::String::From("test:test"); 839 request->url = mojo::String::From("test:test");
791 application_manager.ConnectToApplication( 840 application_manager.ConnectToApplication(
792 nullptr, request.Pass(), std::string(), requestor_url, nullptr, nullptr, 841 nullptr, request.Pass(), std::string(), requestor_url, nullptr, nullptr,
793 GetPermissiveCapabilityFilter(), 842 GetPermissiveCapabilityFilter(),
794 base::Bind(&QuitClosure, base::Unretained(&called))); 843 base::Bind(&QuitClosure, base::Unretained(&called)),
844 EmptyConnectCallback());
795 loop.Run(); 845 loop.Run();
796 EXPECT_TRUE(called); 846 EXPECT_TRUE(called);
797 847
798 ASSERT_EQ(1, loader->num_loads()); 848 ASSERT_EQ(1, loader->num_loads());
799 EXPECT_EQ(requestor_url, loader->last_requestor_url()); 849 EXPECT_EQ(requestor_url, loader->last_requestor_url());
800 } 850 }
801 851
802 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { 852 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) {
803 // 1 because ApplicationManagerTest connects once at startup. 853 // 1 because ApplicationManagerTest connects once at startup.
804 EXPECT_EQ(1, test_loader_->num_loads()); 854 EXPECT_EQ(1, test_loader_->num_loads());
(...skipping 18 matching lines...) Expand all
823 application_manager_->ConnectToService( 873 application_manager_->ConnectToService(
824 GURL("http://www.example.org/another_path"), &test_service); 874 GURL("http://www.example.org/another_path"), &test_service);
825 EXPECT_EQ(3, test_loader_->num_loads()); 875 EXPECT_EQ(3, test_loader_->num_loads());
826 876
827 // A different identity because the domain is different. 877 // A different identity because the domain is different.
828 application_manager_->ConnectToService( 878 application_manager_->ConnectToService(
829 GURL("http://www.another_domain.org/abc"), &test_service); 879 GURL("http://www.another_domain.org/abc"), &test_service);
830 EXPECT_EQ(4, test_loader_->num_loads()); 880 EXPECT_EQ(4, test_loader_->num_loads());
831 } 881 }
832 882
883 TEST(ApplicationManagerTest2,
884 MultipleConnectionsToContentHandlerGetSameContentHandlerId) {
885 base::MessageLoop loop;
886 const GURL content_handler_url("http://test.content.handler");
887 const GURL requestor_url("http://requestor.url");
888 TestContext test_context;
889 TestDelegate test_delegate;
890 test_delegate.set_fetcher_url(GURL("test:test"));
891 test_delegate.set_create_test_fetcher(true);
892 ApplicationManager application_manager(&test_delegate);
893 application_manager.set_default_loader(nullptr);
894 application_manager.RegisterContentHandler(kTestMimeType,
895 content_handler_url);
896
897 TestApplicationLoader* content_handler_loader = new TestApplicationLoader;
898 content_handler_loader->set_create_content_handler(true);
899 content_handler_loader->set_context(&test_context);
900 application_manager.SetLoaderForURL(
901 scoped_ptr<ApplicationLoader>(content_handler_loader),
902 content_handler_url);
903
904 uint32_t content_handler_id;
905 {
906 base::RunLoop run_loop;
907 mojo::URLRequestPtr request(mojo::URLRequest::New());
908 request->url = mojo::String::From("test:test");
909 application_manager.ConnectToApplication(
910 nullptr, request.Pass(), std::string(), requestor_url, nullptr, nullptr,
911 GetPermissiveCapabilityFilter(), base::Closure(),
912 [&content_handler_id, &run_loop](uint32_t t) {
913 content_handler_id = t;
914 run_loop.Quit();
915 });
916 run_loop.Run();
917 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id);
918 }
919
920 uint32_t content_handler_id2;
921 {
922 base::RunLoop run_loop;
923 mojo::URLRequestPtr request(mojo::URLRequest::New());
924 request->url = mojo::String::From("test:test");
925 application_manager.ConnectToApplication(
926 nullptr, request.Pass(), std::string(), requestor_url, nullptr, nullptr,
927 GetPermissiveCapabilityFilter(), base::Closure(),
928 [&content_handler_id2, &run_loop](uint32_t t) {
929 content_handler_id2 = t;
930 run_loop.Quit();
931 });
932 run_loop.Run();
933 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2);
934 }
935 EXPECT_EQ(content_handler_id, content_handler_id2);
936 }
937
938 TEST(ApplicationManagerTest2, DifferedContentHandlersGetDifferentIDs) {
939 base::MessageLoop loop;
940 const GURL content_handler_url("http://test.content.handler");
941 const GURL requestor_url("http://requestor.url");
942 TestContext test_context;
943 TestDelegate test_delegate;
944 test_delegate.set_fetcher_url(GURL("test:test"));
945 test_delegate.set_create_test_fetcher(true);
946 ApplicationManager application_manager(&test_delegate);
947 application_manager.set_default_loader(nullptr);
948 application_manager.RegisterContentHandler(kTestMimeType,
949 content_handler_url);
950
951 TestApplicationLoader* content_handler_loader = new TestApplicationLoader;
952 content_handler_loader->set_create_content_handler(true);
953 content_handler_loader->set_context(&test_context);
954 application_manager.SetLoaderForURL(
955 scoped_ptr<ApplicationLoader>(content_handler_loader),
956 content_handler_url);
957
958 uint32_t content_handler_id;
959 {
960 base::RunLoop run_loop;
961 mojo::URLRequestPtr request(mojo::URLRequest::New());
962 request->url = mojo::String::From("test:test");
963 application_manager.ConnectToApplication(
964 nullptr, request.Pass(), std::string(), requestor_url, nullptr, nullptr,
965 GetPermissiveCapabilityFilter(), base::Closure(),
966 [&content_handler_id, &run_loop](uint32_t t) {
967 content_handler_id = t;
968 run_loop.Quit();
969 });
970 run_loop.Run();
971 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id);
972 }
973
974 const std::string mime_type2("test/mime-type2");
975 const GURL content_handler_url2("http://test.content2.handler");
976 test_delegate.set_fetcher_url(GURL("test2:test2"));
977 test_delegate.set_mime_type(mime_type2);
978 application_manager.RegisterContentHandler(mime_type2, content_handler_url2);
979
980 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader;
981 content_handler_loader->set_create_content_handler(true);
982 content_handler_loader->set_context(&test_context);
983 application_manager.SetLoaderForURL(
984 scoped_ptr<ApplicationLoader>(content_handler_loader2),
985 content_handler_url2);
986
987 uint32_t content_handler_id2;
988 {
989 base::RunLoop run_loop;
990 mojo::URLRequestPtr request(mojo::URLRequest::New());
991 request->url = mojo::String::From("test2:test2");
992 application_manager.ConnectToApplication(
993 nullptr, request.Pass(), std::string(), requestor_url, nullptr, nullptr,
994 GetPermissiveCapabilityFilter(), base::Closure(),
995 [&content_handler_id2, &run_loop](uint32_t t) {
996 content_handler_id2 = t;
997 run_loop.Quit();
998 });
999 run_loop.Run();
1000 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2);
1001 }
1002 EXPECT_NE(content_handler_id, content_handler_id2);
1003 }
1004
1005 TEST_F(ApplicationManagerTest,
1006 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) {
1007 application_manager_->SetLoaderForScheme(
1008 scoped_ptr<ApplicationLoader>(new TestApplicationLoader), "test");
1009
1010 uint32_t content_handler_id = 1u;
1011 mojo::URLRequestPtr request(mojo::URLRequest::New());
1012 request->url = mojo::String::From("test:test");
1013 application_manager_->ConnectToApplication(
1014 nullptr, request.Pass(), std::string(), GURL(), nullptr, nullptr,
1015 GetPermissiveCapabilityFilter(), base::Closure(),
1016 [&content_handler_id](uint32_t t) { content_handler_id = t; });
1017 EXPECT_EQ(0u, content_handler_id);
1018 }
1019
833 } // namespace 1020 } // namespace
834 } // namespace shell 1021 } // namespace shell
835 } // namespace mojo 1022 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager.cc ('k') | mojo/shell/capability_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698