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

Side by Side Diff: mojo/service_manager/service_manager_unittest.cc

Issue 214513009: Change ServiceManager::SetLoaderForUrl() to SetLoaderForScheme() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Keep both SetLoaderForURL() and SetLoaderForScheme() Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « mojo/service_manager/service_manager.cc ('k') | no next file » | 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/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "mojo/public/bindings/allocation_scope.h" 6 #include "mojo/public/bindings/allocation_scope.h"
7 #include "mojo/public/bindings/remote_ptr.h" 7 #include "mojo/public/bindings/remote_ptr.h"
8 #include "mojo/public/environment/environment.h" 8 #include "mojo/public/environment/environment.h"
9 #include "mojo/public/shell/application.h" 9 #include "mojo/public/shell/application.h"
10 #include "mojo/public/shell/shell.mojom.h" 10 #include "mojo/public/shell/shell.mojom.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 protected: 117 protected:
118 mojo::Environment env_; 118 mojo::Environment env_;
119 base::MessageLoop loop_; 119 base::MessageLoop loop_;
120 TestContext context_; 120 TestContext context_;
121 scoped_ptr<Application> test_app_; 121 scoped_ptr<Application> test_app_;
122 scoped_ptr<TestClientImpl> test_client_; 122 scoped_ptr<TestClientImpl> test_client_;
123 scoped_ptr<ServiceManager> service_manager_; 123 scoped_ptr<ServiceManager> service_manager_;
124 DISALLOW_COPY_AND_ASSIGN(ServiceManagerTest); 124 DISALLOW_COPY_AND_ASSIGN(ServiceManagerTest);
125 }; 125 };
126 126
127 class TestServiceLoader : public ServiceLoader {
128 public:
129 TestServiceLoader() : num_loads_(0) {}
130 int num_loads() const { return num_loads_; }
131
132 private:
133 virtual void LoadService(ServiceManager* manager,
134 const GURL& url,
135 ScopedShellHandle service_handle) OVERRIDE {
136 ++num_loads_;
137 }
138 virtual void OnServiceError(ServiceManager* manager, const GURL& url)
139 OVERRIDE {}
140
141 int num_loads_;
142 DISALLOW_COPY_AND_ASSIGN(TestServiceLoader);
143 };
144
127 TEST_F(ServiceManagerTest, Basic) { 145 TEST_F(ServiceManagerTest, Basic) {
128 test_client_->Test("test"); 146 test_client_->Test("test");
129 loop_.Run(); 147 loop_.Run();
130 EXPECT_EQ(std::string("test"), context_.last_test_string); 148 EXPECT_EQ(std::string("test"), context_.last_test_string);
131 } 149 }
132 150
133 TEST_F(ServiceManagerTest, ClientError) { 151 TEST_F(ServiceManagerTest, ClientError) {
134 test_client_->Test("test"); 152 test_client_->Test("test");
135 EXPECT_TRUE(HasFactoryForTestURL()); 153 EXPECT_TRUE(HasFactoryForTestURL());
136 loop_.Run(); 154 loop_.Run();
137 EXPECT_EQ(1, context_.num_impls); 155 EXPECT_EQ(1, context_.num_impls);
138 test_client_.reset(NULL); 156 test_client_.reset(NULL);
139 loop_.Run(); 157 loop_.Run();
140 EXPECT_EQ(0, context_.num_impls); 158 EXPECT_EQ(0, context_.num_impls);
141 EXPECT_FALSE(HasFactoryForTestURL()); 159 EXPECT_FALSE(HasFactoryForTestURL());
142 } 160 }
161
162 // Confirm that both urls and schemes can have their loaders explicitly set.
163 TEST_F(ServiceManagerTest, SetLoaders) {
164 ServiceManager sm;
165 TestServiceLoader default_loader;
166 TestServiceLoader url_loader;
167 TestServiceLoader scheme_loader;
168 sm.set_default_loader(&default_loader);
169 sm.SetLoaderForURL(&url_loader, GURL("test:test1"));
170 sm.SetLoaderForScheme(&scheme_loader, "test");
171
172 // test::test1 should go to url_loader.
173 InterfacePipe<TestService, AnyInterface> pipe1;
174 sm.Connect(GURL("test:test1"), pipe1.handle_to_peer.Pass());
175 EXPECT_EQ(1, url_loader.num_loads());
176 EXPECT_EQ(0, scheme_loader.num_loads());
177 EXPECT_EQ(0, default_loader.num_loads());
178
179 // test::test2 should go to scheme loader.
180 InterfacePipe<TestService, AnyInterface> pipe2;
181 sm.Connect(GURL("test:test2"), pipe2.handle_to_peer.Pass());
182 EXPECT_EQ(1, url_loader.num_loads());
183 EXPECT_EQ(1, scheme_loader.num_loads());
184 EXPECT_EQ(0, default_loader.num_loads());
185
186 // http::test1 should go to default loader.
187 InterfacePipe<TestService, AnyInterface> pipe3;
188 sm.Connect(GURL("http:test1"), pipe3.handle_to_peer.Pass());
189 EXPECT_EQ(1, url_loader.num_loads());
190 EXPECT_EQ(1, scheme_loader.num_loads());
191 EXPECT_EQ(1, default_loader.num_loads());
192 }
193
143 } // namespace mojo 194 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/service_manager/service_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698