Chromium Code Reviews| Index: chrome/browser/chromeos/arc/arc_session_manager_unittest.cc |
| diff --git a/chrome/browser/chromeos/arc/arc_session_manager_unittest.cc b/chrome/browser/chromeos/arc/arc_session_manager_unittest.cc |
| index 62a8c49716b487bb77371cc5a365d14a950099d1..3ba4ed1ab806fd53743e5c7d95782162d1f74333 100644 |
| --- a/chrome/browser/chromeos/arc/arc_session_manager_unittest.cc |
| +++ b/chrome/browser/chromeos/arc/arc_session_manager_unittest.cc |
| @@ -214,6 +214,10 @@ class ArcSessionManagerTest : public ArcSessionManagerTestBase { |
| profile()->GetProfileUserName(), "1234567890")); |
| GetFakeUserManager()->AddUser(account_id); |
| GetFakeUserManager()->LoginUser(account_id); |
| + |
| + ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| + arc_session_manager()->state()); |
| + ASSERT_TRUE(arc_session_manager()->IsSessionStopped()); |
| } |
| private: |
| @@ -221,45 +225,65 @@ class ArcSessionManagerTest : public ArcSessionManagerTestBase { |
| }; |
| TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { |
| - ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| + ASSERT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| + arc_session_manager()->SetProfile(profile()); |
| + arc_session_manager()->StartPreferenceHandler(); |
| + |
| + // If the initial value of Google Play Store enabled preference is false, |
| + // the data dir is being removed. |
| + EXPECT_TRUE( |
| + profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| + EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
| arc_session_manager()->state()); |
| + ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); |
| - PrefService* const pref = profile()->GetPrefs(); |
| - ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
| + SetArcPlayStoreEnabledForProfile(profile(), true); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| + arc_session_manager()->state()); |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| + SetArcPlayStoreEnabledForProfile(profile(), false); |
| ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); |
| - pref->SetBoolean(prefs::kArcEnabled, true); |
| - base::RunLoop().RunUntilIdle(); |
| + // Correctly stop service. |
| + arc_session_manager()->Shutdown(); |
| +} |
| + |
| +TEST_F(ArcSessionManagerTest, PrefChangeTriggersService_Restart) { |
| + // Sets the Google Play Store preference at beginning. |
| + SetArcPlayStoreEnabledForProfile(profile(), true); |
| + |
| + arc_session_manager()->SetProfile(profile()); |
| + arc_session_manager()->StartPreferenceHandler(); |
| + |
| + // Setting profile initiates a code fetching process. |
| ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| arc_session_manager()->state()); |
| - pref->SetBoolean(prefs::kArcEnabled, false); |
| + content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| + base::RunLoop().RunUntilIdle(); |
| - ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); |
| + // UI is disabled in unit tests and this code is unchanged. |
| + ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| + arc_session_manager()->state()); |
| // Correctly stop service. |
| arc_session_manager()->Shutdown(); |
| } |
| TEST_F(ArcSessionManagerTest, BaseWorkflow) { |
| - ASSERT_TRUE(arc_session_manager()->IsSessionStopped()); |
| - ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| - arc_session_manager()->state()); |
| EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| + arc_session_manager()->SetProfile(profile()); |
| - // By default ARC is not enabled. |
| - ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); |
| + // By default, ARC is not enabled. |
| + EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| - profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| + // Enables ARC. First time, ToS negotiation should start. |
| + arc_session_manager()->RequestEnable(); |
| base::RunLoop().RunUntilIdle(); |
| - |
| - // Setting profile and pref initiates a code fetching process. |
| ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| arc_session_manager()->state()); |
| @@ -274,80 +298,66 @@ TEST_F(ArcSessionManagerTest, BaseWorkflow) { |
| ASSERT_TRUE(arc_session_manager()->IsSessionRunning()); |
| arc_session_manager()->Shutdown(); |
| - ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
|
hidehiko
2017/02/24 18:29:13
Note: this is unexpected use case, so may be not a
|
| - arc_session_manager()->state()); |
| - ASSERT_TRUE(arc_session_manager()->IsSessionStopped()); |
| - |
| - // Send profile and don't provide a code. |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| - |
| - // Setting profile initiates a code fetching process. |
| - ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| - arc_session_manager()->state()); |
| - |
| - content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| - base::RunLoop().RunUntilIdle(); |
| - |
| - // UI is disabled in unit tests and this code is unchanged. |
| - ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| - arc_session_manager()->state()); |
| - |
| - // Correctly stop service. |
| - arc_session_manager()->Shutdown(); |
| } |
| TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { |
| - PrefService* const pref = profile()->GetPrefs(); |
| + SetArcPlayStoreEnabledForProfile(profile(), true); |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| - pref->SetBoolean(prefs::kArcEnabled, true); |
| + // Starts ARC. |
| + arc_session_manager()->SetProfile(profile()); |
| + arc_session_manager()->RequestEnable(); |
| base::RunLoop().RunUntilIdle(); |
| - |
| ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| arc_session_manager()->state()); |
| + // Emulate to cancel the ToS UI (e.g. closing the window). |
| arc_session_manager()->CancelAuthCode(); |
| + // Google Play Store enabled preference should be set to false, too. |
| + EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| + |
| + // Emulate the preference handling. |
| + arc_session_manager()->RequestDisable(); |
| + |
| // Wait until data is removed. |
| ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); |
| - ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
| - |
| // Correctly stop service. |
| arc_session_manager()->Shutdown(); |
| } |
| TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { |
| - PrefService* const pref = profile()->GetPrefs(); |
| - |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| - pref->SetBoolean(prefs::kArcEnabled, true); |
| + // Starts ARC. |
| + SetArcPlayStoreEnabledForProfile(profile(), true); |
| + arc_session_manager()->SetProfile(profile()); |
| + arc_session_manager()->RequestEnable(); |
| base::RunLoop().RunUntilIdle(); |
| - |
| + ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| + arc_session_manager()->state()); |
| arc_session_manager()->StartArc(); |
| - |
| ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| + // When ARC is properly started, closing UI should be no-op. |
| arc_session_manager()->CancelAuthCode(); |
| - ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| - ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); |
| + EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| + EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); |
| // Correctly stop service. |
| arc_session_manager()->Shutdown(); |
| } |
| -TEST_F(ArcSessionManagerTest, SignInStatus) { |
| +TEST_F(ArcSessionManagerTest, Provisioning_Success) { |
| PrefService* const prefs = profile()->GetPrefs(); |
| EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); |
| EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); |
| - EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| - prefs->SetBoolean(prefs::kArcEnabled, true); |
| + ASSERT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| - EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| + arc_session_manager()->SetProfile(profile()); |
| + arc_session_manager()->RequestEnable(); |
| + ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| arc_session_manager()->state()); |
| // Emulate to accept the terms of service. |
| @@ -355,23 +365,32 @@ TEST_F(ArcSessionManagerTest, SignInStatus) { |
| arc_session_manager()->StartArc(); |
| EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
| + |
| + // Here, provisining is not yet completed, so kArcSignedIn should be false. |
| EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); |
| EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); |
| + |
| + // Emulate successful provisioning. |
| arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); |
| EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
| EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| EXPECT_TRUE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); |
| +} |
| + |
| +TEST_F(ArcSessionManagerTest, Provisioning_Restart) { |
| + // Set up the situation that provisioning is successfully done in the |
| + // previous session. |
| + PrefService* const prefs = profile()->GetPrefs(); |
| + prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
| + prefs->SetBoolean(prefs::kArcSignedIn, true); |
| + |
| + arc_session_manager()->SetProfile(profile()); |
| + arc_session_manager()->RequestEnable(); |
| // Second start, no fetching code is expected. |
| - arc_session_manager()->Shutdown(); |
|
hidehiko
2017/02/24 18:29:13
Similarly, split into two tests.
|
| - EXPECT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| - arc_session_manager()->state()); |
| - EXPECT_TRUE(arc_session_manager()->IsSessionStopped()); |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| - EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
| @@ -388,73 +407,18 @@ TEST_F(ArcSessionManagerTest, SignInStatus) { |
| arc_session_manager()->Shutdown(); |
| } |
| -TEST_F(ArcSessionManagerTest, DisabledForDeviceLocalAccount) { |
|
hidehiko
2017/02/24 18:29:13
Removed. This is testing for public account, which
|
| - PrefService* const prefs = profile()->GetPrefs(); |
| - EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| - prefs->SetBoolean(prefs::kArcEnabled, true); |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| - arc_session_manager()->StartArc(); |
| - EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| - |
| - // Create device local account and set it as active. |
| - const std::string email = "device-local-account@fake-email.com"; |
| - TestingProfile::Builder profile_builder; |
| - profile_builder.SetProfileName(email); |
| - std::unique_ptr<TestingProfile> device_local_profile(profile_builder.Build()); |
| - const AccountId account_id(AccountId::FromUserEmail(email)); |
| - GetFakeUserManager()->AddPublicAccountUser(account_id); |
| - |
| - // Remove |profile_| to set the device local account be the primary account. |
| - GetFakeUserManager()->RemoveUserFromList( |
| - multi_user_util::GetAccountIdFromProfile(profile())); |
| - GetFakeUserManager()->LoginUser(account_id); |
| - |
| - // Check that user without GAIA account can't use ARC. |
| - device_local_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| - arc_session_manager()->OnPrimaryUserProfilePrepared( |
| - device_local_profile.get()); |
| - EXPECT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| - arc_session_manager()->state()); |
| - |
| - // Correctly stop service. |
| - arc_session_manager()->Shutdown(); |
| -} |
| - |
| -TEST_F(ArcSessionManagerTest, DisabledForNonPrimaryProfile) { |
|
hidehiko
2017/02/24 18:29:13
Removed. Similary, this is also tested in ChromeAr
|
| - profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| - arc_session_manager()->StartArc(); |
| - EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| - |
| - // Create a second profile and set it as the active profile. |
| - const std::string email = "test@example.com"; |
| - TestingProfile::Builder profile_builder; |
| - profile_builder.SetProfileName(email); |
| - std::unique_ptr<TestingProfile> second_profile(profile_builder.Build()); |
| - const AccountId account_id(AccountId::FromUserEmail(email)); |
| - GetFakeUserManager()->AddUser(account_id); |
| - GetFakeUserManager()->SwitchActiveUser(account_id); |
| - second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| - |
| - // Check that non-primary user can't use ARC. |
| - EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); |
| - EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); |
| - |
| - arc_session_manager()->Shutdown(); |
| -} |
| - |
| -TEST_F(ArcSessionManagerTest, RemoveDataFolder) { |
| - profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); |
| - // Starting session manager with prefs::kArcEnabled off automatically removes |
| - // Android's data folder. |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| +TEST_F(ArcSessionManagerTest, RemoveDataDir) { |
| + // Emulate the situation where the initial Google Play Store enabled |
| + // preference is false, i.e., data dir is being removed at beginning. |
| + arc_session_manager()->SetProfile(profile()); |
| + arc_session_manager()->RemoveArcData(); |
| EXPECT_TRUE( |
| profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
| arc_session_manager()->state()); |
| // Enable ARC. Data is removed asyncronously. At this moment session manager |
| // should be in REMOVING_DATA_DIR state. |
| - profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| + arc_session_manager()->RequestEnable(); |
| EXPECT_TRUE( |
| profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
| @@ -478,27 +442,27 @@ TEST_F(ArcSessionManagerTest, RemoveDataFolder) { |
| // Request should persist. |
| ASSERT_TRUE( |
| profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| +} |
| - // Emulate next sign-in. Data should be removed first and ARC started after. |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| +TEST_F(ArcSessionManagerTest, RemoveDataDir_Restart) { |
| + // Emulate second sign-in. Data should be removed first and ARC started after. |
| + PrefService* const prefs = profile()->GetPrefs(); |
| + prefs->SetBoolean(prefs::kArcDataRemoveRequested, true); |
| + arc_session_manager()->SetProfile(profile()); |
| + arc_session_manager()->RequestEnable(); |
| EXPECT_TRUE( |
| profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| - |
| ASSERT_TRUE( |
| WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE)); |
| - |
| EXPECT_FALSE( |
| profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| - arc_session_manager()->StartArc(); |
| - EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| - |
| arc_session_manager()->Shutdown(); |
| } |
| TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) { |
| - profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| + arc_session_manager()->SetProfile(profile()); |
| + arc_session_manager()->RequestEnable(); |
| arc_session_manager()->StartArc(); |
| EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| @@ -549,11 +513,12 @@ TEST_P(ArcSessionManagerPolicyTest, SkippingTerms) { |
| prefs->SetManagedPref(prefs::kArcLocationServiceEnabled, |
| location_service_pref_value().DeepCopy()); |
| } |
| - |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| EXPECT_TRUE(arc::IsArcPlayStoreEnabledForProfile(profile())); |
| EXPECT_TRUE(arc::IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())); |
| + arc_session_manager()->SetProfile(profile()); |
| + arc_session_manager()->RequestEnable(); |
| + |
| // Terms of Service are skipped if both ArcBackupRestoreEnabled and |
| // ArcLocationServiceEnabled are managed. |
| const bool expected_terms_skipping = backup_restore_pref_value().is_bool() && |
| @@ -614,8 +579,8 @@ class ArcSessionManagerKioskTest : public ArcSessionManagerTestBase { |
| }; |
| TEST_F(ArcSessionManagerKioskTest, AuthFailure) { |
| - profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| + arc_session_manager()->SetProfile(profile()); |
| + arc_session_manager()->RequestEnable(); |
| EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| // Replace chrome::AttemptUserExit() for testing. |
| @@ -701,7 +666,8 @@ class ArcSessionOobeOptInNegotiatorTest |
| prefs::kArcEnabled, new base::FundamentalValue(true)); |
| } |
| - arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| + arc_session_manager()->SetProfile(profile()); |
| + arc_session_manager()->StartPreferenceHandler(); |
| } |
| void TearDown() override { |
| @@ -760,9 +726,9 @@ class ArcSessionOobeOptInNegotiatorTest |
| } |
| void Show() override { |
| - // To match ArcTermsOfServiceScreenHandler logic where prefs::kArcEnabled is |
| - // set to true on showing UI. |
| - profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| + // To match ArcTermsOfServiceScreenHandler logic where Google Play Store |
| + // enabled preferencee is set to true on showing UI. |
| + SetArcPlayStoreEnabledForProfile(profile(), true); |
| } |
| void Hide() override {} |