| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 return; | 89 return; |
| 90 run_loop_->Quit(); | 90 run_loop_->Quit(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 std::unique_ptr<base::RunLoop> run_loop_; | 94 std::unique_ptr<base::RunLoop> run_loop_; |
| 95 | 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerShutdownObserver); | 96 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerShutdownObserver); |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 // Observer of ARC data has been removed. |
| 100 class ArcSessionManagerDataRemovedObserver |
| 101 : public ArcSessionManager::Observer { |
| 102 public: |
| 103 ArcSessionManagerDataRemovedObserver() { |
| 104 ArcSessionManager::Get()->AddObserver(this); |
| 105 } |
| 106 |
| 107 ~ArcSessionManagerDataRemovedObserver() override { |
| 108 ArcSessionManager::Get()->RemoveObserver(this); |
| 109 } |
| 110 |
| 111 void Wait() { |
| 112 run_loop_.reset(new base::RunLoop); |
| 113 run_loop_->Run(); |
| 114 run_loop_.reset(); |
| 115 } |
| 116 |
| 117 // ArcSessionManager::Observer: |
| 118 void OnArcDataRemoved() override { |
| 119 if (!run_loop_) |
| 120 return; |
| 121 run_loop_->Quit(); |
| 122 } |
| 123 |
| 124 private: |
| 125 std::unique_ptr<base::RunLoop> run_loop_; |
| 126 |
| 127 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerDataRemovedObserver); |
| 128 }; |
| 129 |
| 99 class ArcSessionManagerTest : public InProcessBrowserTest { | 130 class ArcSessionManagerTest : public InProcessBrowserTest { |
| 100 protected: | 131 protected: |
| 101 ArcSessionManagerTest() {} | 132 ArcSessionManagerTest() {} |
| 102 | 133 |
| 103 // InProcessBrowserTest: | 134 // InProcessBrowserTest: |
| 104 ~ArcSessionManagerTest() override {} | 135 ~ArcSessionManagerTest() override {} |
| 105 | 136 |
| 106 void SetUpInProcessBrowserTestFixture() override { | 137 void SetUpInProcessBrowserTestFixture() override { |
| 107 // Start test device management server. | 138 // Start test device management server. |
| 108 test_server_.reset(new policy::LocalPolicyTestServer()); | 139 test_server_.reset(new policy::LocalPolicyTestServer()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 profile_.reset(); | 201 profile_.reset(); |
| 171 user_manager_enabler_.reset(); | 202 user_manager_enabler_.reset(); |
| 172 test_server_.reset(); | 203 test_server_.reset(); |
| 173 } | 204 } |
| 174 | 205 |
| 175 chromeos::FakeChromeUserManager* GetFakeUserManager() const { | 206 chromeos::FakeChromeUserManager* GetFakeUserManager() const { |
| 176 return static_cast<chromeos::FakeChromeUserManager*>( | 207 return static_cast<chromeos::FakeChromeUserManager*>( |
| 177 user_manager::UserManager::Get()); | 208 user_manager::UserManager::Get()); |
| 178 } | 209 } |
| 179 | 210 |
| 211 void EnableArc() { |
| 212 PrefService* const prefs = profile()->GetPrefs(); |
| 213 prefs->SetBoolean(prefs::kArcEnabled, true); |
| 214 base::RunLoop().RunUntilIdle(); |
| 215 } |
| 216 |
| 180 void set_profile_name(const std::string& username) { | 217 void set_profile_name(const std::string& username) { |
| 181 profile_->set_profile_name(username); | 218 profile_->set_profile_name(username); |
| 182 } | 219 } |
| 183 | 220 |
| 184 Profile* profile() { return profile_.get(); } | 221 Profile* profile() { return profile_.get(); } |
| 185 | 222 |
| 186 FakeProfileOAuth2TokenService* token_service() { return token_service_; } | 223 FakeProfileOAuth2TokenService* token_service() { return token_service_; } |
| 187 | 224 |
| 188 private: | 225 private: |
| 189 std::unique_ptr<policy::LocalPolicyTestServer> test_server_; | 226 std::unique_ptr<policy::LocalPolicyTestServer> test_server_; |
| 190 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 227 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
| 191 base::ScopedTempDir temp_dir_; | 228 base::ScopedTempDir temp_dir_; |
| 192 std::unique_ptr<TestingProfile> profile_; | 229 std::unique_ptr<TestingProfile> profile_; |
| 193 FakeProfileOAuth2TokenService* token_service_; | 230 FakeProfileOAuth2TokenService* token_service_; |
| 194 | 231 |
| 195 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); | 232 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); |
| 196 }; | 233 }; |
| 197 | 234 |
| 198 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ConsumerAccount) { | 235 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ConsumerAccount) { |
| 199 PrefService* const prefs = profile()->GetPrefs(); | 236 EnableArc(); |
| 200 prefs->SetBoolean(prefs::kArcEnabled, true); | |
| 201 token_service()->IssueTokenForAllPendingRequests(kUnmanagedAuthToken, | 237 token_service()->IssueTokenForAllPendingRequests(kUnmanagedAuthToken, |
| 202 base::Time::Max()); | 238 base::Time::Max()); |
| 203 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | 239 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
| 204 ArcSessionManager::Get()->state()); | 240 ArcSessionManager::Get()->state()); |
| 205 } | 241 } |
| 206 | 242 |
| 207 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, WellKnownConsumerAccount) { | 243 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, WellKnownConsumerAccount) { |
| 208 set_profile_name(kWellKnownConsumerName); | 244 set_profile_name(kWellKnownConsumerName); |
| 209 PrefService* const prefs = profile()->GetPrefs(); | 245 EnableArc(); |
| 210 | |
| 211 prefs->SetBoolean(prefs::kArcEnabled, true); | |
| 212 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | 246 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
| 213 ArcSessionManager::Get()->state()); | 247 ArcSessionManager::Get()->state()); |
| 214 } | 248 } |
| 215 | 249 |
| 216 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedChromeAccount) { | 250 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedChromeAccount) { |
| 217 policy::ProfilePolicyConnector* const connector = | 251 policy::ProfilePolicyConnector* const connector = |
| 218 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile()); | 252 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile()); |
| 219 connector->OverrideIsManagedForTesting(true); | 253 connector->OverrideIsManagedForTesting(true); |
| 220 | 254 |
| 221 PrefService* const pref = profile()->GetPrefs(); | 255 EnableArc(); |
| 222 | |
| 223 pref->SetBoolean(prefs::kArcEnabled, true); | |
| 224 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | 256 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
| 225 ArcSessionManager::Get()->state()); | 257 ArcSessionManager::Get()->state()); |
| 226 } | 258 } |
| 227 | 259 |
| 228 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedAndroidAccount) { | 260 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedAndroidAccount) { |
| 229 PrefService* const prefs = profile()->GetPrefs(); | 261 EnableArc(); |
| 230 | |
| 231 prefs->SetBoolean(prefs::kArcEnabled, true); | |
| 232 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, | 262 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, |
| 233 base::Time::Max()); | 263 base::Time::Max()); |
| 234 ArcSessionManagerShutdownObserver observer; | 264 ArcSessionManagerShutdownObserver().Wait(); |
| 235 observer.Wait(); | 265 ASSERT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
| 266 ArcSessionManager::Get()->state()); |
| 267 ArcSessionManagerDataRemovedObserver().Wait(); |
| 236 ASSERT_EQ(ArcSessionManager::State::STOPPED, | 268 ASSERT_EQ(ArcSessionManager::State::STOPPED, |
| 237 ArcSessionManager::Get()->state()); | 269 ArcSessionManager::Get()->state()); |
| 238 } | 270 } |
| 239 | 271 |
| 240 } // namespace arc | 272 } // namespace arc |
| OLD | NEW |