Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/browser/policy/device_management_policy_provider_unittest.cc

Issue 5346005: Unmanaged devices should forget device id/token (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nit Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/policy/device_management_policy_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_loop.h" 6 #include "base/message_loop.h"
6 #include "base/scoped_temp_dir.h" 7 #include "base/scoped_temp_dir.h"
7 #include "chrome/browser/browser_thread.h" 8 #include "chrome/browser/browser_thread.h"
8 #include "chrome/browser/net/gaia/token_service.h" 9 #include "chrome/browser/net/gaia/token_service.h"
9 #include "chrome/browser/policy/configuration_policy_pref_store.h" 10 #include "chrome/browser/policy/configuration_policy_pref_store.h"
10 #include "chrome/browser/policy/device_management_policy_provider.h" 11 #include "chrome/browser/policy/device_management_policy_provider.h"
11 #include "chrome/browser/policy/mock_configuration_policy_store.h" 12 #include "chrome/browser/policy/mock_configuration_policy_store.h"
12 #include "chrome/browser/policy/mock_device_management_backend.h" 13 #include "chrome/browser/policy/mock_device_management_backend.h"
13 #include "chrome/common/net/gaia/gaia_constants.h" 14 #include "chrome/common/net/gaia/gaia_constants.h"
14 #include "chrome/common/notification_service.h" 15 #include "chrome/common/notification_service.h"
(...skipping 11 matching lines...) Expand all
26 using ::testing::InSequence; 27 using ::testing::InSequence;
27 using ::testing::Mock; 28 using ::testing::Mock;
28 29
29 class DeviceManagementPolicyProviderTest : public testing::Test { 30 class DeviceManagementPolicyProviderTest : public testing::Test {
30 public: 31 public:
31 DeviceManagementPolicyProviderTest() 32 DeviceManagementPolicyProviderTest()
32 : ui_thread_(BrowserThread::UI, &loop_), 33 : ui_thread_(BrowserThread::UI, &loop_),
33 file_thread_(BrowserThread::FILE, &loop_) {} 34 file_thread_(BrowserThread::FILE, &loop_) {}
34 35
35 virtual ~DeviceManagementPolicyProviderTest() {} 36 virtual ~DeviceManagementPolicyProviderTest() {}
36
37 virtual void SetUp() { 37 virtual void SetUp() {
38 profile_.reset(new TestingProfile); 38 profile_.reset(new TestingProfile);
39 CreateNewBackend(); 39 CreateNewBackend();
40 CreateNewProvider(); 40 CreateNewProvider();
41 } 41 }
42 42
43 void CreateNewBackend() { 43 void CreateNewBackend() {
44 backend_ = new MockDeviceManagementBackend; 44 backend_ = new MockDeviceManagementBackend;
45 } 45 }
46 46
47 void CreateNewProvider() { 47 void CreateNewProvider() {
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(
53 new TestingDeviceTokenFetcher(backend_, 53 new TestingDeviceTokenFetcher(backend_,
54 profile_.get(), 54 profile_.get(),
55 provider_->GetTokenPath())); 55 provider_->GetTokenPath()));
56 loop_.RunAllPending(); 56 loop_.RunAllPending();
57 } 57 }
58 58
59 FilePath GetTokenPath() const {
markusheintz_ 2010/11/29 09:01:43 Why was this introduced? It looks like it is only
60 return provider_->GetTokenPath();
61 }
62
59 void SimulateSuccessfulLoginAndRunPending() { 63 void SimulateSuccessfulLoginAndRunPending() {
60 loop_.RunAllPending(); 64 loop_.RunAllPending();
61 profile_->GetTokenService()->IssueAuthTokenForTest( 65 profile_->GetTokenService()->IssueAuthTokenForTest(
62 GaiaConstants::kDeviceManagementService, kTestToken); 66 GaiaConstants::kDeviceManagementService, kTestToken);
63 TestingDeviceTokenFetcher* fetcher = 67 TestingDeviceTokenFetcher* fetcher =
64 static_cast<TestingDeviceTokenFetcher*>( 68 static_cast<TestingDeviceTokenFetcher*>(
65 provider_->token_fetcher_.get()); 69 provider_->token_fetcher_.get());
66 fetcher->SimulateLogin(kTestManagedDomainUsername); 70 fetcher->SimulateLogin(kTestManagedDomainUsername);
67 loop_.RunAllPending(); 71 loop_.RunAllPending();
68 } 72 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 246 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
243 MockDeviceManagementBackendFailPolicy( 247 MockDeviceManagementBackendFailPolicy(
244 DeviceManagementBackend::kErrorServiceManagementTokenInvalid)); 248 DeviceManagementBackend::kErrorServiceManagementTokenInvalid));
245 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 249 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
246 MockDeviceManagementBackendSucceedRegister()); 250 MockDeviceManagementBackendSucceedRegister());
247 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 251 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
248 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); 252 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true));
249 SimulateSuccessfulLoginAndRunPending(); 253 SimulateSuccessfulLoginAndRunPending();
250 } 254 }
251 255
256 // If the client is successfully managed, but the admin stops managing the
257 // device, the client should notice and throw away the device token and id.
258 TEST_F(DeviceManagementPolicyProviderTest, DeviceNoLongerManaged) {
259 InSequence s;
260 SetRefreshDelays(provider_.get(), 0, 0, 1000 * 1000, 1000);
261 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
262 MockDeviceManagementBackendSucceedRegister());
263 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
264 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true));
265 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
266 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true));
267 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
268 MockDeviceManagementBackendFailPolicy(
269 DeviceManagementBackend::kErrorServiceManagementNotSupported));
270 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
271 MockDeviceManagementBackendFailRegister(
272 DeviceManagementBackend::kErrorServiceManagementNotSupported));
273 SimulateSuccessfulLoginAndRunPending();
274 FilePath token_path(GetTokenPath());
275 EXPECT_FALSE(file_util::PathExists(token_path));
276 }
277
252 } // namespace policy 278 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_management_policy_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698