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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); | 270 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); |
271 | 271 |
272 // No notifications expected for these calls. | 272 // No notifications expected for these calls. |
273 EXPECT_FALSE(registry->IsReady()); | 273 EXPECT_FALSE(registry->IsReady()); |
274 EXPECT_FALSE(forwarding.IsReady()); | 274 EXPECT_FALSE(forwarding.IsReady()); |
275 | 275 |
276 registry->SetExtensionsDomainsReady(); | 276 registry->SetExtensionsDomainsReady(); |
277 EXPECT_FALSE(registry->IsReady()); | 277 EXPECT_FALSE(registry->IsReady()); |
278 EXPECT_FALSE(forwarding.IsReady()); | 278 EXPECT_FALSE(forwarding.IsReady()); |
279 | 279 |
| 280 EXPECT_CALL(observer, OnSchemaRegistryReady()); |
280 registry->SetDomainReady(POLICY_DOMAIN_CHROME); | 281 registry->SetDomainReady(POLICY_DOMAIN_CHROME); |
281 EXPECT_TRUE(registry->IsReady()); | 282 EXPECT_TRUE(registry->IsReady()); |
282 // The ForwardingSchemaRegistry becomes ready independently of the wrapped | 283 EXPECT_TRUE(forwarding.IsReady()); |
283 // registry. | 284 Mock::VerifyAndClearExpectations(&observer); |
284 EXPECT_FALSE(forwarding.IsReady()); | |
285 | 285 |
286 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); | 286 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); |
287 Mock::VerifyAndClearExpectations(&observer); | 287 Mock::VerifyAndClearExpectations(&observer); |
288 | 288 |
289 forwarding.SetExtensionsDomainsReady(); | 289 forwarding.SetExtensionsDomainsReady(); |
290 EXPECT_FALSE(forwarding.IsReady()); | |
291 Mock::VerifyAndClearExpectations(&observer); | |
292 | |
293 EXPECT_CALL(observer, OnSchemaRegistryReady()); | |
294 forwarding.SetDomainReady(POLICY_DOMAIN_CHROME); | 290 forwarding.SetDomainReady(POLICY_DOMAIN_CHROME); |
295 EXPECT_TRUE(forwarding.IsReady()); | 291 EXPECT_TRUE(forwarding.IsReady()); |
296 Mock::VerifyAndClearExpectations(&observer); | |
297 | 292 |
298 // Keep the same SchemaMap when the original registry is gone. | 293 // Keep the same SchemaMap when the original registry is gone. |
299 // No notifications are expected in this case either. | 294 // No notifications are expected in this case either. |
300 scoped_refptr<SchemaMap> schema_map = registry->schema_map(); | 295 scoped_refptr<SchemaMap> schema_map = registry->schema_map(); |
301 registry.reset(); | 296 registry.reset(); |
302 EXPECT_TRUE(SchemaMapEquals(schema_map, forwarding.schema_map())); | 297 EXPECT_TRUE(SchemaMapEquals(schema_map, forwarding.schema_map())); |
303 Mock::VerifyAndClearExpectations(&observer); | 298 Mock::VerifyAndClearExpectations(&observer); |
304 | 299 |
305 forwarding.RemoveObserver(&observer); | 300 forwarding.RemoveObserver(&observer); |
306 } | 301 } |
307 | 302 |
| 303 TEST(SchemaRegistryTest, ForwardingSchemaRegistryReadiness) { |
| 304 std::unique_ptr<SchemaRegistry> registry(new SchemaRegistry); |
| 305 |
| 306 ForwardingSchemaRegistry forwarding_1(registry.get()); |
| 307 EXPECT_FALSE(registry->IsReady()); |
| 308 EXPECT_FALSE(forwarding_1.IsReady()); |
| 309 |
| 310 // Once the wrapped registry gets ready, the forwarding schema registry |
| 311 // becomes ready too. |
| 312 registry->SetAllDomainsReady(); |
| 313 EXPECT_TRUE(registry->IsReady()); |
| 314 EXPECT_TRUE(forwarding_1.IsReady()); |
| 315 |
| 316 // The wrapped registry was ready at the time when the forwarding registry was |
| 317 // constructed, so the forwarding registry is immediately ready too. |
| 318 ForwardingSchemaRegistry forwarding_2(registry.get()); |
| 319 EXPECT_TRUE(forwarding_2.IsReady()); |
| 320 |
| 321 // Destruction of the wrapped registry doesn't change the readiness of the |
| 322 // forwarding registry. |
| 323 registry.reset(); |
| 324 EXPECT_TRUE(forwarding_1.IsReady()); |
| 325 EXPECT_TRUE(forwarding_2.IsReady()); |
| 326 } |
| 327 |
308 } // namespace policy | 328 } // namespace policy |
OLD | NEW |