OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
8 #include "chrome/browser/browser_thread.h" | 8 #include "chrome/browser/browser_thread.h" |
9 #include "chrome/browser/net/gaia/token_service.h" | 9 #include "chrome/browser/net/gaia/token_service.h" |
10 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 10 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 public: | 32 public: |
33 DeviceManagementPolicyProviderTest() | 33 DeviceManagementPolicyProviderTest() |
34 : ui_thread_(BrowserThread::UI, &loop_), | 34 : ui_thread_(BrowserThread::UI, &loop_), |
35 file_thread_(BrowserThread::FILE, &loop_) {} | 35 file_thread_(BrowserThread::FILE, &loop_) {} |
36 | 36 |
37 virtual ~DeviceManagementPolicyProviderTest() {} | 37 virtual ~DeviceManagementPolicyProviderTest() {} |
38 | 38 |
39 virtual void SetUp() { | 39 virtual void SetUp() { |
40 profile_.reset(new TestingProfile); | 40 profile_.reset(new TestingProfile); |
41 CreateNewProvider(); | 41 CreateNewProvider(); |
42 EXPECT_TRUE(provider_->waiting_for_initial_policies()); | 42 EXPECT_TRUE(waiting_for_initial_policies()); |
43 loop_.RunAllPending(); | 43 loop_.RunAllPending(); |
44 } | 44 } |
45 | 45 |
46 void CreateNewProvider() { | 46 void CreateNewProvider() { |
47 backend_ = new MockDeviceManagementBackend; | 47 backend_ = new MockDeviceManagementBackend; |
48 provider_.reset(new DeviceManagementPolicyProvider( | 48 provider_.reset(new DeviceManagementPolicyProvider( |
49 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), | 49 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), |
50 backend_, | 50 backend_, |
51 profile_.get())); | 51 profile_.get())); |
52 provider_->SetDeviceTokenFetcher( | 52 provider_->SetDeviceTokenFetcher( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 } | 92 } |
93 | 93 |
94 void SimulateSuccessfulInitialPolicyFetch() { | 94 void SimulateSuccessfulInitialPolicyFetch() { |
95 MockConfigurationPolicyStore store; | 95 MockConfigurationPolicyStore store; |
96 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 96 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
97 MockDeviceManagementBackendSucceedRegister()); | 97 MockDeviceManagementBackendSucceedRegister()); |
98 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 98 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
99 MockDeviceManagementBackendSucceedBooleanPolicy( | 99 MockDeviceManagementBackendSucceedBooleanPolicy( |
100 key::kDisableSpdy, true)); | 100 key::kDisableSpdy, true)); |
101 SimulateSuccessfulLoginAndRunPending(); | 101 SimulateSuccessfulLoginAndRunPending(); |
102 EXPECT_FALSE(provider_->waiting_for_initial_policies()); | 102 EXPECT_FALSE(waiting_for_initial_policies()); |
103 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); | 103 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); |
104 provider_->Provide(&store); | 104 provider_->Provide(&store); |
105 ASSERT_EQ(1U, store.policy_map().size()); | 105 ASSERT_EQ(1U, store.policy_map().size()); |
106 Mock::VerifyAndClearExpectations(backend_); | 106 Mock::VerifyAndClearExpectations(backend_); |
107 Mock::VerifyAndClearExpectations(&store); | 107 Mock::VerifyAndClearExpectations(&store); |
108 } | 108 } |
109 | 109 |
110 virtual void TearDown() { | 110 virtual void TearDown() { |
111 loop_.RunAllPending(); | 111 loop_.RunAllPending(); |
112 } | 112 } |
113 | 113 |
114 bool waiting_for_initial_policies() { | |
danno
2010/12/22 14:00:19
const
Mattias Nissler (ping if slow)
2010/12/22 14:11:04
Done.
| |
115 return provider_->waiting_for_initial_policies_; | |
116 } | |
117 | |
114 MockDeviceManagementBackend* backend_; // weak | 118 MockDeviceManagementBackend* backend_; // weak |
115 scoped_ptr<DeviceManagementPolicyProvider> provider_; | 119 scoped_ptr<DeviceManagementPolicyProvider> provider_; |
116 | 120 |
117 protected: | 121 protected: |
118 DeviceManagementPolicyCache* cache(DeviceManagementPolicyProvider* provider) { | 122 DeviceManagementPolicyCache* cache(DeviceManagementPolicyProvider* provider) { |
119 return provider->cache_.get(); | 123 return provider->cache_.get(); |
120 } | 124 } |
121 | 125 |
122 MessageLoop loop_; | 126 MessageLoop loop_; |
123 | 127 |
124 private: | 128 private: |
125 BrowserThread ui_thread_; | 129 BrowserThread ui_thread_; |
126 BrowserThread file_thread_; | 130 BrowserThread file_thread_; |
127 scoped_ptr<Profile> profile_; | 131 scoped_ptr<Profile> profile_; |
128 | 132 |
129 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest); | 133 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest); |
130 }; | 134 }; |
131 | 135 |
132 // If there's no login and no previously-fetched policy, the provider should | 136 // If there's no login and no previously-fetched policy, the provider should |
133 // provide an empty policy. | 137 // provide an empty policy. |
134 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideNoLogin) { | 138 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideNoLogin) { |
135 MockConfigurationPolicyStore store; | 139 MockConfigurationPolicyStore store; |
136 EXPECT_CALL(store, Apply(_, _)).Times(0); | 140 EXPECT_CALL(store, Apply(_, _)).Times(0); |
137 provider_->Provide(&store); | 141 provider_->Provide(&store); |
138 EXPECT_TRUE(store.policy_map().empty()); | 142 EXPECT_TRUE(store.policy_map().empty()); |
139 EXPECT_TRUE(provider_->waiting_for_initial_policies()); | 143 EXPECT_TRUE(waiting_for_initial_policies()); |
140 } | 144 } |
141 | 145 |
142 // If the login is successful and there's no previously-fetched policy, the | 146 // If the login is successful and there's no previously-fetched policy, the |
143 // policy should be fetched from the server and should be available the first | 147 // policy should be fetched from the server and should be available the first |
144 // time the Provide method is called. | 148 // time the Provide method is called. |
145 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideWithLogin) { | 149 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideWithLogin) { |
146 EXPECT_TRUE(provider_->waiting_for_initial_policies()); | 150 EXPECT_TRUE(waiting_for_initial_policies()); |
147 SimulateSuccessfulInitialPolicyFetch(); | 151 SimulateSuccessfulInitialPolicyFetch(); |
148 } | 152 } |
149 | 153 |
150 // If the login succeed but the device management backend is unreachable, | 154 // If the login succeed but the device management backend is unreachable, |
151 // there should be no policy provided if there's no previously-fetched policy, | 155 // there should be no policy provided if there's no previously-fetched policy, |
152 TEST_F(DeviceManagementPolicyProviderTest, EmptyProvideWithFailedBackend) { | 156 TEST_F(DeviceManagementPolicyProviderTest, EmptyProvideWithFailedBackend) { |
153 MockConfigurationPolicyStore store; | 157 MockConfigurationPolicyStore store; |
154 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 158 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
155 MockDeviceManagementBackendFailRegister( | 159 MockDeviceManagementBackendFailRegister( |
156 DeviceManagementBackend::kErrorRequestFailed)); | 160 DeviceManagementBackend::kErrorRequestFailed)); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 302 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
299 MockDeviceManagementBackendFailRegister( | 303 MockDeviceManagementBackendFailRegister( |
300 DeviceManagementBackend::kErrorServiceManagementNotSupported)); | 304 DeviceManagementBackend::kErrorServiceManagementNotSupported)); |
301 SimulateSuccessfulLoginAndRunPending(); | 305 SimulateSuccessfulLoginAndRunPending(); |
302 // (1) The provider's DMPolicyCache should know that the device is not | 306 // (1) The provider's DMPolicyCache should know that the device is not |
303 // managed. | 307 // managed. |
304 EXPECT_TRUE(cache(provider_.get())->is_device_unmanaged()); | 308 EXPECT_TRUE(cache(provider_.get())->is_device_unmanaged()); |
305 // (2) On restart, the provider should detect that this is not the first | 309 // (2) On restart, the provider should detect that this is not the first |
306 // login. | 310 // login. |
307 CreateNewProvider(1000*1000, 0, 0, 0, 0); | 311 CreateNewProvider(1000*1000, 0, 0, 0, 0); |
308 EXPECT_FALSE(provider_->waiting_for_initial_policies()); | 312 EXPECT_FALSE(waiting_for_initial_policies()); |
309 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 313 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
310 MockDeviceManagementBackendSucceedRegister()); | 314 MockDeviceManagementBackendSucceedRegister()); |
311 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 315 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
312 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); | 316 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); |
313 SimulateSuccessfulLoginAndRunPending(); | 317 SimulateSuccessfulLoginAndRunPending(); |
314 // (3) Since the backend call this time returned a device id, the "unmanaged" | 318 // (3) Since the backend call this time returned a device id, the "unmanaged" |
315 // marker should have been deleted. | 319 // marker should have been deleted. |
316 EXPECT_FALSE(cache(provider_.get())->is_device_unmanaged()); | 320 EXPECT_FALSE(cache(provider_.get())->is_device_unmanaged()); |
317 } | 321 } |
318 | 322 |
319 } // namespace policy | 323 } // namespace policy |
OLD | NEW |