| 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" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 16 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 17 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 17 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 18 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 18 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 19 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 20 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 21 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 22 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 24 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 24 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 25 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 37 #include "components/user_manager/user_names.h" | 38 #include "components/user_manager/user_names.h" |
| 38 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
| 39 #include "content/public/test/test_browser_thread_bundle.h" | 40 #include "content/public/test/test_browser_thread_bundle.h" |
| 40 #include "google_apis/gaia/gaia_constants.h" | 41 #include "google_apis/gaia/gaia_constants.h" |
| 41 #include "google_apis/gaia/gaia_urls.h" | 42 #include "google_apis/gaia/gaia_urls.h" |
| 42 #include "net/http/http_status_code.h" | 43 #include "net/http/http_status_code.h" |
| 43 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 44 | 45 |
| 45 namespace arc { | 46 namespace arc { |
| 46 | 47 |
| 47 class ArcAuthServiceTest : public testing::Test { | 48 class ArcSessionManagerTest : public testing::Test { |
| 48 public: | 49 public: |
| 49 ArcAuthServiceTest() | 50 ArcSessionManagerTest() |
| 50 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 51 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 51 user_manager_enabler_(new chromeos::FakeChromeUserManager) {} | 52 user_manager_enabler_(new chromeos::FakeChromeUserManager) {} |
| 52 ~ArcAuthServiceTest() override = default; | 53 ~ArcSessionManagerTest() override = default; |
| 53 | 54 |
| 54 void SetUp() override { | 55 void SetUp() override { |
| 55 chromeos::DBusThreadManager::Initialize(); | 56 chromeos::DBusThreadManager::Initialize(); |
| 56 | 57 |
| 57 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 58 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 58 chromeos::switches::kEnableArc); | 59 chromeos::switches::kEnableArc); |
| 59 ArcAuthService::DisableUIForTesting(); | 60 ArcSessionManager::DisableUIForTesting(); |
| 60 | 61 |
| 61 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 62 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 62 TestingProfile::Builder profile_builder; | 63 TestingProfile::Builder profile_builder; |
| 63 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); | 64 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); |
| 64 | 65 |
| 65 profile_ = profile_builder.Build(); | 66 profile_ = profile_builder.Build(); |
| 66 StartPreferenceSyncing(); | 67 StartPreferenceSyncing(); |
| 67 | 68 |
| 68 bridge_service_.reset(new FakeArcBridgeService()); | 69 bridge_service_.reset(new FakeArcBridgeService()); |
| 69 auth_service_.reset(new ArcAuthService(bridge_service_.get())); | 70 arc_session_manager_.reset(new ArcSessionManager(bridge_service_.get())); |
| 70 | 71 |
| 71 // Check initial conditions. | 72 // Check initial conditions. |
| 72 EXPECT_EQ(bridge_service_.get(), ArcBridgeService::Get()); | 73 EXPECT_EQ(bridge_service_.get(), ArcBridgeService::Get()); |
| 73 EXPECT_TRUE(ArcBridgeService::Get()->stopped()); | 74 EXPECT_TRUE(ArcBridgeService::Get()->stopped()); |
| 74 | 75 |
| 75 const AccountId account_id( | 76 const AccountId account_id( |
| 76 AccountId::FromUserEmailGaiaId("user@gmail.com", "1234567890")); | 77 AccountId::FromUserEmailGaiaId("user@gmail.com", "1234567890")); |
| 77 GetFakeUserManager()->AddUser(account_id); | 78 GetFakeUserManager()->AddUser(account_id); |
| 78 GetFakeUserManager()->LoginUser(account_id); | 79 GetFakeUserManager()->LoginUser(account_id); |
| 79 | 80 |
| 80 chromeos::WallpaperManager::Initialize(); | 81 chromeos::WallpaperManager::Initialize(); |
| 81 } | 82 } |
| 82 | 83 |
| 83 void TearDown() override { | 84 void TearDown() override { |
| 84 chromeos::WallpaperManager::Shutdown(); | 85 chromeos::WallpaperManager::Shutdown(); |
| 85 chromeos::DBusThreadManager::Shutdown(); | 86 chromeos::DBusThreadManager::Shutdown(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 chromeos::FakeChromeUserManager* GetFakeUserManager() const { | 89 chromeos::FakeChromeUserManager* GetFakeUserManager() const { |
| 89 return static_cast<chromeos::FakeChromeUserManager*>( | 90 return static_cast<chromeos::FakeChromeUserManager*>( |
| 90 user_manager::UserManager::Get()); | 91 user_manager::UserManager::Get()); |
| 91 } | 92 } |
| 92 | 93 |
| 93 protected: | 94 protected: |
| 94 Profile* profile() { return profile_.get(); } | 95 Profile* profile() { return profile_.get(); } |
| 95 FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } | 96 FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } |
| 96 ArcAuthService* auth_service() { return auth_service_.get(); } | 97 ArcSessionManager* arc_session_manager() { |
| 98 return arc_session_manager_.get(); |
| 99 } |
| 97 | 100 |
| 98 private: | 101 private: |
| 99 void StartPreferenceSyncing() const { | 102 void StartPreferenceSyncing() const { |
| 100 PrefServiceSyncableFromProfile(profile_.get()) | 103 PrefServiceSyncableFromProfile(profile_.get()) |
| 101 ->GetSyncableService(syncer::PREFERENCES) | 104 ->GetSyncableService(syncer::PREFERENCES) |
| 102 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), | 105 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), |
| 103 std::unique_ptr<syncer::SyncChangeProcessor>( | 106 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 104 new syncer::FakeSyncChangeProcessor), | 107 new syncer::FakeSyncChangeProcessor), |
| 105 std::unique_ptr<syncer::SyncErrorFactory>( | 108 std::unique_ptr<syncer::SyncErrorFactory>( |
| 106 new syncer::SyncErrorFactoryMock())); | 109 new syncer::SyncErrorFactoryMock())); |
| 107 } | 110 } |
| 108 | 111 |
| 109 content::TestBrowserThreadBundle thread_bundle_; | 112 content::TestBrowserThreadBundle thread_bundle_; |
| 110 std::unique_ptr<FakeArcBridgeService> bridge_service_; | 113 std::unique_ptr<FakeArcBridgeService> bridge_service_; |
| 111 std::unique_ptr<TestingProfile> profile_; | 114 std::unique_ptr<TestingProfile> profile_; |
| 112 std::unique_ptr<ArcAuthService> auth_service_; | 115 std::unique_ptr<ArcSessionManager> arc_session_manager_; |
| 113 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 116 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
| 114 base::ScopedTempDir temp_dir_; | 117 base::ScopedTempDir temp_dir_; |
| 115 | 118 |
| 116 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceTest); | 119 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); |
| 117 }; | 120 }; |
| 118 | 121 |
| 119 TEST_F(ArcAuthServiceTest, PrefChangeTriggersService) { | 122 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { |
| 120 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); | 123 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 124 arc_session_manager()->state()); |
| 121 | 125 |
| 122 PrefService* const pref = profile()->GetPrefs(); | 126 PrefService* const pref = profile()->GetPrefs(); |
| 123 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 127 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
| 124 | 128 |
| 125 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 129 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 126 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 130 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 127 | 131 |
| 128 pref->SetBoolean(prefs::kArcEnabled, true); | 132 pref->SetBoolean(prefs::kArcEnabled, true); |
| 129 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, | 133 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 130 auth_service()->state()); | 134 arc_session_manager()->state()); |
| 131 | 135 |
| 132 pref->SetBoolean(prefs::kArcEnabled, false); | 136 pref->SetBoolean(prefs::kArcEnabled, false); |
| 133 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 137 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 134 | 138 |
| 135 // Correctly stop service. | 139 // Correctly stop service. |
| 136 auth_service()->Shutdown(); | 140 arc_session_manager()->Shutdown(); |
| 137 } | 141 } |
| 138 | 142 |
| 139 TEST_F(ArcAuthServiceTest, DisabledForEphemeralDataUsers) { | 143 TEST_F(ArcSessionManagerTest, DisabledForEphemeralDataUsers) { |
| 140 PrefService* const prefs = profile()->GetPrefs(); | 144 PrefService* const prefs = profile()->GetPrefs(); |
| 141 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 145 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 142 prefs->SetBoolean(prefs::kArcEnabled, true); | 146 prefs->SetBoolean(prefs::kArcEnabled, true); |
| 143 | 147 |
| 144 chromeos::FakeChromeUserManager* const fake_user_manager = | 148 chromeos::FakeChromeUserManager* const fake_user_manager = |
| 145 GetFakeUserManager(); | 149 GetFakeUserManager(); |
| 146 | 150 |
| 147 fake_user_manager->AddUser(fake_user_manager->GetGuestAccountId()); | 151 fake_user_manager->AddUser(fake_user_manager->GetGuestAccountId()); |
| 148 fake_user_manager->SwitchActiveUser(fake_user_manager->GetGuestAccountId()); | 152 fake_user_manager->SwitchActiveUser(fake_user_manager->GetGuestAccountId()); |
| 149 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 153 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 150 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); | 154 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 155 arc_session_manager()->state()); |
| 151 | 156 |
| 152 fake_user_manager->AddUser(user_manager::DemoAccountId()); | 157 fake_user_manager->AddUser(user_manager::DemoAccountId()); |
| 153 fake_user_manager->SwitchActiveUser(user_manager::DemoAccountId()); | 158 fake_user_manager->SwitchActiveUser(user_manager::DemoAccountId()); |
| 154 auth_service()->Shutdown(); | 159 arc_session_manager()->Shutdown(); |
| 155 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 160 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 156 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); | 161 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 162 arc_session_manager()->state()); |
| 157 | 163 |
| 158 const AccountId public_account_id( | 164 const AccountId public_account_id( |
| 159 AccountId::FromUserEmail("public_user@gmail.com")); | 165 AccountId::FromUserEmail("public_user@gmail.com")); |
| 160 fake_user_manager->AddPublicAccountUser(public_account_id); | 166 fake_user_manager->AddPublicAccountUser(public_account_id); |
| 161 fake_user_manager->SwitchActiveUser(public_account_id); | 167 fake_user_manager->SwitchActiveUser(public_account_id); |
| 162 auth_service()->Shutdown(); | 168 arc_session_manager()->Shutdown(); |
| 163 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 169 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 164 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); | 170 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 171 arc_session_manager()->state()); |
| 165 | 172 |
| 166 const AccountId not_in_list_account_id( | 173 const AccountId not_in_list_account_id( |
| 167 AccountId::FromUserEmail("not_in_list_user@gmail.com")); | 174 AccountId::FromUserEmail("not_in_list_user@gmail.com")); |
| 168 fake_user_manager->set_ephemeral_users_enabled(true); | 175 fake_user_manager->set_ephemeral_users_enabled(true); |
| 169 fake_user_manager->AddUser(not_in_list_account_id); | 176 fake_user_manager->AddUser(not_in_list_account_id); |
| 170 fake_user_manager->SwitchActiveUser(not_in_list_account_id); | 177 fake_user_manager->SwitchActiveUser(not_in_list_account_id); |
| 171 fake_user_manager->RemoveUserFromList(not_in_list_account_id); | 178 fake_user_manager->RemoveUserFromList(not_in_list_account_id); |
| 172 auth_service()->Shutdown(); | 179 arc_session_manager()->Shutdown(); |
| 173 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 180 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 174 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); | 181 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 182 arc_session_manager()->state()); |
| 175 | 183 |
| 176 // Correctly stop service. | 184 // Correctly stop service. |
| 177 auth_service()->Shutdown(); | 185 arc_session_manager()->Shutdown(); |
| 178 } | 186 } |
| 179 | 187 |
| 180 TEST_F(ArcAuthServiceTest, BaseWorkflow) { | 188 TEST_F(ArcSessionManagerTest, BaseWorkflow) { |
| 181 ASSERT_FALSE(bridge_service()->ready()); | 189 ASSERT_FALSE(bridge_service()->ready()); |
| 182 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); | 190 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 191 arc_session_manager()->state()); |
| 183 | 192 |
| 184 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 193 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 185 | 194 |
| 186 // By default ARC is not enabled. | 195 // By default ARC is not enabled. |
| 187 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 196 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 188 | 197 |
| 189 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 198 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 190 | 199 |
| 191 // Setting profile and pref initiates a code fetching process. | 200 // Setting profile and pref initiates a code fetching process. |
| 192 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, | 201 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 193 auth_service()->state()); | 202 arc_session_manager()->state()); |
| 194 | 203 |
| 195 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> | 204 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> |
| 196 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. | 205 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. |
| 197 auth_service()->StartArc(); | 206 arc_session_manager()->StartArc(); |
| 198 | 207 |
| 199 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 208 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 200 ASSERT_TRUE(bridge_service()->ready()); | 209 ASSERT_TRUE(bridge_service()->ready()); |
| 201 | 210 |
| 202 auth_service()->Shutdown(); | 211 arc_session_manager()->Shutdown(); |
| 203 ASSERT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); | 212 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 213 arc_session_manager()->state()); |
| 204 ASSERT_FALSE(bridge_service()->ready()); | 214 ASSERT_FALSE(bridge_service()->ready()); |
| 205 | 215 |
| 206 // Send profile and don't provide a code. | 216 // Send profile and don't provide a code. |
| 207 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 217 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 208 | 218 |
| 209 // Setting profile initiates a code fetching process. | 219 // Setting profile initiates a code fetching process. |
| 210 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, | 220 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 211 auth_service()->state()); | 221 arc_session_manager()->state()); |
| 212 | 222 |
| 213 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 223 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 214 base::RunLoop().RunUntilIdle(); | 224 base::RunLoop().RunUntilIdle(); |
| 215 | 225 |
| 216 // UI is disabled in unit tests and this code is unchanged. | 226 // UI is disabled in unit tests and this code is unchanged. |
| 217 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, | 227 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 218 auth_service()->state()); | 228 arc_session_manager()->state()); |
| 219 | 229 |
| 220 // Correctly stop service. | 230 // Correctly stop service. |
| 221 auth_service()->Shutdown(); | 231 arc_session_manager()->Shutdown(); |
| 222 } | 232 } |
| 223 | 233 |
| 224 TEST_F(ArcAuthServiceTest, CancelFetchingDisablesArc) { | 234 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { |
| 225 PrefService* const pref = profile()->GetPrefs(); | 235 PrefService* const pref = profile()->GetPrefs(); |
| 226 | 236 |
| 227 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 237 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 228 pref->SetBoolean(prefs::kArcEnabled, true); | 238 pref->SetBoolean(prefs::kArcEnabled, true); |
| 229 ASSERT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, | 239 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 230 auth_service()->state()); | 240 arc_session_manager()->state()); |
| 231 | 241 |
| 232 auth_service()->CancelAuthCode(); | 242 arc_session_manager()->CancelAuthCode(); |
| 233 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 243 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 234 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 244 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
| 235 | 245 |
| 236 // Correctly stop service. | 246 // Correctly stop service. |
| 237 auth_service()->Shutdown(); | 247 arc_session_manager()->Shutdown(); |
| 238 } | 248 } |
| 239 | 249 |
| 240 TEST_F(ArcAuthServiceTest, CloseUIKeepsArcEnabled) { | 250 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { |
| 241 PrefService* const pref = profile()->GetPrefs(); | 251 PrefService* const pref = profile()->GetPrefs(); |
| 242 | 252 |
| 243 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 253 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 244 pref->SetBoolean(prefs::kArcEnabled, true); | 254 pref->SetBoolean(prefs::kArcEnabled, true); |
| 245 | 255 |
| 246 auth_service()->StartArc(); | 256 arc_session_manager()->StartArc(); |
| 247 | 257 |
| 248 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 258 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 249 | 259 |
| 250 auth_service()->CancelAuthCode(); | 260 arc_session_manager()->CancelAuthCode(); |
| 251 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 261 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 252 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); | 262 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); |
| 253 | 263 |
| 254 // Correctly stop service. | 264 // Correctly stop service. |
| 255 auth_service()->Shutdown(); | 265 arc_session_manager()->Shutdown(); |
| 256 } | 266 } |
| 257 | 267 |
| 258 TEST_F(ArcAuthServiceTest, EnableDisablesArc) { | 268 TEST_F(ArcSessionManagerTest, EnableDisablesArc) { |
| 259 const PrefService* pref = profile()->GetPrefs(); | 269 const PrefService* pref = profile()->GetPrefs(); |
| 260 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 270 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 261 | 271 |
| 262 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 272 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
| 263 auth_service()->EnableArc(); | 273 arc_session_manager()->EnableArc(); |
| 264 EXPECT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); | 274 EXPECT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); |
| 265 auth_service()->DisableArc(); | 275 arc_session_manager()->DisableArc(); |
| 266 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 276 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
| 267 | 277 |
| 268 // Correctly stop service. | 278 // Correctly stop service. |
| 269 auth_service()->Shutdown(); | 279 arc_session_manager()->Shutdown(); |
| 270 } | 280 } |
| 271 | 281 |
| 272 TEST_F(ArcAuthServiceTest, SignInStatus) { | 282 TEST_F(ArcSessionManagerTest, SignInStatus) { |
| 273 PrefService* const prefs = profile()->GetPrefs(); | 283 PrefService* const prefs = profile()->GetPrefs(); |
| 274 | 284 |
| 275 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 285 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 276 prefs->SetBoolean(prefs::kArcEnabled, true); | 286 prefs->SetBoolean(prefs::kArcEnabled, true); |
| 277 | 287 |
| 278 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 288 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 279 EXPECT_EQ(ArcAuthService::State::SHOWING_TERMS_OF_SERVICE, | 289 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 280 auth_service()->state()); | 290 arc_session_manager()->state()); |
| 281 auth_service()->StartArc(); | 291 arc_session_manager()->StartArc(); |
| 282 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 292 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 283 EXPECT_TRUE(bridge_service()->ready()); | 293 EXPECT_TRUE(bridge_service()->ready()); |
| 284 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 294 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 285 auth_service()->OnSignInComplete(); | 295 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); |
| 286 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); | 296 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 287 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 297 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 288 EXPECT_TRUE(bridge_service()->ready()); | 298 EXPECT_TRUE(bridge_service()->ready()); |
| 289 | 299 |
| 290 // Second start, no fetching code is expected. | 300 // Second start, no fetching code is expected. |
| 291 auth_service()->Shutdown(); | 301 arc_session_manager()->Shutdown(); |
| 292 EXPECT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); | 302 EXPECT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 303 arc_session_manager()->state()); |
| 293 EXPECT_FALSE(bridge_service()->ready()); | 304 EXPECT_FALSE(bridge_service()->ready()); |
| 294 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 305 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 295 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); | 306 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 296 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 307 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 297 EXPECT_TRUE(bridge_service()->ready()); | 308 EXPECT_TRUE(bridge_service()->ready()); |
| 298 | 309 |
| 299 // Report failure. | 310 // Report failure. |
| 300 auth_service()->OnSignInFailed( | 311 arc_session_manager()->OnProvisioningFinished( |
| 301 mojom::ArcSignInFailureReason::GMS_NETWORK_ERROR); | 312 ProvisioningResult::GMS_NETWORK_ERROR); |
| 302 // On error, UI to send feedback is showing. In that case, | 313 // On error, UI to send feedback is showing. In that case, |
| 303 // the ARC is still necessary to run on background for gathering the logs. | 314 // the ARC is still necessary to run on background for gathering the logs. |
| 304 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); | 315 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 305 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 316 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 306 EXPECT_TRUE(bridge_service()->ready()); | 317 EXPECT_TRUE(bridge_service()->ready()); |
| 307 | 318 |
| 308 // Correctly stop service. | 319 // Correctly stop service. |
| 309 auth_service()->Shutdown(); | 320 arc_session_manager()->Shutdown(); |
| 310 } | 321 } |
| 311 | 322 |
| 312 TEST_F(ArcAuthServiceTest, DisabledForDeviceLocalAccount) { | 323 TEST_F(ArcSessionManagerTest, DisabledForDeviceLocalAccount) { |
| 313 PrefService* const prefs = profile()->GetPrefs(); | 324 PrefService* const prefs = profile()->GetPrefs(); |
| 314 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 325 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 315 prefs->SetBoolean(prefs::kArcEnabled, true); | 326 prefs->SetBoolean(prefs::kArcEnabled, true); |
| 316 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 327 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 317 auth_service()->StartArc(); | 328 arc_session_manager()->StartArc(); |
| 318 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 329 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 319 | 330 |
| 320 // Create device local account and set it as active. | 331 // Create device local account and set it as active. |
| 321 const std::string email = "device-local-account@fake-email.com"; | 332 const std::string email = "device-local-account@fake-email.com"; |
| 322 TestingProfile::Builder profile_builder; | 333 TestingProfile::Builder profile_builder; |
| 323 profile_builder.SetProfileName(email); | 334 profile_builder.SetProfileName(email); |
| 324 std::unique_ptr<TestingProfile> device_local_profile(profile_builder.Build()); | 335 std::unique_ptr<TestingProfile> device_local_profile(profile_builder.Build()); |
| 325 const AccountId account_id(AccountId::FromUserEmail(email)); | 336 const AccountId account_id(AccountId::FromUserEmail(email)); |
| 326 GetFakeUserManager()->AddPublicAccountUser(account_id); | 337 GetFakeUserManager()->AddPublicAccountUser(account_id); |
| 327 | 338 |
| 328 // Remove |profile_| to set the device local account be the primary account. | 339 // Remove |profile_| to set the device local account be the primary account. |
| 329 GetFakeUserManager()->RemoveUserFromList( | 340 GetFakeUserManager()->RemoveUserFromList( |
| 330 multi_user_util::GetAccountIdFromProfile(profile())); | 341 multi_user_util::GetAccountIdFromProfile(profile())); |
| 331 GetFakeUserManager()->LoginUser(account_id); | 342 GetFakeUserManager()->LoginUser(account_id); |
| 332 | 343 |
| 333 // Check that user without GAIA account can't use ARC. | 344 // Check that user without GAIA account can't use ARC. |
| 334 device_local_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 345 device_local_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 335 auth_service()->OnPrimaryUserProfilePrepared(device_local_profile.get()); | 346 arc_session_manager()->OnPrimaryUserProfilePrepared( |
| 336 EXPECT_EQ(ArcAuthService::State::NOT_INITIALIZED, auth_service()->state()); | 347 device_local_profile.get()); |
| 348 EXPECT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 349 arc_session_manager()->state()); |
| 337 | 350 |
| 338 // Correctly stop service. | 351 // Correctly stop service. |
| 339 auth_service()->Shutdown(); | 352 arc_session_manager()->Shutdown(); |
| 340 } | 353 } |
| 341 | 354 |
| 342 TEST_F(ArcAuthServiceTest, DisabledForNonPrimaryProfile) { | 355 TEST_F(ArcSessionManagerTest, DisabledForNonPrimaryProfile) { |
| 343 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 356 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 344 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 357 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
| 345 auth_service()->StartArc(); | 358 arc_session_manager()->StartArc(); |
| 346 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 359 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 347 | 360 |
| 348 // Create a second profile and set it as the active profile. | 361 // Create a second profile and set it as the active profile. |
| 349 const std::string email = "test@example.com"; | 362 const std::string email = "test@example.com"; |
| 350 TestingProfile::Builder profile_builder; | 363 TestingProfile::Builder profile_builder; |
| 351 profile_builder.SetProfileName(email); | 364 profile_builder.SetProfileName(email); |
| 352 std::unique_ptr<TestingProfile> second_profile(profile_builder.Build()); | 365 std::unique_ptr<TestingProfile> second_profile(profile_builder.Build()); |
| 353 const AccountId account_id(AccountId::FromUserEmail(email)); | 366 const AccountId account_id(AccountId::FromUserEmail(email)); |
| 354 GetFakeUserManager()->AddUser(account_id); | 367 GetFakeUserManager()->AddUser(account_id); |
| 355 GetFakeUserManager()->SwitchActiveUser(account_id); | 368 GetFakeUserManager()->SwitchActiveUser(account_id); |
| 356 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 369 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 357 | 370 |
| 358 // Check that non-primary user can't use Arc. | 371 // Check that non-primary user can't use Arc. |
| 359 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); | 372 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); |
| 360 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); | 373 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); |
| 361 | 374 |
| 362 auth_service()->Shutdown(); | 375 arc_session_manager()->Shutdown(); |
| 363 } | 376 } |
| 364 | 377 |
| 365 } // namespace arc | 378 } // namespace arc |
| OLD | NEW |