Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1014)

Side by Side Diff: chrome/browser/chromeos/arc/arc_session_manager_unittest.cc

Issue 2707133006: Start ARC and sign in after Chrome OS login (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <tuple> 7 #include <tuple>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 27 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
28 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 28 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
29 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 29 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
30 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 30 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
31 #include "chrome/browser/chromeos/profiles/profile_helper.h" 31 #include "chrome/browser/chromeos/profiles/profile_helper.h"
32 #include "chrome/browser/policy/profile_policy_connector.h" 32 #include "chrome/browser/policy/profile_policy_connector.h"
33 #include "chrome/browser/policy/profile_policy_connector_factory.h" 33 #include "chrome/browser/policy/profile_policy_connector_factory.h"
34 #include "chrome/browser/prefs/pref_service_syncable_util.h" 34 #include "chrome/browser/prefs/pref_service_syncable_util.h"
35 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
36 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 36 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
37 #include "chrome/browser/ui/app_list/arc/arc_app_test.h"
37 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 38 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
38 #include "chrome/common/pref_names.h" 39 #include "chrome/common/pref_names.h"
39 #include "chrome/test/base/testing_profile.h" 40 #include "chrome/test/base/testing_profile.h"
40 #include "chromeos/chromeos_switches.h" 41 #include "chromeos/chromeos_switches.h"
41 #include "chromeos/dbus/dbus_thread_manager.h" 42 #include "chromeos/dbus/dbus_thread_manager.h"
42 #include "chromeos/dbus/fake_session_manager_client.h" 43 #include "chromeos/dbus/fake_session_manager_client.h"
43 #include "components/arc/arc_service_manager.h" 44 #include "components/arc/arc_service_manager.h"
44 #include "components/arc/arc_session_runner.h" 45 #include "components/arc/arc_session_runner.h"
45 #include "components/arc/arc_util.h" 46 #include "components/arc/arc_util.h"
46 #include "components/arc/test/fake_arc_session.h" 47 #include "components/arc/test/fake_arc_session.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 content::TestBrowserThreadBundle thread_bundle_; 196 content::TestBrowserThreadBundle thread_bundle_;
196 std::unique_ptr<TestingProfile> profile_; 197 std::unique_ptr<TestingProfile> profile_;
197 std::unique_ptr<ArcServiceManager> arc_service_manager_; 198 std::unique_ptr<ArcServiceManager> arc_service_manager_;
198 std::unique_ptr<ArcSessionManager> arc_session_manager_; 199 std::unique_ptr<ArcSessionManager> arc_session_manager_;
199 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 200 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
200 base::ScopedTempDir temp_dir_; 201 base::ScopedTempDir temp_dir_;
201 202
202 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTestBase); 203 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTestBase);
203 }; 204 };
204 205
205 class ArcSessionManagerTest : public ArcSessionManagerTestBase { 206 // Intermediate class so that the children can inject test parameter freely.
207 class AbstractArcSessionManagerTest : public ArcSessionManagerTestBase {
206 public: 208 public:
207 ArcSessionManagerTest() = default; 209 AbstractArcSessionManagerTest() = default;
208
209 void SetUp() override { 210 void SetUp() override {
210 ArcSessionManagerTestBase::SetUp(); 211 ArcSessionManagerTestBase::SetUp();
212 ArcAppTest::Init(IsPersistentArcEnabled());
211 213
212 const AccountId account_id(AccountId::FromUserEmailGaiaId( 214 const AccountId account_id(AccountId::FromUserEmailGaiaId(
213 profile()->GetProfileUserName(), "1234567890")); 215 profile()->GetProfileUserName(), "1234567890"));
214 GetFakeUserManager()->AddUser(account_id); 216 GetFakeUserManager()->AddUser(account_id);
215 GetFakeUserManager()->LoginUser(account_id); 217 GetFakeUserManager()->LoginUser(account_id);
216 } 218 }
217 219
220 protected:
221 virtual bool IsPersistentArcEnabled() = 0;
222
223 private:
224 DISALLOW_COPY_AND_ASSIGN(AbstractArcSessionManagerTest);
225 };
226
227 class ArcSessionManagerTest : public AbstractArcSessionManagerTest,
228 public ::testing::WithParamInterface<bool> {
229 public:
230 ArcSessionManagerTest() = default;
231
232 protected:
233 bool IsPersistentArcEnabled() override { return GetParam(); }
234
218 private: 235 private:
219 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); 236 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest);
220 }; 237 };
221 238
222 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { 239 INSTANTIATE_TEST_CASE_P(,
hidehiko 2017/02/23 10:29:16 Any name?
victorhsieh 2017/02/24 00:44:59 I prefer not to. It will change the test name fro
240 ArcSessionManagerTest,
241 ::testing::Values(false, true));
hidehiko 2017/02/23 10:29:16 ::testing::Bool() can be used?
victorhsieh 2017/02/24 00:44:59 Done.
242
243 TEST_P(ArcSessionManagerTest, PrefChangeTriggersService) {
244 // TODO(victorhsieh): Implement opt-in and opt-out flow.
245 if (arc_session_manager()->IsPersistentArc())
246 return;
247
223 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 248 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
224 arc_session_manager()->state()); 249 arc_session_manager()->state());
225 250
226 PrefService* const pref = profile()->GetPrefs(); 251 PrefService* const pref = profile()->GetPrefs();
227 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 252 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
228 253
229 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 254 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
230 255
231 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); 256 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED));
232 257
233 pref->SetBoolean(prefs::kArcEnabled, true); 258 pref->SetBoolean(prefs::kArcEnabled, true);
234 base::RunLoop().RunUntilIdle(); 259 base::RunLoop().RunUntilIdle();
235 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 260 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
236 arc_session_manager()->state()); 261 arc_session_manager()->state());
237 262
238 pref->SetBoolean(prefs::kArcEnabled, false); 263 pref->SetBoolean(prefs::kArcEnabled, false);
239 264
240 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); 265 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED));
241 266
242 // Correctly stop service. 267 // Correctly stop service.
243 arc_session_manager()->Shutdown(); 268 arc_session_manager()->Shutdown();
244 } 269 }
245 270
246 TEST_F(ArcSessionManagerTest, DisabledForEphemeralDataUsers) { 271 TEST_P(ArcSessionManagerTest, DisabledForEphemeralDataUsers) {
247 PrefService* const prefs = profile()->GetPrefs(); 272 PrefService* const prefs = profile()->GetPrefs();
248 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 273 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
249 prefs->SetBoolean(prefs::kArcEnabled, true); 274 prefs->SetBoolean(prefs::kArcEnabled, true);
250 275
251 chromeos::FakeChromeUserManager* const fake_user_manager = 276 chromeos::FakeChromeUserManager* const fake_user_manager =
252 GetFakeUserManager(); 277 GetFakeUserManager();
253 278
254 fake_user_manager->AddUser(fake_user_manager->GetGuestAccountId()); 279 fake_user_manager->AddUser(fake_user_manager->GetGuestAccountId());
255 fake_user_manager->SwitchActiveUser(fake_user_manager->GetGuestAccountId()); 280 fake_user_manager->SwitchActiveUser(fake_user_manager->GetGuestAccountId());
256 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 281 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
(...skipping 24 matching lines...) Expand all
281 fake_user_manager->RemoveUserFromList(not_in_list_account_id); 306 fake_user_manager->RemoveUserFromList(not_in_list_account_id);
282 arc_session_manager()->Shutdown(); 307 arc_session_manager()->Shutdown();
283 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 308 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
284 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 309 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
285 arc_session_manager()->state()); 310 arc_session_manager()->state());
286 311
287 // Correctly stop service. 312 // Correctly stop service.
288 arc_session_manager()->Shutdown(); 313 arc_session_manager()->Shutdown();
289 } 314 }
290 315
291 TEST_F(ArcSessionManagerTest, BaseWorkflow) { 316 TEST_P(ArcSessionManagerTest, BaseWorkflow) {
317 // See BaseWorkflowOnPersistentArc for Persistent ARC flow.
318 if (arc_session_manager()->IsPersistentArc())
319 return;
320
292 ASSERT_TRUE(arc_session_manager()->IsSessionStopped()); 321 ASSERT_TRUE(arc_session_manager()->IsSessionStopped());
293 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 322 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
294 arc_session_manager()->state()); 323 arc_session_manager()->state());
295 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); 324 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null());
296 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); 325 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null());
297 326
298 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 327 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
299 328
300 // By default ARC is not enabled. 329 // By default ARC is not enabled.
301 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); 330 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 base::RunLoop().RunUntilIdle(); 362 base::RunLoop().RunUntilIdle();
334 363
335 // UI is disabled in unit tests and this code is unchanged. 364 // UI is disabled in unit tests and this code is unchanged.
336 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 365 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
337 arc_session_manager()->state()); 366 arc_session_manager()->state());
338 367
339 // Correctly stop service. 368 // Correctly stop service.
340 arc_session_manager()->Shutdown(); 369 arc_session_manager()->Shutdown();
341 } 370 }
342 371
343 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { 372 TEST_P(ArcSessionManagerTest, CancelFetchingDisablesArc) {
373 // TODO(victorhsieh): Implement opt-in flow on Persistent ARC.
374 if (arc_session_manager()->IsPersistentArc())
375 return;
376
344 PrefService* const pref = profile()->GetPrefs(); 377 PrefService* const pref = profile()->GetPrefs();
345 378
346 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 379 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
347 pref->SetBoolean(prefs::kArcEnabled, true); 380 pref->SetBoolean(prefs::kArcEnabled, true);
348 base::RunLoop().RunUntilIdle(); 381 base::RunLoop().RunUntilIdle();
349 382
350 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 383 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
351 arc_session_manager()->state()); 384 arc_session_manager()->state());
352 385
353 arc_session_manager()->CancelAuthCode(); 386 arc_session_manager()->CancelAuthCode();
354 387
355 // Wait until data is removed. 388 // Wait until data is removed.
356 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); 389 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED));
357 390
358 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 391 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
359 392
360 // Correctly stop service. 393 // Correctly stop service.
361 arc_session_manager()->Shutdown(); 394 arc_session_manager()->Shutdown();
362 } 395 }
363 396
364 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { 397 TEST_P(ArcSessionManagerTest, CloseUIKeepsArcEnabled) {
365 PrefService* const pref = profile()->GetPrefs(); 398 PrefService* const pref = profile()->GetPrefs();
366 399
367 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 400 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
368 pref->SetBoolean(prefs::kArcEnabled, true); 401 pref->SetBoolean(prefs::kArcEnabled, true);
369 base::RunLoop().RunUntilIdle(); 402 base::RunLoop().RunUntilIdle();
370 403
371 arc_session_manager()->StartArc(); 404 arc_session_manager()->StartArc();
372 405
373 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 406 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
374 407
375 arc_session_manager()->CancelAuthCode(); 408 arc_session_manager()->CancelAuthCode();
376 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 409 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
377 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); 410 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled));
378 411
379 // Correctly stop service. 412 // Correctly stop service.
380 arc_session_manager()->Shutdown(); 413 arc_session_manager()->Shutdown();
381 } 414 }
382 415
383 TEST_F(ArcSessionManagerTest, EnableDisablesArc) { 416 TEST_P(ArcSessionManagerTest, EnableDisablesArc) {
384 const PrefService* pref = profile()->GetPrefs(); 417 const PrefService* pref = profile()->GetPrefs();
385 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 418 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
386 419
387 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 420 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
388 arc_session_manager()->SetArcPlayStoreEnabled(true); 421 arc_session_manager()->SetArcPlayStoreEnabled(true);
389 EXPECT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); 422 EXPECT_TRUE(pref->GetBoolean(prefs::kArcEnabled));
390 arc_session_manager()->SetArcPlayStoreEnabled(false); 423 arc_session_manager()->SetArcPlayStoreEnabled(false);
391 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 424 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
392 425
393 // Correctly stop service. 426 // Correctly stop service.
394 arc_session_manager()->Shutdown(); 427 arc_session_manager()->Shutdown();
395 } 428 }
396 429
397 TEST_F(ArcSessionManagerTest, SignInStatus) { 430 TEST_P(ArcSessionManagerTest, SignInStatus) {
398 PrefService* const prefs = profile()->GetPrefs(); 431 PrefService* const prefs = profile()->GetPrefs();
399 432
400 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); 433 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null());
401 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); 434 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null());
402 435
403 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 436 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
404 prefs->SetBoolean(prefs::kArcEnabled, true); 437 prefs->SetBoolean(prefs::kArcEnabled, true);
405 438
406 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 439 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
407 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 440 if (arc_session_manager()->IsPersistentArc()) {
408 arc_session_manager()->state()); 441 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
442 } else {
443 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
444 arc_session_manager()->state());
445 }
409 446
410 // Emulate to accept the terms of service. 447 // Emulate to accept the terms of service.
411 prefs->SetBoolean(prefs::kArcTermsAccepted, true); 448 prefs->SetBoolean(prefs::kArcTermsAccepted, true);
412 arc_session_manager()->StartArc(); 449 if (!arc_session_manager()->IsPersistentArc()) {
450 arc_session_manager()->StartArc();
451 }
413 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 452 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
414 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); 453 EXPECT_TRUE(arc_session_manager()->IsSessionRunning());
415 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 454 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
416 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); 455 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null());
417 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); 456 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS);
418 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); 457 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn));
419 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 458 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
420 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); 459 EXPECT_TRUE(arc_session_manager()->IsSessionRunning());
421 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); 460 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null());
422 461
(...skipping 13 matching lines...) Expand all
436 // On error, UI to send feedback is showing. In that case, 475 // On error, UI to send feedback is showing. In that case,
437 // the ARC is still necessary to run on background for gathering the logs. 476 // the ARC is still necessary to run on background for gathering the logs.
438 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); 477 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn));
439 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 478 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
440 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); 479 EXPECT_TRUE(arc_session_manager()->IsSessionRunning());
441 480
442 // Correctly stop service. 481 // Correctly stop service.
443 arc_session_manager()->Shutdown(); 482 arc_session_manager()->Shutdown();
444 } 483 }
445 484
446 TEST_F(ArcSessionManagerTest, DisabledForDeviceLocalAccount) { 485 TEST_P(ArcSessionManagerTest, DisabledForDeviceLocalAccount) {
447 PrefService* const prefs = profile()->GetPrefs(); 486 PrefService* const prefs = profile()->GetPrefs();
448 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 487 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
449 prefs->SetBoolean(prefs::kArcEnabled, true); 488 prefs->SetBoolean(prefs::kArcEnabled, true);
450 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 489 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
451 arc_session_manager()->StartArc(); 490 arc_session_manager()->StartArc();
452 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 491 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
453 492
454 // Create device local account and set it as active. 493 // Create device local account and set it as active.
455 const std::string email = "device-local-account@fake-email.com"; 494 const std::string email = "device-local-account@fake-email.com";
456 TestingProfile::Builder profile_builder; 495 TestingProfile::Builder profile_builder;
(...skipping 11 matching lines...) Expand all
468 device_local_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 507 device_local_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
469 arc_session_manager()->OnPrimaryUserProfilePrepared( 508 arc_session_manager()->OnPrimaryUserProfilePrepared(
470 device_local_profile.get()); 509 device_local_profile.get());
471 EXPECT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 510 EXPECT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
472 arc_session_manager()->state()); 511 arc_session_manager()->state());
473 512
474 // Correctly stop service. 513 // Correctly stop service.
475 arc_session_manager()->Shutdown(); 514 arc_session_manager()->Shutdown();
476 } 515 }
477 516
478 TEST_F(ArcSessionManagerTest, DisabledForNonPrimaryProfile) { 517 TEST_P(ArcSessionManagerTest, DisabledForNonPrimaryProfile) {
479 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 518 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
480 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 519 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
481 arc_session_manager()->StartArc(); 520 arc_session_manager()->StartArc();
482 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 521 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
483 522
484 // Create a second profile and set it as the active profile. 523 // Create a second profile and set it as the active profile.
485 const std::string email = "test@example.com"; 524 const std::string email = "test@example.com";
486 TestingProfile::Builder profile_builder; 525 TestingProfile::Builder profile_builder;
487 profile_builder.SetProfileName(email); 526 profile_builder.SetProfileName(email);
488 std::unique_ptr<TestingProfile> second_profile(profile_builder.Build()); 527 std::unique_ptr<TestingProfile> second_profile(profile_builder.Build());
489 const AccountId account_id(AccountId::FromUserEmail(email)); 528 const AccountId account_id(AccountId::FromUserEmail(email));
490 GetFakeUserManager()->AddUser(account_id); 529 GetFakeUserManager()->AddUser(account_id);
491 GetFakeUserManager()->SwitchActiveUser(account_id); 530 GetFakeUserManager()->SwitchActiveUser(account_id);
492 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 531 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
493 532
494 // Check that non-primary user can't use ARC. 533 // Check that non-primary user can't use ARC.
495 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); 534 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get()));
496 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); 535 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get()));
497 536
498 arc_session_manager()->Shutdown(); 537 arc_session_manager()->Shutdown();
499 } 538 }
500 539
501 TEST_F(ArcSessionManagerTest, RemoveDataFolder) { 540 TEST_P(ArcSessionManagerTest, RemoveDataFolder) {
541 // TODO(victorhsieh): Implement data removal on Persistent ARC.
542 if (arc_session_manager()->IsPersistentArc())
543 return;
544
502 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); 545 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
503 // Starting session manager with prefs::kArcEnabled off automatically removes 546 // Starting session manager with prefs::kArcEnabled off automatically removes
504 // Android's data folder. 547 // Android's data folder.
505 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 548 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
506 EXPECT_TRUE( 549 EXPECT_TRUE(
507 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); 550 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
508 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, 551 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR,
509 arc_session_manager()->state()); 552 arc_session_manager()->state());
510 // Enable ARC. Data is removed asyncronously. At this moment session manager 553 // Enable ARC. Data is removed asyncronously. At this moment session manager
511 // should be in REMOVING_DATA_DIR state. 554 // should be in REMOVING_DATA_DIR state.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 587
545 EXPECT_FALSE( 588 EXPECT_FALSE(
546 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); 589 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
547 590
548 arc_session_manager()->StartArc(); 591 arc_session_manager()->StartArc();
549 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 592 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
550 593
551 arc_session_manager()->Shutdown(); 594 arc_session_manager()->Shutdown();
552 } 595 }
553 596
554 TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) { 597 TEST_P(ArcSessionManagerTest, IgnoreSecondErrorReporting) {
555 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 598 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
556 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 599 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
557 arc_session_manager()->StartArc(); 600 arc_session_manager()->StartArc();
558 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 601 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
559 602
560 // Report some failure that does not stop the bridge. 603 // Report some failure that does not stop the bridge.
561 arc_session_manager()->OnProvisioningFinished( 604 arc_session_manager()->OnProvisioningFinished(
562 ProvisioningResult::GMS_SIGN_IN_FAILED); 605 ProvisioningResult::GMS_SIGN_IN_FAILED);
563 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 606 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
564 607
565 // Try to send another error that stops the bridge if sent first. It should 608 // Try to send another error that stops the bridge if sent first. It should
566 // be ignored. 609 // be ignored.
567 arc_session_manager()->OnProvisioningFinished( 610 arc_session_manager()->OnProvisioningFinished(
568 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); 611 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
569 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 612 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
570 613
571 arc_session_manager()->Shutdown(); 614 arc_session_manager()->Shutdown();
572 } 615 }
573 616
574 class ArcSessionManagerPolicyTest 617 class ArcSessionManagerPolicyTest
575 : public ArcSessionManagerTest, 618 : public AbstractArcSessionManagerTest,
576 public testing::WithParamInterface<std::tuple<base::Value, base::Value>> { 619 public testing::WithParamInterface<
620 std::tuple<base::Value, base::Value, bool>> {
577 public: 621 public:
578 const base::Value& backup_restore_pref_value() const { 622 const base::Value& backup_restore_pref_value() const {
579 return std::get<0>(GetParam()); 623 return std::get<0>(GetParam());
580 } 624 }
581 625
582 const base::Value& location_service_pref_value() const { 626 const base::Value& location_service_pref_value() const {
583 return std::get<1>(GetParam()); 627 return std::get<1>(GetParam());
584 } 628 }
629
630 protected:
631 bool IsPersistentArcEnabled() override { return std::get<2>(GetParam()); }
585 }; 632 };
586 633
587 TEST_P(ArcSessionManagerPolicyTest, SkippingTerms) { 634 TEST_P(ArcSessionManagerPolicyTest, SkippingTerms) {
588 sync_preferences::TestingPrefServiceSyncable* const prefs = 635 sync_preferences::TestingPrefServiceSyncable* const prefs =
589 profile()->GetTestingPrefService(); 636 profile()->GetTestingPrefService();
590 637
591 // Backup-restore and location-service prefs are off by default. 638 // Backup-restore and location-service prefs are off by default.
592 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 639 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
593 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcTermsAccepted)); 640 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcTermsAccepted));
594 641
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 prefs->RemoveManagedPref(prefs::kArcEnabled); 678 prefs->RemoveManagedPref(prefs::kArcEnabled);
632 WaitForDataRemoved(ArcSessionManager::State::STOPPED); 679 WaitForDataRemoved(ArcSessionManager::State::STOPPED);
633 arc_session_manager()->Shutdown(); 680 arc_session_manager()->Shutdown();
634 } 681 }
635 682
636 INSTANTIATE_TEST_CASE_P( 683 INSTANTIATE_TEST_CASE_P(
637 ArcSessionManagerPolicyTest, 684 ArcSessionManagerPolicyTest,
638 ArcSessionManagerPolicyTest, 685 ArcSessionManagerPolicyTest,
639 testing::Combine( 686 testing::Combine(
640 testing::Values(base::Value(), base::Value(false), base::Value(true)), 687 testing::Values(base::Value(), base::Value(false), base::Value(true)),
641 testing::Values(base::Value(), base::Value(false), base::Value(true)))); 688 testing::Values(base::Value(), base::Value(false), base::Value(true)),
689 testing::Values(true, false)));
642 690
643 class ArcSessionManagerKioskTest : public ArcSessionManagerTestBase { 691 class ArcSessionManagerKioskTest : public ArcSessionManagerTestBase {
644 public: 692 public:
645 ArcSessionManagerKioskTest() = default; 693 ArcSessionManagerKioskTest() = default;
646 694
647 void SetUp() override { 695 void SetUp() override {
648 ArcSessionManagerTestBase::SetUp(); 696 ArcSessionManagerTestBase::SetUp();
649 const AccountId account_id( 697 const AccountId account_id(
650 AccountId::FromUserEmail(profile()->GetProfileUserName())); 698 AccountId::FromUserEmail(profile()->GetProfileUserName()));
651 GetFakeUserManager()->AddArcKioskAppUser(account_id); 699 GetFakeUserManager()->AddArcKioskAppUser(account_id);
(...skipping 15 matching lines...) Expand all
667 // and not invoked then, including TearDown(). 715 // and not invoked then, including TearDown().
668 bool terminated = false; 716 bool terminated = false;
669 arc_session_manager()->SetAttemptUserExitCallbackForTesting( 717 arc_session_manager()->SetAttemptUserExitCallbackForTesting(
670 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); 718 base::Bind([](bool* terminated) { *terminated = true; }, &terminated));
671 719
672 arc_session_manager()->OnProvisioningFinished( 720 arc_session_manager()->OnProvisioningFinished(
673 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); 721 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
674 EXPECT_TRUE(terminated); 722 EXPECT_TRUE(terminated);
675 } 723 }
676 724
677 class ArcSessionOobeOptInTest : public ArcSessionManagerTest { 725 class ArcSessionOobeOptInTest : public AbstractArcSessionManagerTest {
678 public: 726 public:
679 ArcSessionOobeOptInTest() = default; 727 ArcSessionOobeOptInTest() = default;
680 728
681 protected: 729 protected:
730 bool IsPersistentArcEnabled() override { return false; }
hidehiko 2017/02/23 10:29:16 This also should be tested with and without PARC?
victorhsieh 2017/02/24 00:44:59 Done.
731
682 void CreateLoginDisplayHost() { 732 void CreateLoginDisplayHost() {
683 fake_login_display_host_ = base::MakeUnique<FakeLoginDisplayHost>(); 733 fake_login_display_host_ = base::MakeUnique<FakeLoginDisplayHost>();
684 } 734 }
685 735
686 void CloseLoginDisplayHost() { fake_login_display_host_.reset(); } 736 void CloseLoginDisplayHost() { fake_login_display_host_.reset(); }
687 737
688 void AppendEnableArcOOBEOptInSwitch() { 738 void AppendEnableArcOOBEOptInSwitch() {
689 base::CommandLine::ForCurrentProcess()->AppendSwitch( 739 base::CommandLine::ForCurrentProcess()->AppendSwitch(
690 chromeos::switches::kEnableArcOOBEOptIn); 740 chromeos::switches::kEnableArcOOBEOptIn);
691 } 741 }
(...skipping 19 matching lines...) Expand all
711 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); 761 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive());
712 GetFakeUserManager()->set_current_user_new(true); 762 GetFakeUserManager()->set_current_user_new(true);
713 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); 763 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive());
714 CreateLoginDisplayHost(); 764 CreateLoginDisplayHost();
715 EXPECT_TRUE(ArcSessionManager::IsOobeOptInActive()); 765 EXPECT_TRUE(ArcSessionManager::IsOobeOptInActive());
716 } 766 }
717 767
718 class ArcSessionOobeOptInNegotiatorTest 768 class ArcSessionOobeOptInNegotiatorTest
719 : public ArcSessionOobeOptInTest, 769 : public ArcSessionOobeOptInTest,
720 public chromeos::ArcTermsOfServiceScreenActor, 770 public chromeos::ArcTermsOfServiceScreenActor,
721 public testing::WithParamInterface<bool> { 771 public testing::WithParamInterface<std::tuple<bool, bool>> {
722 public: 772 public:
723 ArcSessionOobeOptInNegotiatorTest() = default; 773 ArcSessionOobeOptInNegotiatorTest() = default;
724 774
725 void SetUp() override { 775 void SetUp() override {
726 ArcSessionOobeOptInTest::SetUp(); 776 ArcSessionOobeOptInTest::SetUp();
727 777
728 AppendEnableArcOOBEOptInSwitch(); 778 AppendEnableArcOOBEOptInSwitch();
729 779
730 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( 780 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting(
731 this); 781 this);
(...skipping 19 matching lines...) Expand all
751 // Correctly stop service. 801 // Correctly stop service.
752 arc_session_manager()->Shutdown(); 802 arc_session_manager()->Shutdown();
753 803
754 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting( 804 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenActorForTesting(
755 nullptr); 805 nullptr);
756 806
757 ArcSessionOobeOptInTest::TearDown(); 807 ArcSessionOobeOptInTest::TearDown();
758 } 808 }
759 809
760 protected: 810 protected:
761 bool IsManagedUser() { return GetParam(); } 811 bool IsManagedUser() { return std::get<0>(GetParam()); }
812
813 bool IsPersistentArcEnabled() override { return std::get<1>(GetParam()); }
762 814
763 void ReportResult(bool accepted) { 815 void ReportResult(bool accepted) {
764 for (auto& observer : observer_list_) { 816 for (auto& observer : observer_list_) {
765 if (accepted) 817 if (accepted)
766 observer.OnAccept(); 818 observer.OnAccept();
767 else 819 else
768 observer.OnSkip(); 820 observer.OnSkip();
769 } 821 }
770 base::RunLoop().RunUntilIdle(); 822 base::RunLoop().RunUntilIdle();
771 } 823 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 void Hide() override {} 863 void Hide() override {}
812 864
813 base::ObserverList<chromeos::ArcTermsOfServiceScreenActorObserver> 865 base::ObserverList<chromeos::ArcTermsOfServiceScreenActorObserver>
814 observer_list_; 866 observer_list_;
815 867
816 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); 868 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest);
817 }; 869 };
818 870
819 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl, 871 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl,
820 ArcSessionOobeOptInNegotiatorTest, 872 ArcSessionOobeOptInNegotiatorTest,
821 ::testing::Values(true, false)); 873 testing::Combine(::testing::Values(true, false),
874 ::testing::Values(true, false)));
822 875
823 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { 876 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) {
824 actor()->Show(); 877 actor()->Show();
825 MaybeWaitForDataRemoved(); 878 MaybeWaitForDataRemoved();
826 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 879 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
827 arc_session_manager()->state()); 880 arc_session_manager()->state());
828 ReportResult(true); 881 ReportResult(true);
829 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 882 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
830 EXPECT_TRUE(arc_session_manager()->IsArcPlayStoreEnabled()); 883 EXPECT_TRUE(arc_session_manager()->IsArcPlayStoreEnabled());
831 } 884 }
(...skipping 15 matching lines...) Expand all
847 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 900 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
848 arc_session_manager()->state()); 901 arc_session_manager()->state());
849 CloseLoginDisplayHost(); 902 CloseLoginDisplayHost();
850 ReportActorDestroyed(); 903 ReportActorDestroyed();
851 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 904 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state());
852 EXPECT_FALSE(!IsManagedUser() && 905 EXPECT_FALSE(!IsManagedUser() &&
853 arc_session_manager()->IsArcPlayStoreEnabled()); 906 arc_session_manager()->IsArcPlayStoreEnabled());
854 } 907 }
855 908
856 } // namespace arc 909 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698