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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 profile_.reset(); | 169 profile_.reset(); |
170 user_manager_enabler_.reset(); | 170 user_manager_enabler_.reset(); |
171 test_server_.reset(); | 171 test_server_.reset(); |
172 } | 172 } |
173 | 173 |
174 chromeos::FakeChromeUserManager* GetFakeUserManager() const { | 174 chromeos::FakeChromeUserManager* GetFakeUserManager() const { |
175 return static_cast<chromeos::FakeChromeUserManager*>( | 175 return static_cast<chromeos::FakeChromeUserManager*>( |
176 user_manager::UserManager::Get()); | 176 user_manager::UserManager::Get()); |
177 } | 177 } |
178 | 178 |
179 void EnableArc() { | |
180 PrefService* const prefs = profile()->GetPrefs(); | |
181 prefs->SetBoolean(prefs::kArcEnabled, true); | |
182 base::RunLoop().RunUntilIdle(); | |
183 } | |
184 | |
179 void set_profile_name(const std::string& username) { | 185 void set_profile_name(const std::string& username) { |
180 profile_->set_profile_name(username); | 186 profile_->set_profile_name(username); |
181 } | 187 } |
182 | 188 |
183 Profile* profile() { return profile_.get(); } | 189 Profile* profile() { return profile_.get(); } |
184 | 190 |
185 FakeProfileOAuth2TokenService* token_service() { return token_service_; } | 191 FakeProfileOAuth2TokenService* token_service() { return token_service_; } |
186 | 192 |
187 private: | 193 private: |
188 std::unique_ptr<policy::LocalPolicyTestServer> test_server_; | 194 std::unique_ptr<policy::LocalPolicyTestServer> test_server_; |
189 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 195 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
190 base::ScopedTempDir temp_dir_; | 196 base::ScopedTempDir temp_dir_; |
191 std::unique_ptr<TestingProfile> profile_; | 197 std::unique_ptr<TestingProfile> profile_; |
192 FakeProfileOAuth2TokenService* token_service_; | 198 FakeProfileOAuth2TokenService* token_service_; |
193 | 199 |
194 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); | 200 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); |
195 }; | 201 }; |
196 | 202 |
197 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ConsumerAccount) { | 203 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ConsumerAccount) { |
198 PrefService* const prefs = profile()->GetPrefs(); | 204 EnableArc(); |
199 prefs->SetBoolean(prefs::kArcEnabled, true); | |
200 token_service()->IssueTokenForAllPendingRequests(kUnmanagedAuthToken, | 205 token_service()->IssueTokenForAllPendingRequests(kUnmanagedAuthToken, |
201 base::Time::Max()); | 206 base::Time::Max()); |
202 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | 207 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
203 ArcSessionManager::Get()->state()); | 208 ArcSessionManager::Get()->state()); |
204 } | 209 } |
205 | 210 |
206 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, WellKnownConsumerAccount) { | 211 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, WellKnownConsumerAccount) { |
207 set_profile_name(kWellKnownConsumerName); | 212 set_profile_name(kWellKnownConsumerName); |
208 PrefService* const prefs = profile()->GetPrefs(); | 213 EnableArc(); |
209 | |
210 prefs->SetBoolean(prefs::kArcEnabled, true); | |
211 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | 214 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
212 ArcSessionManager::Get()->state()); | 215 ArcSessionManager::Get()->state()); |
213 } | 216 } |
214 | 217 |
215 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedChromeAccount) { | 218 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedChromeAccount) { |
216 policy::ProfilePolicyConnector* const connector = | 219 policy::ProfilePolicyConnector* const connector = |
217 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile()); | 220 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile()); |
218 connector->OverrideIsManagedForTesting(true); | 221 connector->OverrideIsManagedForTesting(true); |
219 | 222 |
220 PrefService* const pref = profile()->GetPrefs(); | 223 EnableArc(); |
221 | |
222 pref->SetBoolean(prefs::kArcEnabled, true); | |
223 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | 224 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
224 ArcSessionManager::Get()->state()); | 225 ArcSessionManager::Get()->state()); |
225 } | 226 } |
226 | 227 |
227 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedAndroidAccount) { | 228 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedAndroidAccount) { |
228 PrefService* const prefs = profile()->GetPrefs(); | 229 EnableArc(); |
229 | |
230 prefs->SetBoolean(prefs::kArcEnabled, true); | |
231 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, | 230 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, |
232 base::Time::Max()); | 231 base::Time::Max()); |
233 ArcSessionManagerShutdownObserver observer; | 232 ArcSessionManagerShutdownObserver observer; |
234 observer.Wait(); | 233 observer.Wait(); |
235 ASSERT_EQ(ArcSessionManager::State::STOPPED, | 234 ASSERT_EQ(ArcSessionManager::State::STOPPED, |
236 ArcSessionManager::Get()->state()); | 235 ArcSessionManager::Get()->state()); |
237 } | 236 } |
238 | 237 |
238 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, RemoveDataFolder) { | |
hidehiko
2016/12/01 16:15:03
Could you move this into unittest, instead of brow
khmel
2016/12/01 17:18:59
Done.
| |
239 EnableArc(); | |
240 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | |
241 ArcSessionManager::Get()->state()); | |
242 EXPECT_FALSE( | |
243 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
244 | |
245 // Request to remove data folder and close session immediately. | |
246 ArcSessionManager::Get()->RemoveArcData(); | |
247 ASSERT_TRUE( | |
248 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
249 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | |
250 ArcSessionManager::Get()->state()); | |
251 ArcSessionManager::Get()->Shutdown(); | |
252 base::RunLoop().RunUntilIdle(); | |
253 // Request to remove data is still active. | |
254 ASSERT_TRUE( | |
255 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
256 | |
257 ArcServiceLauncher::Get()->OnPrimaryUserProfilePrepared(profile()); | |
258 // Data removal request is in progress. | |
259 ASSERT_EQ(ArcSessionManager::State::STOPPED, | |
260 ArcSessionManager::Get()->state()); | |
261 ASSERT_TRUE( | |
262 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
263 base::RunLoop().RunUntilIdle(); | |
264 // After remove Arc is started. | |
hidehiko
2016/12/01 16:15:03
nit: s/Arc/ARC/ for consistency.
khmel
2016/12/01 17:18:59
Done.
| |
265 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | |
266 ArcSessionManager::Get()->state()); | |
267 ASSERT_FALSE( | |
268 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
269 ArcSessionManager::Get()->Shutdown(); | |
270 } | |
271 | |
239 } // namespace arc | 272 } // namespace arc |
OLD | NEW |