| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 11 #include "chrome/browser/policy/configuration_policy_provider.h" | 11 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 12 #include "chrome/browser/policy/device_management_policy_cache.h" | 12 #include "chrome/browser/policy/device_management_policy_cache.h" |
| 13 #include "chrome/browser/policy/device_management_policy_provider.h" | 13 #include "chrome/browser/policy/device_management_policy_provider.h" |
| 14 #include "chrome/browser/policy/mock_configuration_policy_store.h" | 14 #include "chrome/browser/policy/mock_configuration_policy_store.h" |
| 15 #include "chrome/browser/policy/mock_device_management_backend.h" | 15 #include "chrome/browser/policy/mock_device_management_backend.h" |
| 16 #include "chrome/common/net/gaia/gaia_constants.h" | 16 #include "chrome/common/net/gaia/gaia_constants.h" |
| 17 #include "chrome/common/notification_observer_mock.h" | 17 #include "chrome/common/notification_observer_mock.h" |
| 18 #include "chrome/common/notification_service.h" | 18 #include "chrome/common/notification_service.h" |
| 19 #include "chrome/common/policy_constants.h" | 19 #include "chrome/common/policy_constants.h" |
| 20 #include "chrome/test/testing_device_token_fetcher.h" | 20 #include "chrome/test/testing_device_token_fetcher.h" |
| 21 #include "chrome/test/testing_profile.h" | 21 #include "chrome/test/testing_profile.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 const char kTestToken[] = "device_policy_provider_test_auth_token"; | 25 const char kTestToken[] = "device_policy_provider_test_auth_token"; |
| 26 | 26 |
| 27 namespace policy { | 27 namespace policy { |
| 28 | 28 |
| 29 using ::testing::_; | 29 using ::testing::_; |
| 30 using ::testing::AtLeast; |
| 30 using ::testing::InSequence; | 31 using ::testing::InSequence; |
| 31 using ::testing::Mock; | 32 using ::testing::Mock; |
| 32 | 33 |
| 33 class MockConfigurationPolicyObserver | 34 class MockConfigurationPolicyObserver |
| 34 : public ConfigurationPolicyProvider::Observer { | 35 : public ConfigurationPolicyProvider::Observer { |
| 35 public: | 36 public: |
| 36 MOCK_METHOD0(OnUpdatePolicy, void()); | 37 MOCK_METHOD0(OnUpdatePolicy, void()); |
| 37 void OnProviderGoingAway() {} | 38 void OnProviderGoingAway() {} |
| 38 }; | 39 }; |
| 39 | 40 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 58 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), | 59 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), |
| 59 backend_, | 60 backend_, |
| 60 profile_.get())); | 61 profile_.get())); |
| 61 provider_->SetDeviceTokenFetcher( | 62 provider_->SetDeviceTokenFetcher( |
| 62 new TestingDeviceTokenFetcher(backend_, | 63 new TestingDeviceTokenFetcher(backend_, |
| 63 profile_.get(), | 64 profile_.get(), |
| 64 provider_->GetTokenPath())); | 65 provider_->GetTokenPath())); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void CreateNewProvider(int64 policy_refresh_rate_ms, | 68 void CreateNewProvider(int64 policy_refresh_rate_ms, |
| 68 int64 policy_refresh_max_earlier_ms, | 69 int policy_refresh_fuzz_factor_percent, |
| 70 int64 policy_refresh_fuzz_max, |
| 69 int64 policy_refresh_error_delay_ms, | 71 int64 policy_refresh_error_delay_ms, |
| 70 int64 token_fetch_error_delay_ms, | 72 int64 token_fetch_error_delay_ms, |
| 71 int64 unmanaged_device_refresh_rate_ms) { | 73 int64 unmanaged_device_refresh_rate_ms) { |
| 72 backend_ = new MockDeviceManagementBackend; | 74 backend_ = new MockDeviceManagementBackend; |
| 73 provider_.reset(new DeviceManagementPolicyProvider( | 75 provider_.reset(new DeviceManagementPolicyProvider( |
| 74 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), | 76 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), |
| 75 backend_, | 77 backend_, |
| 76 profile_.get(), | 78 profile_.get(), |
| 77 policy_refresh_rate_ms, | 79 policy_refresh_rate_ms, |
| 78 policy_refresh_max_earlier_ms, | 80 policy_refresh_fuzz_factor_percent, |
| 81 policy_refresh_fuzz_max, |
| 79 policy_refresh_error_delay_ms, | 82 policy_refresh_error_delay_ms, |
| 80 token_fetch_error_delay_ms, | 83 token_fetch_error_delay_ms, |
| 81 unmanaged_device_refresh_rate_ms)); | 84 unmanaged_device_refresh_rate_ms)); |
| 82 provider_->SetDeviceTokenFetcher( | 85 provider_->SetDeviceTokenFetcher( |
| 83 new TestingDeviceTokenFetcher(backend_, | 86 new TestingDeviceTokenFetcher(backend_, |
| 84 profile_.get(), | 87 profile_.get(), |
| 85 provider_->GetTokenPath())); | 88 provider_->GetTokenPath())); |
| 86 } | 89 } |
| 87 | 90 |
| 88 FilePath GetTokenPath() const { | 91 FilePath GetTokenPath() const { |
| 89 return provider_->GetTokenPath(); | 92 return provider_->GetTokenPath(); |
| 90 } | 93 } |
| 91 | 94 |
| 92 void SimulateSuccessfulLoginAndRunPending() { | 95 void SimulateSuccessfulLoginAndRunPending() { |
| 96 // Make sure the notification for the initial policy fetch is generated. |
| 97 MockConfigurationPolicyObserver observer; |
| 98 ConfigurationPolicyObserverRegistrar registrar; |
| 99 registrar.Init(provider_.get(), &observer); |
| 100 EXPECT_CALL(observer, OnUpdatePolicy()).Times(AtLeast(1)); |
| 101 |
| 93 loop_.RunAllPending(); | 102 loop_.RunAllPending(); |
| 94 profile_->GetTokenService()->IssueAuthTokenForTest( | 103 profile_->GetTokenService()->IssueAuthTokenForTest( |
| 95 GaiaConstants::kDeviceManagementService, kTestToken); | 104 GaiaConstants::kDeviceManagementService, kTestToken); |
| 96 TestingDeviceTokenFetcher* fetcher = | 105 TestingDeviceTokenFetcher* fetcher = |
| 97 static_cast<TestingDeviceTokenFetcher*>( | 106 static_cast<TestingDeviceTokenFetcher*>( |
| 98 provider_->token_fetcher_.get()); | 107 provider_->token_fetcher_.get()); |
| 99 fetcher->SimulateLogin(kTestManagedDomainUsername); | 108 fetcher->SimulateLogin(kTestManagedDomainUsername); |
| 100 loop_.RunAllPending(); | 109 loop_.RunAllPending(); |
| 101 } | 110 } |
| 102 | 111 |
| 103 void SimulateSuccessfulInitialPolicyFetch() { | 112 void SimulateSuccessfulInitialPolicyFetch() { |
| 104 MockConfigurationPolicyStore store; | 113 MockConfigurationPolicyStore store; |
| 105 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 114 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 106 MockDeviceManagementBackendSucceedRegister()); | 115 MockDeviceManagementBackendSucceedRegister()); |
| 107 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 116 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 108 MockDeviceManagementBackendSucceedBooleanPolicy( | 117 MockDeviceManagementBackendSucceedBooleanPolicy( |
| 109 key::kDisableSpdy, true)); | 118 key::kDisableSpdy, true)); |
| 110 SimulateSuccessfulLoginAndRunPending(); | 119 SimulateSuccessfulLoginAndRunPending(); |
| 111 EXPECT_FALSE(waiting_for_initial_policies()); | 120 EXPECT_FALSE(waiting_for_initial_policies()); |
| 112 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); | 121 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); |
| 113 provider_->Provide(&store); | 122 provider_->Provide(&store); |
| 114 ASSERT_EQ(1U, store.policy_map().size()); | 123 ASSERT_EQ(1U, store.policy_map().size()); |
| 115 Mock::VerifyAndClearExpectations(backend_); | 124 Mock::VerifyAndClearExpectations(backend_); |
| 116 Mock::VerifyAndClearExpectations(&store); | 125 Mock::VerifyAndClearExpectations(&store); |
| 117 } | 126 } |
| 118 | 127 |
| 119 virtual void TearDown() { | 128 virtual void TearDown() { |
| 129 provider_.reset(); |
| 120 loop_.RunAllPending(); | 130 loop_.RunAllPending(); |
| 121 } | 131 } |
| 122 | 132 |
| 123 bool waiting_for_initial_policies() const { | 133 bool waiting_for_initial_policies() const { |
| 124 return provider_->waiting_for_initial_policies_; | 134 return !provider_->IsInitializationComplete(); |
| 125 } | 135 } |
| 126 | 136 |
| 127 MockDeviceManagementBackend* backend_; // weak | 137 MockDeviceManagementBackend* backend_; // weak |
| 128 scoped_ptr<DeviceManagementPolicyProvider> provider_; | 138 scoped_ptr<DeviceManagementPolicyProvider> provider_; |
| 129 | 139 |
| 130 protected: | 140 protected: |
| 131 DeviceManagementPolicyCache* cache(DeviceManagementPolicyProvider* provider) { | 141 DeviceManagementPolicyCache* cache(DeviceManagementPolicyProvider* provider) { |
| 132 return provider->cache_.get(); | 142 return provider->cache_.get(); |
| 133 } | 143 } |
| 134 | 144 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 loop_.RunAllPending(); | 199 loop_.RunAllPending(); |
| 190 Mock::VerifyAndClearExpectations(backend_); | 200 Mock::VerifyAndClearExpectations(backend_); |
| 191 | 201 |
| 192 // Simulate another app relaunch, this time against a failing backend. | 202 // Simulate another app relaunch, this time against a failing backend. |
| 193 // Cached policy should still be available. | 203 // Cached policy should still be available. |
| 194 MockConfigurationPolicyStore store; | 204 MockConfigurationPolicyStore store; |
| 195 CreateNewProvider(); | 205 CreateNewProvider(); |
| 196 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 206 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 197 MockDeviceManagementBackendFailPolicy( | 207 MockDeviceManagementBackendFailPolicy( |
| 198 DeviceManagementBackend::kErrorRequestFailed)); | 208 DeviceManagementBackend::kErrorRequestFailed)); |
| 199 loop_.RunAllPending(); | |
| 200 SimulateSuccessfulLoginAndRunPending(); | 209 SimulateSuccessfulLoginAndRunPending(); |
| 201 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); | 210 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); |
| 202 provider_->Provide(&store); | 211 provider_->Provide(&store); |
| 203 ASSERT_EQ(1U, store.policy_map().size()); | 212 ASSERT_EQ(1U, store.policy_map().size()); |
| 204 } | 213 } |
| 205 | 214 |
| 206 // When policy is successfully fetched from the device management server, it | 215 // When policy is successfully fetched from the device management server, it |
| 207 // should force a policy refresh. | 216 // should force a policy refresh. |
| 208 TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) { | 217 TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) { |
| 209 MockConfigurationPolicyObserver observer; | 218 MockConfigurationPolicyObserver observer; |
| 210 ConfigurationPolicyObserverRegistrar registrar; | 219 ConfigurationPolicyObserverRegistrar registrar; |
| 211 registrar.Init(provider_.get(), &observer); | 220 registrar.Init(provider_.get(), &observer); |
| 212 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1); | 221 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1); |
| 213 SimulateSuccessfulInitialPolicyFetch(); | 222 SimulateSuccessfulInitialPolicyFetch(); |
| 214 } | 223 } |
| 215 | 224 |
| 216 TEST_F(DeviceManagementPolicyProviderTest, ErrorCausesNewRequest) { | 225 TEST_F(DeviceManagementPolicyProviderTest, ErrorCausesNewRequest) { |
| 217 InSequence s; | 226 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. |
| 218 CreateNewProvider(1000 * 1000, 0, 0, 0, 0); | 227 InSequence s; |
| 219 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 228 CreateNewProvider(1000 * 1000, 0, 0, 0, 0, 0); |
| 220 MockDeviceManagementBackendFailRegister( | 229 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 221 DeviceManagementBackend::kErrorRequestFailed)); | 230 MockDeviceManagementBackendFailRegister( |
| 222 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 231 DeviceManagementBackend::kErrorRequestFailed)); |
| 223 MockDeviceManagementBackendSucceedRegister()); | 232 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 224 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 233 MockDeviceManagementBackendSucceedRegister()); |
| 225 MockDeviceManagementBackendFailPolicy( | 234 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 226 DeviceManagementBackend::kErrorRequestFailed)); | 235 MockDeviceManagementBackendFailPolicy( |
| 227 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 236 DeviceManagementBackend::kErrorRequestFailed)); |
| 228 MockDeviceManagementBackendFailPolicy( | 237 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 229 DeviceManagementBackend::kErrorRequestFailed)); | 238 MockDeviceManagementBackendFailPolicy( |
| 230 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 239 DeviceManagementBackend::kErrorRequestFailed)); |
| 231 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); | 240 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 241 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, |
| 242 true)); |
| 243 } |
| 232 SimulateSuccessfulLoginAndRunPending(); | 244 SimulateSuccessfulLoginAndRunPending(); |
| 233 } | 245 } |
| 234 | 246 |
| 235 TEST_F(DeviceManagementPolicyProviderTest, RefreshPolicies) { | 247 TEST_F(DeviceManagementPolicyProviderTest, RefreshPolicies) { |
| 236 InSequence s; | 248 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. |
| 237 CreateNewProvider(0, 0, 1000 * 1000, 1000, 0); | 249 InSequence s; |
| 238 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 250 CreateNewProvider(0, 0, 0, 1000 * 1000, 1000, 0); |
| 239 MockDeviceManagementBackendSucceedRegister()); | 251 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 240 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 252 MockDeviceManagementBackendSucceedRegister()); |
| 241 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); | 253 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 242 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 254 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, |
| 243 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); | 255 true)); |
| 244 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 256 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 245 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); | 257 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, |
| 246 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 258 true)); |
| 247 MockDeviceManagementBackendFailPolicy( | 259 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 248 DeviceManagementBackend::kErrorRequestFailed)); | 260 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, |
| 261 true)); |
| 262 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 263 MockDeviceManagementBackendFailPolicy( |
| 264 DeviceManagementBackend::kErrorRequestFailed)); |
| 265 } |
| 249 SimulateSuccessfulLoginAndRunPending(); | 266 SimulateSuccessfulLoginAndRunPending(); |
| 250 } | 267 } |
| 251 | 268 |
| 252 // The client should try to re-register the device if the device server reports | 269 // The client should try to re-register the device if the device server reports |
| 253 // back that it doesn't recognize the device token on a policy request. | 270 // back that it doesn't recognize the device token on a policy request. |
| 254 TEST_F(DeviceManagementPolicyProviderTest, DeviceNotFound) { | 271 TEST_F(DeviceManagementPolicyProviderTest, DeviceNotFound) { |
| 255 InSequence s; | 272 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. |
| 256 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 273 InSequence s; |
| 257 MockDeviceManagementBackendSucceedRegister()); | 274 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 258 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 275 MockDeviceManagementBackendSucceedRegister()); |
| 259 MockDeviceManagementBackendFailPolicy( | 276 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 260 DeviceManagementBackend::kErrorServiceDeviceNotFound)); | 277 MockDeviceManagementBackendFailPolicy( |
| 261 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 278 DeviceManagementBackend::kErrorServiceDeviceNotFound)); |
| 262 MockDeviceManagementBackendSucceedRegister()); | 279 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 263 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 280 MockDeviceManagementBackendSucceedRegister()); |
| 264 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); | 281 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 282 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, |
| 283 true)); |
| 284 } |
| 265 SimulateSuccessfulLoginAndRunPending(); | 285 SimulateSuccessfulLoginAndRunPending(); |
| 266 } | 286 } |
| 267 | 287 |
| 268 // The client should try to re-register the device if the device server reports | 288 // The client should try to re-register the device if the device server reports |
| 269 // back that the device token is invalid on a policy request. | 289 // back that the device token is invalid on a policy request. |
| 270 TEST_F(DeviceManagementPolicyProviderTest, InvalidTokenOnPolicyRequest) { | 290 TEST_F(DeviceManagementPolicyProviderTest, InvalidTokenOnPolicyRequest) { |
| 271 InSequence s; | 291 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. |
| 272 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 292 InSequence s; |
| 273 MockDeviceManagementBackendSucceedRegister()); | 293 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 274 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 294 MockDeviceManagementBackendSucceedRegister()); |
| 275 MockDeviceManagementBackendFailPolicy( | 295 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 276 DeviceManagementBackend::kErrorServiceManagementTokenInvalid)); | 296 MockDeviceManagementBackendFailPolicy( |
| 277 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 297 DeviceManagementBackend::kErrorServiceManagementTokenInvalid)); |
| 278 MockDeviceManagementBackendSucceedRegister()); | 298 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 279 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 299 MockDeviceManagementBackendSucceedRegister()); |
| 280 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); | 300 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 301 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, |
| 302 true)); |
| 303 } |
| 281 SimulateSuccessfulLoginAndRunPending(); | 304 SimulateSuccessfulLoginAndRunPending(); |
| 282 } | 305 } |
| 283 | 306 |
| 284 // If the client is successfully managed, but the admin stops managing the | 307 // If the client is successfully managed, but the admin stops managing the |
| 285 // device, the client should notice and throw away the device token and id. | 308 // device, the client should notice and throw away the device token and id. |
| 286 TEST_F(DeviceManagementPolicyProviderTest, DeviceNoLongerManaged) { | 309 TEST_F(DeviceManagementPolicyProviderTest, DeviceNoLongerManaged) { |
| 287 InSequence s; | 310 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. |
| 288 CreateNewProvider(0, 0, 0, 0, 1000 * 1000); | 311 InSequence s; |
| 289 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 312 CreateNewProvider(0, 0, 0, 0, 0, 1000 * 1000); |
| 290 MockDeviceManagementBackendSucceedRegister()); | 313 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 291 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 314 MockDeviceManagementBackendSucceedRegister()); |
| 292 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); | 315 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 293 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 316 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, |
| 294 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); | 317 true)); |
| 295 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 318 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 296 MockDeviceManagementBackendFailPolicy( | 319 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, |
| 297 DeviceManagementBackend::kErrorServiceManagementNotSupported)); | 320 true)); |
| 298 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 321 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 299 MockDeviceManagementBackendFailRegister( | 322 MockDeviceManagementBackendFailPolicy( |
| 300 DeviceManagementBackend::kErrorServiceManagementNotSupported)); | 323 DeviceManagementBackend::kErrorServiceManagementNotSupported)); |
| 324 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 325 MockDeviceManagementBackendFailRegister( |
| 326 DeviceManagementBackend::kErrorServiceManagementNotSupported)); |
| 327 } |
| 301 SimulateSuccessfulLoginAndRunPending(); | 328 SimulateSuccessfulLoginAndRunPending(); |
| 302 FilePath token_path(GetTokenPath()); | 329 FilePath token_path(GetTokenPath()); |
| 303 EXPECT_FALSE(file_util::PathExists(token_path)); | 330 EXPECT_FALSE(file_util::PathExists(token_path)); |
| 304 } | 331 } |
| 305 | 332 |
| 306 // This test tests three things (see numbered comments below): | 333 // This test tests three things (see numbered comments below): |
| 307 TEST_F(DeviceManagementPolicyProviderTest, UnmanagedDevice) { | 334 TEST_F(DeviceManagementPolicyProviderTest, UnmanagedDevice) { |
| 308 InSequence s; | 335 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. |
| 309 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 336 InSequence s; |
| 310 MockDeviceManagementBackendFailRegister( | 337 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 311 DeviceManagementBackend::kErrorServiceManagementNotSupported)); | 338 MockDeviceManagementBackendFailRegister( |
| 339 DeviceManagementBackend::kErrorServiceManagementNotSupported)); |
| 340 } |
| 312 SimulateSuccessfulLoginAndRunPending(); | 341 SimulateSuccessfulLoginAndRunPending(); |
| 313 // (1) The provider's DMPolicyCache should know that the device is not | 342 // (1) The provider's DMPolicyCache should know that the device is not |
| 314 // managed. | 343 // managed. |
| 315 EXPECT_TRUE(cache(provider_.get())->is_device_unmanaged()); | 344 EXPECT_TRUE(cache(provider_.get())->is_device_unmanaged()); |
| 316 // (2) On restart, the provider should detect that this is not the first | 345 // (2) On restart, the provider should detect that this is not the first |
| 317 // login. | 346 // login. |
| 318 CreateNewProvider(1000*1000, 0, 0, 0, 0); | 347 CreateNewProvider(1000 * 1000, 0, 0, 0, 0, 0); |
| 319 EXPECT_FALSE(waiting_for_initial_policies()); | 348 EXPECT_FALSE(waiting_for_initial_policies()); |
| 320 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( | 349 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. |
| 321 MockDeviceManagementBackendSucceedRegister()); | 350 InSequence s; |
| 322 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( | 351 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( |
| 323 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); | 352 MockDeviceManagementBackendSucceedRegister()); |
| 353 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| 354 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, |
| 355 true)); |
| 356 } |
| 324 SimulateSuccessfulLoginAndRunPending(); | 357 SimulateSuccessfulLoginAndRunPending(); |
| 325 // (3) Since the backend call this time returned a device id, the "unmanaged" | 358 // (3) Since the backend call this time returned a device id, the "unmanaged" |
| 326 // marker should have been deleted. | 359 // marker should have been deleted. |
| 327 EXPECT_FALSE(cache(provider_.get())->is_device_unmanaged()); | 360 EXPECT_FALSE(cache(provider_.get())->is_device_unmanaged()); |
| 328 } | 361 } |
| 329 | 362 |
| 330 } // namespace policy | 363 } // namespace policy |
| OLD | NEW |