OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/process/process_handle.h" | 15 #include "base/process/process_handle.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "mojo/public/cpp/bindings/binding_set.h" | 17 #include "mojo/public/cpp/bindings/binding_set.h" |
18 #include "services/service_manager/public/cpp/interface_factory.h" | 18 #include "services/service_manager/public/cpp/interface_factory.h" |
19 #include "services/service_manager/public/cpp/service.h" | 19 #include "services/service_manager/public/cpp/service.h" |
20 #include "services/service_manager/public/cpp/service_test.h" | 20 #include "services/service_manager/public/cpp/service_test.h" |
21 #include "services/service_manager/public/interfaces/service_manager.mojom.h" | 21 #include "services/service_manager/public/interfaces/service_manager.mojom.h" |
22 #include "services/service_manager/tests/shell/shell_unittest.mojom.h" | 22 #include "services/service_manager/tests/shell/shell_unittest.mojom.h" |
23 | 23 |
24 namespace shell { | 24 namespace service_manager { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 class ShellTestClient | 28 class ShellTestClient |
29 : public test::ServiceTestClient, | 29 : public test::ServiceTestClient, |
30 public InterfaceFactory<test::mojom::CreateInstanceTest>, | 30 public InterfaceFactory<test::mojom::CreateInstanceTest>, |
31 public test::mojom::CreateInstanceTest { | 31 public test::mojom::CreateInstanceTest { |
32 public: | 32 public: |
33 explicit ShellTestClient(test::ServiceTest* test) | 33 explicit ShellTestClient(test::ServiceTest* test) |
34 : test::ServiceTestClient(test), | 34 : test::ServiceTestClient(test), |
(...skipping 11 matching lines...) Expand all Loading... |
46 } | 46 } |
47 | 47 |
48 // InterfaceFactory<test::mojom::CreateInstanceTest>: | 48 // InterfaceFactory<test::mojom::CreateInstanceTest>: |
49 void Create( | 49 void Create( |
50 const Identity& remote_identity, | 50 const Identity& remote_identity, |
51 test::mojom::CreateInstanceTestRequest request) override { | 51 test::mojom::CreateInstanceTestRequest request) override { |
52 binding_.Bind(std::move(request)); | 52 binding_.Bind(std::move(request)); |
53 } | 53 } |
54 | 54 |
55 // test::mojom::CreateInstanceTest: | 55 // test::mojom::CreateInstanceTest: |
56 void SetTargetIdentity(const shell::Identity& identity) override { | 56 void SetTargetIdentity(const service_manager::Identity& identity) override { |
57 target_identity_ = identity; | 57 target_identity_ = identity; |
58 base::MessageLoop::current()->QuitWhenIdle(); | 58 base::MessageLoop::current()->QuitWhenIdle(); |
59 } | 59 } |
60 | 60 |
61 shell::Identity target_identity_; | 61 service_manager::Identity target_identity_; |
62 | 62 |
63 mojo::Binding<test::mojom::CreateInstanceTest> binding_; | 63 mojo::Binding<test::mojom::CreateInstanceTest> binding_; |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(ShellTestClient); | 65 DISALLOW_COPY_AND_ASSIGN(ShellTestClient); |
66 }; | 66 }; |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 class ShellTest : public test::ServiceTest, | 70 class ShellTest : public test::ServiceTest, |
71 public mojom::ServiceManagerListener { | 71 public mojom::ServiceManagerListener { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 void OnInit(std::vector<mojom::ServiceInfoPtr> instances) override { | 131 void OnInit(std::vector<mojom::ServiceInfoPtr> instances) override { |
132 for (size_t i = 0; i < instances.size(); ++i) | 132 for (size_t i = 0; i < instances.size(); ++i) |
133 initial_instances_.push_back(InstanceInfo(instances[i]->identity)); | 133 initial_instances_.push_back(InstanceInfo(instances[i]->identity)); |
134 | 134 |
135 DCHECK(wait_for_instances_loop_); | 135 DCHECK(wait_for_instances_loop_); |
136 wait_for_instances_loop_->Quit(); | 136 wait_for_instances_loop_->Quit(); |
137 } | 137 } |
138 void OnServiceCreated(mojom::ServiceInfoPtr instance) override { | 138 void OnServiceCreated(mojom::ServiceInfoPtr instance) override { |
139 instances_.push_back(InstanceInfo(instance->identity)); | 139 instances_.push_back(InstanceInfo(instance->identity)); |
140 } | 140 } |
141 void OnServiceStarted(const shell::Identity& identity, | 141 void OnServiceStarted(const service_manager::Identity& identity, |
142 uint32_t pid) override { | 142 uint32_t pid) override { |
143 for (auto& instance : instances_) { | 143 for (auto& instance : instances_) { |
144 if (instance.identity == identity) { | 144 if (instance.identity == identity) { |
145 instance.pid = pid; | 145 instance.pid = pid; |
146 break; | 146 break; |
147 } | 147 } |
148 } | 148 } |
149 } | 149 } |
150 void OnServiceStopped(const shell::Identity& identity) override { | 150 void OnServiceStopped(const service_manager::Identity& identity) override { |
151 for (auto it = instances_.begin(); it != instances_.end(); ++it) { | 151 for (auto it = instances_.begin(); it != instances_.end(); ++it) { |
152 auto& instance = *it; | 152 auto& instance = *it; |
153 if (instance.identity == identity) { | 153 if (instance.identity == identity) { |
154 instances_.erase(it); | 154 instances_.erase(it); |
155 break; | 155 break; |
156 } | 156 } |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 ShellTestClient* service_; | 160 ShellTestClient* service_; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 EXPECT_NE(base::kNullProcessId, instance.pid); | 205 EXPECT_NE(base::kNullProcessId, instance.pid); |
206 } | 206 } |
207 | 207 |
208 driver.set_connection_error_handler( | 208 driver.set_connection_error_handler( |
209 base::Bind(&ShellTest::OnDriverQuit, | 209 base::Bind(&ShellTest::OnDriverQuit, |
210 base::Unretained(this))); | 210 base::Unretained(this))); |
211 driver->QuitDriver(); | 211 driver->QuitDriver(); |
212 base::RunLoop().Run(); | 212 base::RunLoop().Run(); |
213 } | 213 } |
214 | 214 |
215 } // namespace shell | 215 } // namespace service_manager |
OLD | NEW |