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

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: Merge 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 TestServiceImpl() : client_(NULL) {} 29 TestServiceImpl(TestContext* context) : context_(context), client_(NULL) {
30 ++context_->num_impls;
31 }
31 32
32 virtual ~TestServiceImpl() { 33 virtual ~TestServiceImpl() {
33 if (context()) 34 --context_->num_impls;
34 --context()->num_impls;
35 } 35 }
36 36
37 void Initialize() { 37 // InterfaceImpl<TestService> implementation.
38 if (context()) 38 virtual void OnConnectionError() OVERRIDE {
39 ++context()->num_impls;
40 } 39 }
41 40
42 // TestService implementation: 41 // TestService implementation:
43 virtual void SetClient(TestClient* client) OVERRIDE { 42 virtual void SetClient(TestClient* client) OVERRIDE {
44 client_ = client; 43 client_ = client;
45 } 44 }
45
46 virtual void Test(const mojo::String& test_string) OVERRIDE { 46 virtual void Test(const mojo::String& test_string) OVERRIDE {
47 context()->last_test_string = test_string.To<std::string>(); 47 context_->last_test_string = test_string.To<std::string>();
48 client_->AckTest(); 48 client_->AckTest();
49 } 49 }
50 50
51 private: 51 private:
52 TestContext* context_;
52 TestClient* client_; 53 TestClient* client_;
53 }; 54 };
54 55
55 class TestClientImpl : public TestClient { 56 class TestClientImpl : public TestClient {
56 public: 57 public:
57 explicit TestClientImpl(TestServicePtr service) 58 explicit TestClientImpl(TestServicePtr service)
58 : service_(service.Pass()), 59 : service_(service.Pass()),
59 quit_after_ack_(false) { 60 quit_after_ack_(false) {
60 service_->SetClient(this); 61 service_->SetClient(this);
61 } 62 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 100 }
100 101
101 int num_loads() const { return num_loads_; } 102 int num_loads() const { return num_loads_; }
102 103
103 private: 104 private:
104 virtual void LoadService(ServiceManager* manager, 105 virtual void LoadService(ServiceManager* manager,
105 const GURL& url, 106 const GURL& url,
106 ScopedMessagePipeHandle shell_handle) OVERRIDE { 107 ScopedMessagePipeHandle shell_handle) OVERRIDE {
107 ++num_loads_; 108 ++num_loads_;
108 test_app_.reset(new Application(shell_handle.Pass())); 109 test_app_.reset(new Application(shell_handle.Pass()));
109 test_app_->AddServiceConnector( 110 test_app_->AddService<TestServiceImpl>(context_);
110 new ServiceConnector<TestServiceImpl, TestContext>(context_));
111 } 111 }
112 112
113 virtual void OnServiceError(ServiceManager* manager, 113 virtual void OnServiceError(ServiceManager* manager,
114 const GURL& url) OVERRIDE { 114 const GURL& url) OVERRIDE {
115 if (quit_after_error_) { 115 if (quit_after_error_) {
116 base::MessageLoop::current()->PostTask(FROM_HERE, 116 base::MessageLoop::current()->PostTask(FROM_HERE,
117 base::MessageLoop::QuitClosure()); 117 base::MessageLoop::QuitClosure());
118 } 118 }
119 } 119 }
120 120
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 279
280 std::string url("test:test3"); 280 std::string url("test:test3");
281 MessagePipe pipe1; 281 MessagePipe pipe1;
282 sm.Connect(GURL(url), pipe1.handle0.Pass()); 282 sm.Connect(GURL(url), pipe1.handle0.Pass());
283 EXPECT_EQ(1, interceptor.call_count()); 283 EXPECT_EQ(1, interceptor.call_count());
284 EXPECT_EQ(url, interceptor.url_spec()); 284 EXPECT_EQ(url, interceptor.url_spec());
285 EXPECT_EQ(1, default_loader->num_loads()); 285 EXPECT_EQ(1, default_loader->num_loads());
286 } 286 }
287 287
288 } // namespace mojo 288 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698