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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "components/policy/core/common/policy_namespace.h" | 8 #include "components/policy/core/common/policy_namespace.h" |
9 #include "components/policy/core/common/schema.h" | 9 #include "components/policy/core/common/schema.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 combined.RemoveObserver(&observer); | 245 combined.RemoveObserver(&observer); |
246 } | 246 } |
247 | 247 |
248 TEST(SchemaRegistryTest, ForwardingSchemaRegistry) { | 248 TEST(SchemaRegistryTest, ForwardingSchemaRegistry) { |
249 scoped_ptr<SchemaRegistry> registry(new SchemaRegistry); | 249 scoped_ptr<SchemaRegistry> registry(new SchemaRegistry); |
250 ForwardingSchemaRegistry forwarding(registry.get()); | 250 ForwardingSchemaRegistry forwarding(registry.get()); |
251 MockSchemaRegistryObserver observer; | 251 MockSchemaRegistryObserver observer; |
252 forwarding.AddObserver(&observer); | 252 forwarding.AddObserver(&observer); |
253 | 253 |
254 EXPECT_FALSE(registry->IsReady()); | 254 EXPECT_FALSE(registry->IsReady()); |
255 // The ForwardingSchemaRegistry is always ready, even if the wrapped registry | 255 EXPECT_FALSE(forwarding.IsReady()); |
256 // isn't. | 256 // They always have the same SchemaMap. |
257 EXPECT_TRUE(forwarding.IsReady()); | |
258 // But they alreday have the same SchemaMap. | |
259 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); | 257 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); |
260 | 258 |
261 EXPECT_CALL(observer, OnSchemaRegistryUpdated(true)); | 259 EXPECT_CALL(observer, OnSchemaRegistryUpdated(true)); |
262 registry->RegisterComponent(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "abc"), | 260 registry->RegisterComponent(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "abc"), |
263 Schema()); | 261 Schema()); |
264 Mock::VerifyAndClearExpectations(&observer); | 262 Mock::VerifyAndClearExpectations(&observer); |
265 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); | 263 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); |
266 | 264 |
267 EXPECT_CALL(observer, OnSchemaRegistryUpdated(false)); | 265 EXPECT_CALL(observer, OnSchemaRegistryUpdated(false)); |
268 registry->UnregisterComponent( | 266 registry->UnregisterComponent( |
269 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "abc")); | 267 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "abc")); |
270 Mock::VerifyAndClearExpectations(&observer); | 268 Mock::VerifyAndClearExpectations(&observer); |
271 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); | 269 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); |
272 | 270 |
273 // No notifications expected for this call. | 271 // No notifications expected for these calls. |
274 EXPECT_FALSE(registry->IsReady()); | 272 EXPECT_FALSE(registry->IsReady()); |
| 273 EXPECT_FALSE(forwarding.IsReady()); |
| 274 |
275 registry->SetReady(POLICY_DOMAIN_CHROME); | 275 registry->SetReady(POLICY_DOMAIN_CHROME); |
| 276 EXPECT_FALSE(registry->IsReady()); |
| 277 EXPECT_FALSE(forwarding.IsReady()); |
| 278 |
276 registry->SetReady(POLICY_DOMAIN_EXTENSIONS); | 279 registry->SetReady(POLICY_DOMAIN_EXTENSIONS); |
277 EXPECT_TRUE(registry->IsReady()); | 280 EXPECT_TRUE(registry->IsReady()); |
| 281 // The ForwardingSchemaRegistry becomes ready independently of the wrapped |
| 282 // registry. |
| 283 EXPECT_FALSE(forwarding.IsReady()); |
| 284 |
278 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); | 285 EXPECT_TRUE(SchemaMapEquals(registry->schema_map(), forwarding.schema_map())); |
279 Mock::VerifyAndClearExpectations(&observer); | 286 Mock::VerifyAndClearExpectations(&observer); |
280 | 287 |
| 288 forwarding.SetReady(POLICY_DOMAIN_EXTENSIONS); |
| 289 EXPECT_FALSE(forwarding.IsReady()); |
| 290 Mock::VerifyAndClearExpectations(&observer); |
| 291 |
| 292 EXPECT_CALL(observer, OnSchemaRegistryReady()); |
| 293 forwarding.SetReady(POLICY_DOMAIN_CHROME); |
| 294 EXPECT_TRUE(forwarding.IsReady()); |
| 295 Mock::VerifyAndClearExpectations(&observer); |
| 296 |
281 // Keep the same SchemaMap when the original registry is gone. | 297 // Keep the same SchemaMap when the original registry is gone. |
282 // No notifications are expected in this case either. | 298 // No notifications are expected in this case either. |
283 scoped_refptr<SchemaMap> schema_map = registry->schema_map(); | 299 scoped_refptr<SchemaMap> schema_map = registry->schema_map(); |
284 registry.reset(); | 300 registry.reset(); |
285 EXPECT_TRUE(SchemaMapEquals(schema_map, forwarding.schema_map())); | 301 EXPECT_TRUE(SchemaMapEquals(schema_map, forwarding.schema_map())); |
286 Mock::VerifyAndClearExpectations(&observer); | 302 Mock::VerifyAndClearExpectations(&observer); |
287 | 303 |
288 forwarding.RemoveObserver(&observer); | 304 forwarding.RemoveObserver(&observer); |
289 } | 305 } |
290 | 306 |
291 } // namespace policy | 307 } // namespace policy |
OLD | NEW |