OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/policy/user_cloud_policy_manager.h" | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/message_loop.h" | |
10 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | |
11 #include "chrome/browser/policy/mock_user_cloud_policy_store.h" | |
12 #include "testing/gmock/include/gmock/gmock.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 namespace em = enterprise_management; | |
16 | |
17 using testing::AnyNumber; | |
18 using testing::AtLeast; | |
19 using testing::Mock; | |
20 using testing::_; | |
21 | |
22 namespace policy { | |
23 namespace { | |
24 | |
25 class UserCloudPolicyManagerTest : public testing::Test { | |
26 protected: | |
27 UserCloudPolicyManagerTest() | |
28 : store_(NULL) {} | |
29 | |
30 virtual void SetUp() OVERRIDE { | |
31 // Set up a policy map for testing. | |
32 policy_map_.Set("key", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | |
33 base::Value::CreateStringValue("value")); | |
34 expected_bundle_.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | |
35 .CopyFrom(policy_map_); | |
36 } | |
37 | |
38 virtual void TearDown() OVERRIDE { | |
39 if (manager_) { | |
40 manager_->RemoveObserver(&observer_); | |
41 manager_->Shutdown(); | |
42 } | |
43 } | |
44 | |
45 void CreateManager() { | |
46 store_ = new MockUserCloudPolicyStore(); | |
47 EXPECT_CALL(*store_, Load()); | |
48 manager_.reset( | |
49 new UserCloudPolicyManager(NULL, | |
50 scoped_ptr<UserCloudPolicyStore>(store_))); | |
51 manager_->Init(); | |
52 manager_->AddObserver(&observer_); | |
53 Mock::VerifyAndClearExpectations(store_); | |
54 } | |
55 | |
56 // Required by the refresh scheduler that's created by the manager. | |
57 MessageLoop loop_; | |
58 | |
59 // Convenience policy objects. | |
60 PolicyMap policy_map_; | |
61 PolicyBundle expected_bundle_; | |
62 | |
63 // Policy infrastructure. | |
64 MockConfigurationPolicyObserver observer_; | |
65 MockUserCloudPolicyStore* store_; | |
66 scoped_ptr<UserCloudPolicyManager> manager_; | |
67 | |
68 private: | |
69 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest); | |
70 }; | |
71 | |
72 TEST_F(UserCloudPolicyManagerTest, DisconnectAndRemovePolicy) { | |
73 // Load policy, make sure it goes away when DisconnectAndRemovePolicy() is | |
74 // called. | |
75 CreateManager(); | |
76 store_->policy_map_.CopyFrom(policy_map_); | |
77 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | |
78 store_->NotifyStoreLoaded(); | |
79 EXPECT_TRUE(expected_bundle_.Equals(manager_->policies())); | |
80 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); | |
81 EXPECT_CALL(*store_, Clear()); | |
82 manager_->DisconnectAndRemovePolicy(); | |
83 EXPECT_FALSE(manager_->core()->service()); | |
84 } | |
85 | |
86 } // namespace | |
87 } // namespace policy | |
OLD | NEW |