OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/policy/core/common/schema_registry.h" | 5 #include "components/policy/core/common/schema_registry.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "components/policy/core/common/policy_namespace.h" | 9 #include "components/policy/core/common/policy_namespace.h" |
10 #include "components/policy/core/common/schema.h" | 10 #include "components/policy/core/common/schema.h" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 242 |
243 EXPECT_CALL(observer, OnSchemaRegistryUpdated(false)); | 243 EXPECT_CALL(observer, OnSchemaRegistryUpdated(false)); |
244 registry2.reset(); | 244 registry2.reset(); |
245 Mock::VerifyAndClearExpectations(&observer); | 245 Mock::VerifyAndClearExpectations(&observer); |
246 | 246 |
247 combined.RemoveObserver(&observer); | 247 combined.RemoveObserver(&observer); |
248 } | 248 } |
249 | 249 |
250 TEST(SchemaRegistryTest, ForwardingSchemaRegistry) { | 250 TEST(SchemaRegistryTest, ForwardingSchemaRegistry) { |
251 std::unique_ptr<SchemaRegistry> registry(new SchemaRegistry); | 251 std::unique_ptr<SchemaRegistry> registry(new SchemaRegistry); |
252 ForwardingSchemaRegistry forwarding(registry.get()); | 252 ForwardingSchemaRegistry forwarding(registry.get(), |
| 253 false /* forward_readiness */); |
253 MockSchemaRegistryObserver observer; | 254 MockSchemaRegistryObserver observer; |
254 forwarding.AddObserver(&observer); | 255 forwarding.AddObserver(&observer); |
255 | 256 |
256 EXPECT_FALSE(registry->IsReady()); | 257 EXPECT_FALSE(registry->IsReady()); |
257 EXPECT_FALSE(forwarding.IsReady()); | 258 EXPECT_FALSE(forwarding.IsReady()); |
258 // They always have the same SchemaMap. | 259 // They always have the same SchemaMap. |
259 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); | 260 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); |
260 | 261 |
261 EXPECT_CALL(observer, OnSchemaRegistryUpdated(true)); | 262 EXPECT_CALL(observer, OnSchemaRegistryUpdated(true)); |
262 registry->RegisterComponent(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "abc"), | 263 registry->RegisterComponent(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "abc"), |
(...skipping 11 matching lines...) Expand all Loading... |
274 EXPECT_FALSE(registry->IsReady()); | 275 EXPECT_FALSE(registry->IsReady()); |
275 EXPECT_FALSE(forwarding.IsReady()); | 276 EXPECT_FALSE(forwarding.IsReady()); |
276 | 277 |
277 registry->SetReady(POLICY_DOMAIN_EXTENSIONS); | 278 registry->SetReady(POLICY_DOMAIN_EXTENSIONS); |
278 registry->SetReady(POLICY_DOMAIN_SIGNIN_EXTENSIONS); | 279 registry->SetReady(POLICY_DOMAIN_SIGNIN_EXTENSIONS); |
279 EXPECT_FALSE(registry->IsReady()); | 280 EXPECT_FALSE(registry->IsReady()); |
280 EXPECT_FALSE(forwarding.IsReady()); | 281 EXPECT_FALSE(forwarding.IsReady()); |
281 | 282 |
282 registry->SetReady(POLICY_DOMAIN_CHROME); | 283 registry->SetReady(POLICY_DOMAIN_CHROME); |
283 EXPECT_TRUE(registry->IsReady()); | 284 EXPECT_TRUE(registry->IsReady()); |
284 // The ForwardingSchemaRegistry becomes ready independently of the wrapped | 285 // The ForwardingSchemaRegistry, if constructed with forward_readiness |
| 286 // parameter equal to false, becomes ready independently of the wrapped |
285 // registry. | 287 // registry. |
286 EXPECT_FALSE(forwarding.IsReady()); | 288 EXPECT_FALSE(forwarding.IsReady()); |
287 | 289 |
288 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); | 290 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); |
289 Mock::VerifyAndClearExpectations(&observer); | 291 Mock::VerifyAndClearExpectations(&observer); |
290 | 292 |
291 forwarding.SetReady(POLICY_DOMAIN_EXTENSIONS); | 293 forwarding.SetReady(POLICY_DOMAIN_EXTENSIONS); |
292 forwarding.SetReady(POLICY_DOMAIN_SIGNIN_EXTENSIONS); | 294 forwarding.SetReady(POLICY_DOMAIN_SIGNIN_EXTENSIONS); |
293 EXPECT_FALSE(forwarding.IsReady()); | 295 EXPECT_FALSE(forwarding.IsReady()); |
294 Mock::VerifyAndClearExpectations(&observer); | 296 Mock::VerifyAndClearExpectations(&observer); |
295 | 297 |
296 EXPECT_CALL(observer, OnSchemaRegistryReady()); | 298 EXPECT_CALL(observer, OnSchemaRegistryReady()); |
297 forwarding.SetReady(POLICY_DOMAIN_CHROME); | 299 forwarding.SetReady(POLICY_DOMAIN_CHROME); |
298 EXPECT_TRUE(forwarding.IsReady()); | 300 EXPECT_TRUE(forwarding.IsReady()); |
299 Mock::VerifyAndClearExpectations(&observer); | 301 Mock::VerifyAndClearExpectations(&observer); |
300 | 302 |
301 // Keep the same SchemaMap when the original registry is gone. | 303 // Keep the same SchemaMap when the original registry is gone. |
302 // No notifications are expected in this case either. | 304 // No notifications are expected in this case either. |
303 scoped_refptr<SchemaMap> schema_map = registry->schema_map(); | 305 scoped_refptr<SchemaMap> schema_map = registry->schema_map(); |
304 registry.reset(); | 306 registry.reset(); |
305 EXPECT_TRUE(SchemaMapEquals(schema_map, forwarding.schema_map())); | 307 EXPECT_TRUE(SchemaMapEquals(schema_map, forwarding.schema_map())); |
306 Mock::VerifyAndClearExpectations(&observer); | 308 Mock::VerifyAndClearExpectations(&observer); |
307 | 309 |
308 forwarding.RemoveObserver(&observer); | 310 forwarding.RemoveObserver(&observer); |
309 } | 311 } |
310 | 312 |
| 313 TEST(SchemaRegistryTest, ReadinessForwardingSchemaRegistry) { |
| 314 // Test ForwardingSchemaRegistry when constructed with forward_readiness equal |
| 315 // to true. |
| 316 |
| 317 std::unique_ptr<SchemaRegistry> registry(new SchemaRegistry); |
| 318 |
| 319 ForwardingSchemaRegistry forwarding_1(registry.get(), |
| 320 true /* forward_readiness */); |
| 321 EXPECT_FALSE(registry->IsReady()); |
| 322 EXPECT_FALSE(forwarding_1.IsReady()); |
| 323 |
| 324 // Once the wrapped registry gets ready, the forwarding schema registry |
| 325 // becomes ready too. |
| 326 registry->SetReady(POLICY_DOMAIN_CHROME); |
| 327 registry->SetReady(POLICY_DOMAIN_EXTENSIONS); |
| 328 registry->SetReady(POLICY_DOMAIN_SIGNIN_EXTENSIONS); |
| 329 EXPECT_TRUE(registry->IsReady()); |
| 330 EXPECT_TRUE(forwarding_1.IsReady()); |
| 331 |
| 332 // The wrapped registry was ready at the time when the forwarding registry was |
| 333 // constructed, so the forwarding registry is immediately ready too. |
| 334 ForwardingSchemaRegistry forwarding_2(registry.get(), |
| 335 true /* forward_readiness */); |
| 336 EXPECT_TRUE(forwarding_2.IsReady()); |
| 337 |
| 338 // Destruction of the wrapped registry doesn't change the readiness of |
| 339 // forwarding registry. |
| 340 registry.reset(); |
| 341 EXPECT_TRUE(forwarding_1.IsReady()); |
| 342 EXPECT_TRUE(forwarding_2.IsReady()); |
| 343 } |
| 344 |
311 } // namespace policy | 345 } // namespace policy |
OLD | NEW |