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

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

Issue 327523004: Introduce very beginning of navigation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add url dependency to two smaple apps Created 6 years, 6 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" 6 #include "mojo/public/cpp/application/application.h"
7 #include "mojo/public/cpp/environment/environment.h" 7 #include "mojo/public/cpp/environment/environment.h"
8 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" 8 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
9 #include "mojo/service_manager/service_loader.h" 9 #include "mojo/service_manager/service_loader.h"
10 #include "mojo/service_manager/service_manager.h" 10 #include "mojo/service_manager/service_manager.h"
(...skipping 17 matching lines...) Expand all
28 class TestServiceImpl : public InterfaceImpl<TestService> { 28 class TestServiceImpl : public InterfaceImpl<TestService> {
29 public: 29 public:
30 explicit TestServiceImpl(TestContext* context) : context_(context) { 30 explicit TestServiceImpl(TestContext* context) : context_(context) {
31 ++context_->num_impls; 31 ++context_->num_impls;
32 } 32 }
33 33
34 virtual ~TestServiceImpl() { 34 virtual ~TestServiceImpl() {
35 --context_->num_impls; 35 --context_->num_impls;
36 } 36 }
37 37
38 virtual void OnConnectionError() OVERRIDE {
39 base::MessageLoop::current()->Quit();
40 }
41
38 // TestService implementation: 42 // TestService implementation:
39 virtual void Test(const String& test_string) OVERRIDE { 43 virtual void Test(const String& test_string) OVERRIDE {
40 context_->last_test_string = test_string; 44 context_->last_test_string = test_string;
41 client()->AckTest(); 45 client()->AckTest();
42 } 46 }
43 47
44 private: 48 private:
45 TestContext* context_; 49 TestContext* context_;
46 }; 50 };
47 51
(...skipping 20 matching lines...) Expand all
68 private: 72 private:
69 TestServicePtr service_; 73 TestServicePtr service_;
70 bool quit_after_ack_; 74 bool quit_after_ack_;
71 DISALLOW_COPY_AND_ASSIGN(TestClientImpl); 75 DISALLOW_COPY_AND_ASSIGN(TestClientImpl);
72 }; 76 };
73 77
74 class TestServiceLoader : public ServiceLoader { 78 class TestServiceLoader : public ServiceLoader {
75 public: 79 public:
76 TestServiceLoader() 80 TestServiceLoader()
77 : context_(NULL), 81 : context_(NULL),
78 num_loads_(0), 82 num_loads_(0) {
79 quit_after_error_(false) {
80 } 83 }
81 84
82 virtual ~TestServiceLoader() { 85 virtual ~TestServiceLoader() {
83 if (context_) 86 if (context_)
84 ++context_->num_loader_deletes; 87 ++context_->num_loader_deletes;
85 test_app_.reset(NULL); 88 test_app_.reset(NULL);
86 } 89 }
87 90
88 void set_context(TestContext* context) { context_ = context; } 91 void set_context(TestContext* context) { context_ = context; }
89 void set_quit_after_error(bool quit_after_error) {
90 quit_after_error_ = quit_after_error;
91 }
92
93 int num_loads() const { return num_loads_; } 92 int num_loads() const { return num_loads_; }
94 93
95 private: 94 private:
96 virtual void LoadService( 95 virtual void LoadService(
97 ServiceManager* manager, 96 ServiceManager* manager,
98 const GURL& url, 97 const GURL& url,
99 ScopedMessagePipeHandle service_provider_handle) OVERRIDE { 98 ScopedMessagePipeHandle service_provider_handle) OVERRIDE {
100 ++num_loads_; 99 ++num_loads_;
101 test_app_.reset(new Application(service_provider_handle.Pass())); 100 test_app_.reset(new Application(service_provider_handle.Pass()));
102 test_app_->AddService<TestServiceImpl>(context_); 101 test_app_->AddService<TestServiceImpl>(context_);
103 } 102 }
104 103
105 virtual void OnServiceError(ServiceManager* manager, 104 virtual void OnServiceError(ServiceManager* manager,
106 const GURL& url) OVERRIDE { 105 const GURL& url) OVERRIDE {
107 if (quit_after_error_) {
108 base::MessageLoop::current()->PostTask(FROM_HERE,
109 base::MessageLoop::QuitClosure());
110 }
111 } 106 }
112 107
113 scoped_ptr<Application> test_app_; 108 scoped_ptr<Application> test_app_;
114 TestContext* context_; 109 TestContext* context_;
115 int num_loads_; 110 int num_loads_;
116 bool quit_after_error_;
117 DISALLOW_COPY_AND_ASSIGN(TestServiceLoader); 111 DISALLOW_COPY_AND_ASSIGN(TestServiceLoader);
118 }; 112 };
119 113
120 // Used to test that the requestor url will be correctly passed. 114 // Used to test that the requestor url will be correctly passed.
121 class TestAImpl : public InterfaceImpl<TestA> { 115 class TestAImpl : public InterfaceImpl<TestA> {
122 public: 116 public:
123 TestAImpl(Application* app) : app_(app) {} 117 TestAImpl(Application* app) : app_(app) {}
124 118
125 virtual void LoadB() OVERRIDE { 119 virtual void LoadB() OVERRIDE {
126 TestBPtr b; 120 TestBPtr b;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 virtual void SetUp() OVERRIDE { 210 virtual void SetUp() OVERRIDE {
217 GURL test_url(kTestURLString); 211 GURL test_url(kTestURLString);
218 service_manager_.reset(new ServiceManager); 212 service_manager_.reset(new ServiceManager);
219 213
220 MessagePipe pipe; 214 MessagePipe pipe;
221 TestServicePtr service_proxy = MakeProxy<TestService>(pipe.handle0.Pass()); 215 TestServicePtr service_proxy = MakeProxy<TestService>(pipe.handle0.Pass());
222 test_client_.reset(new TestClientImpl(service_proxy.Pass())); 216 test_client_.reset(new TestClientImpl(service_proxy.Pass()));
223 217
224 TestServiceLoader* default_loader = new TestServiceLoader; 218 TestServiceLoader* default_loader = new TestServiceLoader;
225 default_loader->set_context(&context_); 219 default_loader->set_context(&context_);
226 default_loader->set_quit_after_error(true);
227 service_manager_->set_default_loader( 220 service_manager_->set_default_loader(
228 scoped_ptr<ServiceLoader>(default_loader)); 221 scoped_ptr<ServiceLoader>(default_loader));
229 222
230 service_manager_->ConnectToService( 223 service_manager_->ConnectToService(
231 test_url, TestService::Name_, pipe.handle1.Pass(), GURL()); 224 test_url, TestService::Name_, pipe.handle1.Pass(), GURL());
232 } 225 }
233 226
234 virtual void TearDown() OVERRIDE { 227 virtual void TearDown() OVERRIDE {
235 test_client_.reset(NULL); 228 test_client_.reset(NULL);
236 service_manager_.reset(NULL); 229 service_manager_.reset(NULL);
(...skipping 20 matching lines...) Expand all
257 } 250 }
258 251
259 TEST_F(ServiceManagerTest, ClientError) { 252 TEST_F(ServiceManagerTest, ClientError) {
260 test_client_->Test("test"); 253 test_client_->Test("test");
261 EXPECT_TRUE(HasFactoryForTestURL()); 254 EXPECT_TRUE(HasFactoryForTestURL());
262 loop_.Run(); 255 loop_.Run();
263 EXPECT_EQ(1, context_.num_impls); 256 EXPECT_EQ(1, context_.num_impls);
264 test_client_.reset(NULL); 257 test_client_.reset(NULL);
265 loop_.Run(); 258 loop_.Run();
266 EXPECT_EQ(0, context_.num_impls); 259 EXPECT_EQ(0, context_.num_impls);
267 EXPECT_FALSE(HasFactoryForTestURL()); 260 EXPECT_TRUE(HasFactoryForTestURL());
268 } 261 }
269 262
270 TEST_F(ServiceManagerTest, Deletes) { 263 TEST_F(ServiceManagerTest, Deletes) {
271 { 264 {
272 ServiceManager sm; 265 ServiceManager sm;
273 TestServiceLoader* default_loader = new TestServiceLoader; 266 TestServiceLoader* default_loader = new TestServiceLoader;
274 default_loader->set_context(&context_); 267 default_loader->set_context(&context_);
275 TestServiceLoader* url_loader1 = new TestServiceLoader; 268 TestServiceLoader* url_loader1 = new TestServiceLoader;
276 TestServiceLoader* url_loader2 = new TestServiceLoader; 269 TestServiceLoader* url_loader2 = new TestServiceLoader;
277 url_loader1->set_context(&context_); 270 url_loader1->set_context(&context_);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 367
375 std::string url("test:test3"); 368 std::string url("test:test3");
376 TestServicePtr test_service; 369 TestServicePtr test_service;
377 sm.ConnectTo(GURL(url), &test_service, GURL()); 370 sm.ConnectTo(GURL(url), &test_service, GURL());
378 EXPECT_EQ(1, interceptor.call_count()); 371 EXPECT_EQ(1, interceptor.call_count());
379 EXPECT_EQ(url, interceptor.url_spec()); 372 EXPECT_EQ(url, interceptor.url_spec());
380 EXPECT_EQ(1, default_loader->num_loads()); 373 EXPECT_EQ(1, default_loader->num_loads());
381 } 374 }
382 375
383 } // namespace mojo 376 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/lib/service_connector.h ('k') | mojo/services/navigation/navigation.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698