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

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

Issue 275363002: Internalize ServiceConnector<> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add OnConnectionEstablished() 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/bindings/allocation_scope.h" 6 #include "mojo/public/cpp/bindings/allocation_scope.h"
7 #include "mojo/public/cpp/environment/environment.h" 7 #include "mojo/public/cpp/environment/environment.h"
8 #include "mojo/public/cpp/shell/application.h" 8 #include "mojo/public/cpp/shell/application.h"
9 #include "mojo/public/interfaces/shell/shell.mojom.h" 9 #include "mojo/public/interfaces/shell/shell.mojom.h"
10 #include "mojo/service_manager/service_loader.h" 10 #include "mojo/service_manager/service_loader.h"
11 #include "mojo/service_manager/service_manager.h" 11 #include "mojo/service_manager/service_manager.h"
12 #include "mojo/service_manager/test.mojom.h" 12 #include "mojo/service_manager/test.mojom.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 namespace { 16 namespace {
17 17
18 const char kTestURLString[] = "test:testService"; 18 const char kTestURLString[] = "test:testService";
19 19
20 struct TestContext { 20 struct TestContext {
21 TestContext() : num_impls(0), num_loader_deletes(0) {} 21 TestContext() : num_impls(0), num_loader_deletes(0) {}
22 std::string last_test_string; 22 std::string last_test_string;
23 int num_impls; 23 int num_impls;
24 int num_loader_deletes; 24 int num_loader_deletes;
25 }; 25 };
26 26
27 class TestServiceImpl : 27 class TestServiceImpl : public InterfaceImpl<TestService> {
28 public ServiceConnection<TestService, TestServiceImpl, TestContext> {
29 public: 28 public:
30 virtual ~TestServiceImpl() { 29 explicit TestServiceImpl(TestContext* context) : context_(context) {
31 if (context()) 30 ++context_->num_impls;
32 --context()->num_impls;
33 } 31 }
34 32
35 void Initialize() { 33 virtual ~TestServiceImpl() {
36 if (context()) 34 --context_->num_impls;
37 ++context()->num_impls; 35 }
36
37 // InterfaceImpl<TestService> implementation.
38 virtual void OnConnectionError() OVERRIDE {
38 } 39 }
39 40
40 // TestService implementation: 41 // TestService implementation:
41 virtual void Test(const mojo::String& test_string) OVERRIDE { 42 virtual void Test(const mojo::String& test_string) OVERRIDE {
42 context()->last_test_string = test_string.To<std::string>(); 43 context_->last_test_string = test_string.To<std::string>();
43 client()->AckTest(); 44 client()->AckTest();
44 } 45 }
46
47 private:
48 TestContext* context_;
45 }; 49 };
46 50
47 class TestClientImpl : public TestClient { 51 class TestClientImpl : public TestClient {
48 public: 52 public:
49 explicit TestClientImpl(TestServicePtr service) 53 explicit TestClientImpl(TestServicePtr service)
50 : service_(service.Pass()), 54 : service_(service.Pass()),
51 quit_after_ack_(false) { 55 quit_after_ack_(false) {
52 service_->SetClient(this); 56 service_->SetClient(this);
53 } 57 }
54 58
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 95 }
92 96
93 int num_loads() const { return num_loads_; } 97 int num_loads() const { return num_loads_; }
94 98
95 private: 99 private:
96 virtual void LoadService(ServiceManager* manager, 100 virtual void LoadService(ServiceManager* manager,
97 const GURL& url, 101 const GURL& url,
98 ScopedMessagePipeHandle shell_handle) OVERRIDE { 102 ScopedMessagePipeHandle shell_handle) OVERRIDE {
99 ++num_loads_; 103 ++num_loads_;
100 test_app_.reset(new Application(shell_handle.Pass())); 104 test_app_.reset(new Application(shell_handle.Pass()));
101 test_app_->AddServiceConnector( 105 test_app_->AddService<TestServiceImpl>(context_);
102 new ServiceConnector<TestServiceImpl, TestContext>(context_));
103 } 106 }
104 107
105 virtual void OnServiceError(ServiceManager* manager, 108 virtual void OnServiceError(ServiceManager* manager,
106 const GURL& url) OVERRIDE { 109 const GURL& url) OVERRIDE {
107 if (quit_after_error_) { 110 if (quit_after_error_) {
108 base::MessageLoop::current()->PostTask(FROM_HERE, 111 base::MessageLoop::current()->PostTask(FROM_HERE,
109 base::MessageLoop::QuitClosure()); 112 base::MessageLoop::QuitClosure());
110 } 113 }
111 } 114 }
112 115
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 274
272 std::string url("test:test3"); 275 std::string url("test:test3");
273 MessagePipe pipe1; 276 MessagePipe pipe1;
274 sm.Connect(GURL(url), pipe1.handle0.Pass()); 277 sm.Connect(GURL(url), pipe1.handle0.Pass());
275 EXPECT_EQ(1, interceptor.call_count()); 278 EXPECT_EQ(1, interceptor.call_count());
276 EXPECT_EQ(url, interceptor.url_spec()); 279 EXPECT_EQ(url, interceptor.url_spec());
277 EXPECT_EQ(1, default_loader->num_loads()); 280 EXPECT_EQ(1, default_loader->num_loads());
278 } 281 }
279 282
280 } // namespace mojo 283 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698