| 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 <tuple> | 7 #include <tuple> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 public: | 207 public: |
| 208 ArcSessionManagerTest() = default; | 208 ArcSessionManagerTest() = default; |
| 209 | 209 |
| 210 void SetUp() override { | 210 void SetUp() override { |
| 211 ArcSessionManagerTestBase::SetUp(); | 211 ArcSessionManagerTestBase::SetUp(); |
| 212 | 212 |
| 213 const AccountId account_id(AccountId::FromUserEmailGaiaId( | 213 const AccountId account_id(AccountId::FromUserEmailGaiaId( |
| 214 profile()->GetProfileUserName(), "1234567890")); | 214 profile()->GetProfileUserName(), "1234567890")); |
| 215 GetFakeUserManager()->AddUser(account_id); | 215 GetFakeUserManager()->AddUser(account_id); |
| 216 GetFakeUserManager()->LoginUser(account_id); | 216 GetFakeUserManager()->LoginUser(account_id); |
| 217 |
| 218 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 219 arc_session_manager()->state()); |
| 220 ASSERT_TRUE(arc_session_manager()->IsSessionStopped()); |
| 217 } | 221 } |
| 218 | 222 |
| 219 private: | 223 private: |
| 220 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); | 224 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); |
| 221 }; | 225 }; |
| 222 | 226 |
| 223 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { | 227 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { |
| 224 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, | 228 ASSERT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 225 arc_session_manager()->state()); | 229 arc_session_manager()->SetProfile(profile()); |
| 230 arc_session_manager()->StartPreferenceHandler(); |
| 226 | 231 |
| 227 PrefService* const pref = profile()->GetPrefs(); | 232 EXPECT_FALSE( |
| 228 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 233 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 234 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 229 | 235 |
| 230 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 236 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 231 | |
| 232 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | |
| 233 | |
| 234 pref->SetBoolean(prefs::kArcEnabled, true); | |
| 235 base::RunLoop().RunUntilIdle(); | 237 base::RunLoop().RunUntilIdle(); |
| 236 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 238 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 237 arc_session_manager()->state()); | 239 arc_session_manager()->state()); |
| 238 | 240 |
| 239 pref->SetBoolean(prefs::kArcEnabled, false); | 241 SetArcPlayStoreEnabledForProfile(profile(), false); |
| 240 | 242 |
| 241 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); | 243 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); |
| 242 | 244 |
| 243 // Correctly stop service. | 245 // Correctly stop service. |
| 244 arc_session_manager()->Shutdown(); | 246 arc_session_manager()->Shutdown(); |
| 245 } | 247 } |
| 246 | 248 |
| 249 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService_Restart) { |
| 250 // Sets the Google Play Store preference at beginning. |
| 251 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 252 |
| 253 arc_session_manager()->SetProfile(profile()); |
| 254 arc_session_manager()->StartPreferenceHandler(); |
| 255 |
| 256 // Setting profile initiates a code fetching process. |
| 257 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 258 arc_session_manager()->state()); |
| 259 |
| 260 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 261 base::RunLoop().RunUntilIdle(); |
| 262 |
| 263 // UI is disabled in unit tests and this code is unchanged. |
| 264 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 265 arc_session_manager()->state()); |
| 266 |
| 267 // Correctly stop service. |
| 268 arc_session_manager()->Shutdown(); |
| 269 } |
| 270 |
| 247 TEST_F(ArcSessionManagerTest, BaseWorkflow) { | 271 TEST_F(ArcSessionManagerTest, BaseWorkflow) { |
| 248 ASSERT_TRUE(arc_session_manager()->IsSessionStopped()); | |
| 249 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, | |
| 250 arc_session_manager()->state()); | |
| 251 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 272 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| 252 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); | 273 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); |
| 253 | 274 |
| 254 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 275 arc_session_manager()->SetProfile(profile()); |
| 255 | 276 |
| 256 // By default ARC is not enabled. | 277 // By default ARC is not enabled. |
| 257 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 278 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 258 | 279 |
| 259 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 280 // Enables ARC. First time, ToS negotiation should start. |
| 281 arc_session_manager()->RequestEnable(); |
| 260 base::RunLoop().RunUntilIdle(); | 282 base::RunLoop().RunUntilIdle(); |
| 261 | |
| 262 // Setting profile and pref initiates a code fetching process. | |
| 263 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 283 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 264 arc_session_manager()->state()); | 284 arc_session_manager()->state()); |
| 265 | 285 |
| 266 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> | 286 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> |
| 267 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. | 287 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. |
| 268 arc_session_manager()->StartArc(); | 288 arc_session_manager()->StartArc(); |
| 269 | 289 |
| 270 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 290 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| 271 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); | 291 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); |
| 272 | 292 |
| 273 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 293 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 274 ASSERT_TRUE(arc_session_manager()->IsSessionRunning()); | 294 ASSERT_TRUE(arc_session_manager()->IsSessionRunning()); |
| 275 | 295 |
| 276 arc_session_manager()->Shutdown(); | 296 arc_session_manager()->Shutdown(); |
| 277 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, | |
| 278 arc_session_manager()->state()); | |
| 279 ASSERT_TRUE(arc_session_manager()->IsSessionStopped()); | |
| 280 | |
| 281 // Send profile and don't provide a code. | |
| 282 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | |
| 283 | |
| 284 // Setting profile initiates a code fetching process. | |
| 285 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 286 arc_session_manager()->state()); | |
| 287 | |
| 288 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
| 289 base::RunLoop().RunUntilIdle(); | |
| 290 | |
| 291 // UI is disabled in unit tests and this code is unchanged. | |
| 292 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 293 arc_session_manager()->state()); | |
| 294 | |
| 295 // Correctly stop service. | |
| 296 arc_session_manager()->Shutdown(); | |
| 297 } | 297 } |
| 298 | 298 |
| 299 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { | 299 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { |
| 300 PrefService* const pref = profile()->GetPrefs(); | 300 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 301 | 301 |
| 302 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 302 // Starts ARC. |
| 303 pref->SetBoolean(prefs::kArcEnabled, true); | 303 arc_session_manager()->SetProfile(profile()); |
| 304 arc_session_manager()->RequestEnable(); |
| 304 base::RunLoop().RunUntilIdle(); | 305 base::RunLoop().RunUntilIdle(); |
| 305 | |
| 306 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 306 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 307 arc_session_manager()->state()); | 307 arc_session_manager()->state()); |
| 308 | 308 |
| 309 // Emulate to cancel the ToS UI (e.g. closing the window). |
| 309 arc_session_manager()->CancelAuthCode(); | 310 arc_session_manager()->CancelAuthCode(); |
| 310 | 311 |
| 312 // Google Play Store enabled preference should be set to false, too. |
| 313 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 314 |
| 315 // Emulate the preference handling. |
| 316 arc_session_manager()->RequestDisable(); |
| 317 |
| 311 // Wait until data is removed. | 318 // Wait until data is removed. |
| 312 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); | 319 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); |
| 313 | 320 |
| 314 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | |
| 315 | |
| 316 // Correctly stop service. | 321 // Correctly stop service. |
| 317 arc_session_manager()->Shutdown(); | 322 arc_session_manager()->Shutdown(); |
| 318 } | 323 } |
| 319 | 324 |
| 320 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { | 325 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { |
| 321 PrefService* const pref = profile()->GetPrefs(); | 326 // Starts ARC. |
| 322 | 327 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 323 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 328 arc_session_manager()->SetProfile(profile()); |
| 324 pref->SetBoolean(prefs::kArcEnabled, true); | 329 arc_session_manager()->RequestEnable(); |
| 325 base::RunLoop().RunUntilIdle(); | 330 base::RunLoop().RunUntilIdle(); |
| 326 | 331 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 332 arc_session_manager()->state()); |
| 327 arc_session_manager()->StartArc(); | 333 arc_session_manager()->StartArc(); |
| 328 | |
| 329 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 334 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 330 | 335 |
| 336 // When ARC is properly started, closing UI should be no-op. |
| 331 arc_session_manager()->CancelAuthCode(); | 337 arc_session_manager()->CancelAuthCode(); |
| 332 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 338 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 333 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); | 339 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); |
| 334 | 340 |
| 335 // Correctly stop service. | 341 // Correctly stop service. |
| 336 arc_session_manager()->Shutdown(); | 342 arc_session_manager()->Shutdown(); |
| 337 } | 343 } |
| 338 | 344 |
| 339 TEST_F(ArcSessionManagerTest, SignInStatus) { | 345 TEST_F(ArcSessionManagerTest, Provisioning_Success) { |
| 340 PrefService* const prefs = profile()->GetPrefs(); | 346 PrefService* const prefs = profile()->GetPrefs(); |
| 341 | 347 |
| 342 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 348 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| 343 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); | 349 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); |
| 344 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); | 350 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); |
| 345 | 351 |
| 346 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 352 ASSERT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 347 prefs->SetBoolean(prefs::kArcEnabled, true); | |
| 348 | 353 |
| 349 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 354 arc_session_manager()->SetProfile(profile()); |
| 350 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 355 arc_session_manager()->RequestEnable(); |
| 356 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 351 arc_session_manager()->state()); | 357 arc_session_manager()->state()); |
| 352 | 358 |
| 353 // Emulate to accept the terms of service. | 359 // Emulate to accept the terms of service. |
| 354 prefs->SetBoolean(prefs::kArcTermsAccepted, true); | 360 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
| 355 arc_session_manager()->StartArc(); | 361 arc_session_manager()->StartArc(); |
| 356 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 362 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 357 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); | 363 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
| 364 |
| 365 // Here, provisining is not yet completed, so kArcSignedIn should be false. |
| 358 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 366 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 359 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); | 367 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); |
| 360 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); | 368 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); |
| 369 |
| 370 // Emulate successful provisioning. |
| 361 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); | 371 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); |
| 362 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); | 372 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 363 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 373 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 364 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); | 374 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
| 365 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 375 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| 366 EXPECT_TRUE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); | 376 EXPECT_TRUE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); |
| 377 } |
| 378 |
| 379 TEST_F(ArcSessionManagerTest, Provisioning_Restart) { |
| 380 // Set up the situation that provisioning is successfully done in the |
| 381 // previous session. |
| 382 PrefService* const prefs = profile()->GetPrefs(); |
| 383 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
| 384 prefs->SetBoolean(prefs::kArcSignedIn, true); |
| 385 |
| 386 arc_session_manager()->SetProfile(profile()); |
| 387 arc_session_manager()->RequestEnable(); |
| 367 | 388 |
| 368 // Second start, no fetching code is expected. | 389 // Second start, no fetching code is expected. |
| 369 arc_session_manager()->Shutdown(); | |
| 370 EXPECT_EQ(ArcSessionManager::State::NOT_INITIALIZED, | |
| 371 arc_session_manager()->state()); | |
| 372 EXPECT_TRUE(arc_session_manager()->IsSessionStopped()); | |
| 373 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | |
| 374 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); | |
| 375 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 390 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 376 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); | 391 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
| 377 | 392 |
| 378 // Report failure. | 393 // Report failure. |
| 379 arc_session_manager()->OnProvisioningFinished( | 394 arc_session_manager()->OnProvisioningFinished( |
| 380 ProvisioningResult::GMS_NETWORK_ERROR); | 395 ProvisioningResult::GMS_NETWORK_ERROR); |
| 381 // On error, UI to send feedback is showing. In that case, | 396 // On error, UI to send feedback is showing. In that case, |
| 382 // the ARC is still necessary to run on background for gathering the logs. | 397 // the ARC is still necessary to run on background for gathering the logs. |
| 383 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); | 398 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 384 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 399 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 385 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); | 400 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
| 386 | 401 |
| 387 // Correctly stop service. | 402 // Correctly stop service. |
| 388 arc_session_manager()->Shutdown(); | 403 arc_session_manager()->Shutdown(); |
| 389 } | 404 } |
| 390 | 405 |
| 391 TEST_F(ArcSessionManagerTest, DisabledForDeviceLocalAccount) { | 406 TEST_F(ArcSessionManagerTest, RemoveDataDir) { |
| 392 PrefService* const prefs = profile()->GetPrefs(); | 407 // Emulate the situation where the initial Google Play Store enabled |
| 393 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 408 // preference is false for managed user, i.e., data dir is being removed at |
| 394 prefs->SetBoolean(prefs::kArcEnabled, true); | 409 // beginning. |
| 395 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 410 arc_session_manager()->SetProfile(profile()); |
| 396 arc_session_manager()->StartArc(); | 411 arc_session_manager()->RemoveArcData(); |
| 397 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 412 EXPECT_TRUE( |
| 398 | 413 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 399 // Create device local account and set it as active. | 414 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
| 400 const std::string email = "device-local-account@fake-email.com"; | |
| 401 TestingProfile::Builder profile_builder; | |
| 402 profile_builder.SetProfileName(email); | |
| 403 std::unique_ptr<TestingProfile> device_local_profile(profile_builder.Build()); | |
| 404 const AccountId account_id(AccountId::FromUserEmail(email)); | |
| 405 GetFakeUserManager()->AddPublicAccountUser(account_id); | |
| 406 | |
| 407 // Remove |profile_| to set the device local account be the primary account. | |
| 408 GetFakeUserManager()->RemoveUserFromList( | |
| 409 multi_user_util::GetAccountIdFromProfile(profile())); | |
| 410 GetFakeUserManager()->LoginUser(account_id); | |
| 411 | |
| 412 // Check that user without GAIA account can't use ARC. | |
| 413 device_local_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | |
| 414 arc_session_manager()->OnPrimaryUserProfilePrepared( | |
| 415 device_local_profile.get()); | |
| 416 EXPECT_EQ(ArcSessionManager::State::NOT_INITIALIZED, | |
| 417 arc_session_manager()->state()); | 415 arc_session_manager()->state()); |
| 418 | 416 |
| 419 // Correctly stop service. | |
| 420 arc_session_manager()->Shutdown(); | |
| 421 } | |
| 422 | |
| 423 TEST_F(ArcSessionManagerTest, DisabledForNonPrimaryProfile) { | |
| 424 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | |
| 425 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | |
| 426 arc_session_manager()->StartArc(); | |
| 427 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | |
| 428 | |
| 429 // Create a second profile and set it as the active profile. | |
| 430 const std::string email = "test@example.com"; | |
| 431 TestingProfile::Builder profile_builder; | |
| 432 profile_builder.SetProfileName(email); | |
| 433 std::unique_ptr<TestingProfile> second_profile(profile_builder.Build()); | |
| 434 const AccountId account_id(AccountId::FromUserEmail(email)); | |
| 435 GetFakeUserManager()->AddUser(account_id); | |
| 436 GetFakeUserManager()->SwitchActiveUser(account_id); | |
| 437 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | |
| 438 | |
| 439 // Check that non-primary user can't use ARC. | |
| 440 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); | |
| 441 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); | |
| 442 | |
| 443 arc_session_manager()->Shutdown(); | |
| 444 } | |
| 445 | |
| 446 TEST_F(ArcSessionManagerTest, RemoveDataFolder) { | |
| 447 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); | |
| 448 | |
| 449 // Starting session manager with prefs::kArcEnabled off does not automatically | |
| 450 // remove Android's data folder. | |
| 451 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | |
| 452 EXPECT_FALSE( | |
| 453 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
| 454 EXPECT_EQ(ArcSessionManager::State::STOPPED, | |
| 455 arc_session_manager()->state()); | |
| 456 // Enable ARC. Data is removed asyncronously. At this moment session manager | 417 // Enable ARC. Data is removed asyncronously. At this moment session manager |
| 457 // should be in REMOVING_DATA_DIR state. | 418 // should be in REMOVING_DATA_DIR state. |
| 458 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 419 arc_session_manager()->RequestEnable(); |
| 459 // Data should still not be removed. | 420 EXPECT_TRUE( |
| 421 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 422 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
| 423 arc_session_manager()->state()); |
| 424 // Wait until data is removed. |
| 425 base::RunLoop().RunUntilIdle(); |
| 460 EXPECT_FALSE( | 426 EXPECT_FALSE( |
| 461 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 427 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 462 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 428 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 463 arc_session_manager()->state()); | 429 arc_session_manager()->state()); |
| 464 arc_session_manager()->StartArc(); | 430 arc_session_manager()->StartArc(); |
| 465 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 431 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 466 | 432 |
| 467 // Request to remove data and stop session manager. | 433 // Request to remove data and stop session manager. |
| 468 arc_session_manager()->RemoveArcData(); | 434 arc_session_manager()->RemoveArcData(); |
| 469 ASSERT_TRUE( | 435 ASSERT_TRUE( |
| 470 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 436 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 471 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 437 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 472 arc_session_manager()->Shutdown(); | 438 arc_session_manager()->Shutdown(); |
| 473 base::RunLoop().RunUntilIdle(); | 439 base::RunLoop().RunUntilIdle(); |
| 474 // Request should persist. | 440 // Request should persist. |
| 475 ASSERT_TRUE( | 441 ASSERT_TRUE( |
| 476 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 442 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 443 } |
| 477 | 444 |
| 478 // Emulate next sign-in. Data should be removed first and ARC started after. | 445 TEST_F(ArcSessionManagerTest, RemoveDataDir_Restart) { |
| 479 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 446 // Emulate second sign-in. Data should be removed first and ARC started after. |
| 447 PrefService* const prefs = profile()->GetPrefs(); |
| 448 prefs->SetBoolean(prefs::kArcDataRemoveRequested, true); |
| 449 arc_session_manager()->SetProfile(profile()); |
| 450 arc_session_manager()->RequestEnable(); |
| 480 EXPECT_TRUE( | 451 EXPECT_TRUE( |
| 481 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 452 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 482 | |
| 483 ASSERT_TRUE( | 453 ASSERT_TRUE( |
| 484 WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE)); | 454 WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE)); |
| 485 | |
| 486 EXPECT_FALSE( | 455 EXPECT_FALSE( |
| 487 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 456 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 488 | 457 |
| 489 arc_session_manager()->StartArc(); | |
| 490 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | |
| 491 | |
| 492 arc_session_manager()->Shutdown(); | 458 arc_session_manager()->Shutdown(); |
| 493 } | 459 } |
| 494 | 460 |
| 495 TEST_F(ArcSessionManagerTest, RemoveDataFolder_Managed) { | 461 TEST_F(ArcSessionManagerTest, RemoveDataDir_Managed) { |
| 496 // Set ARC to be managed and disabled. | 462 // Set ARC to be managed and disabled. |
| 497 profile()->GetTestingPrefService()->SetManagedPref(prefs::kArcEnabled, | 463 profile()->GetTestingPrefService()->SetManagedPref(prefs::kArcEnabled, |
| 498 new base::Value(false)); | 464 new base::Value(false)); |
| 499 | 465 |
| 500 // Starting session manager with prefs::kArcEnabled off in a managed profile | 466 // Starting session manager with prefs::kArcEnabled off in a managed profile |
| 501 // does automatically remove Android's data folder. | 467 // does automatically remove Android's data folder. |
| 502 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 468 arc_session_manager()->SetProfile(profile()); |
| 469 arc_session_manager()->StartPreferenceHandler(); |
| 503 EXPECT_TRUE( | 470 EXPECT_TRUE( |
| 504 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 471 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 505 } | 472 } |
| 506 | 473 |
| 507 TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) { | 474 TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) { |
| 508 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 475 arc_session_manager()->SetProfile(profile()); |
| 509 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 476 arc_session_manager()->RequestEnable(); |
| 510 arc_session_manager()->StartArc(); | 477 arc_session_manager()->StartArc(); |
| 511 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 478 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 512 | 479 |
| 513 // Report some failure that does not stop the bridge. | 480 // Report some failure that does not stop the bridge. |
| 514 arc_session_manager()->OnProvisioningFinished( | 481 arc_session_manager()->OnProvisioningFinished( |
| 515 ProvisioningResult::GMS_SIGN_IN_FAILED); | 482 ProvisioningResult::GMS_SIGN_IN_FAILED); |
| 516 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 483 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 517 | 484 |
| 518 // Try to send another error that stops the bridge if sent first. It should | 485 // Try to send another error that stops the bridge if sent first. It should |
| 519 // be ignored. | 486 // be ignored. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 550 | 517 |
| 551 // Assign test values to the prefs. | 518 // Assign test values to the prefs. |
| 552 if (backup_restore_pref_value().is_bool()) { | 519 if (backup_restore_pref_value().is_bool()) { |
| 553 prefs->SetManagedPref(prefs::kArcBackupRestoreEnabled, | 520 prefs->SetManagedPref(prefs::kArcBackupRestoreEnabled, |
| 554 backup_restore_pref_value().DeepCopy()); | 521 backup_restore_pref_value().DeepCopy()); |
| 555 } | 522 } |
| 556 if (location_service_pref_value().is_bool()) { | 523 if (location_service_pref_value().is_bool()) { |
| 557 prefs->SetManagedPref(prefs::kArcLocationServiceEnabled, | 524 prefs->SetManagedPref(prefs::kArcLocationServiceEnabled, |
| 558 location_service_pref_value().DeepCopy()); | 525 location_service_pref_value().DeepCopy()); |
| 559 } | 526 } |
| 560 | |
| 561 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | |
| 562 EXPECT_TRUE(arc::IsArcPlayStoreEnabledForProfile(profile())); | 527 EXPECT_TRUE(arc::IsArcPlayStoreEnabledForProfile(profile())); |
| 563 EXPECT_TRUE(arc::IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); | 528 EXPECT_TRUE(arc::IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); |
| 564 | 529 |
| 530 arc_session_manager()->SetProfile(profile()); |
| 531 arc_session_manager()->RequestEnable(); |
| 532 |
| 565 // Terms of Service are skipped if both ArcBackupRestoreEnabled and | 533 // Terms of Service are skipped if both ArcBackupRestoreEnabled and |
| 566 // ArcLocationServiceEnabled are managed. | 534 // ArcLocationServiceEnabled are managed. |
| 567 const bool expected_terms_skipping = backup_restore_pref_value().is_bool() && | 535 const bool expected_terms_skipping = backup_restore_pref_value().is_bool() && |
| 568 location_service_pref_value().is_bool(); | 536 location_service_pref_value().is_bool(); |
| 569 EXPECT_EQ(expected_terms_skipping | 537 EXPECT_EQ(expected_terms_skipping |
| 570 ? ArcSessionManager::State::ACTIVE | 538 ? ArcSessionManager::State::ACTIVE |
| 571 : ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 539 : ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 572 arc_session_manager()->state()); | 540 arc_session_manager()->state()); |
| 573 | 541 |
| 574 // Complete provisioning if it's not done yet. | 542 // Complete provisioning if it's not done yet. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 AccountId::FromUserEmail(profile()->GetProfileUserName())); | 583 AccountId::FromUserEmail(profile()->GetProfileUserName())); |
| 616 GetFakeUserManager()->AddArcKioskAppUser(account_id); | 584 GetFakeUserManager()->AddArcKioskAppUser(account_id); |
| 617 GetFakeUserManager()->LoginUser(account_id); | 585 GetFakeUserManager()->LoginUser(account_id); |
| 618 } | 586 } |
| 619 | 587 |
| 620 private: | 588 private: |
| 621 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerKioskTest); | 589 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerKioskTest); |
| 622 }; | 590 }; |
| 623 | 591 |
| 624 TEST_F(ArcSessionManagerKioskTest, AuthFailure) { | 592 TEST_F(ArcSessionManagerKioskTest, AuthFailure) { |
| 625 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 593 arc_session_manager()->SetProfile(profile()); |
| 626 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 594 arc_session_manager()->RequestEnable(); |
| 627 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 595 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 628 | 596 |
| 629 // Replace chrome::AttemptUserExit() for testing. | 597 // Replace chrome::AttemptUserExit() for testing. |
| 630 // At the end of test, leave the dangling pointer |terminated|, | 598 // At the end of test, leave the dangling pointer |terminated|, |
| 631 // assuming the callback is invoked exactly once in OnProvisioningFinished() | 599 // assuming the callback is invoked exactly once in OnProvisioningFinished() |
| 632 // and not invoked then, including TearDown(). | 600 // and not invoked then, including TearDown(). |
| 633 bool terminated = false; | 601 bool terminated = false; |
| 634 arc_session_manager()->SetAttemptUserExitCallbackForTesting( | 602 arc_session_manager()->SetAttemptUserExitCallbackForTesting( |
| 635 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); | 603 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); |
| 636 | 604 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 if (IsManagedUser()) { | 670 if (IsManagedUser()) { |
| 703 policy::ProfilePolicyConnector* const connector = | 671 policy::ProfilePolicyConnector* const connector = |
| 704 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | 672 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
| 705 profile()); | 673 profile()); |
| 706 connector->OverrideIsManagedForTesting(true); | 674 connector->OverrideIsManagedForTesting(true); |
| 707 | 675 |
| 708 profile()->GetTestingPrefService()->SetManagedPref( | 676 profile()->GetTestingPrefService()->SetManagedPref( |
| 709 prefs::kArcEnabled, new base::FundamentalValue(true)); | 677 prefs::kArcEnabled, new base::FundamentalValue(true)); |
| 710 } | 678 } |
| 711 | 679 |
| 712 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 680 arc_session_manager()->SetProfile(profile()); |
| 681 arc_session_manager()->StartPreferenceHandler(); |
| 713 } | 682 } |
| 714 | 683 |
| 715 void TearDown() override { | 684 void TearDown() override { |
| 716 // Correctly stop service. | 685 // Correctly stop service. |
| 717 arc_session_manager()->Shutdown(); | 686 arc_session_manager()->Shutdown(); |
| 718 | 687 |
| 719 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenViewForTesting( | 688 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenViewForTesting( |
| 720 nullptr); | 689 nullptr); |
| 721 | 690 |
| 722 ArcSessionOobeOptInTest::TearDown(); | 691 ArcSessionOobeOptInTest::TearDown(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 749 chromeos::ArcTermsOfServiceScreenViewObserver* observer) override { | 718 chromeos::ArcTermsOfServiceScreenViewObserver* observer) override { |
| 750 observer_list_.AddObserver(observer); | 719 observer_list_.AddObserver(observer); |
| 751 } | 720 } |
| 752 | 721 |
| 753 void RemoveObserver( | 722 void RemoveObserver( |
| 754 chromeos::ArcTermsOfServiceScreenViewObserver* observer) override { | 723 chromeos::ArcTermsOfServiceScreenViewObserver* observer) override { |
| 755 observer_list_.RemoveObserver(observer); | 724 observer_list_.RemoveObserver(observer); |
| 756 } | 725 } |
| 757 | 726 |
| 758 void Show() override { | 727 void Show() override { |
| 759 // To match ArcTermsOfServiceScreenHandler logic where prefs::kArcEnabled is | 728 // To match ArcTermsOfServiceScreenHandler logic where Google Play Store |
| 760 // set to true on showing UI. | 729 // enabled preferencee is set to true on showing UI. |
| 761 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 730 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 762 } | 731 } |
| 763 | 732 |
| 764 void Hide() override {} | 733 void Hide() override {} |
| 765 | 734 |
| 766 base::ObserverList<chromeos::ArcTermsOfServiceScreenViewObserver> | 735 base::ObserverList<chromeos::ArcTermsOfServiceScreenViewObserver> |
| 767 observer_list_; | 736 observer_list_; |
| 768 | 737 |
| 769 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); | 738 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); |
| 770 }; | 739 }; |
| 771 | 740 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 797 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 766 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 798 arc_session_manager()->state()); | 767 arc_session_manager()->state()); |
| 799 CloseLoginDisplayHost(); | 768 CloseLoginDisplayHost(); |
| 800 ReportViewDestroyed(); | 769 ReportViewDestroyed(); |
| 801 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 770 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 802 if (!IsManagedUser()) | 771 if (!IsManagedUser()) |
| 803 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); | 772 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 804 } | 773 } |
| 805 | 774 |
| 806 } // namespace arc | 775 } // namespace arc |
| OLD | NEW |