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" | |
7 #include "mojo/public/cpp/environment/environment.h" | 6 #include "mojo/public/cpp/environment/environment.h" |
8 #include "mojo/public/cpp/shell/application.h" | 7 #include "mojo/public/cpp/shell/application.h" |
9 #include "mojo/public/interfaces/shell/shell.mojom.h" | 8 #include "mojo/public/interfaces/shell/shell.mojom.h" |
10 #include "mojo/service_manager/service_loader.h" | 9 #include "mojo/service_manager/service_loader.h" |
11 #include "mojo/service_manager/service_manager.h" | 10 #include "mojo/service_manager/service_manager.h" |
12 #include "mojo/service_manager/test.mojom.h" | 11 #include "mojo/service_manager/test.mojom.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
14 | 13 |
15 namespace mojo { | 14 namespace mojo { |
16 namespace { | 15 namespace { |
(...skipping 11 matching lines...) Expand all Loading... |
28 public: | 27 public: |
29 explicit TestServiceImpl(TestContext* context) : context_(context) { | 28 explicit TestServiceImpl(TestContext* context) : context_(context) { |
30 ++context_->num_impls; | 29 ++context_->num_impls; |
31 } | 30 } |
32 | 31 |
33 virtual ~TestServiceImpl() { | 32 virtual ~TestServiceImpl() { |
34 --context_->num_impls; | 33 --context_->num_impls; |
35 } | 34 } |
36 | 35 |
37 // TestService implementation: | 36 // TestService implementation: |
38 virtual void Test(const mojo::String& test_string) OVERRIDE { | 37 virtual void Test(const String& test_string) OVERRIDE { |
39 context_->last_test_string = test_string.To<std::string>(); | 38 context_->last_test_string = test_string; |
40 client()->AckTest(); | 39 client()->AckTest(); |
41 } | 40 } |
42 | 41 |
43 private: | 42 private: |
44 TestContext* context_; | 43 TestContext* context_; |
45 }; | 44 }; |
46 | 45 |
47 class TestClientImpl : public TestClient { | 46 class TestClientImpl : public TestClient { |
48 public: | 47 public: |
49 explicit TestClientImpl(TestServicePtr service) | 48 explicit TestClientImpl(TestServicePtr service) |
50 : service_(service.Pass()), | 49 : service_(service.Pass()), |
51 quit_after_ack_(false) { | 50 quit_after_ack_(false) { |
52 service_.set_client(this); | 51 service_.set_client(this); |
53 } | 52 } |
54 | 53 |
55 virtual ~TestClientImpl() {} | 54 virtual ~TestClientImpl() {} |
56 | 55 |
57 virtual void AckTest() OVERRIDE { | 56 virtual void AckTest() OVERRIDE { |
58 if (quit_after_ack_) | 57 if (quit_after_ack_) |
59 base::MessageLoop::current()->Quit(); | 58 base::MessageLoop::current()->Quit(); |
60 } | 59 } |
61 | 60 |
62 void Test(std::string test_string) { | 61 void Test(std::string test_string) { |
63 AllocationScope scope; | |
64 quit_after_ack_ = true; | 62 quit_after_ack_ = true; |
65 service_->Test(test_string); | 63 service_->Test(test_string); |
66 } | 64 } |
67 | 65 |
68 private: | 66 private: |
69 TestServicePtr service_; | 67 TestServicePtr service_; |
70 bool quit_after_ack_; | 68 bool quit_after_ack_; |
71 DISALLOW_COPY_AND_ASSIGN(TestClientImpl); | 69 DISALLOW_COPY_AND_ASSIGN(TestClientImpl); |
72 }; | 70 }; |
73 | 71 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 268 |
271 std::string url("test:test3"); | 269 std::string url("test:test3"); |
272 MessagePipe pipe1; | 270 MessagePipe pipe1; |
273 sm.Connect(GURL(url), pipe1.handle0.Pass()); | 271 sm.Connect(GURL(url), pipe1.handle0.Pass()); |
274 EXPECT_EQ(1, interceptor.call_count()); | 272 EXPECT_EQ(1, interceptor.call_count()); |
275 EXPECT_EQ(url, interceptor.url_spec()); | 273 EXPECT_EQ(url, interceptor.url_spec()); |
276 EXPECT_EQ(1, default_loader->num_loads()); | 274 EXPECT_EQ(1, default_loader->num_loads()); |
277 } | 275 } |
278 | 276 |
279 } // namespace mojo | 277 } // namespace mojo |
OLD | NEW |