| 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 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 profile_.reset(); | 170 profile_.reset(); |
| 171 user_manager_enabler_.reset(); | 171 user_manager_enabler_.reset(); |
| 172 test_server_.reset(); | 172 test_server_.reset(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 chromeos::FakeChromeUserManager* GetFakeUserManager() const { | 175 chromeos::FakeChromeUserManager* GetFakeUserManager() const { |
| 176 return static_cast<chromeos::FakeChromeUserManager*>( | 176 return static_cast<chromeos::FakeChromeUserManager*>( |
| 177 user_manager::UserManager::Get()); | 177 user_manager::UserManager::Get()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void EnableArc() { |
| 181 PrefService* const prefs = profile()->GetPrefs(); |
| 182 prefs->SetBoolean(prefs::kArcEnabled, true); |
| 183 base::RunLoop().RunUntilIdle(); |
| 184 } |
| 185 |
| 180 void set_profile_name(const std::string& username) { | 186 void set_profile_name(const std::string& username) { |
| 181 profile_->set_profile_name(username); | 187 profile_->set_profile_name(username); |
| 182 } | 188 } |
| 183 | 189 |
| 184 Profile* profile() { return profile_.get(); } | 190 Profile* profile() { return profile_.get(); } |
| 185 | 191 |
| 186 FakeProfileOAuth2TokenService* token_service() { return token_service_; } | 192 FakeProfileOAuth2TokenService* token_service() { return token_service_; } |
| 187 | 193 |
| 188 private: | 194 private: |
| 189 std::unique_ptr<policy::LocalPolicyTestServer> test_server_; | 195 std::unique_ptr<policy::LocalPolicyTestServer> test_server_; |
| 190 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 196 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
| 191 base::ScopedTempDir temp_dir_; | 197 base::ScopedTempDir temp_dir_; |
| 192 std::unique_ptr<TestingProfile> profile_; | 198 std::unique_ptr<TestingProfile> profile_; |
| 193 FakeProfileOAuth2TokenService* token_service_; | 199 FakeProfileOAuth2TokenService* token_service_; |
| 194 | 200 |
| 195 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); | 201 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); |
| 196 }; | 202 }; |
| 197 | 203 |
| 198 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ConsumerAccount) { | 204 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ConsumerAccount) { |
| 199 PrefService* const prefs = profile()->GetPrefs(); | 205 EnableArc(); |
| 200 prefs->SetBoolean(prefs::kArcEnabled, true); | |
| 201 token_service()->IssueTokenForAllPendingRequests(kUnmanagedAuthToken, | 206 token_service()->IssueTokenForAllPendingRequests(kUnmanagedAuthToken, |
| 202 base::Time::Max()); | 207 base::Time::Max()); |
| 203 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | 208 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
| 204 ArcSessionManager::Get()->state()); | 209 ArcSessionManager::Get()->state()); |
| 205 } | 210 } |
| 206 | 211 |
| 207 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, WellKnownConsumerAccount) { | 212 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, WellKnownConsumerAccount) { |
| 208 set_profile_name(kWellKnownConsumerName); | 213 set_profile_name(kWellKnownConsumerName); |
| 209 PrefService* const prefs = profile()->GetPrefs(); | 214 EnableArc(); |
| 210 | |
| 211 prefs->SetBoolean(prefs::kArcEnabled, true); | |
| 212 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | 215 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
| 213 ArcSessionManager::Get()->state()); | 216 ArcSessionManager::Get()->state()); |
| 214 } | 217 } |
| 215 | 218 |
| 216 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedChromeAccount) { | 219 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedChromeAccount) { |
| 217 policy::ProfilePolicyConnector* const connector = | 220 policy::ProfilePolicyConnector* const connector = |
| 218 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile()); | 221 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile()); |
| 219 connector->OverrideIsManagedForTesting(true); | 222 connector->OverrideIsManagedForTesting(true); |
| 220 | 223 |
| 221 PrefService* const pref = profile()->GetPrefs(); | 224 EnableArc(); |
| 222 | |
| 223 pref->SetBoolean(prefs::kArcEnabled, true); | |
| 224 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | 225 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
| 225 ArcSessionManager::Get()->state()); | 226 ArcSessionManager::Get()->state()); |
| 226 } | 227 } |
| 227 | 228 |
| 228 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedAndroidAccount) { | 229 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedAndroidAccount) { |
| 229 PrefService* const prefs = profile()->GetPrefs(); | 230 EnableArc(); |
| 230 | |
| 231 prefs->SetBoolean(prefs::kArcEnabled, true); | |
| 232 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, | 231 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, |
| 233 base::Time::Max()); | 232 base::Time::Max()); |
| 234 ArcSessionManagerShutdownObserver observer; | 233 ArcSessionManagerShutdownObserver observer; |
| 235 observer.Wait(); | 234 observer.Wait(); |
| 236 ASSERT_EQ(ArcSessionManager::State::STOPPED, | 235 ASSERT_EQ(ArcSessionManager::State::STOPPED, |
| 237 ArcSessionManager::Get()->state()); | 236 ArcSessionManager::Get()->state()); |
| 238 } | 237 } |
| 239 | 238 |
| 240 } // namespace arc | 239 } // namespace arc |
| OLD | NEW |