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

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

Powered by Google App Engine
This is Rietveld 408576698