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

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // Process pending tasks. This performs multiple thread hops, so we need 86 // Process pending tasks. This performs multiple thread hops, so we need
87 // to run it continuously until it is resolved. 87 // to run it continuously until it is resolved.
88 do { 88 do {
89 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 89 content::BrowserThread::GetBlockingPool()->FlushForTesting();
90 base::RunLoop().RunUntilIdle(); 90 base::RunLoop().RunUntilIdle();
91 } while (!base::PathExists(icon_path)); 91 } while (!base::PathExists(icon_path));
92 } 92 }
93 93
94 } // namespace 94 } // namespace
95 95
96 class ArcAppModelBuilderTest : public AppListTestBase { 96 class ArcAppModelBuilderTest : public AppListTestBase,
97 public ::testing::WithParamInterface<bool> {
97 public: 98 public:
98 ArcAppModelBuilderTest() = default; 99 ArcAppModelBuilderTest() = default;
99 ~ArcAppModelBuilderTest() override { 100 ~ArcAppModelBuilderTest() override {
100 // Release profile file in order to keep right sequence. 101 // Release profile file in order to keep right sequence.
101 profile_.reset(); 102 profile_.reset();
102 } 103 }
103 104
104 void SetUp() override { 105 void SetUp() override {
106 ArcAppTest::Init(/* is_persistent_arc */ GetParam());
105 AppListTestBase::SetUp(); 107 AppListTestBase::SetUp();
106 OnBeforeArcTestSetup(); 108 OnBeforeArcTestSetup();
107 arc_test_.SetUp(profile_.get()); 109 arc_test_.SetUp(profile_.get());
108 CreateBuilder(); 110 CreateBuilder();
109 111
110 // Validating decoded content does not fit well for unit tests. 112 // Validating decoded content does not fit well for unit tests.
111 ArcAppIcon::DisableSafeDecodingForTesting(); 113 ArcAppIcon::DisableSafeDecodingForTesting();
112 } 114 }
113 115
114 void TearDown() override { 116 void TearDown() override {
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { 330 void RemovePackage(const arc::mojom::ArcPackageInfo& package) {
329 arc_test_.RemovePackage(package); 331 arc_test_.RemovePackage(package);
330 } 332 }
331 333
332 AppListControllerDelegate* controller() { return controller_.get(); } 334 AppListControllerDelegate* controller() { return controller_.get(); }
333 335
334 Profile* profile() { return profile_.get(); } 336 Profile* profile() { return profile_.get(); }
335 337
336 ArcAppTest* arc_test() { return &arc_test_; } 338 ArcAppTest* arc_test() { return &arc_test_; }
337 339
340 bool IsPersistentArc() {
341 return arc_test()->arc_session_manager()->IsPersistentArc();
342 }
343
338 const std::vector<arc::mojom::AppInfo>& fake_apps() const { 344 const std::vector<arc::mojom::AppInfo>& fake_apps() const {
339 return arc_test_.fake_apps(); 345 return arc_test_.fake_apps();
340 } 346 }
341 347
342 const std::vector<arc::mojom::AppInfo>& fake_default_apps() const { 348 const std::vector<arc::mojom::AppInfo>& fake_default_apps() const {
343 return arc_test_.fake_default_apps(); 349 return arc_test_.fake_default_apps();
344 } 350 }
345 351
346 const std::vector<arc::mojom::ArcPackageInfo>& fake_packages() const { 352 const std::vector<arc::mojom::ArcPackageInfo>& fake_packages() const {
347 return arc_test_.fake_packages(); 353 return arc_test_.fake_packages();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 // ArcAppModelBuilderTest: 451 // ArcAppModelBuilderTest:
446 void OnBeforeArcTestSetup() override { 452 void OnBeforeArcTestSetup() override {
447 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( 453 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory(
448 profile_.get(), nullptr); 454 profile_.get(), nullptr);
449 } 455 }
450 456
451 private: 457 private:
452 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderRecreate); 458 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderRecreate);
453 }; 459 };
454 460
455 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { 461 TEST_P(ArcAppModelBuilderTest, ArcPackagePref) {
456 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); 462 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>());
457 app_instance()->SendRefreshPackageList(fake_packages()); 463 app_instance()->SendRefreshPackageList(fake_packages());
458 ValidateHavePackages(fake_packages()); 464 ValidateHavePackages(fake_packages());
459 465
460 arc::mojom::ArcPackageInfo package; 466 arc::mojom::ArcPackageInfo package;
461 package.package_name = kTestPackageName; 467 package.package_name = kTestPackageName;
462 package.package_version = 2; 468 package.package_version = 2;
463 package.last_backup_android_id = 2; 469 package.last_backup_android_id = 2;
464 package.last_backup_time = 2; 470 package.last_backup_time = 2;
465 package.sync = true; 471 package.sync = true;
466 472
467 RemovePackage(package); 473 RemovePackage(package);
468 app_instance()->SendPackageUninstalled(package.package_name); 474 app_instance()->SendPackageUninstalled(package.package_name);
469 ValidateHavePackages(fake_packages()); 475 ValidateHavePackages(fake_packages());
470 476
471 AddPackage(package); 477 AddPackage(package);
472 app_instance()->SendPackageAdded(package); 478 app_instance()->SendPackageAdded(package);
473 ValidateHavePackages(fake_packages()); 479 ValidateHavePackages(fake_packages());
474 } 480 }
475 481
476 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) { 482 TEST_P(ArcAppModelBuilderTest, RefreshAllOnReady) {
477 // There should already have been one call, when the interface was 483 // There should already have been one call, when the interface was
478 // registered. 484 // registered.
479 EXPECT_EQ(1, app_instance()->refresh_app_list_count()); 485 EXPECT_EQ(1, app_instance()->refresh_app_list_count());
480 app_instance()->RefreshAppList(); 486 app_instance()->RefreshAppList();
481 EXPECT_EQ(2, app_instance()->refresh_app_list_count()); 487 EXPECT_EQ(2, app_instance()->refresh_app_list_count());
482 } 488 }
483 489
484 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) { 490 TEST_P(ArcAppModelBuilderTest, RefreshAllFillsContent) {
485 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 491 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
486 app_instance()->RefreshAppList(); 492 app_instance()->RefreshAppList();
487 app_instance()->SendRefreshAppList(fake_apps()); 493 app_instance()->SendRefreshAppList(fake_apps());
488 ValidateHaveApps(fake_apps()); 494 ValidateHaveApps(fake_apps());
489 } 495 }
490 496
491 TEST_F(ArcAppModelBuilderTest, InstallShortcut) { 497 TEST_P(ArcAppModelBuilderTest, InstallShortcut) {
492 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 498 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
493 499
494 app_instance()->SendInstallShortcuts(fake_shortcuts()); 500 app_instance()->SendInstallShortcuts(fake_shortcuts());
495 ValidateHaveShortcuts(fake_shortcuts()); 501 ValidateHaveShortcuts(fake_shortcuts());
496 } 502 }
497 503
498 TEST_F(ArcAppModelBuilderTest, RefreshAllPreservesShortcut) { 504 TEST_P(ArcAppModelBuilderTest, RefreshAllPreservesShortcut) {
499 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 505 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
500 app_instance()->RefreshAppList(); 506 app_instance()->RefreshAppList();
501 app_instance()->SendRefreshAppList(fake_apps()); 507 app_instance()->SendRefreshAppList(fake_apps());
502 ValidateHaveApps(fake_apps()); 508 ValidateHaveApps(fake_apps());
503 509
504 app_instance()->SendInstallShortcuts(fake_shortcuts()); 510 app_instance()->SendInstallShortcuts(fake_shortcuts());
505 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts()); 511 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts());
506 512
507 app_instance()->RefreshAppList(); 513 app_instance()->RefreshAppList();
508 app_instance()->SendRefreshAppList(fake_apps()); 514 app_instance()->SendRefreshAppList(fake_apps());
509 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts()); 515 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts());
510 } 516 }
511 517
512 TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) { 518 TEST_P(ArcAppModelBuilderTest, MultipleRefreshAll) {
513 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 519 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
514 app_instance()->RefreshAppList(); 520 app_instance()->RefreshAppList();
515 // Send info about all fake apps except last. 521 // Send info about all fake apps except last.
516 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(), 522 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(),
517 fake_apps().end() - 1); 523 fake_apps().end() - 1);
518 app_instance()->SendRefreshAppList(apps1); 524 app_instance()->SendRefreshAppList(apps1);
519 // At this point all apps (except last) should exist and be ready. 525 // At this point all apps (except last) should exist and be ready.
520 ValidateHaveApps(apps1); 526 ValidateHaveApps(apps1);
521 ValidateAppReadyState(apps1, true); 527 ValidateAppReadyState(apps1, true);
522 528
(...skipping 11 matching lines...) Expand all
534 ValidateHaveApps(fake_apps()); 540 ValidateHaveApps(fake_apps());
535 ValidateAppReadyState(fake_apps(), true); 541 ValidateAppReadyState(fake_apps(), true);
536 542
537 // Send info no app available. 543 // Send info no app available.
538 std::vector<arc::mojom::AppInfo> no_apps; 544 std::vector<arc::mojom::AppInfo> no_apps;
539 app_instance()->SendRefreshAppList(no_apps); 545 app_instance()->SendRefreshAppList(no_apps);
540 // At this point no app should exist. 546 // At this point no app should exist.
541 ValidateHaveApps(no_apps); 547 ValidateHaveApps(no_apps);
542 } 548 }
543 549
544 TEST_F(ArcAppModelBuilderTest, StopStartServicePreserveApps) { 550 TEST_P(ArcAppModelBuilderTest, StopStartServicePreserveApps) {
545 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 551 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
546 ASSERT_NE(nullptr, prefs); 552 ASSERT_NE(nullptr, prefs);
547 553
548 app_instance()->RefreshAppList(); 554 app_instance()->RefreshAppList();
549 EXPECT_EQ(0u, GetArcItemCount()); 555 EXPECT_EQ(0u, GetArcItemCount());
550 EXPECT_EQ(0u, prefs->GetAppIds().size()); 556 EXPECT_EQ(0u, prefs->GetAppIds().size());
551 557
552 app_instance()->SendRefreshAppList(fake_apps()); 558 app_instance()->SendRefreshAppList(fake_apps());
553 std::vector<std::string> ids = prefs->GetAppIds(); 559 std::vector<std::string> ids = prefs->GetAppIds();
554 EXPECT_EQ(fake_apps().size(), ids.size()); 560 EXPECT_EQ(fake_apps().size(), ids.size());
555 ValidateAppReadyState(fake_apps(), true); 561 ValidateAppReadyState(fake_apps(), true);
556 562
557 // Stopping service does not delete items. It makes them non-ready. 563 // Stopping service does not delete items. It makes them non-ready.
558 arc_test()->StopArcInstance(); 564 arc_test()->StopArcInstance();
559 // Ids should be the same. 565 // Ids should be the same.
560 EXPECT_EQ(ids, prefs->GetAppIds()); 566 EXPECT_EQ(ids, prefs->GetAppIds());
561 ValidateAppReadyState(fake_apps(), false); 567 ValidateAppReadyState(fake_apps(), false);
562 568
563 // Ids should be the same. 569 // Ids should be the same.
564 EXPECT_EQ(ids, prefs->GetAppIds()); 570 EXPECT_EQ(ids, prefs->GetAppIds());
565 ValidateAppReadyState(fake_apps(), false); 571 ValidateAppReadyState(fake_apps(), false);
566 572
567 // Refreshing app list makes apps available. 573 // Refreshing app list makes apps available.
568 app_instance()->SendRefreshAppList(fake_apps()); 574 app_instance()->SendRefreshAppList(fake_apps());
569 EXPECT_EQ(ids, prefs->GetAppIds()); 575 EXPECT_EQ(ids, prefs->GetAppIds());
570 ValidateAppReadyState(fake_apps(), true); 576 ValidateAppReadyState(fake_apps(), true);
571 } 577 }
572 578
573 TEST_F(ArcAppModelBuilderTest, StopStartServicePreserveShortcuts) { 579 TEST_P(ArcAppModelBuilderTest, StopStartServicePreserveShortcuts) {
574 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 580 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
575 ASSERT_NE(nullptr, prefs); 581 ASSERT_NE(nullptr, prefs);
576 582
577 app_instance()->RefreshAppList(); 583 app_instance()->RefreshAppList();
578 EXPECT_EQ(0u, GetArcItemCount()); 584 EXPECT_EQ(0u, GetArcItemCount());
579 EXPECT_EQ(0u, prefs->GetAppIds().size()); 585 EXPECT_EQ(0u, prefs->GetAppIds().size());
580 586
581 app_instance()->SendInstallShortcuts(fake_shortcuts()); 587 app_instance()->SendInstallShortcuts(fake_shortcuts());
582 std::vector<std::string> ids = prefs->GetAppIds(); 588 std::vector<std::string> ids = prefs->GetAppIds();
583 EXPECT_EQ(fake_shortcuts().size(), ids.size()); 589 EXPECT_EQ(fake_shortcuts().size(), ids.size());
584 ValidateShortcutReadyState(fake_shortcuts(), true); 590 ValidateShortcutReadyState(fake_shortcuts(), true);
585 591
586 // Stopping service does not delete items. It makes them non-ready. 592 // Stopping service does not delete items. It makes them non-ready.
587 arc_test()->StopArcInstance(); 593 arc_test()->StopArcInstance();
588 // Ids should be the same. 594 // Ids should be the same.
589 EXPECT_EQ(ids, prefs->GetAppIds()); 595 EXPECT_EQ(ids, prefs->GetAppIds());
590 ValidateShortcutReadyState(fake_shortcuts(), false); 596 ValidateShortcutReadyState(fake_shortcuts(), false);
591 597
592 // Ids should be the same. 598 // Ids should be the same.
593 EXPECT_EQ(ids, prefs->GetAppIds()); 599 EXPECT_EQ(ids, prefs->GetAppIds());
594 ValidateShortcutReadyState(fake_shortcuts(), false); 600 ValidateShortcutReadyState(fake_shortcuts(), false);
595 601
596 // Refreshing app list makes apps available. 602 // Refreshing app list makes apps available.
597 app_instance()->RefreshAppList(); 603 app_instance()->RefreshAppList();
598 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>()); 604 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>());
599 EXPECT_EQ(ids, prefs->GetAppIds()); 605 EXPECT_EQ(ids, prefs->GetAppIds());
600 ValidateShortcutReadyState(fake_shortcuts(), true); 606 ValidateShortcutReadyState(fake_shortcuts(), true);
601 } 607 }
602 608
603 TEST_F(ArcAppModelBuilderTest, RestartPreserveApps) { 609 TEST_P(ArcAppModelBuilderTest, RestartPreserveApps) {
604 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 610 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
605 ASSERT_NE(nullptr, prefs); 611 ASSERT_NE(nullptr, prefs);
606 612
607 // Start from scratch and fill with apps. 613 // Start from scratch and fill with apps.
608 app_instance()->SendRefreshAppList(fake_apps()); 614 app_instance()->SendRefreshAppList(fake_apps());
609 std::vector<std::string> ids = prefs->GetAppIds(); 615 std::vector<std::string> ids = prefs->GetAppIds();
610 EXPECT_EQ(fake_apps().size(), ids.size()); 616 EXPECT_EQ(fake_apps().size(), ids.size());
611 ValidateAppReadyState(fake_apps(), true); 617 ValidateAppReadyState(fake_apps(), true);
612 618
613 // This recreates model and ARC apps will be read from prefs. 619 // This recreates model and ARC apps will be read from prefs.
614 arc_test()->StopArcInstance(); 620 arc_test()->StopArcInstance();
615 CreateBuilder(); 621 CreateBuilder();
616 ValidateAppReadyState(fake_apps(), false); 622 ValidateAppReadyState(fake_apps(), false);
617 } 623 }
618 624
619 TEST_F(ArcAppModelBuilderTest, RestartPreserveShortcuts) { 625 TEST_P(ArcAppModelBuilderTest, RestartPreserveShortcuts) {
620 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 626 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
621 ASSERT_NE(nullptr, prefs); 627 ASSERT_NE(nullptr, prefs);
622 628
623 // Start from scratch and install shortcuts. 629 // Start from scratch and install shortcuts.
624 app_instance()->SendInstallShortcuts(fake_shortcuts()); 630 app_instance()->SendInstallShortcuts(fake_shortcuts());
625 std::vector<std::string> ids = prefs->GetAppIds(); 631 std::vector<std::string> ids = prefs->GetAppIds();
626 EXPECT_EQ(fake_apps().size(), ids.size()); 632 EXPECT_EQ(fake_apps().size(), ids.size());
627 ValidateShortcutReadyState(fake_shortcuts(), true); 633 ValidateShortcutReadyState(fake_shortcuts(), true);
628 634
629 // This recreates model and ARC apps and shortcuts will be read from prefs. 635 // This recreates model and ARC apps and shortcuts will be read from prefs.
630 arc_test()->StopArcInstance(); 636 arc_test()->StopArcInstance();
631 CreateBuilder(); 637 CreateBuilder();
632 ValidateShortcutReadyState(fake_shortcuts(), false); 638 ValidateShortcutReadyState(fake_shortcuts(), false);
633 } 639 }
634 640
635 TEST_F(ArcAppModelBuilderTest, LaunchApps) { 641 TEST_P(ArcAppModelBuilderTest, LaunchApps) {
636 // Disable attempts to dismiss app launcher view. 642 // Disable attempts to dismiss app launcher view.
637 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); 643 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller());
638 644
639 app_instance()->RefreshAppList(); 645 app_instance()->RefreshAppList();
640 app_instance()->SendRefreshAppList(fake_apps()); 646 app_instance()->SendRefreshAppList(fake_apps());
641 647
642 // Simulate item activate. 648 // Simulate item activate.
643 const arc::mojom::AppInfo& app_first = fake_apps()[0]; 649 const arc::mojom::AppInfo& app_first = fake_apps()[0];
644 const arc::mojom::AppInfo& app_last = fake_apps()[0]; 650 const arc::mojom::AppInfo& app_last = fake_apps()[0];
645 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 651 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
(...skipping 15 matching lines...) Expand all
661 arc_test()->StopArcInstance(); 667 arc_test()->StopArcInstance();
662 item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 668 item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
663 ASSERT_NE(nullptr, item_first); 669 ASSERT_NE(nullptr, item_first);
664 size_t launch_request_count_before = app_instance()->launch_requests().size(); 670 size_t launch_request_count_before = app_instance()->launch_requests().size();
665 item_first->Activate(0); 671 item_first->Activate(0);
666 // Number of launch requests must not change. 672 // Number of launch requests must not change.
667 EXPECT_EQ(launch_request_count_before, 673 EXPECT_EQ(launch_request_count_before,
668 app_instance()->launch_requests().size()); 674 app_instance()->launch_requests().size());
669 } 675 }
670 676
671 TEST_F(ArcAppModelBuilderTest, LaunchShortcuts) { 677 TEST_P(ArcAppModelBuilderTest, LaunchShortcuts) {
672 // Disable attempts to dismiss app launcher view. 678 // Disable attempts to dismiss app launcher view.
673 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); 679 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller());
674 680
675 app_instance()->RefreshAppList(); 681 app_instance()->RefreshAppList();
676 app_instance()->SendInstallShortcuts(fake_shortcuts()); 682 app_instance()->SendInstallShortcuts(fake_shortcuts());
677 683
678 // Simulate item activate. 684 // Simulate item activate.
679 const arc::mojom::ShortcutInfo& app_first = fake_shortcuts()[0]; 685 const arc::mojom::ShortcutInfo& app_first = fake_shortcuts()[0];
680 const arc::mojom::ShortcutInfo& app_last = fake_shortcuts()[0]; 686 const arc::mojom::ShortcutInfo& app_last = fake_shortcuts()[0];
681 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 687 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
(...skipping 15 matching lines...) Expand all
697 arc_test()->StopArcInstance(); 703 arc_test()->StopArcInstance();
698 item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 704 item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
699 ASSERT_NE(nullptr, item_first); 705 ASSERT_NE(nullptr, item_first);
700 size_t launch_request_count_before = app_instance()->launch_intents().size(); 706 size_t launch_request_count_before = app_instance()->launch_intents().size();
701 item_first->Activate(0); 707 item_first->Activate(0);
702 // Number of launch requests must not change. 708 // Number of launch requests must not change.
703 EXPECT_EQ(launch_request_count_before, 709 EXPECT_EQ(launch_request_count_before,
704 app_instance()->launch_intents().size()); 710 app_instance()->launch_intents().size());
705 } 711 }
706 712
707 TEST_F(ArcAppModelBuilderTest, RequestIcons) { 713 TEST_P(ArcAppModelBuilderTest, RequestIcons) {
708 // Make sure we are on UI thread. 714 // Make sure we are on UI thread.
709 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 715 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
710 716
711 app_instance()->RefreshAppList(); 717 app_instance()->RefreshAppList();
712 app_instance()->SendRefreshAppList(fake_apps()); 718 app_instance()->SendRefreshAppList(fake_apps());
713 719
714 // Validate that no icon exists at the beginning and request icon for 720 // Validate that no icon exists at the beginning and request icon for
715 // each supported scale factor. This will start asynchronous loading. 721 // each supported scale factor. This will start asynchronous loading.
716 uint32_t expected_mask = 0; 722 uint32_t expected_mask = 0;
717 const std::vector<ui::ScaleFactor>& scale_factors = 723 const std::vector<ui::ScaleFactor>& scale_factors =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 // Validate that we have a request for each icon for each supported scale 758 // Validate that we have a request for each icon for each supported scale
753 // factor. 759 // factor.
754 EXPECT_EQ(fake_apps().size(), app_masks.size()); 760 EXPECT_EQ(fake_apps().size(), app_masks.size());
755 for (auto& app : fake_apps()) { 761 for (auto& app : fake_apps()) {
756 const std::string id = ArcAppTest::GetAppId(app); 762 const std::string id = ArcAppTest::GetAppId(app);
757 ASSERT_NE(app_masks.find(id), app_masks.end()); 763 ASSERT_NE(app_masks.find(id), app_masks.end());
758 EXPECT_EQ(app_masks[id], expected_mask); 764 EXPECT_EQ(app_masks[id], expected_mask);
759 } 765 }
760 } 766 }
761 767
762 TEST_F(ArcAppModelBuilderTest, RequestShortcutIcons) { 768 TEST_P(ArcAppModelBuilderTest, RequestShortcutIcons) {
763 // Make sure we are on UI thread. 769 // Make sure we are on UI thread.
764 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 770 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
765 771
766 const arc::mojom::ShortcutInfo& shortcut = fake_shortcuts()[0]; 772 const arc::mojom::ShortcutInfo& shortcut = fake_shortcuts()[0];
767 app_instance()->SendInstallShortcut(shortcut); 773 app_instance()->SendInstallShortcut(shortcut);
768 774
769 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 775 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
770 ASSERT_NE(nullptr, prefs); 776 ASSERT_NE(nullptr, prefs);
771 777
772 // Icons representations loading is done asynchronously and is started once 778 // Icons representations loading is done asynchronously and is started once
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 EXPECT_EQ(app_mask, expected_mask); 811 EXPECT_EQ(app_mask, expected_mask);
806 812
807 // Validate all icon files are installed. 813 // Validate all icon files are installed.
808 for (auto& scale_factor : scale_factors) { 814 for (auto& scale_factor : scale_factors) {
809 const base::FilePath icon_path = 815 const base::FilePath icon_path =
810 prefs->GetIconPath(ArcAppTest::GetAppId(shortcut), scale_factor); 816 prefs->GetIconPath(ArcAppTest::GetAppId(shortcut), scale_factor);
811 EXPECT_TRUE(base::PathExists(icon_path)); 817 EXPECT_TRUE(base::PathExists(icon_path));
812 } 818 }
813 } 819 }
814 820
815 TEST_F(ArcAppModelBuilderTest, InstallIcon) { 821 TEST_P(ArcAppModelBuilderTest, InstallIcon) {
816 // Make sure we are on UI thread. 822 // Make sure we are on UI thread.
817 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 823 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
818 824
819 app_instance()->RefreshAppList(); 825 app_instance()->RefreshAppList();
820 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 826 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
821 fake_apps().begin(), fake_apps().begin() + 1)); 827 fake_apps().begin(), fake_apps().begin() + 1));
822 const arc::mojom::AppInfo& app = fake_apps()[0]; 828 const arc::mojom::AppInfo& app = fake_apps()[0];
823 829
824 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 830 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
825 ASSERT_NE(nullptr, prefs); 831 ASSERT_NE(nullptr, prefs);
(...skipping 18 matching lines...) Expand all
844 // Validate that icons are installed, have right content and icon is 850 // Validate that icons are installed, have right content and icon is
845 // refreshed for ARC app item. 851 // refreshed for ARC app item.
846 EXPECT_TRUE(base::PathExists(icon_path)); 852 EXPECT_TRUE(base::PathExists(icon_path));
847 853
848 std::string icon_data; 854 std::string icon_data;
849 // Read the file from disk and compare with reference data. 855 // Read the file from disk and compare with reference data.
850 EXPECT_TRUE(base::ReadFileToString(icon_path, &icon_data)); 856 EXPECT_TRUE(base::ReadFileToString(icon_path, &icon_data));
851 ASSERT_EQ(icon_data, png_data); 857 ASSERT_EQ(icon_data, png_data);
852 } 858 }
853 859
854 TEST_F(ArcAppModelBuilderTest, RemoveAppCleanUpFolder) { 860 TEST_P(ArcAppModelBuilderTest, RemoveAppCleanUpFolder) {
855 // Make sure we are on UI thread. 861 // Make sure we are on UI thread.
856 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 862 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
857 863
858 app_instance()->RefreshAppList(); 864 app_instance()->RefreshAppList();
859 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 865 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
860 fake_apps().begin(), fake_apps().begin() + 1)); 866 fake_apps().begin(), fake_apps().begin() + 1));
861 const arc::mojom::AppInfo& app = fake_apps()[0]; 867 const arc::mojom::AppInfo& app = fake_apps()[0];
862 868
863 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 869 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
864 ASSERT_NE(nullptr, prefs); 870 ASSERT_NE(nullptr, prefs);
(...skipping 21 matching lines...) Expand all
886 // removed, not added. 892 // removed, not added.
887 // Process pending tasks. This performs multiple thread hops, so we need 893 // Process pending tasks. This performs multiple thread hops, so we need
888 // to run it continuously until it is resolved. 894 // to run it continuously until it is resolved.
889 do { 895 do {
890 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 896 content::BrowserThread::GetBlockingPool()->FlushForTesting();
891 base::RunLoop().RunUntilIdle(); 897 base::RunLoop().RunUntilIdle();
892 } while (base::PathExists(app_path)); 898 } while (base::PathExists(app_path));
893 EXPECT_FALSE(base::PathExists(app_path)); 899 EXPECT_FALSE(base::PathExists(app_path));
894 } 900 }
895 901
896 TEST_F(ArcAppModelBuilderTest, LastLaunchTime) { 902 TEST_P(ArcAppModelBuilderTest, LastLaunchTime) {
897 // Make sure we are on UI thread. 903 // Make sure we are on UI thread.
898 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 904 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
899 905
900 app_instance()->RefreshAppList(); 906 app_instance()->RefreshAppList();
901 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 907 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
902 fake_apps().begin(), fake_apps().begin() + 2)); 908 fake_apps().begin(), fake_apps().begin() + 2));
903 const arc::mojom::AppInfo& app1 = fake_apps()[0]; 909 const arc::mojom::AppInfo& app1 = fake_apps()[0];
904 const arc::mojom::AppInfo& app2 = fake_apps()[1]; 910 const arc::mojom::AppInfo& app2 = fake_apps()[1];
905 const std::string id1 = ArcAppTest::GetAppId(app1); 911 const std::string id1 = ArcAppTest::GetAppId(app1);
906 const std::string id2 = ArcAppTest::GetAppId(app2); 912 const std::string id2 = ArcAppTest::GetAppId(app2);
(...skipping 23 matching lines...) Expand all
930 arc::LaunchApp(profile(), id2, ui::EF_NONE); 936 arc::LaunchApp(profile(), id2, ui::EF_NONE);
931 base::Time time_after = base::Time::Now(); 937 base::Time time_after = base::Time::Now();
932 938
933 app_info = prefs->GetApp(id2); 939 app_info = prefs->GetApp(id2);
934 ASSERT_NE(nullptr, app_info.get()); 940 ASSERT_NE(nullptr, app_info.get());
935 ASSERT_LE(time_before, app_info->last_launch_time); 941 ASSERT_LE(time_before, app_info->last_launch_time);
936 ASSERT_GE(time_after, app_info->last_launch_time); 942 ASSERT_GE(time_after, app_info->last_launch_time);
937 } 943 }
938 944
939 // Validate that arc model contains expected elements on restart. 945 // Validate that arc model contains expected elements on restart.
940 TEST_F(ArcAppModelBuilderRecreate, AppModelRestart) { 946 TEST_P(ArcAppModelBuilderRecreate, AppModelRestart) {
941 // No apps on initial start. 947 // No apps on initial start.
942 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 948 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
943 949
944 // Send info about all fake apps except last. 950 // Send info about all fake apps except last.
945 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(), 951 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(),
946 fake_apps().end() - 1); 952 fake_apps().end() - 1);
947 app_instance()->RefreshAppList(); 953 app_instance()->RefreshAppList();
948 app_instance()->SendRefreshAppList(apps1); 954 app_instance()->SendRefreshAppList(apps1);
949 // Model has refreshed apps. 955 // Model has refreshed apps.
950 ValidateHaveApps(apps1); 956 ValidateHaveApps(apps1);
(...skipping 12 matching lines...) Expand all
963 ValidateHaveApps(apps1); 969 ValidateHaveApps(apps1);
964 EXPECT_EQ(apps1.size(), GetArcItemCount()); 970 EXPECT_EQ(apps1.size(), GetArcItemCount());
965 971
966 // Now refresh old apps with new one. 972 // Now refresh old apps with new one.
967 app_instance()->RefreshAppList(); 973 app_instance()->RefreshAppList();
968 app_instance()->SendRefreshAppList(fake_apps()); 974 app_instance()->SendRefreshAppList(fake_apps());
969 ValidateHaveApps(fake_apps()); 975 ValidateHaveApps(fake_apps());
970 EXPECT_EQ(fake_apps().size(), GetArcItemCount()); 976 EXPECT_EQ(fake_apps().size(), GetArcItemCount());
971 } 977 }
972 978
973 TEST_F(ArcPlayStoreAppTest, PlayStore) { 979 TEST_P(ArcPlayStoreAppTest, PlayStore) {
974 // Make sure PlayStore is available. 980 // Make sure PlayStore is available.
975 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 981 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
976 982
977 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 983 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
978 ASSERT_TRUE(prefs); 984 ASSERT_TRUE(prefs);
979 985
980 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp( 986 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(
981 arc::kPlayStoreAppId); 987 arc::kPlayStoreAppId);
982 ASSERT_TRUE(app_info); 988 ASSERT_TRUE(app_info);
983 EXPECT_FALSE(app_info->ready); 989 EXPECT_FALSE(app_info->ready);
984 990
985 arc::mojom::AppInfo app; 991 arc::mojom::AppInfo app;
986 std::vector<arc::mojom::AppInfo> apps; 992 std::vector<arc::mojom::AppInfo> apps;
987 app.name = "Play Store"; 993 app.name = "Play Store";
988 app.package_name = arc::kPlayStorePackage; 994 app.package_name = arc::kPlayStorePackage;
989 app.activity = arc::kPlayStoreActivity; 995 app.activity = arc::kPlayStoreActivity;
990 app.sticky = false; 996 app.sticky = false;
991 apps.push_back(app); 997 apps.push_back(app);
992 998
993 app_instance()->RefreshAppList(); 999 app_instance()->RefreshAppList();
994 app_instance()->SendRefreshAppList(apps); 1000 app_instance()->SendRefreshAppList(apps);
995 1001
996 app_info = prefs->GetApp(arc::kPlayStoreAppId); 1002 app_info = prefs->GetApp(arc::kPlayStoreAppId);
997 ASSERT_TRUE(app_info); 1003 ASSERT_TRUE(app_info);
998 EXPECT_TRUE(app_info->ready); 1004 EXPECT_TRUE(app_info->ready);
999 1005
1006 // TODO(victorhsieh): Opt-out on Persistent ARC is special. Skip until
1007 // implemented.
1008 if (IsPersistentArc())
1009 return;
1000 arc_test()->arc_session_manager()->SetArcPlayStoreEnabled(false); 1010 arc_test()->arc_session_manager()->SetArcPlayStoreEnabled(false);
1001 1011
1002 app_info = prefs->GetApp(arc::kPlayStoreAppId); 1012 app_info = prefs->GetApp(arc::kPlayStoreAppId);
1003 ASSERT_TRUE(app_info); 1013 ASSERT_TRUE(app_info);
1004 EXPECT_FALSE(app_info->ready); 1014 EXPECT_FALSE(app_info->ready);
1005 1015
1006 arc::LaunchApp(profile(), arc::kPlayStoreAppId, ui::EF_NONE); 1016 arc::LaunchApp(profile(), arc::kPlayStoreAppId, ui::EF_NONE);
1007 EXPECT_TRUE(arc_test()->arc_session_manager()->IsArcPlayStoreEnabled()); 1017 EXPECT_TRUE(arc_test()->arc_session_manager()->IsArcPlayStoreEnabled());
1008 } 1018 }
1009 1019
1010 // Test that icon is correctly extracted for shelf group. 1020 // Test that icon is correctly extracted for shelf group.
1011 TEST_F(ArcAppModelBuilderTest, IconLoaderForShelfGroup) { 1021 TEST_P(ArcAppModelBuilderTest, IconLoaderForShelfGroup) {
1012 const arc::mojom::AppInfo& app = fake_apps()[0]; 1022 const arc::mojom::AppInfo& app = fake_apps()[0];
1013 const std::string app_id = ArcAppTest::GetAppId(app); 1023 const std::string app_id = ArcAppTest::GetAppId(app);
1014 1024
1015 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1025 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1016 ASSERT_NE(nullptr, prefs); 1026 ASSERT_NE(nullptr, prefs);
1017 1027
1018 app_instance()->RefreshAppList(); 1028 app_instance()->RefreshAppList();
1019 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 1029 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
1020 fake_apps().begin(), fake_apps().begin() + 1)); 1030 fake_apps().begin(), fake_apps().begin() + 1));
1021 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 1031 content::BrowserThread::GetBlockingPool()->FlushForTesting();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 EXPECT_EQ(shortcut_request_cnt, 1078 EXPECT_EQ(shortcut_request_cnt,
1069 app_instance()->shortcut_icon_requests().size()); 1079 app_instance()->shortcut_icon_requests().size());
1070 for (size_t i = initial_icon_request_count; 1080 for (size_t i = initial_icon_request_count;
1071 i < app_instance()->icon_requests().size(); ++i) { 1081 i < app_instance()->icon_requests().size(); ++i) {
1072 const auto& request = app_instance()->icon_requests()[i]; 1082 const auto& request = app_instance()->icon_requests()[i];
1073 EXPECT_TRUE(request->IsForApp(app)); 1083 EXPECT_TRUE(request->IsForApp(app));
1074 } 1084 }
1075 } 1085 }
1076 1086
1077 // TODO(crbug.com/628425) -- reenable once this test is less flaky. 1087 // TODO(crbug.com/628425) -- reenable once this test is less flaky.
1078 TEST_F(ArcAppModelBuilderTest, DISABLED_IconLoader) { 1088 TEST_P(ArcAppModelBuilderTest, DISABLED_IconLoader) {
1079 const arc::mojom::AppInfo& app = fake_apps()[0]; 1089 const arc::mojom::AppInfo& app = fake_apps()[0];
1080 const std::string app_id = ArcAppTest::GetAppId(app); 1090 const std::string app_id = ArcAppTest::GetAppId(app);
1081 1091
1082 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1092 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1083 ASSERT_NE(nullptr, prefs); 1093 ASSERT_NE(nullptr, prefs);
1084 1094
1085 app_instance()->RefreshAppList(); 1095 app_instance()->RefreshAppList();
1086 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 1096 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
1087 fake_apps().begin(), fake_apps().begin() + 1)); 1097 fake_apps().begin(), fake_apps().begin() + 1));
1088 1098
(...skipping 21 matching lines...) Expand all
1110 app_item->icon().GetRepresentation(scale); 1120 app_item->icon().GetRepresentation(scale);
1111 WaitForIconReady(prefs, app_id, scale_factor); 1121 WaitForIconReady(prefs, app_id, scale_factor);
1112 } 1122 }
1113 1123
1114 // Validate loaded image. 1124 // Validate loaded image.
1115 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); 1125 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt());
1116 EXPECT_EQ(app_id, delegate.app_id()); 1126 EXPECT_EQ(app_id, delegate.app_id());
1117 ValidateIcon(delegate.image()); 1127 ValidateIcon(delegate.image());
1118 } 1128 }
1119 1129
1120 TEST_F(ArcAppModelBuilderTest, AppLauncher) { 1130 TEST_P(ArcAppModelBuilderTest, AppLauncher) {
1121 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); 1131 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile());
1122 ASSERT_NE(nullptr, prefs); 1132 ASSERT_NE(nullptr, prefs);
1123 1133
1124 // App1 is called in deferred mode, after refreshing apps. 1134 // App1 is called in deferred mode, after refreshing apps.
1125 // App2 is never called since app is not avaialble. 1135 // App2 is never called since app is not avaialble.
1126 // App3 is never called immediately because app is available already. 1136 // App3 is never called immediately because app is available already.
1127 const arc::mojom::AppInfo& app1 = fake_apps()[0]; 1137 const arc::mojom::AppInfo& app1 = fake_apps()[0];
1128 const arc::mojom::AppInfo& app2 = fake_apps()[1]; 1138 const arc::mojom::AppInfo& app2 = fake_apps()[1];
1129 const arc::mojom::AppInfo& app3 = fake_apps()[2]; 1139 const arc::mojom::AppInfo& app3 = fake_apps()[2];
1130 const std::string id1 = ArcAppTest::GetAppId(app1); 1140 const std::string id1 = ArcAppTest::GetAppId(app1);
(...skipping 24 matching lines...) Expand all
1155 EXPECT_TRUE(prefs->HasObserver(&launcher3)); 1165 EXPECT_TRUE(prefs->HasObserver(&launcher3));
1156 1166
1157 ArcAppLauncher launcher2(profile(), id2, true); 1167 ArcAppLauncher launcher2(profile(), id2, true);
1158 EXPECT_TRUE(launcher2.app_launched()); 1168 EXPECT_TRUE(launcher2.app_launched());
1159 EXPECT_FALSE(prefs->HasObserver(&launcher2)); 1169 EXPECT_FALSE(prefs->HasObserver(&launcher2));
1160 ASSERT_EQ(2u, app_instance()->launch_requests().size()); 1170 ASSERT_EQ(2u, app_instance()->launch_requests().size());
1161 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2)); 1171 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2));
1162 } 1172 }
1163 1173
1164 // Validates an app that have no launchable flag. 1174 // Validates an app that have no launchable flag.
1165 TEST_F(ArcAppModelBuilderTest, NonLaunchableApp) { 1175 TEST_P(ArcAppModelBuilderTest, NonLaunchableApp) {
1166 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1176 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1167 ASSERT_NE(nullptr, prefs); 1177 ASSERT_NE(nullptr, prefs);
1168 1178
1169 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 1179 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
1170 app_instance()->RefreshAppList(); 1180 app_instance()->RefreshAppList();
1171 // Send all except first. 1181 // Send all except first.
1172 std::vector<arc::mojom::AppInfo> apps(fake_apps().begin() + 1, 1182 std::vector<arc::mojom::AppInfo> apps(fake_apps().begin() + 1,
1173 fake_apps().end()); 1183 fake_apps().end());
1174 app_instance()->SendRefreshAppList(apps); 1184 app_instance()->SendRefreshAppList(apps);
1175 ValidateHaveApps(apps); 1185 ValidateHaveApps(apps);
1176 1186
1177 const std::string app_id = ArcAppTest::GetAppId(fake_apps()[0]); 1187 const std::string app_id = ArcAppTest::GetAppId(fake_apps()[0]);
1178 1188
1179 EXPECT_FALSE(prefs->IsRegistered(app_id)); 1189 EXPECT_FALSE(prefs->IsRegistered(app_id));
1180 EXPECT_FALSE(FindArcItem(app_id)); 1190 EXPECT_FALSE(FindArcItem(app_id));
1181 app_instance()->SendTaskCreated(0, fake_apps()[0], std::string()); 1191 app_instance()->SendTaskCreated(0, fake_apps()[0], std::string());
1182 // App should not appear now in the model but should be registered. 1192 // App should not appear now in the model but should be registered.
1183 EXPECT_FALSE(FindArcItem(app_id)); 1193 EXPECT_FALSE(FindArcItem(app_id));
1184 EXPECT_TRUE(prefs->IsRegistered(app_id)); 1194 EXPECT_TRUE(prefs->IsRegistered(app_id));
1185 } 1195 }
1186 1196
1187 TEST_F(ArcAppModelBuilderTest, ArcAppsOnPackageUpdated) { 1197 TEST_P(ArcAppModelBuilderTest, ArcAppsOnPackageUpdated) {
1188 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1198 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1189 ASSERT_NE(nullptr, prefs); 1199 ASSERT_NE(nullptr, prefs);
1190 1200
1191 std::vector<arc::mojom::AppInfo> apps = fake_apps(); 1201 std::vector<arc::mojom::AppInfo> apps = fake_apps();
1192 ASSERT_GE(3u, apps.size()); 1202 ASSERT_GE(3u, apps.size());
1193 apps[0].package_name = apps[2].package_name; 1203 apps[0].package_name = apps[2].package_name;
1194 apps[1].package_name = apps[2].package_name; 1204 apps[1].package_name = apps[2].package_name;
1195 // Second app should be preserved after update. 1205 // Second app should be preserved after update.
1196 std::vector<arc::mojom::AppInfo> apps1(apps.begin(), apps.begin() + 2); 1206 std::vector<arc::mojom::AppInfo> apps1(apps.begin(), apps.begin() + 2);
1197 std::vector<arc::mojom::AppInfo> apps2(apps.begin() + 1, apps.begin() + 3); 1207 std::vector<arc::mojom::AppInfo> apps2(apps.begin() + 1, apps.begin() + 3);
(...skipping 12 matching lines...) Expand all
1210 1220
1211 app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps2); 1221 app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps2);
1212 ValidateHaveApps(apps2); 1222 ValidateHaveApps(apps2);
1213 1223
1214 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_after = 1224 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_after =
1215 prefs->GetApp(app_id); 1225 prefs->GetApp(app_id);
1216 ASSERT_TRUE(app_info_after); 1226 ASSERT_TRUE(app_info_after);
1217 EXPECT_EQ(now_time, app_info_after->last_launch_time); 1227 EXPECT_EQ(now_time, app_info_after->last_launch_time);
1218 } 1228 }
1219 1229
1220 TEST_F(ArcDefaulAppTest, DefaultApps) { 1230 TEST_P(ArcDefaulAppTest, DefaultApps) {
1221 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1231 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1222 ASSERT_NE(nullptr, prefs); 1232 ASSERT_NE(nullptr, prefs);
1223 1233
1224 ValidateHaveApps(fake_default_apps()); 1234 ValidateHaveApps(fake_default_apps());
1225 1235
1226 // Start normal apps. We should have apps from 2 subsets. 1236 // Start normal apps. We should have apps from 2 subsets.
1227 app_instance()->RefreshAppList(); 1237 app_instance()->RefreshAppList();
1228 app_instance()->SendRefreshAppList(fake_apps()); 1238 app_instance()->SendRefreshAppList(fake_apps());
1229 1239
1230 std::vector<arc::mojom::AppInfo> all_apps = fake_default_apps(); 1240 std::vector<arc::mojom::AppInfo> all_apps = fake_default_apps();
(...skipping 25 matching lines...) Expand all
1256 EXPECT_TRUE(app_info->ready); 1266 EXPECT_TRUE(app_info->ready);
1257 oem_states[app_id] = prefs->IsOem(app_id); 1267 oem_states[app_id] = prefs->IsOem(app_id);
1258 } 1268 }
1259 1269
1260 // Uninstall first default package. Default app should go away. 1270 // Uninstall first default package. Default app should go away.
1261 app_instance()->SendPackageUninstalled(all_apps[0].package_name); 1271 app_instance()->SendPackageUninstalled(all_apps[0].package_name);
1262 all_apps.erase(all_apps.begin()); 1272 all_apps.erase(all_apps.begin());
1263 ValidateHaveApps(all_apps); 1273 ValidateHaveApps(all_apps);
1264 1274
1265 // OptOut and default apps should exist minus first. 1275 // OptOut and default apps should exist minus first.
1276 // TODO(victorhsieh): Opt-out on Persistent ARC is special. Skip until
1277 // implemented.
1278 if (IsPersistentArc())
1279 return;
1266 arc_test()->arc_session_manager()->SetArcPlayStoreEnabled(false); 1280 arc_test()->arc_session_manager()->SetArcPlayStoreEnabled(false);
1267 all_apps = fake_default_apps(); 1281 all_apps = fake_default_apps();
1268 all_apps.erase(all_apps.begin()); 1282 all_apps.erase(all_apps.begin());
1269 ValidateHaveApps(all_apps); 1283 ValidateHaveApps(all_apps);
1270 1284
1271 // Sign-out and sign-in again. Removed default app should not appear. 1285 // Sign-out and sign-in again. Removed default app should not appear.
1272 arc_test()->TearDown(); 1286 arc_test()->TearDown();
1273 ResetBuilder(); 1287 ResetBuilder();
1274 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( 1288 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting(
1275 profile_.get()); 1289 profile_.get());
1276 arc_test()->SetUp(profile_.get()); 1290 arc_test()->SetUp(profile_.get());
1277 CreateBuilder(); 1291 CreateBuilder();
1278 1292
1279 // Prefs are changed. 1293 // Prefs are changed.
1280 prefs = ArcAppListPrefs::Get(profile_.get()); 1294 prefs = ArcAppListPrefs::Get(profile_.get());
1281 ASSERT_NE(nullptr, prefs); 1295 ASSERT_NE(nullptr, prefs);
1282
1283 ValidateHaveApps(all_apps); 1296 ValidateHaveApps(all_apps);
1284 1297
1285 // Install deleted default app again. 1298 // Install deleted default app again.
1286 std::vector<arc::mojom::AppInfo> package_apps; 1299 std::vector<arc::mojom::AppInfo> package_apps;
1287 package_apps.push_back(fake_default_apps()[0]); 1300 package_apps.push_back(fake_default_apps()[0]);
1288 app_instance()->SendPackageAppListRefreshed( 1301 app_instance()->SendPackageAppListRefreshed(
1289 fake_default_apps()[0].package_name, package_apps); 1302 fake_default_apps()[0].package_name, package_apps);
1290 ValidateHaveApps(fake_default_apps()); 1303 ValidateHaveApps(fake_default_apps());
1291 1304
1292 // Validate that OEM state is preserved. 1305 // Validate that OEM state is preserved.
1293 for (const auto& default_app : fake_default_apps()) { 1306 for (const auto& default_app : fake_default_apps()) {
1294 const std::string app_id = ArcAppTest::GetAppId(default_app); 1307 const std::string app_id = ArcAppTest::GetAppId(default_app);
1295 EXPECT_EQ(oem_states[app_id], prefs->IsOem(app_id)); 1308 EXPECT_EQ(oem_states[app_id], prefs->IsOem(app_id));
1296 } 1309 }
1297 } 1310 }
1298 1311
1299 TEST_F(ArcDefaulAppTest, DefaultAppsNotAvailable) { 1312 TEST_P(ArcDefaulAppTest, DefaultAppsNotAvailable) {
1300 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1313 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1301 ASSERT_NE(nullptr, prefs); 1314 ASSERT_NE(nullptr, prefs);
1302 1315
1303 ValidateHaveApps(fake_default_apps()); 1316 ValidateHaveApps(fake_default_apps());
1304 1317
1305 const std::vector<arc::mojom::AppInfo> empty_app_list; 1318 const std::vector<arc::mojom::AppInfo> empty_app_list;
1306 1319
1307 app_instance()->RefreshAppList(); 1320 app_instance()->RefreshAppList();
1308 app_instance()->SendRefreshAppList(empty_app_list); 1321 app_instance()->SendRefreshAppList(empty_app_list);
1309 1322
1310 ValidateHaveApps(fake_default_apps()); 1323 ValidateHaveApps(fake_default_apps());
1311 1324
1312 prefs->SimulateDefaultAppAvailabilityTimeoutForTesting(); 1325 prefs->SimulateDefaultAppAvailabilityTimeoutForTesting();
1313 1326
1314 // No default app installation and already installed packages. 1327 // No default app installation and already installed packages.
1315 ValidateHaveApps(empty_app_list); 1328 ValidateHaveApps(empty_app_list);
1316 } 1329 }
1317 1330
1318 TEST_F(ArcDefaulAppTest, DefaultAppsInstallation) { 1331 TEST_P(ArcDefaulAppTest, DefaultAppsInstallation) {
1319 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1332 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1320 ASSERT_NE(nullptr, prefs); 1333 ASSERT_NE(nullptr, prefs);
1321 1334
1322 const std::vector<arc::mojom::AppInfo> empty_app_list; 1335 const std::vector<arc::mojom::AppInfo> empty_app_list;
1323 1336
1324 ValidateHaveApps(fake_default_apps()); 1337 ValidateHaveApps(fake_default_apps());
1325 1338
1326 app_instance()->RefreshAppList(); 1339 app_instance()->RefreshAppList();
1327 app_instance()->SendRefreshAppList(empty_app_list); 1340 app_instance()->SendRefreshAppList(empty_app_list);
1328 1341
(...skipping 19 matching lines...) Expand all
1348 // completed. 1361 // completed.
1349 ValidateHaveApps(fake_default_apps()); 1362 ValidateHaveApps(fake_default_apps());
1350 1363
1351 // Last default app installation failed. 1364 // Last default app installation failed.
1352 app_instance()->SendInstallationFinished(app_last.package_name, false); 1365 app_instance()->SendInstallationFinished(app_last.package_name, false);
1353 1366
1354 // We should have all default apps except last. 1367 // We should have all default apps except last.
1355 ValidateHaveApps(available_apps); 1368 ValidateHaveApps(available_apps);
1356 } 1369 }
1357 1370
1358 TEST_F(ArcDefaulAppForManagedUserTest, DefaultAppsForManagedUser) { 1371 TEST_P(ArcDefaulAppForManagedUserTest, DefaultAppsForManagedUser) {
1359 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(profile_.get()); 1372 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(profile_.get());
1360 ASSERT_TRUE(prefs); 1373 ASSERT_TRUE(prefs);
1361 1374
1362 // There is no default app for managed users except Play Store 1375 // There is no default app for managed users except Play Store
1363 for (const auto& app : fake_default_apps()) { 1376 for (const auto& app : fake_default_apps()) {
1364 const std::string app_id = ArcAppTest::GetAppId(app); 1377 const std::string app_id = ArcAppTest::GetAppId(app);
1365 EXPECT_FALSE(prefs->IsRegistered(app_id)); 1378 EXPECT_FALSE(prefs->IsRegistered(app_id));
1366 EXPECT_FALSE(prefs->GetApp(app_id)); 1379 EXPECT_FALSE(prefs->GetApp(app_id));
1367 } 1380 }
1368 } 1381 }
1382
1383 INSTANTIATE_TEST_CASE_P(,
1384 ArcAppModelBuilderTest,
1385 ::testing::Values(false, true));
1386 INSTANTIATE_TEST_CASE_P(, ArcDefaulAppTest, ::testing::Values(false, true));
1387 INSTANTIATE_TEST_CASE_P(,
1388 ArcDefaulAppForManagedUserTest,
1389 ::testing::Values(false, true));
1390 INSTANTIATE_TEST_CASE_P(, ArcPlayStoreAppTest, ::testing::Values(false, true));
1391 INSTANTIATE_TEST_CASE_P(,
1392 ArcAppModelBuilderRecreate,
1393 ::testing::Values(false, true));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698