Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| 11 #include "base/prefs/testing_pref_service.h" | 11 #include "base/prefs/testing_pref_service.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/browser_process_platform_part.h" | 14 #include "chrome/browser/browser_process_platform_part.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 16 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 19 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" | 19 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" |
| 20 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" | 20 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" |
| 21 #include "chrome/browser/chromeos/policy/fake_device_cloud_policy_initializer.h" | 21 #include "chrome/browser/chromeos/policy/fake_device_cloud_policy_initializer.h" |
| 22 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 24 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 24 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 25 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 26 #include "chrome/browser/signin/signin_manager_factory.h" | 27 #include "chrome/browser/signin/signin_manager_factory.h" |
| 27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/test/base/scoped_testing_local_state.h" | 29 #include "chrome/test/base/browser_with_test_window_test.h" |
| 29 #include "chrome/test/base/testing_browser_process.h" | 30 #include "chrome/test/base/testing_browser_process.h" |
| 30 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
| 32 #include "chrome/test/base/testing_profile_manager.h" | |
| 31 #include "chromeos/dbus/cryptohome/rpc.pb.h" | 33 #include "chromeos/dbus/cryptohome/rpc.pb.h" |
| 32 #include "chromeos/dbus/cryptohome_client.h" | 34 #include "chromeos/dbus/cryptohome_client.h" |
| 33 #include "chromeos/dbus/mock_cryptohome_client.h" | 35 #include "chromeos/dbus/mock_cryptohome_client.h" |
| 34 #include "components/policy/core/common/cloud/device_management_service.h" | 36 #include "components/policy/core/common/cloud/device_management_service.h" |
| 35 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 37 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 36 #include "components/signin/core/browser/signin_manager_base.h" | 38 #include "components/signin/core/browser/signin_manager_base.h" |
| 37 #include "content/public/browser/notification_details.h" | 39 #include "content/public/browser/notification_details.h" |
| 38 #include "content/public/browser/notification_source.h" | 40 #include "content/public/browser/notification_source.h" |
| 39 #include "content/public/test/test_browser_thread_bundle.h" | |
| 40 #include "google_apis/gaia/google_service_auth_error.h" | 41 #include "google_apis/gaia/google_service_auth_error.h" |
| 41 #include "policy/proto/device_management_backend.pb.h" | 42 #include "policy/proto/device_management_backend.pb.h" |
| 42 #include "testing/gmock/include/gmock/gmock.h" | 43 #include "testing/gmock/include/gmock/gmock.h" |
| 43 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
|
bartfab (slow)
2014/08/20 13:55:52
Nit: No longer used.
davidyu
2014/08/21 04:08:26
Shouldn't I include it for EXPECT_* and ASSERT_*?
bartfab (slow)
2014/08/21 12:04:25
Yes, you are right. Sorry, the include policy gets
davidyu
2014/08/22 04:23:10
Do you have a way to automatically check the heade
bartfab (slow)
2014/08/25 13:07:30
Sorry, I mistyped. I meant to say "include police"
| |
| 44 | 45 |
| 45 using testing::Invoke; | 46 using testing::Invoke; |
| 46 using testing::NiceMock; | 47 using testing::NiceMock; |
| 47 using testing::Return; | 48 using testing::Return; |
| 48 using testing::_; | 49 using testing::_; |
| 49 | 50 |
| 50 namespace { | 51 namespace { |
| 51 const char* kAttributeOwnerId = "consumer_management.owner_id"; | 52 const char* kAttributeOwnerId = "consumer_management.owner_id"; |
| 52 const char* kTestOwner = "test@chromium.org.test"; | 53 const char* kTestOwner = "test@chromium.org.test"; |
| 53 } | 54 } |
| 54 | 55 |
| 55 namespace policy { | 56 namespace policy { |
| 56 | 57 |
| 57 class ConsumerManagementServiceTest : public testing::Test { | 58 class ConsumerManagementServiceTest : public BrowserWithTestWindowTest { |
| 58 public: | 59 public: |
| 59 ConsumerManagementServiceTest() | 60 ConsumerManagementServiceTest() |
| 60 : testing_local_state_(TestingBrowserProcess::GetGlobal()), | 61 : service_(new ConsumerManagementService(&mock_cryptohome_client_)), |
| 61 service_(new ConsumerManagementService(&mock_cryptohome_client_)), | |
| 62 cryptohome_result_(false), | 62 cryptohome_result_(false), |
| 63 set_owner_status_(false) { | 63 set_owner_status_(false) { |
| 64 ON_CALL(mock_cryptohome_client_, GetBootAttribute(_, _)) | 64 ON_CALL(mock_cryptohome_client_, GetBootAttribute(_, _)) |
| 65 .WillByDefault( | 65 .WillByDefault( |
| 66 Invoke(this, &ConsumerManagementServiceTest::MockGetBootAttribute)); | 66 Invoke(this, &ConsumerManagementServiceTest::MockGetBootAttribute)); |
| 67 ON_CALL(mock_cryptohome_client_, SetBootAttribute(_, _)) | 67 ON_CALL(mock_cryptohome_client_, SetBootAttribute(_, _)) |
| 68 .WillByDefault( | 68 .WillByDefault( |
| 69 Invoke(this, &ConsumerManagementServiceTest::MockSetBootAttribute)); | 69 Invoke(this, &ConsumerManagementServiceTest::MockSetBootAttribute)); |
| 70 ON_CALL(mock_cryptohome_client_, FlushAndSignBootAttributes(_, _)) | 70 ON_CALL(mock_cryptohome_client_, FlushAndSignBootAttributes(_, _)) |
| 71 .WillByDefault( | 71 .WillByDefault( |
| 72 Invoke(this, | 72 Invoke(this, |
| 73 &ConsumerManagementServiceTest:: | 73 &ConsumerManagementServiceTest:: |
| 74 MockFlushAndSignBootAttributes)); | 74 MockFlushAndSignBootAttributes)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 virtual void SetUp() OVERRIDE { | |
| 78 BrowserWithTestWindowTest::SetUp(); | |
| 79 | |
| 80 testing_profile_manager_.reset(new TestingProfileManager( | |
| 81 TestingBrowserProcess::GetGlobal())); | |
| 82 ASSERT_TRUE(testing_profile_manager_->SetUp()); | |
| 83 } | |
| 84 | |
| 85 virtual void TearDown() OVERRIDE { | |
| 86 testing_profile_manager_.reset(); | |
| 87 | |
| 88 BrowserWithTestWindowTest::TearDown(); | |
| 89 } | |
| 90 | |
| 77 ConsumerManagementService::ConsumerEnrollmentState GetEnrollmentState() { | 91 ConsumerManagementService::ConsumerEnrollmentState GetEnrollmentState() { |
| 78 return static_cast<ConsumerManagementService::ConsumerEnrollmentState>( | 92 return static_cast<ConsumerManagementService::ConsumerEnrollmentState>( |
| 79 testing_local_state_.Get()->GetInteger( | 93 g_browser_process->local_state()->GetInteger( |
|
bartfab (slow)
2014/08/20 13:55:52
Nit: #include "base/prefs/pref_service.h"
davidyu
2014/08/21 04:08:26
Done.
| |
| 80 prefs::kConsumerManagementEnrollmentState)); | 94 prefs::kConsumerManagementEnrollmentState)); |
| 81 } | 95 } |
| 82 | 96 |
| 83 void SetEnrollmentState( | 97 void SetEnrollmentState( |
| 84 ConsumerManagementService::ConsumerEnrollmentState state) { | 98 ConsumerManagementService::ConsumerEnrollmentState state) { |
| 85 testing_local_state_.Get()->SetInteger( | 99 g_browser_process->local_state()->SetInteger( |
| 86 prefs::kConsumerManagementEnrollmentState, state); | 100 prefs::kConsumerManagementEnrollmentState, state); |
| 87 } | 101 } |
| 88 | 102 |
| 89 void MockGetBootAttribute( | 103 void MockGetBootAttribute( |
| 90 const cryptohome::GetBootAttributeRequest& request, | 104 const cryptohome::GetBootAttributeRequest& request, |
| 91 const chromeos::CryptohomeClient::ProtobufMethodCallback& callback) { | 105 const chromeos::CryptohomeClient::ProtobufMethodCallback& callback) { |
| 92 get_boot_attribute_request_ = request; | 106 get_boot_attribute_request_ = request; |
| 93 callback.Run(cryptohome_status_, cryptohome_result_, cryptohome_reply_); | 107 callback.Run(cryptohome_status_, cryptohome_result_, cryptohome_reply_); |
| 94 } | 108 } |
| 95 | 109 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 107 } | 121 } |
| 108 | 122 |
| 109 void OnGetOwnerDone(const std::string& owner) { | 123 void OnGetOwnerDone(const std::string& owner) { |
| 110 owner_ = owner; | 124 owner_ = owner; |
| 111 } | 125 } |
| 112 | 126 |
| 113 void OnSetOwnerDone(bool status) { | 127 void OnSetOwnerDone(bool status) { |
| 114 set_owner_status_ = status; | 128 set_owner_status_ = status; |
| 115 } | 129 } |
| 116 | 130 |
| 117 ScopedTestingLocalState testing_local_state_; | |
| 118 NiceMock<chromeos::MockCryptohomeClient> mock_cryptohome_client_; | 131 NiceMock<chromeos::MockCryptohomeClient> mock_cryptohome_client_; |
| 119 scoped_ptr<ConsumerManagementService> service_; | 132 scoped_ptr<ConsumerManagementService> service_; |
| 120 | 133 |
| 134 scoped_ptr<TestingProfileManager> testing_profile_manager_; | |
| 121 chromeos::DBusMethodCallStatus cryptohome_status_; | 135 chromeos::DBusMethodCallStatus cryptohome_status_; |
| 122 bool cryptohome_result_; | 136 bool cryptohome_result_; |
| 123 cryptohome::BaseReply cryptohome_reply_; | 137 cryptohome::BaseReply cryptohome_reply_; |
| 124 cryptohome::GetBootAttributeRequest get_boot_attribute_request_; | 138 cryptohome::GetBootAttributeRequest get_boot_attribute_request_; |
| 125 cryptohome::SetBootAttributeRequest set_boot_attribute_request_; | 139 cryptohome::SetBootAttributeRequest set_boot_attribute_request_; |
| 126 | 140 |
| 127 std::string owner_; | 141 std::string owner_; |
| 128 bool set_owner_status_; | 142 bool set_owner_status_; |
| 129 }; | 143 }; |
| 130 | 144 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 } | 211 } |
| 198 | 212 |
| 199 class ConsumerManagementServiceEnrollmentTest | 213 class ConsumerManagementServiceEnrollmentTest |
| 200 : public ConsumerManagementServiceTest { | 214 : public ConsumerManagementServiceTest { |
| 201 public: | 215 public: |
| 202 ConsumerManagementServiceEnrollmentTest() | 216 ConsumerManagementServiceEnrollmentTest() |
| 203 : mock_user_manager_(new NiceMock<chromeos::MockUserManager>()), | 217 : mock_user_manager_(new NiceMock<chromeos::MockUserManager>()), |
| 204 scoped_user_manager_enabler_(mock_user_manager_), | 218 scoped_user_manager_enabler_(mock_user_manager_), |
| 205 fake_initializer_(new FakeDeviceCloudPolicyInitializer()), | 219 fake_initializer_(new FakeDeviceCloudPolicyInitializer()), |
| 206 enrollment_status_(EnrollmentStatus::ForStatus( | 220 enrollment_status_(EnrollmentStatus::ForStatus( |
| 207 EnrollmentStatus::STATUS_SUCCESS)){ | 221 EnrollmentStatus::STATUS_SUCCESS)) { |
| 208 // Set up MockUserManager. The first user will be the owner. | 222 // Set up MockUserManager. The first user will be the owner. |
| 209 mock_user_manager_->AddUser(kTestOwner); | 223 mock_user_manager_->AddUser(kTestOwner); |
| 210 | 224 |
| 211 // Return false for IsCurrentUserOwner() so that the enrollment state is not | 225 // Return false for IsCurrentUserOwner() so that the enrollment state is not |
| 212 // reset. | 226 // reset. |
| 213 ON_CALL(*mock_user_manager_, IsCurrentUserOwner()) | 227 ON_CALL(*mock_user_manager_, IsCurrentUserOwner()) |
| 214 .WillByDefault(Return(false)); | 228 .WillByDefault(Return(false)); |
| 215 | 229 |
| 216 // Create test profile and set up FakeProfileOAuth2TokenService. | |
| 217 TestingProfile::Builder builder; | |
| 218 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), | |
| 219 &BuildAutoIssuingFakeProfileOAuth2TokenService); | |
| 220 testing_owner_profile_ = builder.Build(); | |
| 221 testing_owner_profile_->set_profile_name(kTestOwner); | |
| 222 | |
| 223 // Set up the authenticated user name and ID. | |
| 224 SigninManagerFactory::GetForProfile(testing_owner_profile_.get())-> | |
| 225 SetAuthenticatedUsername(kTestOwner); | |
| 226 | |
| 227 // Issue a fake refresh token. | |
| 228 GetFakeProfileOAuth2TokenService()-> | |
| 229 IssueRefreshTokenForUser(kTestOwner, "fake_token"); | |
| 230 | |
| 231 // Inject FakeDeviceCloudPolicyInitializer. | 230 // Inject FakeDeviceCloudPolicyInitializer. |
| 232 BrowserPolicyConnectorChromeOS* connector = | 231 BrowserPolicyConnectorChromeOS* connector = |
| 233 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 232 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 234 connector->SetDeviceCloudPolicyInitializerForTesting( | 233 connector->SetDeviceCloudPolicyInitializerForTesting( |
| 235 scoped_ptr<DeviceCloudPolicyInitializer>(fake_initializer_)); | 234 scoped_ptr<DeviceCloudPolicyInitializer>(fake_initializer_)); |
| 235 } | |
| 236 | |
| 237 virtual void SetUp() OVERRIDE { | |
| 238 ConsumerManagementServiceTest::SetUp(); | |
| 239 | |
| 240 // Set up the testing profile. | |
| 241 profile()->set_profile_name(kTestOwner); | |
| 242 | |
| 243 // Set up FakeProfileOAuth2TokenService and issue a fake refresh token. | |
| 244 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( | |
| 245 profile(), &BuildAutoIssuingFakeProfileOAuth2TokenService); | |
| 246 GetFakeProfileOAuth2TokenService()-> | |
| 247 IssueRefreshTokenForUser(kTestOwner, "fake_token"); | |
| 248 | |
| 249 // Set up the authenticated user name and ID. | |
| 250 SigninManagerFactory::GetForProfile(profile())-> | |
| 251 SetAuthenticatedUsername(kTestOwner); | |
| 236 | 252 |
| 237 // The service should continue the enrollment process if the state is | 253 // The service should continue the enrollment process if the state is |
| 238 // ENROLLMENT_OWNER_STORED. | 254 // ENROLLMENT_OWNER_STORED. |
| 239 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_OWNER_STORED); | 255 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_OWNER_STORED); |
| 240 } | 256 } |
| 241 | 257 |
| 258 virtual void TearDown() OVERRIDE { | |
| 259 g_browser_process->notification_ui_manager()->CancelAll(); | |
| 260 | |
| 261 ConsumerManagementServiceTest::TearDown(); | |
| 262 } | |
| 263 | |
| 242 FakeProfileOAuth2TokenService* GetFakeProfileOAuth2TokenService() { | 264 FakeProfileOAuth2TokenService* GetFakeProfileOAuth2TokenService() { |
| 243 return static_cast<FakeProfileOAuth2TokenService*>( | 265 return static_cast<FakeProfileOAuth2TokenService*>( |
| 244 ProfileOAuth2TokenServiceFactory::GetForProfile( | 266 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); |
| 245 testing_owner_profile_.get())); | 267 } |
| 268 | |
| 269 bool HasEnrollmentNotification() { | |
| 270 return g_browser_process->notification_ui_manager()-> | |
| 271 FindById("consumer_management.enroll") != NULL; | |
|
bartfab (slow)
2014/08/20 13:55:52
Nit: No need for the "!= NULL" part.
davidyu
2014/08/21 04:08:26
Done.
| |
| 246 } | 272 } |
| 247 | 273 |
| 248 void RunEnrollmentTest() { | 274 void RunEnrollmentTest() { |
| 249 // Send the profile prepared notification to continue the enrollment. | 275 // Send the profile prepared notification to continue the enrollment. |
| 250 service_->Observe(chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 276 service_->Observe(chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 251 content::Source<void>(NULL), // Not used. | 277 content::Source<void>(NULL), // Not used. |
| 252 content::Details<Profile>(testing_owner_profile_.get())); | 278 content::Details<Profile>(profile())); |
| 253 base::RunLoop().RunUntilIdle(); | 279 base::RunLoop().RunUntilIdle(); |
| 254 } | 280 } |
| 255 | 281 |
| 256 content::TestBrowserThreadBundle thread_bundle_; | |
| 257 | |
| 258 NiceMock<chromeos::MockUserManager>* mock_user_manager_; | 282 NiceMock<chromeos::MockUserManager>* mock_user_manager_; |
| 259 chromeos::ScopedUserManagerEnabler scoped_user_manager_enabler_; | 283 chromeos::ScopedUserManagerEnabler scoped_user_manager_enabler_; |
| 260 scoped_ptr<TestingProfile> testing_owner_profile_; | |
| 261 FakeDeviceCloudPolicyInitializer* fake_initializer_; | 284 FakeDeviceCloudPolicyInitializer* fake_initializer_; |
| 262 EnrollmentStatus enrollment_status_; | 285 EnrollmentStatus enrollment_status_; |
| 263 }; | 286 }; |
| 264 | 287 |
| 265 TEST_F(ConsumerManagementServiceEnrollmentTest, EnrollsSuccessfully) { | 288 TEST_F(ConsumerManagementServiceEnrollmentTest, EnrollsSuccessfully) { |
| 266 EXPECT_FALSE(fake_initializer_->is_start_enrollment_called()); | 289 EXPECT_FALSE(fake_initializer_->is_start_enrollment_called()); |
| 290 EXPECT_FALSE(HasEnrollmentNotification()); | |
| 267 | 291 |
| 268 RunEnrollmentTest(); | 292 RunEnrollmentTest(); |
| 269 | 293 |
| 270 EXPECT_TRUE(fake_initializer_->is_start_enrollment_called()); | 294 EXPECT_TRUE(fake_initializer_->is_start_enrollment_called()); |
| 271 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_SUCCESS, | 295 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_SUCCESS, |
| 272 GetEnrollmentState()); | 296 GetEnrollmentState()); |
| 297 EXPECT_FALSE(HasEnrollmentNotification()); | |
| 273 } | 298 } |
| 274 | 299 |
| 275 TEST_F(ConsumerManagementServiceEnrollmentTest, | 300 TEST_F(ConsumerManagementServiceEnrollmentTest, |
| 276 EnrollmentStateIsResetIfCurrentUserIsOwner) { | 301 ShowsDesktopNotificationAndResetsEnrollmentStateIfCurrentUserIsOwner) { |
| 277 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_OWNER_STORED, | 302 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_OWNER_STORED, |
| 278 GetEnrollmentState()); | 303 GetEnrollmentState()); |
| 279 | 304 EXPECT_FALSE(HasEnrollmentNotification()); |
| 280 EXPECT_CALL(*mock_user_manager_, IsCurrentUserOwner()) | 305 EXPECT_CALL(*mock_user_manager_, IsCurrentUserOwner()) |
| 281 .WillOnce(Return(true)); | 306 .WillOnce(Return(true)); |
| 282 | 307 |
| 283 RunEnrollmentTest(); | 308 RunEnrollmentTest(); |
| 284 | 309 |
| 285 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_NONE, GetEnrollmentState()); | 310 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_NONE, GetEnrollmentState()); |
| 311 EXPECT_TRUE(HasEnrollmentNotification()); | |
| 286 } | 312 } |
| 287 | 313 |
| 288 TEST_F(ConsumerManagementServiceEnrollmentTest, FailsToGetAccessToken) { | 314 TEST_F(ConsumerManagementServiceEnrollmentTest, FailsToGetAccessToken) { |
| 289 // Disable auto-posting so that RunEnrollmentTest() should stop and wait for | 315 // Disable auto-posting so that RunEnrollmentTest() should stop and wait for |
| 290 // the access token to be available. | 316 // the access token to be available. |
| 291 GetFakeProfileOAuth2TokenService()-> | 317 GetFakeProfileOAuth2TokenService()-> |
| 292 set_auto_post_fetch_response_on_message_loop(false); | 318 set_auto_post_fetch_response_on_message_loop(false); |
| 293 EXPECT_FALSE(fake_initializer_->is_start_enrollment_called()); | 319 EXPECT_FALSE(fake_initializer_->is_start_enrollment_called()); |
| 294 | 320 |
| 295 RunEnrollmentTest(); | 321 RunEnrollmentTest(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 315 fake_initializer_->set_enrollment_status(EnrollmentStatus::ForStatus( | 341 fake_initializer_->set_enrollment_status(EnrollmentStatus::ForStatus( |
| 316 EnrollmentStatus::STATUS_REGISTRATION_FAILED)); | 342 EnrollmentStatus::STATUS_REGISTRATION_FAILED)); |
| 317 | 343 |
| 318 RunEnrollmentTest(); | 344 RunEnrollmentTest(); |
| 319 | 345 |
| 320 EXPECT_TRUE(fake_initializer_->is_start_enrollment_called()); | 346 EXPECT_TRUE(fake_initializer_->is_start_enrollment_called()); |
| 321 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_DM_SERVER_FAILED, | 347 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_DM_SERVER_FAILED, |
| 322 GetEnrollmentState()); | 348 GetEnrollmentState()); |
| 323 } | 349 } |
| 324 | 350 |
| 325 TEST_F(ConsumerManagementServiceEnrollmentTest, ShowsDesktopNotificationOnly) { | 351 TEST_F(ConsumerManagementServiceEnrollmentTest, |
| 352 ShowsDesktopNotificationOnlyIfEnrollmentIsAlreadyCompleted) { | |
| 326 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_CANCELED); | 353 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_CANCELED); |
| 327 EXPECT_FALSE(fake_initializer_->is_start_enrollment_called()); | 354 EXPECT_FALSE(HasEnrollmentNotification()); |
| 328 | 355 |
| 329 RunEnrollmentTest(); | 356 RunEnrollmentTest(); |
| 330 | 357 |
| 331 // TODO(davidyu): Check that the desktop notification was shown. | |
| 332 | |
| 333 EXPECT_FALSE(fake_initializer_->is_start_enrollment_called()); | 358 EXPECT_FALSE(fake_initializer_->is_start_enrollment_called()); |
| 334 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_NONE, GetEnrollmentState()); | 359 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_NONE, GetEnrollmentState()); |
| 360 EXPECT_TRUE(HasEnrollmentNotification()); | |
| 335 } | 361 } |
| 336 | 362 |
| 337 } // namespace policy | 363 } // namespace policy |
| OLD | NEW |