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

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

Issue 4960003: Don't register gmail users at the device management server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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
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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/scoped_temp_dir.h" 6 #include "base/scoped_temp_dir.h"
7 #include "chrome/browser/browser_thread.h" 7 #include "chrome/browser/browser_thread.h"
8 #include "chrome/browser/net/gaia/token_service.h" 8 #include "chrome/browser/net/gaia/token_service.h"
9 #include "chrome/browser/policy/configuration_policy_pref_store.h" 9 #include "chrome/browser/policy/configuration_policy_pref_store.h"
10 #include "chrome/browser/policy/device_management_policy_provider.h" 10 #include "chrome/browser/policy/device_management_policy_provider.h"
11 #include "chrome/browser/policy/mock_configuration_policy_store.h" 11 #include "chrome/browser/policy/mock_configuration_policy_store.h"
12 #include "chrome/browser/policy/mock_device_management_backend.h" 12 #include "chrome/browser/policy/mock_device_management_backend.h"
13 #include "chrome/common/net/gaia/gaia_constants.h" 13 #include "chrome/common/net/gaia/gaia_constants.h"
14 #include "chrome/common/notification_service.h" 14 #include "chrome/common/notification_service.h"
15 #include "chrome/common/policy_constants.h" 15 #include "chrome/common/policy_constants.h"
16 #include "chrome/test/mock_notification_observer.h" 16 #include "chrome/test/mock_notification_observer.h"
17 #include "chrome/test/testing_device_token_fetcher.h"
18 #include "chrome/test/testing_profile.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 20
19 const char kTestToken[] = "device_policy_provider_test_auth_token"; 21 const char kTestToken[] = "device_policy_provider_test_auth_token";
20 22
21 namespace policy { 23 namespace policy {
22 24
23 using ::testing::_; 25 using ::testing::_;
24 using ::testing::InSequence; 26 using ::testing::InSequence;
25 using ::testing::Mock; 27 using ::testing::Mock;
26 28
27 class DeviceManagementPolicyProviderTest : public testing::Test { 29 class DeviceManagementPolicyProviderTest : public testing::Test {
28 public: 30 public:
29 DeviceManagementPolicyProviderTest() 31 DeviceManagementPolicyProviderTest()
30 : ui_thread_(BrowserThread::UI, &loop_), 32 : ui_thread_(BrowserThread::UI, &loop_),
31 file_thread_(BrowserThread::FILE, &loop_) {} 33 file_thread_(BrowserThread::FILE, &loop_) {}
32 34
33 virtual ~DeviceManagementPolicyProviderTest() {} 35 virtual ~DeviceManagementPolicyProviderTest() {}
34 36
35 virtual void SetUp() { 37 virtual void SetUp() {
36 EXPECT_TRUE(storage_dir_.CreateUniqueTempDir()); 38 profile_.reset(new TestingProfile);
37 CreateNewBackend(); 39 CreateNewBackend();
38 CreateNewProvider(); 40 CreateNewProvider();
39 } 41 }
40 42
41 void CreateNewBackend() { 43 void CreateNewBackend() {
42 backend_ = new MockDeviceManagementBackend; 44 backend_ = new MockDeviceManagementBackend;
43 } 45 }
44 46
45 void CreateNewProvider() { 47 void CreateNewProvider() {
46 token_service_.reset(new TokenService);
47 provider_.reset(new DeviceManagementPolicyProvider( 48 provider_.reset(new DeviceManagementPolicyProvider(
48 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), 49 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
49 backend_, 50 backend_,
50 token_service_.get(), 51 profile_.get()));
51 storage_dir_.path())); 52 provider_->SetDeviceTokenFetcher(
53 new TestingDeviceTokenFetcher(backend_,
54 profile_.get(),
55 provider_->GetTokenPath()));
52 loop_.RunAllPending(); 56 loop_.RunAllPending();
53 } 57 }
54 58
55 void SimulateSuccessfulLoginAndRunPending() { 59 void SimulateSuccessfulLoginAndRunPending() {
56 loop_.RunAllPending(); 60 loop_.RunAllPending();
57 token_service_->IssueAuthTokenForTest( 61 profile_->GetTokenService()->IssueAuthTokenForTest(
58 GaiaConstants::kDeviceManagementService, kTestToken); 62 GaiaConstants::kDeviceManagementService, kTestToken);
63 TestingDeviceTokenFetcher* fetcher =
64 static_cast<TestingDeviceTokenFetcher*>(
65 provider_->token_fetcher_.get());
66 fetcher->SimulateLogin(kTestManagedDomainUsername);
59 loop_.RunAllPending(); 67 loop_.RunAllPending();
60 } 68 }
61 69
62 void SimulateSuccessfulInitialPolicyFetch() { 70 void SimulateSuccessfulInitialPolicyFetch() {
63 MockConfigurationPolicyStore store; 71 MockConfigurationPolicyStore store;
64 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 72 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
65 MockDeviceManagementBackendSucceedRegister()); 73 MockDeviceManagementBackendSucceedRegister());
66 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 74 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
67 MockDeviceManagementBackendSucceedBooleanPolicy( 75 MockDeviceManagementBackendSucceedBooleanPolicy(
68 key::kDisableSpdy, true)); 76 key::kDisableSpdy, true));
(...skipping 21 matching lines...) Expand all
90 provider->set_policy_refresh_rate_ms(policy_refresh_rate_ms); 98 provider->set_policy_refresh_rate_ms(policy_refresh_rate_ms);
91 provider->set_policy_refresh_max_earlier_ms(policy_refresh_max_earlier_ms); 99 provider->set_policy_refresh_max_earlier_ms(policy_refresh_max_earlier_ms);
92 provider->set_policy_refresh_error_delay_ms(policy_refresh_error_delay_ms); 100 provider->set_policy_refresh_error_delay_ms(policy_refresh_error_delay_ms);
93 provider->set_token_fetch_error_delay_ms(token_fetch_error_delay_ms); 101 provider->set_token_fetch_error_delay_ms(token_fetch_error_delay_ms);
94 } 102 }
95 103
96 private: 104 private:
97 MessageLoop loop_; 105 MessageLoop loop_;
98 BrowserThread ui_thread_; 106 BrowserThread ui_thread_;
99 BrowserThread file_thread_; 107 BrowserThread file_thread_;
100 ScopedTempDir storage_dir_; 108 scoped_ptr<Profile> profile_;
101 scoped_ptr<TokenService> token_service_;
102 109
103 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest); 110 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProviderTest);
104 }; 111 };
105 112
106 // If there's no login and no previously-fetched policy, the provider should 113 // If there's no login and no previously-fetched policy, the provider should
107 // provide an empty policy. 114 // provide an empty policy.
108 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideNoLogin) { 115 TEST_F(DeviceManagementPolicyProviderTest, InitialProvideNoLogin) {
109 MockConfigurationPolicyStore store; 116 MockConfigurationPolicyStore store;
110 EXPECT_CALL(store, Apply(_, _)).Times(0); 117 EXPECT_CALL(store, Apply(_, _)).Times(0);
111 provider_->Provide(&store); 118 provider_->Provide(&store);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); 211 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true));
205 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 212 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
206 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true)); 213 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, true));
207 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 214 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
208 MockDeviceManagementBackendFailPolicy( 215 MockDeviceManagementBackendFailPolicy(
209 DeviceManagementBackend::kErrorRequestFailed)); 216 DeviceManagementBackend::kErrorRequestFailed));
210 SimulateSuccessfulLoginAndRunPending(); 217 SimulateSuccessfulLoginAndRunPending();
211 } 218 }
212 219
213 } // namespace policy 220 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698