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/service_manager/service_manager_unittest.cc

Issue 298653010: Change Shell / ShellClient to ServiceProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Support content Mojo stuff Created 6 years, 7 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
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/cpp/application/application.h"
7 #include "mojo/public/cpp/application/application.h"
6 #include "mojo/public/cpp/bindings/allocation_scope.h" 8 #include "mojo/public/cpp/bindings/allocation_scope.h"
7 #include "mojo/public/cpp/environment/environment.h" 9 #include "mojo/public/cpp/environment/environment.h"
8 #include "mojo/public/cpp/shell/application.h" 10 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
9 #include "mojo/public/interfaces/shell/shell.mojom.h"
10 #include "mojo/service_manager/service_loader.h" 11 #include "mojo/service_manager/service_loader.h"
11 #include "mojo/service_manager/service_manager.h" 12 #include "mojo/service_manager/service_manager.h"
12 #include "mojo/service_manager/test.mojom.h" 13 #include "mojo/service_manager/test.mojom.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace mojo { 16 namespace mojo {
16 namespace { 17 namespace {
17 18
18 const char kTestURLString[] = "test:testService"; 19 const char kTestURLString[] = "test:testService";
19 20
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 87 }
87 88
88 void set_context(TestContext* context) { context_ = context; } 89 void set_context(TestContext* context) { context_ = context; }
89 void set_quit_after_error(bool quit_after_error) { 90 void set_quit_after_error(bool quit_after_error) {
90 quit_after_error_ = quit_after_error; 91 quit_after_error_ = quit_after_error;
91 } 92 }
92 93
93 int num_loads() const { return num_loads_; } 94 int num_loads() const { return num_loads_; }
94 95
95 private: 96 private:
96 virtual void LoadService(ServiceManager* manager, 97 virtual void LoadService(
97 const GURL& url, 98 ServiceManager* manager,
98 ScopedMessagePipeHandle shell_handle) OVERRIDE { 99 const GURL& url,
100 ScopedMessagePipeHandle service_provider_handle) OVERRIDE {
99 ++num_loads_; 101 ++num_loads_;
100 test_app_.reset(new Application(shell_handle.Pass())); 102 test_app_.reset(new Application(service_provider_handle.Pass()));
101 test_app_->AddService<TestServiceImpl>(context_); 103 test_app_->AddService<TestServiceImpl>(context_);
102 } 104 }
103 105
104 virtual void OnServiceError(ServiceManager* manager, 106 virtual void OnServiceError(ServiceManager* manager,
105 const GURL& url) OVERRIDE { 107 const GURL& url) OVERRIDE {
106 if (quit_after_error_) { 108 if (quit_after_error_) {
107 base::MessageLoop::current()->PostTask(FROM_HERE, 109 base::MessageLoop::current()->PostTask(FROM_HERE,
108 base::MessageLoop::QuitClosure()); 110 base::MessageLoop::QuitClosure());
109 } 111 }
110 } 112 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 MessagePipe pipe; 161 MessagePipe pipe;
160 TestServicePtr service_proxy = MakeProxy<TestService>(pipe.handle0.Pass()); 162 TestServicePtr service_proxy = MakeProxy<TestService>(pipe.handle0.Pass());
161 test_client_.reset(new TestClientImpl(service_proxy.Pass())); 163 test_client_.reset(new TestClientImpl(service_proxy.Pass()));
162 164
163 TestServiceLoader* default_loader = new TestServiceLoader; 165 TestServiceLoader* default_loader = new TestServiceLoader;
164 default_loader->set_context(&context_); 166 default_loader->set_context(&context_);
165 default_loader->set_quit_after_error(true); 167 default_loader->set_quit_after_error(true);
166 service_manager_->set_default_loader( 168 service_manager_->set_default_loader(
167 scoped_ptr<ServiceLoader>(default_loader)); 169 scoped_ptr<ServiceLoader>(default_loader));
168 170
169 service_manager_->Connect(test_url, pipe.handle1.Pass()); 171 service_manager_->ConnectToService(test_url, pipe.handle1.Pass());
170 } 172 }
171 173
172 virtual void TearDown() OVERRIDE { 174 virtual void TearDown() OVERRIDE {
173 test_client_.reset(NULL); 175 test_client_.reset(NULL);
174 service_manager_.reset(NULL); 176 service_manager_.reset(NULL);
175 } 177 }
176 178
177 bool HasFactoryForTestURL() { 179 bool HasFactoryForTestURL() {
178 ServiceManager::TestAPI manager_test_api(service_manager_.get()); 180 ServiceManager::TestAPI manager_test_api(service_manager_.get());
179 return manager_test_api.HasFactoryForURL(GURL(kTestURLString)); 181 return manager_test_api.HasFactoryForURL(GURL(kTestURLString));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 ServiceManager sm; 236 ServiceManager sm;
235 TestServiceLoader* default_loader = new TestServiceLoader; 237 TestServiceLoader* default_loader = new TestServiceLoader;
236 TestServiceLoader* url_loader = new TestServiceLoader; 238 TestServiceLoader* url_loader = new TestServiceLoader;
237 TestServiceLoader* scheme_loader = new TestServiceLoader; 239 TestServiceLoader* scheme_loader = new TestServiceLoader;
238 sm.set_default_loader(scoped_ptr<ServiceLoader>(default_loader)); 240 sm.set_default_loader(scoped_ptr<ServiceLoader>(default_loader));
239 sm.SetLoaderForURL(scoped_ptr<ServiceLoader>(url_loader), GURL("test:test1")); 241 sm.SetLoaderForURL(scoped_ptr<ServiceLoader>(url_loader), GURL("test:test1"));
240 sm.SetLoaderForScheme(scoped_ptr<ServiceLoader>(scheme_loader), "test"); 242 sm.SetLoaderForScheme(scoped_ptr<ServiceLoader>(scheme_loader), "test");
241 243
242 // test::test1 should go to url_loader. 244 // test::test1 should go to url_loader.
243 MessagePipe pipe1; 245 MessagePipe pipe1;
244 sm.Connect(GURL("test:test1"), pipe1.handle0.Pass()); 246 sm.ConnectToService(GURL("test:test1"), pipe1.handle0.Pass());
245 EXPECT_EQ(1, url_loader->num_loads()); 247 EXPECT_EQ(1, url_loader->num_loads());
246 EXPECT_EQ(0, scheme_loader->num_loads()); 248 EXPECT_EQ(0, scheme_loader->num_loads());
247 EXPECT_EQ(0, default_loader->num_loads()); 249 EXPECT_EQ(0, default_loader->num_loads());
248 250
249 // test::test2 should go to scheme loader. 251 // test::test2 should go to scheme loader.
250 MessagePipe pipe2; 252 MessagePipe pipe2;
251 sm.Connect(GURL("test:test2"), pipe2.handle0.Pass()); 253 sm.ConnectToService(GURL("test:test2"), pipe2.handle0.Pass());
252 EXPECT_EQ(1, url_loader->num_loads()); 254 EXPECT_EQ(1, url_loader->num_loads());
253 EXPECT_EQ(1, scheme_loader->num_loads()); 255 EXPECT_EQ(1, scheme_loader->num_loads());
254 EXPECT_EQ(0, default_loader->num_loads()); 256 EXPECT_EQ(0, default_loader->num_loads());
255 257
256 // http::test1 should go to default loader. 258 // http::test1 should go to default loader.
257 MessagePipe pipe3; 259 MessagePipe pipe3;
258 sm.Connect(GURL("http:test1"), pipe3.handle0.Pass()); 260 sm.ConnectToService(GURL("http:test1"), pipe3.handle0.Pass());
259 EXPECT_EQ(1, url_loader->num_loads()); 261 EXPECT_EQ(1, url_loader->num_loads());
260 EXPECT_EQ(1, scheme_loader->num_loads()); 262 EXPECT_EQ(1, scheme_loader->num_loads());
261 EXPECT_EQ(1, default_loader->num_loads()); 263 EXPECT_EQ(1, default_loader->num_loads());
262 } 264 }
263 265
264 TEST_F(ServiceManagerTest, Interceptor) { 266 TEST_F(ServiceManagerTest, Interceptor) {
265 ServiceManager sm; 267 ServiceManager sm;
266 TestServiceInterceptor interceptor; 268 TestServiceInterceptor interceptor;
267 TestServiceLoader* default_loader = new TestServiceLoader; 269 TestServiceLoader* default_loader = new TestServiceLoader;
268 sm.set_default_loader(scoped_ptr<ServiceLoader>(default_loader)); 270 sm.set_default_loader(scoped_ptr<ServiceLoader>(default_loader));
269 sm.SetInterceptor(&interceptor); 271 sm.SetInterceptor(&interceptor);
270 272
271 std::string url("test:test3"); 273 std::string url("test:test3");
272 MessagePipe pipe1; 274 MessagePipe pipe1;
273 sm.Connect(GURL(url), pipe1.handle0.Pass()); 275 sm.ConnectToService(GURL(url), pipe1.handle0.Pass());
274 EXPECT_EQ(1, interceptor.call_count()); 276 EXPECT_EQ(1, interceptor.call_count());
275 EXPECT_EQ(url, interceptor.url_spec()); 277 EXPECT_EQ(url, interceptor.url_spec());
276 EXPECT_EQ(1, default_loader->num_loads()); 278 EXPECT_EQ(1, default_loader->num_loads());
277 } 279 }
278 280
279 } // namespace mojo 281 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698