OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <memory> | 5 #include <memory> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "components/arc/arc_bridge_service.h" | 10 #include "components/arc/arc_bridge_service.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 172 |
173 EXPECT_TRUE(manager->AddService(base::MakeUnique<EmptyNamedService>( | 173 EXPECT_TRUE(manager->AddService(base::MakeUnique<EmptyNamedService>( |
174 arc_bridge_service(), &empty_named_service_alive))); | 174 arc_bridge_service(), &empty_named_service_alive))); |
175 EXPECT_TRUE(empty_named_service_alive); | 175 EXPECT_TRUE(empty_named_service_alive); |
176 EXPECT_EQ(nullptr, manager->GetService<EmptyNamedService>()); | 176 EXPECT_EQ(nullptr, manager->GetService<EmptyNamedService>()); |
177 | 177 |
178 manager.reset(); | 178 manager.reset(); |
179 EXPECT_FALSE(empty_named_service_alive); | 179 EXPECT_FALSE(empty_named_service_alive); |
180 } | 180 } |
181 | 181 |
| 182 // Tests if GetGlobalService works as expected regardless of whether the |
| 183 // global pointer is null. |
| 184 TEST_F(ArcServiceManagerTest, TestGetGlobalService) { |
| 185 // The getter should return nullptr when no global instance is available. |
| 186 EXPECT_EQ(nullptr, ArcServiceManager::GetGlobalService<NamedService>()); |
| 187 |
| 188 // Create a manager. This will automatically be registered as a global |
| 189 // instance. |
| 190 auto manager = base::MakeUnique<ArcServiceManager>(nullptr); |
| 191 |
| 192 // The getter should return nullptr when the manager doesn't know about the |
| 193 // NamedService instance. |
| 194 EXPECT_EQ(nullptr, ArcServiceManager::GetGlobalService<NamedService>()); |
| 195 |
| 196 // Register the instance and retry. The getter should return non-null this |
| 197 // time. |
| 198 bool unused; |
| 199 EXPECT_TRUE(manager->AddService(base::MakeUnique<NamedService>( |
| 200 arc_bridge_service(), &unused))); |
| 201 EXPECT_NE(nullptr, ArcServiceManager::GetGlobalService<NamedService>()); |
| 202 |
| 203 // Remove the global instance. The same GetGlobalService() call should return |
| 204 // nullptr now. |
| 205 manager.reset(); |
| 206 EXPECT_EQ(nullptr, ArcServiceManager::GetGlobalService<NamedService>()); |
| 207 } |
| 208 |
182 } // namespace arc | 209 } // namespace arc |
OLD | NEW |