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

Side by Side Diff: chrome/browser/chromeos/policy/consumer_management_service_unittest.cc

Issue 493613002: Add an enrolling state for consumer management section in settings page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dn
Patch Set: Created 6 years, 4 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/chromeos/policy/consumer_management_service.h" 5 #include "chrome/browser/chromeos/policy/consumer_management_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h"
bartfab (slow) 2014/08/21 11:39:35 Actually, I missed it that the header already incl
davidyu 2014/08/22 05:14:13 Done.
10 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
12 #include "base/prefs/testing_pref_service.h" 13 #include "base/prefs/testing_pref_service.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/browser_process_platform_part.h" 16 #include "chrome/browser/browser_process_platform_part.h"
16 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" 18 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
18 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
20 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" 21 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h"
22 #include "chrome/browser/chromeos/policy/device_policy_builder.h"
21 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" 23 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h"
22 #include "chrome/browser/chromeos/policy/fake_device_cloud_policy_initializer.h" 24 #include "chrome/browser/chromeos/policy/fake_device_cloud_policy_initializer.h"
25 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
23 #include "chrome/browser/notifications/notification_ui_manager.h" 26 #include "chrome/browser/notifications/notification_ui_manager.h"
24 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 28 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
26 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 29 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 30 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
28 #include "chrome/browser/signin/signin_manager_factory.h" 31 #include "chrome/browser/signin/signin_manager_factory.h"
29 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
30 #include "chrome/test/base/browser_with_test_window_test.h" 33 #include "chrome/test/base/browser_with_test_window_test.h"
34 #include "chrome/test/base/scoped_testing_local_state.h"
31 #include "chrome/test/base/testing_browser_process.h" 35 #include "chrome/test/base/testing_browser_process.h"
32 #include "chrome/test/base/testing_profile.h" 36 #include "chrome/test/base/testing_profile.h"
33 #include "chrome/test/base/testing_profile_manager.h" 37 #include "chrome/test/base/testing_profile_manager.h"
34 #include "chromeos/dbus/cryptohome/rpc.pb.h" 38 #include "chromeos/dbus/cryptohome/rpc.pb.h"
35 #include "chromeos/dbus/cryptohome_client.h" 39 #include "chromeos/dbus/cryptohome_client.h"
36 #include "chromeos/dbus/mock_cryptohome_client.h" 40 #include "chromeos/dbus/mock_cryptohome_client.h"
37 #include "components/signin/core/browser/profile_oauth2_token_service.h" 41 #include "components/signin/core/browser/profile_oauth2_token_service.h"
38 #include "components/signin/core/browser/signin_manager_base.h" 42 #include "components/signin/core/browser/signin_manager_base.h"
39 #include "content/public/browser/notification_details.h" 43 #include "content/public/browser/notification_details.h"
40 #include "content/public/browser/notification_source.h" 44 #include "content/public/browser/notification_source.h"
41 #include "google_apis/gaia/google_service_auth_error.h" 45 #include "google_apis/gaia/google_service_auth_error.h"
46 #include "policy/proto/device_management_backend.pb.h"
42 #include "testing/gmock/include/gmock/gmock.h" 47 #include "testing/gmock/include/gmock/gmock.h"
43 #include "testing/gtest/include/gtest/gtest.h" 48 #include "testing/gtest/include/gtest/gtest.h"
44 49
45 using testing::Invoke; 50 using testing::Invoke;
46 using testing::NiceMock; 51 using testing::NiceMock;
47 using testing::Return; 52 using testing::Return;
48 using testing::_; 53 using testing::_;
49 54
55 namespace em = enterprise_management;
56
50 namespace { 57 namespace {
51 const char* kAttributeOwnerId = "consumer_management.owner_id"; 58 const char* kAttributeOwnerId = "consumer_management.owner_id";
52 const char* kTestOwner = "test@chromium.org.test"; 59 const char* kTestOwner = "test@chromium.org.test";
53 } 60 }
54 61
55 namespace policy { 62 namespace policy {
56 63
57 class ConsumerManagementServiceTest : public BrowserWithTestWindowTest { 64 class ConsumerManagementServiceTest : public BrowserWithTestWindowTest {
58 public: 65 public:
59 ConsumerManagementServiceTest() 66 ConsumerManagementServiceTest()
(...skipping 12 matching lines...) Expand all
72 MockFlushAndSignBootAttributes)); 79 MockFlushAndSignBootAttributes));
73 } 80 }
74 81
75 virtual void SetUp() OVERRIDE { 82 virtual void SetUp() OVERRIDE {
76 BrowserWithTestWindowTest::SetUp(); 83 BrowserWithTestWindowTest::SetUp();
77 84
78 testing_profile_manager_.reset(new TestingProfileManager( 85 testing_profile_manager_.reset(new TestingProfileManager(
79 TestingBrowserProcess::GetGlobal())); 86 TestingBrowserProcess::GetGlobal()));
80 ASSERT_TRUE(testing_profile_manager_->SetUp()); 87 ASSERT_TRUE(testing_profile_manager_->SetUp());
81 88
82 service_.reset(new ConsumerManagementService(&mock_cryptohome_client_)); 89 service_.reset(new ConsumerManagementService(&mock_cryptohome_client_,
90 NULL));
83 } 91 }
84 92
85 virtual void TearDown() OVERRIDE { 93 virtual void TearDown() OVERRIDE {
86 testing_profile_manager_.reset(); 94 testing_profile_manager_.reset();
87 95
88 service_.reset(); 96 service_.reset();
89 97
90 BrowserWithTestWindowTest::TearDown(); 98 BrowserWithTestWindowTest::TearDown();
91 } 99 }
92 100
93 ConsumerManagementService::ConsumerEnrollmentState GetEnrollmentState() { 101 ConsumerManagementService::EnrollmentStage GetEnrollmentStage() {
94 return static_cast<ConsumerManagementService::ConsumerEnrollmentState>( 102 return static_cast<ConsumerManagementService::EnrollmentStage>(
95 g_browser_process->local_state()->GetInteger( 103 g_browser_process->local_state()->GetInteger(
96 prefs::kConsumerManagementEnrollmentState)); 104 prefs::kConsumerManagementEnrollmentStage));
97 } 105 }
98 106
99 void SetEnrollmentState( 107 void SetEnrollmentStage(ConsumerManagementService::EnrollmentStage stage) {
100 ConsumerManagementService::ConsumerEnrollmentState state) {
101 g_browser_process->local_state()->SetInteger( 108 g_browser_process->local_state()->SetInteger(
102 prefs::kConsumerManagementEnrollmentState, state); 109 prefs::kConsumerManagementEnrollmentStage, stage);
103 } 110 }
104 111
105 void MockGetBootAttribute( 112 void MockGetBootAttribute(
106 const cryptohome::GetBootAttributeRequest& request, 113 const cryptohome::GetBootAttributeRequest& request,
107 const chromeos::CryptohomeClient::ProtobufMethodCallback& callback) { 114 const chromeos::CryptohomeClient::ProtobufMethodCallback& callback) {
108 get_boot_attribute_request_ = request; 115 get_boot_attribute_request_ = request;
109 callback.Run(cryptohome_status_, cryptohome_result_, cryptohome_reply_); 116 callback.Run(cryptohome_status_, cryptohome_result_, cryptohome_reply_);
110 } 117 }
111 118
112 void MockSetBootAttribute( 119 void MockSetBootAttribute(
(...skipping 10 matching lines...) Expand all
123 } 130 }
124 131
125 void OnGetOwnerDone(const std::string& owner) { 132 void OnGetOwnerDone(const std::string& owner) {
126 owner_ = owner; 133 owner_ = owner;
127 } 134 }
128 135
129 void OnSetOwnerDone(bool status) { 136 void OnSetOwnerDone(bool status) {
130 set_owner_status_ = status; 137 set_owner_status_ = status;
131 } 138 }
132 139
140 // Variables for building the service.
133 NiceMock<chromeos::MockCryptohomeClient> mock_cryptohome_client_; 141 NiceMock<chromeos::MockCryptohomeClient> mock_cryptohome_client_;
134 scoped_ptr<ConsumerManagementService> service_; 142 scoped_ptr<ConsumerManagementService> service_;
135 143
136 scoped_ptr<TestingProfileManager> testing_profile_manager_; 144 scoped_ptr<TestingProfileManager> testing_profile_manager_;
145
146 // Variables for setting the return value or catching the arguments of mock
147 // functions.
137 chromeos::DBusMethodCallStatus cryptohome_status_; 148 chromeos::DBusMethodCallStatus cryptohome_status_;
138 bool cryptohome_result_; 149 bool cryptohome_result_;
139 cryptohome::BaseReply cryptohome_reply_; 150 cryptohome::BaseReply cryptohome_reply_;
140 cryptohome::GetBootAttributeRequest get_boot_attribute_request_; 151 cryptohome::GetBootAttributeRequest get_boot_attribute_request_;
141 cryptohome::SetBootAttributeRequest set_boot_attribute_request_; 152 cryptohome::SetBootAttributeRequest set_boot_attribute_request_;
142
143 std::string owner_; 153 std::string owner_;
144 bool set_owner_status_; 154 bool set_owner_status_;
145 }; 155 };
146 156
147 TEST_F(ConsumerManagementServiceTest, CanGetEnrollmentState) { 157 TEST_F(ConsumerManagementServiceTest, CanGetEnrollmentStage) {
148 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_NONE, 158 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_NONE,
149 service_->GetEnrollmentState()); 159 service_->GetEnrollmentStage());
150 160
151 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_REQUESTED); 161 SetEnrollmentStage(ConsumerManagementService::ENROLLMENT_STAGE_REQUESTED);
152 162
153 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_REQUESTED, 163 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_REQUESTED,
154 service_->GetEnrollmentState()); 164 service_->GetEnrollmentStage());
155 } 165 }
156 166
157 TEST_F(ConsumerManagementServiceTest, CanSetEnrollmentState) { 167 TEST_F(ConsumerManagementServiceTest, CanSetEnrollmentStage) {
158 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_NONE, GetEnrollmentState()); 168 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_NONE,
169 GetEnrollmentStage());
159 170
160 service_->SetEnrollmentState(ConsumerManagementService::ENROLLMENT_REQUESTED); 171 service_->SetEnrollmentStage(
172 ConsumerManagementService::ENROLLMENT_STAGE_REQUESTED);
161 173
162 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_REQUESTED, 174 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_REQUESTED,
163 GetEnrollmentState()); 175 GetEnrollmentStage());
164 } 176 }
165 177
166 TEST_F(ConsumerManagementServiceTest, CanGetOwner) { 178 TEST_F(ConsumerManagementServiceTest, CanGetOwner) {
167 cryptohome_status_ = chromeos::DBUS_METHOD_CALL_SUCCESS; 179 cryptohome_status_ = chromeos::DBUS_METHOD_CALL_SUCCESS;
168 cryptohome_result_ = true; 180 cryptohome_result_ = true;
169 cryptohome_reply_.MutableExtension(cryptohome::GetBootAttributeReply::reply)-> 181 cryptohome_reply_.MutableExtension(cryptohome::GetBootAttributeReply::reply)->
170 set_value(kTestOwner); 182 set_value(kTestOwner);
171 183
172 service_->GetOwner(base::Bind(&ConsumerManagementServiceTest::OnGetOwnerDone, 184 service_->GetOwner(base::Bind(&ConsumerManagementServiceTest::OnGetOwnerDone,
173 base::Unretained(this))); 185 base::Unretained(this)));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 public: 229 public:
218 ConsumerManagementServiceEnrollmentTest() 230 ConsumerManagementServiceEnrollmentTest()
219 : mock_user_manager_(new NiceMock<chromeos::MockUserManager>()), 231 : mock_user_manager_(new NiceMock<chromeos::MockUserManager>()),
220 scoped_user_manager_enabler_(mock_user_manager_), 232 scoped_user_manager_enabler_(mock_user_manager_),
221 fake_initializer_(new FakeDeviceCloudPolicyInitializer()), 233 fake_initializer_(new FakeDeviceCloudPolicyInitializer()),
222 enrollment_status_(EnrollmentStatus::ForStatus( 234 enrollment_status_(EnrollmentStatus::ForStatus(
223 EnrollmentStatus::STATUS_SUCCESS)) { 235 EnrollmentStatus::STATUS_SUCCESS)) {
224 // Set up MockUserManager. The first user will be the owner. 236 // Set up MockUserManager. The first user will be the owner.
225 mock_user_manager_->AddUser(kTestOwner); 237 mock_user_manager_->AddUser(kTestOwner);
226 238
227 // Return false for IsCurrentUserOwner() so that the enrollment state is not 239 // Return false for IsCurrentUserOwner() so that the enrollment stage is not
228 // reset. 240 // reset.
229 ON_CALL(*mock_user_manager_, IsCurrentUserOwner()) 241 ON_CALL(*mock_user_manager_, IsCurrentUserOwner())
230 .WillByDefault(Return(false)); 242 .WillByDefault(Return(false));
231 243
232 // Inject FakeDeviceCloudPolicyInitializer. 244 // Inject FakeDeviceCloudPolicyInitializer.
233 BrowserPolicyConnectorChromeOS* connector = 245 BrowserPolicyConnectorChromeOS* connector =
234 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 246 g_browser_process->platform_part()->browser_policy_connector_chromeos();
235 connector->SetDeviceCloudPolicyInitializerForTesting( 247 connector->SetDeviceCloudPolicyInitializerForTesting(
236 scoped_ptr<DeviceCloudPolicyInitializer>(fake_initializer_)); 248 scoped_ptr<DeviceCloudPolicyInitializer>(fake_initializer_));
237 } 249 }
238 250
239 virtual void SetUp() OVERRIDE { 251 virtual void SetUp() OVERRIDE {
240 ConsumerManagementServiceTest::SetUp(); 252 ConsumerManagementServiceTest::SetUp();
241 253
242 // Set up the testing profile. 254 // Set up the testing profile.
243 profile()->set_profile_name(kTestOwner); 255 profile()->set_profile_name(kTestOwner);
244 256
245 // Set up FakeProfileOAuth2TokenService and issue a fake refresh token. 257 // Set up FakeProfileOAuth2TokenService and issue a fake refresh token.
246 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( 258 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory(
247 profile(), &BuildAutoIssuingFakeProfileOAuth2TokenService); 259 profile(), &BuildAutoIssuingFakeProfileOAuth2TokenService);
248 GetFakeProfileOAuth2TokenService()-> 260 GetFakeProfileOAuth2TokenService()->
249 IssueRefreshTokenForUser(kTestOwner, "fake_token"); 261 IssueRefreshTokenForUser(kTestOwner, "fake_token");
250 262
251 // Set up the authenticated user name and ID. 263 // Set up the authenticated user name and ID.
252 SigninManagerFactory::GetForProfile(profile())-> 264 SigninManagerFactory::GetForProfile(profile())->
253 SetAuthenticatedUsername(kTestOwner); 265 SetAuthenticatedUsername(kTestOwner);
254 266
255 // The service should continue the enrollment process if the state is 267 // The service should continue the enrollment process if the stage is
256 // ENROLLMENT_OWNER_STORED. 268 // ENROLLMENT_STAGE_OWNER_STORED.
257 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_OWNER_STORED); 269 SetEnrollmentStage(
270 ConsumerManagementService::ENROLLMENT_STAGE_OWNER_STORED);
258 } 271 }
259 272
260 virtual void TearDown() OVERRIDE { 273 virtual void TearDown() OVERRIDE {
261 g_browser_process->notification_ui_manager()->CancelAll(); 274 g_browser_process->notification_ui_manager()->CancelAll();
262 275
263 ConsumerManagementServiceTest::TearDown(); 276 ConsumerManagementServiceTest::TearDown();
264 } 277 }
265 278
266 FakeProfileOAuth2TokenService* GetFakeProfileOAuth2TokenService() { 279 FakeProfileOAuth2TokenService* GetFakeProfileOAuth2TokenService() {
267 return static_cast<FakeProfileOAuth2TokenService*>( 280 return static_cast<FakeProfileOAuth2TokenService*>(
(...skipping 18 matching lines...) Expand all
286 FakeDeviceCloudPolicyInitializer* fake_initializer_; 299 FakeDeviceCloudPolicyInitializer* fake_initializer_;
287 EnrollmentStatus enrollment_status_; 300 EnrollmentStatus enrollment_status_;
288 }; 301 };
289 302
290 TEST_F(ConsumerManagementServiceEnrollmentTest, EnrollsSuccessfully) { 303 TEST_F(ConsumerManagementServiceEnrollmentTest, EnrollsSuccessfully) {
291 EXPECT_FALSE(fake_initializer_->was_start_enrollment_called()); 304 EXPECT_FALSE(fake_initializer_->was_start_enrollment_called());
292 305
293 RunEnrollmentTest(); 306 RunEnrollmentTest();
294 307
295 EXPECT_TRUE(fake_initializer_->was_start_enrollment_called()); 308 EXPECT_TRUE(fake_initializer_->was_start_enrollment_called());
296 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_SUCCESS, 309 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_SUCCESS,
297 GetEnrollmentState()); 310 GetEnrollmentStage());
298 EXPECT_FALSE(HasEnrollmentNotification()); 311 EXPECT_FALSE(HasEnrollmentNotification());
299 } 312 }
300 313
301 TEST_F(ConsumerManagementServiceEnrollmentTest, 314 TEST_F(ConsumerManagementServiceEnrollmentTest,
302 ShowsDesktopNotificationAndResetsEnrollmentStateIfCurrentUserIsOwner) { 315 ShowsDesktopNotificationAndResetsEnrollmentStageIfCurrentUserIsOwner) {
303 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_OWNER_STORED, 316 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_OWNER_STORED,
304 GetEnrollmentState()); 317 GetEnrollmentStage());
305 EXPECT_FALSE(HasEnrollmentNotification()); 318 EXPECT_FALSE(HasEnrollmentNotification());
306 EXPECT_CALL(*mock_user_manager_, IsCurrentUserOwner()) 319 EXPECT_CALL(*mock_user_manager_, IsCurrentUserOwner())
307 .WillOnce(Return(true)); 320 .WillOnce(Return(true));
308 321
309 RunEnrollmentTest(); 322 RunEnrollmentTest();
310 323
311 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_NONE, GetEnrollmentState()); 324 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_NONE,
325 GetEnrollmentStage());
312 EXPECT_TRUE(HasEnrollmentNotification()); 326 EXPECT_TRUE(HasEnrollmentNotification());
313 } 327 }
314 328
315 TEST_F(ConsumerManagementServiceEnrollmentTest, FailsToGetAccessToken) { 329 TEST_F(ConsumerManagementServiceEnrollmentTest, FailsToGetAccessToken) {
316 // Disable auto-posting so that RunEnrollmentTest() should stop and wait for 330 // Disable auto-posting so that RunEnrollmentTest() should stop and wait for
317 // the access token to be available. 331 // the access token to be available.
318 GetFakeProfileOAuth2TokenService()-> 332 GetFakeProfileOAuth2TokenService()->
319 set_auto_post_fetch_response_on_message_loop(false); 333 set_auto_post_fetch_response_on_message_loop(false);
320 334
321 RunEnrollmentTest(); 335 RunEnrollmentTest();
322 336
323 // The service should have a pending token request. 337 // The service should have a pending token request.
324 OAuth2TokenService::Request* token_request = 338 OAuth2TokenService::Request* token_request =
325 service_->GetTokenRequestForTesting(); 339 service_->GetTokenRequestForTesting();
326 EXPECT_TRUE(token_request); 340 EXPECT_TRUE(token_request);
327 341
328 // Tell the service that the access token is not available because of some 342 // Tell the service that the access token is not available because of some
329 // backend issue. 343 // backend issue.
330 service_->OnGetTokenFailure( 344 service_->OnGetTokenFailure(
331 token_request, 345 token_request,
332 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR)); 346 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR));
333 347
334 EXPECT_FALSE(fake_initializer_->was_start_enrollment_called()); 348 EXPECT_FALSE(fake_initializer_->was_start_enrollment_called());
335 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_GET_TOKEN_FAILED, 349 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_GET_TOKEN_FAILED,
336 GetEnrollmentState()); 350 GetEnrollmentStage());
337 } 351 }
338 352
339 TEST_F(ConsumerManagementServiceEnrollmentTest, FailsToRegister) { 353 TEST_F(ConsumerManagementServiceEnrollmentTest, FailsToRegister) {
340 EXPECT_FALSE(fake_initializer_->was_start_enrollment_called()); 354 EXPECT_FALSE(fake_initializer_->was_start_enrollment_called());
341 fake_initializer_->set_enrollment_status(EnrollmentStatus::ForStatus( 355 fake_initializer_->set_enrollment_status(EnrollmentStatus::ForStatus(
342 EnrollmentStatus::STATUS_REGISTRATION_FAILED)); 356 EnrollmentStatus::STATUS_REGISTRATION_FAILED));
343 357
344 RunEnrollmentTest(); 358 RunEnrollmentTest();
345 359
346 EXPECT_TRUE(fake_initializer_->was_start_enrollment_called()); 360 EXPECT_TRUE(fake_initializer_->was_start_enrollment_called());
347 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_DM_SERVER_FAILED, 361 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_DM_SERVER_FAILED,
348 GetEnrollmentState()); 362 GetEnrollmentStage());
349 } 363 }
350 364
351 TEST_F(ConsumerManagementServiceEnrollmentTest, 365 TEST_F(ConsumerManagementServiceEnrollmentTest,
352 ShowsDesktopNotificationOnlyIfEnrollmentIsAlreadyCompleted) { 366 ShowsDesktopNotificationOnlyIfEnrollmentIsAlreadyCompleted) {
353 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_CANCELED); 367 SetEnrollmentStage(ConsumerManagementService::ENROLLMENT_STAGE_CANCELED);
354 EXPECT_FALSE(HasEnrollmentNotification()); 368 EXPECT_FALSE(HasEnrollmentNotification());
355 369
356 RunEnrollmentTest(); 370 RunEnrollmentTest();
357 371
358 EXPECT_FALSE(fake_initializer_->was_start_enrollment_called()); 372 EXPECT_FALSE(fake_initializer_->was_start_enrollment_called());
359 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_NONE, GetEnrollmentState()); 373 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_NONE,
374 GetEnrollmentStage());
360 EXPECT_TRUE(HasEnrollmentNotification()); 375 EXPECT_TRUE(HasEnrollmentNotification());
361 } 376 }
362 377
378 class ConsumerManagementServiceStatusTest
379 : public chromeos::DeviceSettingsTestBase {
380 public:
381 ConsumerManagementServiceStatusTest()
382 : testing_local_state_(TestingBrowserProcess::GetGlobal()),
383 service_(NULL, &device_settings_service_) {
384 }
385
386 void SetEnrollmentStage(ConsumerManagementService::EnrollmentStage stage) {
387 testing_local_state_.Get()->SetInteger(
388 prefs::kConsumerManagementEnrollmentStage, stage);
389 }
390
391 void SetManagementMode(em::PolicyData::ManagementMode mode) {
392 device_policy_.policy_data().set_management_mode(mode);
393 device_policy_.Build();
394 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
395 ReloadDeviceSettings();
396 }
397
398 ScopedTestingLocalState testing_local_state_;
399 ConsumerManagementService service_;
400 };
401
402 TEST_F(ConsumerManagementServiceStatusTest, GetStatusWorks) {
403 EXPECT_EQ(ConsumerManagementService::STATUS_UNKNOWN, service_.GetStatus());
404
405 SetManagementMode(em::PolicyData::NOT_MANAGED);
406 SetEnrollmentStage(ConsumerManagementService::ENROLLMENT_STAGE_NONE);
407
408 EXPECT_EQ(ConsumerManagementService::STATUS_UNENROLLED, service_.GetStatus());
409
410 SetEnrollmentStage(ConsumerManagementService::ENROLLMENT_STAGE_REQUESTED);
411
412 EXPECT_EQ(ConsumerManagementService::STATUS_ENROLLING, service_.GetStatus());
413
414 SetManagementMode(em::PolicyData::CONSUMER_MANAGED);
415 SetEnrollmentStage(ConsumerManagementService::ENROLLMENT_STAGE_SUCCESS);
416
417 EXPECT_EQ(ConsumerManagementService::STATUS_ENROLLED, service_.GetStatus());
418
419 // TODO(davidyu): Test for STATUS_UNENROLLING when it is implemented.
420 // http://crbug.com/353050.
421 }
422
423 TEST_F(ConsumerManagementServiceStatusTest, GetStatusStringWorks) {
424 EXPECT_EQ("STATUS_UNKNOWN",
425 ConsumerManagementService::GetStatusString(
426 ConsumerManagementService::STATUS_UNKNOWN));
427
428 EXPECT_EQ("STATUS_UNENROLLED",
429 ConsumerManagementService::GetStatusString(
430 ConsumerManagementService::STATUS_UNENROLLED));
431 }
432
363 } // namespace policy 433 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698