| 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::SHOWING_TERMS_OF_SERVICE, |
| 136 auth_service()->state()); |
| 136 | 137 |
| 137 pref->SetBoolean(prefs::kArcEnabled, false); | 138 pref->SetBoolean(prefs::kArcEnabled, false); |
| 138 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 139 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
| 139 | 140 |
| 140 // Correctly stop service. | 141 // Correctly stop service. |
| 141 auth_service()->Shutdown(); | 142 auth_service()->Shutdown(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 TEST_F(ArcAuthServiceTest, DisabledForEphemeralDataUsers) { | 145 TEST_F(ArcAuthServiceTest, DisabledForEphemeralDataUsers) { |
| 145 PrefService* const prefs = profile()->GetPrefs(); | 146 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()); | 189 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); |
| 189 | 190 |
| 190 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 191 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
| 191 | 192 |
| 192 // By default ARC is not enabled. | 193 // By default ARC is not enabled. |
| 193 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 194 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
| 194 | 195 |
| 195 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 196 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 196 | 197 |
| 197 // Setting profile and pref initiates a code fetching process. | 198 // Setting profile and pref initiates a code fetching process. |
| 198 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 199 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, |
| 200 auth_service()->state()); |
| 199 | 201 |
| 202 // TODO(hidehiko): Verify state transition from SHOWINING_TERMS_OF_SERVICE -> |
| 203 // CHECKING_ANDROID_MANAGEMENT -> FETCHING_CODE, when we extract |
| 204 // ArcSessionManager. |
| 200 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); | 205 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); |
| 201 | 206 |
| 202 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 207 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
| 203 ASSERT_TRUE(bridge_service()->ready()); | 208 ASSERT_TRUE(bridge_service()->ready()); |
| 204 // Auth code valid only for one call. | 209 // Auth code valid only for one call. |
| 205 ASSERT_EQ(kTestAuthCode, auth_service()->GetAndResetAuthCode()); | 210 ASSERT_EQ(kTestAuthCode, auth_service()->GetAndResetAuthCode()); |
| 206 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); | 211 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); |
| 207 | 212 |
| 208 auth_service()->Shutdown(); | 213 auth_service()->Shutdown(); |
| 209 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); | 214 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); |
| 210 ASSERT_FALSE(bridge_service()->ready()); | 215 ASSERT_FALSE(bridge_service()->ready()); |
| 211 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); | 216 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); |
| 212 | 217 |
| 213 // Send profile and don't provide a code. | 218 // Send profile and don't provide a code. |
| 214 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 219 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
| 215 | 220 |
| 216 // Setting profile initiates a code fetching process. | 221 // Setting profile initiates a code fetching process. |
| 217 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 222 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, |
| 223 auth_service()->state()); |
| 218 | 224 |
| 219 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 225 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 220 base::RunLoop().RunUntilIdle(); | 226 base::RunLoop().RunUntilIdle(); |
| 221 | 227 |
| 222 // UI is disabled in unit tests and this code is unchanged. | 228 // UI is disabled in unit tests and this code is unchanged. |
| 223 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 229 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, |
| 230 auth_service()->state()); |
| 224 | 231 |
| 225 // Correctly stop service. | 232 // Correctly stop service. |
| 226 auth_service()->Shutdown(); | 233 auth_service()->Shutdown(); |
| 227 } | 234 } |
| 228 | 235 |
| 229 TEST_F(ArcAuthServiceTest, CancelFetchingDisablesArc) { | 236 TEST_F(ArcAuthServiceTest, CancelFetchingDisablesArc) { |
| 230 PrefService* const pref = profile()->GetPrefs(); | 237 PrefService* const pref = profile()->GetPrefs(); |
| 231 | 238 |
| 232 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 239 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
| 233 pref->SetBoolean(prefs::kArcEnabled, true); | 240 pref->SetBoolean(prefs::kArcEnabled, true); |
| 234 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 241 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, |
| 242 auth_service()->state()); |
| 235 | 243 |
| 236 auth_service()->CancelAuthCode(); | 244 auth_service()->CancelAuthCode(); |
| 237 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 245 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
| 238 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 246 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
| 239 | 247 |
| 240 // Correctly stop service. | 248 // Correctly stop service. |
| 241 auth_service()->Shutdown(); | 249 auth_service()->Shutdown(); |
| 242 } | 250 } |
| 243 | 251 |
| 244 TEST_F(ArcAuthServiceTest, CloseUIKeepsArcEnabled) { | 252 TEST_F(ArcAuthServiceTest, CloseUIKeepsArcEnabled) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 273 auth_service()->Shutdown(); | 281 auth_service()->Shutdown(); |
| 274 } | 282 } |
| 275 | 283 |
| 276 TEST_F(ArcAuthServiceTest, SignInStatus) { | 284 TEST_F(ArcAuthServiceTest, SignInStatus) { |
| 277 PrefService* const prefs = profile()->GetPrefs(); | 285 PrefService* const prefs = profile()->GetPrefs(); |
| 278 | 286 |
| 279 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 287 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 280 prefs->SetBoolean(prefs::kArcEnabled, true); | 288 prefs->SetBoolean(prefs::kArcEnabled, true); |
| 281 | 289 |
| 282 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 290 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
| 283 EXPECT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 291 EXPECT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, |
| 292 auth_service()->state()); |
| 284 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); | 293 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); |
| 285 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 294 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
| 286 EXPECT_TRUE(bridge_service()->ready()); | 295 EXPECT_TRUE(bridge_service()->ready()); |
| 287 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 296 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 288 auth_service()->OnSignInComplete(); | 297 auth_service()->OnSignInComplete(); |
| 289 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); | 298 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 290 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 299 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
| 291 EXPECT_TRUE(bridge_service()->ready()); | 300 EXPECT_TRUE(bridge_service()->ready()); |
| 292 | 301 |
| 293 // Second start, no fetching code is expected. | 302 // 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); | 368 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 360 | 369 |
| 361 // Check that non-primary user can't use Arc. | 370 // Check that non-primary user can't use Arc. |
| 362 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); | 371 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); |
| 363 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); | 372 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); |
| 364 | 373 |
| 365 auth_service()->Shutdown(); | 374 auth_service()->Shutdown(); |
| 366 } | 375 } |
| 367 | 376 |
| 368 } // namespace arc | 377 } // namespace arc |
| OLD | NEW |