OLD | NEW |
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 : |
28 public ServiceConnection<TestService, TestServiceImpl, TestContext> { | 28 public ServiceConnection<TestService, TestServiceImpl, TestContext> { |
29 public: | 29 public: |
30 TestServiceImpl() : client_(NULL) {} | |
31 | |
32 virtual ~TestServiceImpl() { | 30 virtual ~TestServiceImpl() { |
33 if (context()) | 31 if (context()) |
34 --context()->num_impls; | 32 --context()->num_impls; |
35 } | 33 } |
36 | 34 |
37 void Initialize() { | 35 void Initialize() { |
38 if (context()) | 36 if (context()) |
39 ++context()->num_impls; | 37 ++context()->num_impls; |
40 } | 38 } |
41 | 39 |
42 // TestService implementation: | 40 // TestService implementation: |
43 virtual void SetClient(TestClient* client) OVERRIDE { | |
44 client_ = client; | |
45 } | |
46 virtual void Test(const mojo::String& test_string) OVERRIDE { | 41 virtual void Test(const mojo::String& test_string) OVERRIDE { |
47 context()->last_test_string = test_string.To<std::string>(); | 42 context()->last_test_string = test_string.To<std::string>(); |
48 client_->AckTest(); | 43 client()->AckTest(); |
49 } | 44 } |
50 | |
51 private: | |
52 TestClient* client_; | |
53 }; | 45 }; |
54 | 46 |
55 class TestClientImpl : public TestClient { | 47 class TestClientImpl : public TestClient { |
56 public: | 48 public: |
57 explicit TestClientImpl(TestServicePtr service) | 49 explicit TestClientImpl(TestServicePtr service) |
58 : service_(service.Pass()), | 50 : service_(service.Pass()), |
59 quit_after_ack_(false) { | 51 quit_after_ack_(false) { |
60 service_->SetClient(this); | 52 service_->SetClient(this); |
61 } | 53 } |
62 | 54 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 271 |
280 std::string url("test:test3"); | 272 std::string url("test:test3"); |
281 MessagePipe pipe1; | 273 MessagePipe pipe1; |
282 sm.Connect(GURL(url), pipe1.handle0.Pass()); | 274 sm.Connect(GURL(url), pipe1.handle0.Pass()); |
283 EXPECT_EQ(1, interceptor.call_count()); | 275 EXPECT_EQ(1, interceptor.call_count()); |
284 EXPECT_EQ(url, interceptor.url_spec()); | 276 EXPECT_EQ(url, interceptor.url_spec()); |
285 EXPECT_EQ(1, default_loader->num_loads()); | 277 EXPECT_EQ(1, default_loader->num_loads()); |
286 } | 278 } |
287 | 279 |
288 } // namespace mojo | 280 } // namespace mojo |
OLD | NEW |