| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 TEST_F(ArcAuthServiceTest, PrefChangeTriggersService) { | 125 TEST_F(ArcAuthServiceTest, PrefChangeTriggersService) { |
| 126 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); | 126 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); |
| 127 | 127 |
| 128 PrefService* const pref = profile()->GetPrefs(); | 128 PrefService* const pref = profile()->GetPrefs(); |
| 129 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 129 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
| 130 | 130 |
| 131 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 131 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
| 132 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 132 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
| 133 | 133 |
| 134 pref->SetBoolean(prefs::kArcEnabled, true); | 134 pref->SetBoolean(prefs::kArcEnabled, true); |
| 135 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 135 ASSERT_EQ(ArcAuthService::State::TERMS, auth_service()->state()); |
| 136 | 136 |
| 137 pref->SetBoolean(prefs::kArcEnabled, false); | 137 pref->SetBoolean(prefs::kArcEnabled, false); |
| 138 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 138 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
| 139 | 139 |
| 140 // Correctly stop service. | 140 // Correctly stop service. |
| 141 auth_service()->Shutdown(); | 141 auth_service()->Shutdown(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 TEST_F(ArcAuthServiceTest, DisabledForEphemeralDataUsers) { | 144 TEST_F(ArcAuthServiceTest, DisabledForEphemeralDataUsers) { |
| 145 PrefService* const prefs = profile()->GetPrefs(); | 145 PrefService* const prefs = profile()->GetPrefs(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); | 188 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); |
| 189 | 189 |
| 190 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 190 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
| 191 | 191 |
| 192 // By default ARC is not enabled. | 192 // By default ARC is not enabled. |
| 193 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 193 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
| 194 | 194 |
| 195 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 195 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 196 | 196 |
| 197 // Setting profile and pref initiates a code fetching process. | 197 // Setting profile and pref initiates a code fetching process. |
| 198 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 198 ASSERT_EQ(ArcAuthService::State::TERMS, auth_service()->state()); |
| 199 | 199 |
| 200 // TODO(hidehiko): Verify state transition from TERMS -> |
| 201 // ANDROID_MANAGEMENT_CHECK -> FETCHING_CODE, when we extract |
| 202 // ArcSessionManager. |
| 200 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); | 203 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); |
| 201 | 204 |
| 202 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 205 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
| 203 ASSERT_TRUE(bridge_service()->ready()); | 206 ASSERT_TRUE(bridge_service()->ready()); |
| 204 // Auth code valid only for one call. | 207 // Auth code valid only for one call. |
| 205 ASSERT_EQ(kTestAuthCode, auth_service()->GetAndResetAuthCode()); | 208 ASSERT_EQ(kTestAuthCode, auth_service()->GetAndResetAuthCode()); |
| 206 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); | 209 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); |
| 207 | 210 |
| 208 auth_service()->Shutdown(); | 211 auth_service()->Shutdown(); |
| 209 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); | 212 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); |
| 210 ASSERT_FALSE(bridge_service()->ready()); | 213 ASSERT_FALSE(bridge_service()->ready()); |
| 211 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); | 214 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); |
| 212 | 215 |
| 213 // Send profile and don't provide a code. | 216 // Send profile and don't provide a code. |
| 214 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 217 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
| 215 | 218 |
| 216 // Setting profile initiates a code fetching process. | 219 // Setting profile initiates a code fetching process. |
| 217 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 220 ASSERT_EQ(ArcAuthService::State::TERMS, auth_service()->state()); |
| 218 | 221 |
| 219 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 222 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 220 base::RunLoop().RunUntilIdle(); | 223 base::RunLoop().RunUntilIdle(); |
| 221 | 224 |
| 222 // UI is disabled in unit tests and this code is unchanged. | 225 // UI is disabled in unit tests and this code is unchanged. |
| 223 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 226 ASSERT_EQ(ArcAuthService::State::TERMS, auth_service()->state()); |
| 224 | 227 |
| 225 // Correctly stop service. | 228 // Correctly stop service. |
| 226 auth_service()->Shutdown(); | 229 auth_service()->Shutdown(); |
| 227 } | 230 } |
| 228 | 231 |
| 229 TEST_F(ArcAuthServiceTest, CancelFetchingDisablesArc) { | 232 TEST_F(ArcAuthServiceTest, CancelFetchingDisablesArc) { |
| 230 PrefService* const pref = profile()->GetPrefs(); | 233 PrefService* const pref = profile()->GetPrefs(); |
| 231 | 234 |
| 232 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 235 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
| 233 pref->SetBoolean(prefs::kArcEnabled, true); | 236 pref->SetBoolean(prefs::kArcEnabled, true); |
| 234 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 237 ASSERT_EQ(ArcAuthService::State::TERMS, auth_service()->state()); |
| 235 | 238 |
| 236 auth_service()->CancelAuthCode(); | 239 auth_service()->CancelAuthCode(); |
| 237 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 240 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
| 238 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 241 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
| 239 | 242 |
| 240 // Correctly stop service. | 243 // Correctly stop service. |
| 241 auth_service()->Shutdown(); | 244 auth_service()->Shutdown(); |
| 242 } | 245 } |
| 243 | 246 |
| 244 TEST_F(ArcAuthServiceTest, CloseUIKeepsArcEnabled) { | 247 TEST_F(ArcAuthServiceTest, CloseUIKeepsArcEnabled) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 273 auth_service()->Shutdown(); | 276 auth_service()->Shutdown(); |
| 274 } | 277 } |
| 275 | 278 |
| 276 TEST_F(ArcAuthServiceTest, SignInStatus) { | 279 TEST_F(ArcAuthServiceTest, SignInStatus) { |
| 277 PrefService* const prefs = profile()->GetPrefs(); | 280 PrefService* const prefs = profile()->GetPrefs(); |
| 278 | 281 |
| 279 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 282 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 280 prefs->SetBoolean(prefs::kArcEnabled, true); | 283 prefs->SetBoolean(prefs::kArcEnabled, true); |
| 281 | 284 |
| 282 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 285 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
| 283 EXPECT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 286 EXPECT_EQ(ArcAuthService::State::TERMS, auth_service()->state()); |
| 284 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); | 287 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); |
| 285 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 288 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
| 286 EXPECT_TRUE(bridge_service()->ready()); | 289 EXPECT_TRUE(bridge_service()->ready()); |
| 287 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 290 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 288 auth_service()->OnSignInComplete(); | 291 auth_service()->OnSignInComplete(); |
| 289 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); | 292 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 290 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 293 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
| 291 EXPECT_TRUE(bridge_service()->ready()); | 294 EXPECT_TRUE(bridge_service()->ready()); |
| 292 | 295 |
| 293 // Second start, no fetching code is expected. | 296 // Second start, no fetching code is expected. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 362 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 360 | 363 |
| 361 // Check that non-primary user can't use Arc. | 364 // Check that non-primary user can't use Arc. |
| 362 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); | 365 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); |
| 363 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); | 366 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); |
| 364 | 367 |
| 365 auth_service()->Shutdown(); | 368 auth_service()->Shutdown(); |
| 366 } | 369 } |
| 367 | 370 |
| 368 } // namespace arc | 371 } // namespace arc |
| OLD | NEW |