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

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_unittest.cc

Issue 2781623005: [Merge M58] arg: Enable Play Store item in App Launcher for managed case. (Closed)
Patch Set: fix merge conflicts / unit tests passed / manually tested on device Created 3 years, 8 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>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/task_runner_util.h" 18 #include "base/task_runner_util.h"
19 #include "base/threading/sequenced_worker_pool.h" 19 #include "base/threading/sequenced_worker_pool.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "chrome/browser/chromeos/arc/arc_support_host.h" 21 #include "chrome/browser/chromeos/arc/arc_support_host.h"
22 #include "chrome/browser/chromeos/arc/arc_util.h" 22 #include "chrome/browser/chromeos/arc/arc_util.h"
23 #include "chrome/browser/extensions/extension_service.h" 23 #include "chrome/browser/extensions/extension_service.h"
24 #include "chrome/browser/extensions/extension_service_test_base.h"
24 #include "chrome/browser/policy/profile_policy_connector.h" 25 #include "chrome/browser/policy/profile_policy_connector.h"
25 #include "chrome/browser/policy/profile_policy_connector_factory.h" 26 #include "chrome/browser/policy/profile_policy_connector_factory.h"
26 #include "chrome/browser/ui/app_list/app_list_test_util.h"
27 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" 27 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h"
28 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" 28 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h"
29 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" 29 #include "chrome/browser/ui/app_list/arc/arc_app_item.h"
30 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" 30 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h"
31 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 31 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
32 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" 32 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h"
33 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h" 33 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h"
34 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" 34 #include "chrome/browser/ui/app_list/arc/arc_app_test.h"
35 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 35 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
36 #include "chrome/browser/ui/app_list/arc/arc_default_app_list.h" 36 #include "chrome/browser/ui/app_list/arc/arc_default_app_list.h"
37 #include "chrome/browser/ui/app_list/arc/arc_package_syncable_service_factory.h" 37 #include "chrome/browser/ui/app_list/arc/arc_package_syncable_service_factory.h"
38 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" 38 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h"
39 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" 39 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h"
40 #include "chrome/common/pref_names.h"
40 #include "chrome/test/base/testing_profile.h" 41 #include "chrome/test/base/testing_profile.h"
41 #include "components/arc/test/fake_app_instance.h" 42 #include "components/arc/test/fake_app_instance.h"
43 #include "components/sync_preferences/testing_pref_service_syncable.h"
42 #include "content/public/browser/browser_thread.h" 44 #include "content/public/browser/browser_thread.h"
43 #include "extensions/browser/extension_system.h" 45 #include "extensions/browser/extension_system.h"
44 #include "extensions/common/extension.h" 46 #include "extensions/common/extension.h"
45 #include "extensions/common/manifest_constants.h" 47 #include "extensions/common/manifest_constants.h"
46 #include "testing/gtest/include/gtest/gtest.h" 48 #include "testing/gtest/include/gtest/gtest.h"
47 #include "ui/app_list/app_list_constants.h" 49 #include "ui/app_list/app_list_constants.h"
48 #include "ui/app_list/app_list_model.h" 50 #include "ui/app_list/app_list_model.h"
49 #include "ui/events/event_constants.h" 51 #include "ui/events/event_constants.h"
50 #include "ui/gfx/geometry/safe_integer_conversions.h" 52 #include "ui/gfx/geometry/safe_integer_conversions.h"
51 #include "ui/gfx/image/image_skia.h" 53 #include "ui/gfx/image/image_skia.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 ui::ScaleFactor scale_factor) { 87 ui::ScaleFactor scale_factor) {
86 const base::FilePath icon_path = prefs->GetIconPath(app_id, scale_factor); 88 const base::FilePath icon_path = prefs->GetIconPath(app_id, scale_factor);
87 // Process pending tasks. This performs multiple thread hops, so we need 89 // Process pending tasks. This performs multiple thread hops, so we need
88 // to run it continuously until it is resolved. 90 // to run it continuously until it is resolved.
89 do { 91 do {
90 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 92 content::BrowserThread::GetBlockingPool()->FlushForTesting();
91 base::RunLoop().RunUntilIdle(); 93 base::RunLoop().RunUntilIdle();
92 } while (!base::PathExists(icon_path)); 94 } while (!base::PathExists(icon_path));
93 } 95 }
94 96
97 enum class ArcState {
98 // By default, ARC is non-persistent and Play Store is unmanaged.
99 ARC_PLAY_STORE_UNMANAGED,
100 // ARC is non-persistent and Play Store is managed and enabled.
101 ARC_PLAY_STORE_MANAGED_AND_ENABLED,
102 // ARC is non-persistent and Play Store is managed and disabled.
103 ARC_PLAY_STORE_MANAGED_AND_DISABLED,
104 };
105
106 constexpr ArcState kManagedArcStates[] = {
107 ArcState::ARC_PLAY_STORE_MANAGED_AND_ENABLED,
108 ArcState::ARC_PLAY_STORE_MANAGED_AND_DISABLED,
109 };
110
111 constexpr ArcState kUnmanagedArcStates[] = {
112 ArcState::ARC_PLAY_STORE_UNMANAGED,
113 };
114
95 } // namespace 115 } // namespace
96 116
97 class ArcAppModelBuilderTest : public AppListTestBase { 117 class ArcAppModelBuilderTest : public extensions::ExtensionServiceTestBase,
118 public ::testing::WithParamInterface<ArcState> {
98 public: 119 public:
99 ArcAppModelBuilderTest() = default; 120 ArcAppModelBuilderTest() = default;
100 ~ArcAppModelBuilderTest() override { 121 ~ArcAppModelBuilderTest() override {
101 // Release profile file in order to keep right sequence. 122 // Release profile file in order to keep right sequence.
102 profile_.reset(); 123 profile_.reset();
103 } 124 }
104 125
105 void SetUp() override { 126 void SetUp() override {
106 AppListTestBase::SetUp(); 127 extensions::ExtensionServiceTestBase::SetUp();
128 InitializeExtensionService(ExtensionServiceInitParams());
129 service_->Init();
130 // ExtensionService needs a real I/O thread.
131 service_->SetFileTaskRunnerForTesting(
132 content::BrowserThread::GetBlockingPool()
133 ->GetSequencedTaskRunnerWithShutdownBehavior(
134 content::BrowserThread::GetBlockingPool()
135 ->GetNamedSequenceToken("ext_install-"),
136 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
137
107 OnBeforeArcTestSetup(); 138 OnBeforeArcTestSetup();
108 arc_test_.SetUp(profile_.get()); 139 arc_test_.SetUp(profile_.get());
109 CreateBuilder(); 140 CreateBuilder();
110 141
111 // Validating decoded content does not fit well for unit tests. 142 // Validating decoded content does not fit well for unit tests.
112 ArcAppIcon::DisableSafeDecodingForTesting(); 143 ArcAppIcon::DisableSafeDecodingForTesting();
113 } 144 }
114 145
115 void TearDown() override { 146 void TearDown() override {
116 arc_test_.TearDown(); 147 arc_test_.TearDown();
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 void AddPackage(const arc::mojom::ArcPackageInfo& package) { 364 void AddPackage(const arc::mojom::ArcPackageInfo& package) {
334 arc_test_.AddPackage(package); 365 arc_test_.AddPackage(package);
335 } 366 }
336 367
337 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { 368 void RemovePackage(const arc::mojom::ArcPackageInfo& package) {
338 arc_test_.RemovePackage(package); 369 arc_test_.RemovePackage(package);
339 } 370 }
340 371
341 AppListControllerDelegate* controller() { return controller_.get(); } 372 AppListControllerDelegate* controller() { return controller_.get(); }
342 373
343 Profile* profile() { return profile_.get(); } 374 TestingProfile* profile() { return profile_.get(); }
344 375
345 ArcAppTest* arc_test() { return &arc_test_; } 376 ArcAppTest* arc_test() { return &arc_test_; }
346 377
347 const std::vector<arc::mojom::AppInfo>& fake_apps() const { 378 const std::vector<arc::mojom::AppInfo>& fake_apps() const {
348 return arc_test_.fake_apps(); 379 return arc_test_.fake_apps();
349 } 380 }
350 381
351 const std::vector<arc::mojom::AppInfo>& fake_default_apps() const { 382 const std::vector<arc::mojom::AppInfo>& fake_default_apps() const {
352 return arc_test_.fake_default_apps(); 383 return arc_test_.fake_default_apps();
353 } 384 }
(...skipping 29 matching lines...) Expand all
383 void OnBeforeArcTestSetup() override { 414 void OnBeforeArcTestSetup() override {
384 ArcDefaultAppList::UseTestAppsDirectory(); 415 ArcDefaultAppList::UseTestAppsDirectory();
385 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( 416 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory(
386 profile_.get(), nullptr); 417 profile_.get(), nullptr);
387 } 418 }
388 419
389 private: 420 private:
390 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); 421 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest);
391 }; 422 };
392 423
393 class ArcDefaulAppForManagedUserTest : public ArcDefaulAppTest {
394 public:
395 ArcDefaulAppForManagedUserTest() = default;
396 ~ArcDefaulAppForManagedUserTest() override = default;
397
398 protected:
399 // ArcAppModelBuilderTest:
400 void OnBeforeArcTestSetup() override {
401 ArcDefaulAppTest::OnBeforeArcTestSetup();
402
403 policy::ProfilePolicyConnector* const connector =
404 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(
405 profile());
406 connector->OverrideIsManagedForTesting(true);
407 }
408
409 private:
410 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppForManagedUserTest);
411 };
412
413 class ArcPlayStoreAppTest : public ArcDefaulAppTest { 424 class ArcPlayStoreAppTest : public ArcDefaulAppTest {
414 public: 425 public:
415 ArcPlayStoreAppTest() = default; 426 ArcPlayStoreAppTest() = default;
416 ~ArcPlayStoreAppTest() override = default; 427 ~ArcPlayStoreAppTest() override = default;
417 428
418 protected: 429 protected:
419 // ArcAppModelBuilderTest: 430 // ArcAppModelBuilderTest:
420 void OnBeforeArcTestSetup() override { 431 void OnBeforeArcTestSetup() override {
421 ArcDefaulAppTest::OnBeforeArcTestSetup(); 432 ArcDefaulAppTest::OnBeforeArcTestSetup();
422 433
(...skipping 15 matching lines...) Expand all
438 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); 449 extensions::ExtensionSystem::Get(profile_.get())->extension_service();
439 extension_service->AddExtension(arc_support_host_.get()); 450 extension_service->AddExtension(arc_support_host_.get());
440 } 451 }
441 452
442 private: 453 private:
443 scoped_refptr<extensions::Extension> arc_support_host_; 454 scoped_refptr<extensions::Extension> arc_support_host_;
444 455
445 DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreAppTest); 456 DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreAppTest);
446 }; 457 };
447 458
459 class ArcDefaulAppForManagedUserTest : public ArcPlayStoreAppTest {
460 public:
461 ArcDefaulAppForManagedUserTest() = default;
462 ~ArcDefaulAppForManagedUserTest() override = default;
463
464 protected:
465 bool IsEnabledByPolicy() const {
466 switch (GetParam()) {
467 case ArcState::ARC_PLAY_STORE_MANAGED_AND_ENABLED:
468 return true;
469 case ArcState::ARC_PLAY_STORE_MANAGED_AND_DISABLED:
470 return false;
471 default:
472 NOTREACHED();
473 return false;
474 }
475 }
476
477 // ArcPlayStoreAppTest:
478 void OnBeforeArcTestSetup() override {
479 policy::ProfilePolicyConnector* const connector =
480 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile());
481 connector->OverrideIsManagedForTesting(true);
482 profile()->GetTestingPrefService()->SetManagedPref(
483 prefs::kArcEnabled, new base::Value(IsEnabledByPolicy()));
484
485 ArcPlayStoreAppTest::OnBeforeArcTestSetup();
486 }
487
488 private:
489 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppForManagedUserTest);
490 };
491
448 class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest { 492 class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest {
449 public: 493 public:
450 ArcAppModelBuilderRecreate() = default; 494 ArcAppModelBuilderRecreate() = default;
451 ~ArcAppModelBuilderRecreate() override = default; 495 ~ArcAppModelBuilderRecreate() override = default;
452 496
453 protected: 497 protected:
454 // ArcAppModelBuilderTest: 498 // ArcAppModelBuilderTest:
455 void OnBeforeArcTestSetup() override { 499 void OnBeforeArcTestSetup() override {
456 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( 500 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory(
457 profile_.get(), nullptr); 501 profile_.get(), nullptr);
458 } 502 }
459 503
460 private: 504 private:
461 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderRecreate); 505 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderRecreate);
462 }; 506 };
463 507
464 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { 508 TEST_P(ArcAppModelBuilderTest, ArcPackagePref) {
465 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); 509 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>());
466 app_instance()->SendRefreshPackageList(fake_packages()); 510 app_instance()->SendRefreshPackageList(fake_packages());
467 ValidateHavePackages(fake_packages()); 511 ValidateHavePackages(fake_packages());
468 512
469 arc::mojom::ArcPackageInfo package; 513 arc::mojom::ArcPackageInfo package;
470 package.package_name = kTestPackageName; 514 package.package_name = kTestPackageName;
471 package.package_version = 2; 515 package.package_version = 2;
472 package.last_backup_android_id = 2; 516 package.last_backup_android_id = 2;
473 package.last_backup_time = 2; 517 package.last_backup_time = 2;
474 package.sync = true; 518 package.sync = true;
475 519
476 RemovePackage(package); 520 RemovePackage(package);
477 app_instance()->SendPackageUninstalled(package.package_name); 521 app_instance()->SendPackageUninstalled(package.package_name);
478 ValidateHavePackages(fake_packages()); 522 ValidateHavePackages(fake_packages());
479 523
480 AddPackage(package); 524 AddPackage(package);
481 app_instance()->SendPackageAdded(package); 525 app_instance()->SendPackageAdded(package);
482 ValidateHavePackages(fake_packages()); 526 ValidateHavePackages(fake_packages());
483 } 527 }
484 528
485 TEST_F(ArcAppModelBuilderTest, RefreshAllOnReady) { 529 TEST_P(ArcAppModelBuilderTest, RefreshAllOnReady) {
486 // There should already have been one call, when the interface was 530 // There should already have been one call, when the interface was
487 // registered. 531 // registered.
488 EXPECT_EQ(1, app_instance()->refresh_app_list_count()); 532 EXPECT_EQ(1, app_instance()->refresh_app_list_count());
489 app_instance()->RefreshAppList(); 533 app_instance()->RefreshAppList();
490 EXPECT_EQ(2, app_instance()->refresh_app_list_count()); 534 EXPECT_EQ(2, app_instance()->refresh_app_list_count());
491 } 535 }
492 536
493 TEST_F(ArcAppModelBuilderTest, RefreshAllFillsContent) { 537 TEST_P(ArcAppModelBuilderTest, RefreshAllFillsContent) {
494 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 538 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
495 app_instance()->RefreshAppList(); 539 app_instance()->RefreshAppList();
496 app_instance()->SendRefreshAppList(fake_apps()); 540 app_instance()->SendRefreshAppList(fake_apps());
497 ValidateHaveApps(fake_apps()); 541 ValidateHaveApps(fake_apps());
498 } 542 }
499 543
500 TEST_F(ArcAppModelBuilderTest, InstallShortcut) { 544 TEST_P(ArcAppModelBuilderTest, InstallShortcut) {
501 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 545 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
502 546
503 app_instance()->SendInstallShortcuts(fake_shortcuts()); 547 app_instance()->SendInstallShortcuts(fake_shortcuts());
504 ValidateHaveShortcuts(fake_shortcuts()); 548 ValidateHaveShortcuts(fake_shortcuts());
505 } 549 }
506 550
507 TEST_F(ArcAppModelBuilderTest, RefreshAllPreservesShortcut) { 551 TEST_P(ArcAppModelBuilderTest, RefreshAllPreservesShortcut) {
508 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 552 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
509 app_instance()->RefreshAppList(); 553 app_instance()->RefreshAppList();
510 app_instance()->SendRefreshAppList(fake_apps()); 554 app_instance()->SendRefreshAppList(fake_apps());
511 ValidateHaveApps(fake_apps()); 555 ValidateHaveApps(fake_apps());
512 556
513 app_instance()->SendInstallShortcuts(fake_shortcuts()); 557 app_instance()->SendInstallShortcuts(fake_shortcuts());
514 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts()); 558 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts());
515 559
516 app_instance()->RefreshAppList(); 560 app_instance()->RefreshAppList();
517 app_instance()->SendRefreshAppList(fake_apps()); 561 app_instance()->SendRefreshAppList(fake_apps());
518 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts()); 562 ValidateHaveAppsAndShortcuts(fake_apps(), fake_shortcuts());
519 } 563 }
520 564
521 TEST_F(ArcAppModelBuilderTest, MultipleRefreshAll) { 565 TEST_P(ArcAppModelBuilderTest, MultipleRefreshAll) {
522 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 566 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
523 app_instance()->RefreshAppList(); 567 app_instance()->RefreshAppList();
524 // Send info about all fake apps except last. 568 // Send info about all fake apps except last.
525 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(), 569 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(),
526 fake_apps().end() - 1); 570 fake_apps().end() - 1);
527 app_instance()->SendRefreshAppList(apps1); 571 app_instance()->SendRefreshAppList(apps1);
528 // At this point all apps (except last) should exist and be ready. 572 // At this point all apps (except last) should exist and be ready.
529 ValidateHaveApps(apps1); 573 ValidateHaveApps(apps1);
530 ValidateAppReadyState(apps1, true); 574 ValidateAppReadyState(apps1, true);
531 575
(...skipping 11 matching lines...) Expand all
543 ValidateHaveApps(fake_apps()); 587 ValidateHaveApps(fake_apps());
544 ValidateAppReadyState(fake_apps(), true); 588 ValidateAppReadyState(fake_apps(), true);
545 589
546 // Send info no app available. 590 // Send info no app available.
547 std::vector<arc::mojom::AppInfo> no_apps; 591 std::vector<arc::mojom::AppInfo> no_apps;
548 app_instance()->SendRefreshAppList(no_apps); 592 app_instance()->SendRefreshAppList(no_apps);
549 // At this point no app should exist. 593 // At this point no app should exist.
550 ValidateHaveApps(no_apps); 594 ValidateHaveApps(no_apps);
551 } 595 }
552 596
553 TEST_F(ArcAppModelBuilderTest, StopStartServicePreserveApps) { 597 TEST_P(ArcAppModelBuilderTest, StopStartServicePreserveApps) {
554 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 598 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
555 ASSERT_NE(nullptr, prefs); 599 ASSERT_NE(nullptr, prefs);
556 600
557 app_instance()->RefreshAppList(); 601 app_instance()->RefreshAppList();
558 EXPECT_EQ(0u, GetArcItemCount()); 602 EXPECT_EQ(0u, GetArcItemCount());
559 EXPECT_EQ(0u, prefs->GetAppIds().size()); 603 EXPECT_EQ(0u, prefs->GetAppIds().size());
560 604
561 app_instance()->SendRefreshAppList(fake_apps()); 605 app_instance()->SendRefreshAppList(fake_apps());
562 std::vector<std::string> ids = prefs->GetAppIds(); 606 std::vector<std::string> ids = prefs->GetAppIds();
563 EXPECT_EQ(fake_apps().size(), ids.size()); 607 EXPECT_EQ(fake_apps().size(), ids.size());
564 ValidateAppReadyState(fake_apps(), true); 608 ValidateAppReadyState(fake_apps(), true);
565 609
566 // Stopping service does not delete items. It makes them non-ready. 610 // Stopping service does not delete items. It makes them non-ready.
567 arc_test()->StopArcInstance(); 611 arc_test()->StopArcInstance();
568 // Ids should be the same. 612 // Ids should be the same.
569 EXPECT_EQ(ids, prefs->GetAppIds()); 613 EXPECT_EQ(ids, prefs->GetAppIds());
570 ValidateAppReadyState(fake_apps(), false); 614 ValidateAppReadyState(fake_apps(), false);
571 615
572 // Ids should be the same. 616 // Ids should be the same.
573 EXPECT_EQ(ids, prefs->GetAppIds()); 617 EXPECT_EQ(ids, prefs->GetAppIds());
574 ValidateAppReadyState(fake_apps(), false); 618 ValidateAppReadyState(fake_apps(), false);
575 619
576 // Refreshing app list makes apps available. 620 // Refreshing app list makes apps available.
577 app_instance()->SendRefreshAppList(fake_apps()); 621 app_instance()->SendRefreshAppList(fake_apps());
578 EXPECT_EQ(ids, prefs->GetAppIds()); 622 EXPECT_EQ(ids, prefs->GetAppIds());
579 ValidateAppReadyState(fake_apps(), true); 623 ValidateAppReadyState(fake_apps(), true);
580 } 624 }
581 625
582 TEST_F(ArcAppModelBuilderTest, StopStartServicePreserveShortcuts) { 626 TEST_P(ArcAppModelBuilderTest, StopStartServicePreserveShortcuts) {
583 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 627 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
584 ASSERT_NE(nullptr, prefs); 628 ASSERT_NE(nullptr, prefs);
585 629
586 app_instance()->RefreshAppList(); 630 app_instance()->RefreshAppList();
587 EXPECT_EQ(0u, GetArcItemCount()); 631 EXPECT_EQ(0u, GetArcItemCount());
588 EXPECT_EQ(0u, prefs->GetAppIds().size()); 632 EXPECT_EQ(0u, prefs->GetAppIds().size());
589 633
590 app_instance()->SendInstallShortcuts(fake_shortcuts()); 634 app_instance()->SendInstallShortcuts(fake_shortcuts());
591 std::vector<std::string> ids = prefs->GetAppIds(); 635 std::vector<std::string> ids = prefs->GetAppIds();
592 EXPECT_EQ(fake_shortcuts().size(), ids.size()); 636 EXPECT_EQ(fake_shortcuts().size(), ids.size());
593 ValidateShortcutReadyState(fake_shortcuts(), true); 637 ValidateShortcutReadyState(fake_shortcuts(), true);
594 638
595 // Stopping service does not delete items. It makes them non-ready. 639 // Stopping service does not delete items. It makes them non-ready.
596 arc_test()->StopArcInstance(); 640 arc_test()->StopArcInstance();
597 // Ids should be the same. 641 // Ids should be the same.
598 EXPECT_EQ(ids, prefs->GetAppIds()); 642 EXPECT_EQ(ids, prefs->GetAppIds());
599 ValidateShortcutReadyState(fake_shortcuts(), false); 643 ValidateShortcutReadyState(fake_shortcuts(), false);
600 644
601 // Ids should be the same. 645 // Ids should be the same.
602 EXPECT_EQ(ids, prefs->GetAppIds()); 646 EXPECT_EQ(ids, prefs->GetAppIds());
603 ValidateShortcutReadyState(fake_shortcuts(), false); 647 ValidateShortcutReadyState(fake_shortcuts(), false);
604 648
605 // Refreshing app list makes apps available. 649 // Refreshing app list makes apps available.
606 app_instance()->RefreshAppList(); 650 app_instance()->RefreshAppList();
607 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>()); 651 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>());
608 EXPECT_EQ(ids, prefs->GetAppIds()); 652 EXPECT_EQ(ids, prefs->GetAppIds());
609 ValidateShortcutReadyState(fake_shortcuts(), true); 653 ValidateShortcutReadyState(fake_shortcuts(), true);
610 } 654 }
611 655
612 TEST_F(ArcAppModelBuilderTest, RestartPreserveApps) { 656 TEST_P(ArcAppModelBuilderTest, RestartPreserveApps) {
613 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 657 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
614 ASSERT_NE(nullptr, prefs); 658 ASSERT_NE(nullptr, prefs);
615 659
616 // Start from scratch and fill with apps. 660 // Start from scratch and fill with apps.
617 app_instance()->SendRefreshAppList(fake_apps()); 661 app_instance()->SendRefreshAppList(fake_apps());
618 std::vector<std::string> ids = prefs->GetAppIds(); 662 std::vector<std::string> ids = prefs->GetAppIds();
619 EXPECT_EQ(fake_apps().size(), ids.size()); 663 EXPECT_EQ(fake_apps().size(), ids.size());
620 ValidateAppReadyState(fake_apps(), true); 664 ValidateAppReadyState(fake_apps(), true);
621 665
622 // This recreates model and ARC apps will be read from prefs. 666 // This recreates model and ARC apps will be read from prefs.
623 arc_test()->StopArcInstance(); 667 arc_test()->StopArcInstance();
624 CreateBuilder(); 668 CreateBuilder();
625 ValidateAppReadyState(fake_apps(), false); 669 ValidateAppReadyState(fake_apps(), false);
626 } 670 }
627 671
628 TEST_F(ArcAppModelBuilderTest, RestartPreserveShortcuts) { 672 TEST_P(ArcAppModelBuilderTest, RestartPreserveShortcuts) {
629 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 673 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
630 ASSERT_NE(nullptr, prefs); 674 ASSERT_NE(nullptr, prefs);
631 675
632 // Start from scratch and install shortcuts. 676 // Start from scratch and install shortcuts.
633 app_instance()->SendInstallShortcuts(fake_shortcuts()); 677 app_instance()->SendInstallShortcuts(fake_shortcuts());
634 std::vector<std::string> ids = prefs->GetAppIds(); 678 std::vector<std::string> ids = prefs->GetAppIds();
635 EXPECT_EQ(fake_apps().size(), ids.size()); 679 EXPECT_EQ(fake_apps().size(), ids.size());
636 ValidateShortcutReadyState(fake_shortcuts(), true); 680 ValidateShortcutReadyState(fake_shortcuts(), true);
637 681
638 // This recreates model and ARC apps and shortcuts will be read from prefs. 682 // This recreates model and ARC apps and shortcuts will be read from prefs.
639 arc_test()->StopArcInstance(); 683 arc_test()->StopArcInstance();
640 CreateBuilder(); 684 CreateBuilder();
641 ValidateShortcutReadyState(fake_shortcuts(), false); 685 ValidateShortcutReadyState(fake_shortcuts(), false);
642 } 686 }
643 687
644 TEST_F(ArcAppModelBuilderTest, LaunchApps) { 688 TEST_P(ArcAppModelBuilderTest, LaunchApps) {
645 // Disable attempts to dismiss app launcher view. 689 // Disable attempts to dismiss app launcher view.
646 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); 690 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller());
647 691
648 app_instance()->RefreshAppList(); 692 app_instance()->RefreshAppList();
649 app_instance()->SendRefreshAppList(fake_apps()); 693 app_instance()->SendRefreshAppList(fake_apps());
650 694
651 // Simulate item activate. 695 // Simulate item activate.
652 const arc::mojom::AppInfo& app_first = fake_apps()[0]; 696 const arc::mojom::AppInfo& app_first = fake_apps()[0];
653 const arc::mojom::AppInfo& app_last = fake_apps()[0]; 697 const arc::mojom::AppInfo& app_last = fake_apps()[0];
654 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 698 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
(...skipping 15 matching lines...) Expand all
670 arc_test()->StopArcInstance(); 714 arc_test()->StopArcInstance();
671 item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 715 item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
672 ASSERT_NE(nullptr, item_first); 716 ASSERT_NE(nullptr, item_first);
673 size_t launch_request_count_before = app_instance()->launch_requests().size(); 717 size_t launch_request_count_before = app_instance()->launch_requests().size();
674 item_first->Activate(0); 718 item_first->Activate(0);
675 // Number of launch requests must not change. 719 // Number of launch requests must not change.
676 EXPECT_EQ(launch_request_count_before, 720 EXPECT_EQ(launch_request_count_before,
677 app_instance()->launch_requests().size()); 721 app_instance()->launch_requests().size());
678 } 722 }
679 723
680 TEST_F(ArcAppModelBuilderTest, LaunchShortcuts) { 724 TEST_P(ArcAppModelBuilderTest, LaunchShortcuts) {
681 // Disable attempts to dismiss app launcher view. 725 // Disable attempts to dismiss app launcher view.
682 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller()); 726 ChromeAppListItem::OverrideAppListControllerDelegateForTesting(controller());
683 727
684 app_instance()->RefreshAppList(); 728 app_instance()->RefreshAppList();
685 app_instance()->SendInstallShortcuts(fake_shortcuts()); 729 app_instance()->SendInstallShortcuts(fake_shortcuts());
686 730
687 // Simulate item activate. 731 // Simulate item activate.
688 const arc::mojom::ShortcutInfo& app_first = fake_shortcuts()[0]; 732 const arc::mojom::ShortcutInfo& app_first = fake_shortcuts()[0];
689 const arc::mojom::ShortcutInfo& app_last = fake_shortcuts()[0]; 733 const arc::mojom::ShortcutInfo& app_last = fake_shortcuts()[0];
690 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 734 ArcAppItem* item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
(...skipping 15 matching lines...) Expand all
706 arc_test()->StopArcInstance(); 750 arc_test()->StopArcInstance();
707 item_first = FindArcItem(ArcAppTest::GetAppId(app_first)); 751 item_first = FindArcItem(ArcAppTest::GetAppId(app_first));
708 ASSERT_NE(nullptr, item_first); 752 ASSERT_NE(nullptr, item_first);
709 size_t launch_request_count_before = app_instance()->launch_intents().size(); 753 size_t launch_request_count_before = app_instance()->launch_intents().size();
710 item_first->Activate(0); 754 item_first->Activate(0);
711 // Number of launch requests must not change. 755 // Number of launch requests must not change.
712 EXPECT_EQ(launch_request_count_before, 756 EXPECT_EQ(launch_request_count_before,
713 app_instance()->launch_intents().size()); 757 app_instance()->launch_intents().size());
714 } 758 }
715 759
716 TEST_F(ArcAppModelBuilderTest, RequestIcons) { 760 TEST_P(ArcAppModelBuilderTest, RequestIcons) {
717 // Make sure we are on UI thread. 761 // Make sure we are on UI thread.
718 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 762 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
719 763
720 app_instance()->RefreshAppList(); 764 app_instance()->RefreshAppList();
721 app_instance()->SendRefreshAppList(fake_apps()); 765 app_instance()->SendRefreshAppList(fake_apps());
722 766
723 // Validate that no icon exists at the beginning and request icon for 767 // Validate that no icon exists at the beginning and request icon for
724 // each supported scale factor. This will start asynchronous loading. 768 // each supported scale factor. This will start asynchronous loading.
725 uint32_t expected_mask = 0; 769 uint32_t expected_mask = 0;
726 const std::vector<ui::ScaleFactor>& scale_factors = 770 const std::vector<ui::ScaleFactor>& scale_factors =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 // Validate that we have a request for each icon for each supported scale 805 // Validate that we have a request for each icon for each supported scale
762 // factor. 806 // factor.
763 EXPECT_EQ(fake_apps().size(), app_masks.size()); 807 EXPECT_EQ(fake_apps().size(), app_masks.size());
764 for (auto& app : fake_apps()) { 808 for (auto& app : fake_apps()) {
765 const std::string id = ArcAppTest::GetAppId(app); 809 const std::string id = ArcAppTest::GetAppId(app);
766 ASSERT_NE(app_masks.find(id), app_masks.end()); 810 ASSERT_NE(app_masks.find(id), app_masks.end());
767 EXPECT_EQ(app_masks[id], expected_mask); 811 EXPECT_EQ(app_masks[id], expected_mask);
768 } 812 }
769 } 813 }
770 814
771 TEST_F(ArcAppModelBuilderTest, RequestShortcutIcons) { 815 TEST_P(ArcAppModelBuilderTest, RequestShortcutIcons) {
772 // Make sure we are on UI thread. 816 // Make sure we are on UI thread.
773 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 817 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
774 818
775 const arc::mojom::ShortcutInfo& shortcut = fake_shortcuts()[0]; 819 const arc::mojom::ShortcutInfo& shortcut = fake_shortcuts()[0];
776 app_instance()->SendInstallShortcut(shortcut); 820 app_instance()->SendInstallShortcut(shortcut);
777 821
778 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 822 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
779 ASSERT_NE(nullptr, prefs); 823 ASSERT_NE(nullptr, prefs);
780 824
781 // Icons representations loading is done asynchronously and is started once 825 // Icons representations loading is done asynchronously and is started once
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 EXPECT_EQ(app_mask, expected_mask); 858 EXPECT_EQ(app_mask, expected_mask);
815 859
816 // Validate all icon files are installed. 860 // Validate all icon files are installed.
817 for (auto& scale_factor : scale_factors) { 861 for (auto& scale_factor : scale_factors) {
818 const base::FilePath icon_path = 862 const base::FilePath icon_path =
819 prefs->GetIconPath(ArcAppTest::GetAppId(shortcut), scale_factor); 863 prefs->GetIconPath(ArcAppTest::GetAppId(shortcut), scale_factor);
820 EXPECT_TRUE(base::PathExists(icon_path)); 864 EXPECT_TRUE(base::PathExists(icon_path));
821 } 865 }
822 } 866 }
823 867
824 TEST_F(ArcAppModelBuilderTest, InstallIcon) { 868 TEST_P(ArcAppModelBuilderTest, InstallIcon) {
825 // Make sure we are on UI thread. 869 // Make sure we are on UI thread.
826 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 870 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
827 871
828 app_instance()->RefreshAppList(); 872 app_instance()->RefreshAppList();
829 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 873 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
830 fake_apps().begin(), fake_apps().begin() + 1)); 874 fake_apps().begin(), fake_apps().begin() + 1));
831 const arc::mojom::AppInfo& app = fake_apps()[0]; 875 const arc::mojom::AppInfo& app = fake_apps()[0];
832 876
833 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 877 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
834 ASSERT_NE(nullptr, prefs); 878 ASSERT_NE(nullptr, prefs);
(...skipping 18 matching lines...) Expand all
853 // Validate that icons are installed, have right content and icon is 897 // Validate that icons are installed, have right content and icon is
854 // refreshed for ARC app item. 898 // refreshed for ARC app item.
855 EXPECT_TRUE(base::PathExists(icon_path)); 899 EXPECT_TRUE(base::PathExists(icon_path));
856 900
857 std::string icon_data; 901 std::string icon_data;
858 // Read the file from disk and compare with reference data. 902 // Read the file from disk and compare with reference data.
859 EXPECT_TRUE(base::ReadFileToString(icon_path, &icon_data)); 903 EXPECT_TRUE(base::ReadFileToString(icon_path, &icon_data));
860 ASSERT_EQ(icon_data, png_data); 904 ASSERT_EQ(icon_data, png_data);
861 } 905 }
862 906
863 TEST_F(ArcAppModelBuilderTest, RemoveAppCleanUpFolder) { 907 TEST_P(ArcAppModelBuilderTest, RemoveAppCleanUpFolder) {
864 // Make sure we are on UI thread. 908 // Make sure we are on UI thread.
865 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 909 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
866 910
867 app_instance()->RefreshAppList(); 911 app_instance()->RefreshAppList();
868 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 912 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
869 fake_apps().begin(), fake_apps().begin() + 1)); 913 fake_apps().begin(), fake_apps().begin() + 1));
870 const arc::mojom::AppInfo& app = fake_apps()[0]; 914 const arc::mojom::AppInfo& app = fake_apps()[0];
871 915
872 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 916 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
873 ASSERT_NE(nullptr, prefs); 917 ASSERT_NE(nullptr, prefs);
(...skipping 19 matching lines...) Expand all
893 // removed, not added. 937 // removed, not added.
894 // Process pending tasks. This performs multiple thread hops, so we need 938 // Process pending tasks. This performs multiple thread hops, so we need
895 // to run it continuously until it is resolved. 939 // to run it continuously until it is resolved.
896 do { 940 do {
897 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 941 content::BrowserThread::GetBlockingPool()->FlushForTesting();
898 base::RunLoop().RunUntilIdle(); 942 base::RunLoop().RunUntilIdle();
899 } while (base::PathExists(app_path)); 943 } while (base::PathExists(app_path));
900 EXPECT_FALSE(base::PathExists(app_path)); 944 EXPECT_FALSE(base::PathExists(app_path));
901 } 945 }
902 946
903 TEST_F(ArcAppModelBuilderTest, LastLaunchTime) { 947 TEST_P(ArcAppModelBuilderTest, LastLaunchTime) {
904 // Make sure we are on UI thread. 948 // Make sure we are on UI thread.
905 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 949 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
906 950
907 app_instance()->RefreshAppList(); 951 app_instance()->RefreshAppList();
908 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 952 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
909 fake_apps().begin(), fake_apps().begin() + 2)); 953 fake_apps().begin(), fake_apps().begin() + 2));
910 const arc::mojom::AppInfo& app1 = fake_apps()[0]; 954 const arc::mojom::AppInfo& app1 = fake_apps()[0];
911 const arc::mojom::AppInfo& app2 = fake_apps()[1]; 955 const arc::mojom::AppInfo& app2 = fake_apps()[1];
912 const std::string id1 = ArcAppTest::GetAppId(app1); 956 const std::string id1 = ArcAppTest::GetAppId(app1);
913 const std::string id2 = ArcAppTest::GetAppId(app2); 957 const std::string id2 = ArcAppTest::GetAppId(app2);
(...skipping 23 matching lines...) Expand all
937 arc::LaunchApp(profile(), id2, ui::EF_NONE); 981 arc::LaunchApp(profile(), id2, ui::EF_NONE);
938 base::Time time_after = base::Time::Now(); 982 base::Time time_after = base::Time::Now();
939 983
940 app_info = prefs->GetApp(id2); 984 app_info = prefs->GetApp(id2);
941 ASSERT_NE(nullptr, app_info.get()); 985 ASSERT_NE(nullptr, app_info.get());
942 ASSERT_LE(time_before, app_info->last_launch_time); 986 ASSERT_LE(time_before, app_info->last_launch_time);
943 ASSERT_GE(time_after, app_info->last_launch_time); 987 ASSERT_GE(time_after, app_info->last_launch_time);
944 } 988 }
945 989
946 // Validate that arc model contains expected elements on restart. 990 // Validate that arc model contains expected elements on restart.
947 TEST_F(ArcAppModelBuilderRecreate, AppModelRestart) { 991 TEST_P(ArcAppModelBuilderRecreate, AppModelRestart) {
948 // No apps on initial start. 992 // No apps on initial start.
949 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 993 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
950 994
951 // Send info about all fake apps except last. 995 // Send info about all fake apps except last.
952 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(), 996 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(),
953 fake_apps().end() - 1); 997 fake_apps().end() - 1);
954 app_instance()->RefreshAppList(); 998 app_instance()->RefreshAppList();
955 app_instance()->SendRefreshAppList(apps1); 999 app_instance()->SendRefreshAppList(apps1);
956 // Model has refreshed apps. 1000 // Model has refreshed apps.
957 ValidateHaveApps(apps1); 1001 ValidateHaveApps(apps1);
(...skipping 12 matching lines...) Expand all
970 ValidateHaveApps(apps1); 1014 ValidateHaveApps(apps1);
971 EXPECT_EQ(apps1.size(), GetArcItemCount()); 1015 EXPECT_EQ(apps1.size(), GetArcItemCount());
972 1016
973 // Now refresh old apps with new one. 1017 // Now refresh old apps with new one.
974 app_instance()->RefreshAppList(); 1018 app_instance()->RefreshAppList();
975 app_instance()->SendRefreshAppList(fake_apps()); 1019 app_instance()->SendRefreshAppList(fake_apps());
976 ValidateHaveApps(fake_apps()); 1020 ValidateHaveApps(fake_apps());
977 EXPECT_EQ(fake_apps().size(), GetArcItemCount()); 1021 EXPECT_EQ(fake_apps().size(), GetArcItemCount());
978 } 1022 }
979 1023
980 TEST_F(ArcPlayStoreAppTest, PlayStore) { 1024 TEST_P(ArcPlayStoreAppTest, PlayStore) {
981 // Make sure PlayStore is available. 1025 // Make sure PlayStore is available.
982 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 1026 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
983 1027
984 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1028 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
985 ASSERT_TRUE(prefs); 1029 ASSERT_TRUE(prefs);
986 1030
987 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp( 1031 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(
988 arc::kPlayStoreAppId); 1032 arc::kPlayStoreAppId);
989 ASSERT_TRUE(app_info); 1033 ASSERT_TRUE(app_info);
990 EXPECT_FALSE(app_info->ready); 1034 EXPECT_FALSE(app_info->ready);
(...skipping 17 matching lines...) Expand all
1008 1052
1009 app_info = prefs->GetApp(arc::kPlayStoreAppId); 1053 app_info = prefs->GetApp(arc::kPlayStoreAppId);
1010 ASSERT_TRUE(app_info); 1054 ASSERT_TRUE(app_info);
1011 EXPECT_FALSE(app_info->ready); 1055 EXPECT_FALSE(app_info->ready);
1012 1056
1013 arc::LaunchApp(profile(), arc::kPlayStoreAppId, ui::EF_NONE); 1057 arc::LaunchApp(profile(), arc::kPlayStoreAppId, ui::EF_NONE);
1014 EXPECT_TRUE(arc::IsArcPlayStoreEnabledForProfile(profile())); 1058 EXPECT_TRUE(arc::IsArcPlayStoreEnabledForProfile(profile()));
1015 } 1059 }
1016 1060
1017 // Test that icon is correctly extracted for shelf group. 1061 // Test that icon is correctly extracted for shelf group.
1018 TEST_F(ArcAppModelBuilderTest, IconLoaderForShelfGroup) { 1062 TEST_P(ArcAppModelBuilderTest, IconLoaderForShelfGroup) {
1019 const arc::mojom::AppInfo& app = fake_apps()[0]; 1063 const arc::mojom::AppInfo& app = fake_apps()[0];
1020 const std::string app_id = ArcAppTest::GetAppId(app); 1064 const std::string app_id = ArcAppTest::GetAppId(app);
1021 1065
1022 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1066 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1023 ASSERT_NE(nullptr, prefs); 1067 ASSERT_NE(nullptr, prefs);
1024 1068
1025 app_instance()->RefreshAppList(); 1069 app_instance()->RefreshAppList();
1026 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 1070 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
1027 fake_apps().begin(), fake_apps().begin() + 1)); 1071 fake_apps().begin(), fake_apps().begin() + 1));
1028 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 1072 content::BrowserThread::GetBlockingPool()->FlushForTesting();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 app_instance()->shortcut_icon_requests().size()); 1125 app_instance()->shortcut_icon_requests().size());
1082 for (size_t i = initial_icon_request_count; 1126 for (size_t i = initial_icon_request_count;
1083 i < app_instance()->icon_requests().size(); ++i) { 1127 i < app_instance()->icon_requests().size(); ++i) {
1084 const auto& request = app_instance()->icon_requests()[i]; 1128 const auto& request = app_instance()->icon_requests()[i];
1085 EXPECT_TRUE(request->IsForApp(app)); 1129 EXPECT_TRUE(request->IsForApp(app));
1086 } 1130 }
1087 } 1131 }
1088 1132
1089 // If the cached icon file is corrupted, we expect send request to ARC for a new 1133 // If the cached icon file is corrupted, we expect send request to ARC for a new
1090 // icon. 1134 // icon.
1091 TEST_F(ArcAppModelBuilderTest, IconLoaderWithBadIcon) { 1135 TEST_P(ArcAppModelBuilderTest, IconLoaderWithBadIcon) {
1092 const arc::mojom::AppInfo& app = fake_apps()[0]; 1136 const arc::mojom::AppInfo& app = fake_apps()[0];
1093 const std::string app_id = ArcAppTest::GetAppId(app); 1137 const std::string app_id = ArcAppTest::GetAppId(app);
1094 1138
1095 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1139 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1096 ASSERT_NE(nullptr, prefs); 1140 ASSERT_NE(nullptr, prefs);
1097 1141
1098 app_instance()->RefreshAppList(); 1142 app_instance()->RefreshAppList();
1099 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 1143 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
1100 fake_apps().begin(), fake_apps().begin() + 1)); 1144 fake_apps().begin(), fake_apps().begin() + 1));
1101 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 1145 content::BrowserThread::GetBlockingPool()->FlushForTesting();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 EXPECT_TRUE(app_instance()->icon_requests().size() > 1182 EXPECT_TRUE(app_instance()->icon_requests().size() >
1139 initial_icon_request_count); 1183 initial_icon_request_count);
1140 for (size_t i = initial_icon_request_count; 1184 for (size_t i = initial_icon_request_count;
1141 i < app_instance()->icon_requests().size(); ++i) { 1185 i < app_instance()->icon_requests().size(); ++i) {
1142 const auto& request = app_instance()->icon_requests()[i]; 1186 const auto& request = app_instance()->icon_requests()[i];
1143 EXPECT_TRUE(request->IsForApp(app)); 1187 EXPECT_TRUE(request->IsForApp(app));
1144 } 1188 }
1145 } 1189 }
1146 1190
1147 // TODO(crbug.com/628425) -- reenable once this test is less flaky. 1191 // TODO(crbug.com/628425) -- reenable once this test is less flaky.
1148 TEST_F(ArcAppModelBuilderTest, DISABLED_IconLoader) { 1192 TEST_P(ArcAppModelBuilderTest, DISABLED_IconLoader) {
1149 const arc::mojom::AppInfo& app = fake_apps()[0]; 1193 const arc::mojom::AppInfo& app = fake_apps()[0];
1150 const std::string app_id = ArcAppTest::GetAppId(app); 1194 const std::string app_id = ArcAppTest::GetAppId(app);
1151 1195
1152 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1196 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1153 ASSERT_NE(nullptr, prefs); 1197 ASSERT_NE(nullptr, prefs);
1154 1198
1155 app_instance()->RefreshAppList(); 1199 app_instance()->RefreshAppList();
1156 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( 1200 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>(
1157 fake_apps().begin(), fake_apps().begin() + 1)); 1201 fake_apps().begin(), fake_apps().begin() + 1));
1158 1202
(...skipping 21 matching lines...) Expand all
1180 app_item->icon().GetRepresentation(scale); 1224 app_item->icon().GetRepresentation(scale);
1181 WaitForIconReady(prefs, app_id, scale_factor); 1225 WaitForIconReady(prefs, app_id, scale_factor);
1182 } 1226 }
1183 1227
1184 // Validate loaded image. 1228 // Validate loaded image.
1185 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); 1229 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt());
1186 EXPECT_EQ(app_id, delegate.app_id()); 1230 EXPECT_EQ(app_id, delegate.app_id());
1187 ValidateIcon(delegate.image()); 1231 ValidateIcon(delegate.image());
1188 } 1232 }
1189 1233
1190 TEST_F(ArcAppModelBuilderTest, AppLauncher) { 1234 TEST_P(ArcAppModelBuilderTest, AppLauncher) {
1191 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); 1235 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile());
1192 ASSERT_NE(nullptr, prefs); 1236 ASSERT_NE(nullptr, prefs);
1193 1237
1194 // App1 is called in deferred mode, after refreshing apps. 1238 // App1 is called in deferred mode, after refreshing apps.
1195 // App2 is never called since app is not avaialble. 1239 // App2 is never called since app is not avaialble.
1196 // App3 is never called immediately because app is available already. 1240 // App3 is never called immediately because app is available already.
1197 const arc::mojom::AppInfo& app1 = fake_apps()[0]; 1241 const arc::mojom::AppInfo& app1 = fake_apps()[0];
1198 const arc::mojom::AppInfo& app2 = fake_apps()[1]; 1242 const arc::mojom::AppInfo& app2 = fake_apps()[1];
1199 const arc::mojom::AppInfo& app3 = fake_apps()[2]; 1243 const arc::mojom::AppInfo& app3 = fake_apps()[2];
1200 const std::string id1 = ArcAppTest::GetAppId(app1); 1244 const std::string id1 = ArcAppTest::GetAppId(app1);
(...skipping 24 matching lines...) Expand all
1225 EXPECT_TRUE(prefs->HasObserver(&launcher3)); 1269 EXPECT_TRUE(prefs->HasObserver(&launcher3));
1226 1270
1227 ArcAppLauncher launcher2(profile(), id2, true); 1271 ArcAppLauncher launcher2(profile(), id2, true);
1228 EXPECT_TRUE(launcher2.app_launched()); 1272 EXPECT_TRUE(launcher2.app_launched());
1229 EXPECT_FALSE(prefs->HasObserver(&launcher2)); 1273 EXPECT_FALSE(prefs->HasObserver(&launcher2));
1230 ASSERT_EQ(2u, app_instance()->launch_requests().size()); 1274 ASSERT_EQ(2u, app_instance()->launch_requests().size());
1231 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2)); 1275 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2));
1232 } 1276 }
1233 1277
1234 // Validates an app that have no launchable flag. 1278 // Validates an app that have no launchable flag.
1235 TEST_F(ArcAppModelBuilderTest, NonLaunchableApp) { 1279 TEST_P(ArcAppModelBuilderTest, NonLaunchableApp) {
1236 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1280 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1237 ASSERT_NE(nullptr, prefs); 1281 ASSERT_NE(nullptr, prefs);
1238 1282
1239 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); 1283 ValidateHaveApps(std::vector<arc::mojom::AppInfo>());
1240 app_instance()->RefreshAppList(); 1284 app_instance()->RefreshAppList();
1241 // Send all except first. 1285 // Send all except first.
1242 std::vector<arc::mojom::AppInfo> apps(fake_apps().begin() + 1, 1286 std::vector<arc::mojom::AppInfo> apps(fake_apps().begin() + 1,
1243 fake_apps().end()); 1287 fake_apps().end());
1244 app_instance()->SendRefreshAppList(apps); 1288 app_instance()->SendRefreshAppList(apps);
1245 ValidateHaveApps(apps); 1289 ValidateHaveApps(apps);
1246 1290
1247 const std::string app_id = ArcAppTest::GetAppId(fake_apps()[0]); 1291 const std::string app_id = ArcAppTest::GetAppId(fake_apps()[0]);
1248 1292
1249 EXPECT_FALSE(prefs->IsRegistered(app_id)); 1293 EXPECT_FALSE(prefs->IsRegistered(app_id));
1250 EXPECT_FALSE(FindArcItem(app_id)); 1294 EXPECT_FALSE(FindArcItem(app_id));
1251 app_instance()->SendTaskCreated(0, fake_apps()[0], std::string()); 1295 app_instance()->SendTaskCreated(0, fake_apps()[0], std::string());
1252 // App should not appear now in the model but should be registered. 1296 // App should not appear now in the model but should be registered.
1253 EXPECT_FALSE(FindArcItem(app_id)); 1297 EXPECT_FALSE(FindArcItem(app_id));
1254 EXPECT_TRUE(prefs->IsRegistered(app_id)); 1298 EXPECT_TRUE(prefs->IsRegistered(app_id));
1255 } 1299 }
1256 1300
1257 TEST_F(ArcAppModelBuilderTest, ArcAppsOnPackageUpdated) { 1301 TEST_P(ArcAppModelBuilderTest, ArcAppsOnPackageUpdated) {
1258 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1302 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1259 ASSERT_NE(nullptr, prefs); 1303 ASSERT_NE(nullptr, prefs);
1260 1304
1261 std::vector<arc::mojom::AppInfo> apps = fake_apps(); 1305 std::vector<arc::mojom::AppInfo> apps = fake_apps();
1262 ASSERT_GE(3u, apps.size()); 1306 ASSERT_GE(3u, apps.size());
1263 apps[0].package_name = apps[2].package_name; 1307 apps[0].package_name = apps[2].package_name;
1264 apps[1].package_name = apps[2].package_name; 1308 apps[1].package_name = apps[2].package_name;
1265 // Second app should be preserved after update. 1309 // Second app should be preserved after update.
1266 std::vector<arc::mojom::AppInfo> apps1(apps.begin(), apps.begin() + 2); 1310 std::vector<arc::mojom::AppInfo> apps1(apps.begin(), apps.begin() + 2);
1267 std::vector<arc::mojom::AppInfo> apps2(apps.begin() + 1, apps.begin() + 3); 1311 std::vector<arc::mojom::AppInfo> apps2(apps.begin() + 1, apps.begin() + 3);
(...skipping 12 matching lines...) Expand all
1280 1324
1281 app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps2); 1325 app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps2);
1282 ValidateHaveApps(apps2); 1326 ValidateHaveApps(apps2);
1283 1327
1284 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_after = 1328 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_after =
1285 prefs->GetApp(app_id); 1329 prefs->GetApp(app_id);
1286 ASSERT_TRUE(app_info_after); 1330 ASSERT_TRUE(app_info_after);
1287 EXPECT_EQ(now_time, app_info_after->last_launch_time); 1331 EXPECT_EQ(now_time, app_info_after->last_launch_time);
1288 } 1332 }
1289 1333
1290 TEST_F(ArcDefaulAppTest, DefaultApps) { 1334 TEST_P(ArcDefaulAppTest, DefaultApps) {
1291 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1335 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1292 ASSERT_NE(nullptr, prefs); 1336 ASSERT_NE(nullptr, prefs);
1293 1337
1294 ValidateHaveApps(fake_default_apps()); 1338 ValidateHaveApps(fake_default_apps());
1295 1339
1296 // Start normal apps. We should have apps from 2 subsets. 1340 // Start normal apps. We should have apps from 2 subsets.
1297 app_instance()->RefreshAppList(); 1341 app_instance()->RefreshAppList();
1298 app_instance()->SendRefreshAppList(fake_apps()); 1342 app_instance()->SendRefreshAppList(fake_apps());
1299 1343
1300 std::vector<arc::mojom::AppInfo> all_apps = fake_default_apps(); 1344 std::vector<arc::mojom::AppInfo> all_apps = fake_default_apps();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 fake_default_apps()[0].package_name, package_apps); 1403 fake_default_apps()[0].package_name, package_apps);
1360 ValidateHaveApps(fake_default_apps()); 1404 ValidateHaveApps(fake_default_apps());
1361 1405
1362 // Validate that OEM state is preserved. 1406 // Validate that OEM state is preserved.
1363 for (const auto& default_app : fake_default_apps()) { 1407 for (const auto& default_app : fake_default_apps()) {
1364 const std::string app_id = ArcAppTest::GetAppId(default_app); 1408 const std::string app_id = ArcAppTest::GetAppId(default_app);
1365 EXPECT_EQ(oem_states[app_id], prefs->IsOem(app_id)); 1409 EXPECT_EQ(oem_states[app_id], prefs->IsOem(app_id));
1366 } 1410 }
1367 } 1411 }
1368 1412
1369 TEST_F(ArcDefaulAppTest, DefaultAppsNotAvailable) { 1413 TEST_P(ArcDefaulAppTest, DefaultAppsNotAvailable) {
1370 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1414 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1371 ASSERT_NE(nullptr, prefs); 1415 ASSERT_NE(nullptr, prefs);
1372 1416
1373 ValidateHaveApps(fake_default_apps()); 1417 ValidateHaveApps(fake_default_apps());
1374 1418
1375 const std::vector<arc::mojom::AppInfo> empty_app_list; 1419 const std::vector<arc::mojom::AppInfo> empty_app_list;
1376 1420
1377 app_instance()->RefreshAppList(); 1421 app_instance()->RefreshAppList();
1378 app_instance()->SendRefreshAppList(empty_app_list); 1422 app_instance()->SendRefreshAppList(empty_app_list);
1379 1423
1380 ValidateHaveApps(fake_default_apps()); 1424 ValidateHaveApps(fake_default_apps());
1381 1425
1382 prefs->SimulateDefaultAppAvailabilityTimeoutForTesting(); 1426 prefs->SimulateDefaultAppAvailabilityTimeoutForTesting();
1383 1427
1384 // No default app installation and already installed packages. 1428 // No default app installation and already installed packages.
1385 ValidateHaveApps(empty_app_list); 1429 ValidateHaveApps(empty_app_list);
1386 } 1430 }
1387 1431
1388 TEST_F(ArcDefaulAppTest, DefaultAppsInstallation) { 1432 TEST_P(ArcDefaulAppTest, DefaultAppsInstallation) {
1389 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1433 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1390 ASSERT_NE(nullptr, prefs); 1434 ASSERT_NE(nullptr, prefs);
1391 1435
1392 const std::vector<arc::mojom::AppInfo> empty_app_list; 1436 const std::vector<arc::mojom::AppInfo> empty_app_list;
1393 1437
1394 ValidateHaveApps(fake_default_apps()); 1438 ValidateHaveApps(fake_default_apps());
1395 1439
1396 app_instance()->RefreshAppList(); 1440 app_instance()->RefreshAppList();
1397 app_instance()->SendRefreshAppList(empty_app_list); 1441 app_instance()->SendRefreshAppList(empty_app_list);
1398 1442
(...skipping 19 matching lines...) Expand all
1418 // completed. 1462 // completed.
1419 ValidateHaveApps(fake_default_apps()); 1463 ValidateHaveApps(fake_default_apps());
1420 1464
1421 // Last default app installation failed. 1465 // Last default app installation failed.
1422 app_instance()->SendInstallationFinished(app_last.package_name, false); 1466 app_instance()->SendInstallationFinished(app_last.package_name, false);
1423 1467
1424 // We should have all default apps except last. 1468 // We should have all default apps except last.
1425 ValidateHaveApps(available_apps); 1469 ValidateHaveApps(available_apps);
1426 } 1470 }
1427 1471
1428 TEST_F(ArcDefaulAppForManagedUserTest, DefaultAppsForManagedUser) { 1472 TEST_P(ArcDefaulAppForManagedUserTest, DefaultAppsForManagedUser) {
1429 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(profile_.get()); 1473 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(profile_.get());
1430 ASSERT_TRUE(prefs); 1474 ASSERT_TRUE(prefs);
1431 1475
1432 // There is no default app for managed users except Play Store 1476 // There is no default app for managed users except Play Store
1433 for (const auto& app : fake_default_apps()) { 1477 for (const auto& app : fake_default_apps()) {
1434 const std::string app_id = ArcAppTest::GetAppId(app); 1478 const std::string app_id = ArcAppTest::GetAppId(app);
1435 EXPECT_FALSE(prefs->IsRegistered(app_id)); 1479 EXPECT_FALSE(prefs->IsRegistered(app_id));
1436 EXPECT_FALSE(prefs->GetApp(app_id)); 1480 EXPECT_FALSE(prefs->GetApp(app_id));
1437 } 1481 }
1482
1483 // PlayStor exists for managed and enabled state.
1484 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
1485 prefs->GetApp(arc::kPlayStoreAppId);
1486 if (IsEnabledByPolicy()) {
1487 ASSERT_TRUE(app_info);
1488 EXPECT_FALSE(app_info->ready);
1489 } else {
1490 EXPECT_FALSE(prefs->IsRegistered(arc::kPlayStoreAppId));
1491 EXPECT_FALSE(app_info);
1492 }
1438 } 1493 }
1494
1495 INSTANTIATE_TEST_CASE_P(,
1496 ArcAppModelBuilderTest,
1497 ::testing::ValuesIn(kUnmanagedArcStates));
1498 INSTANTIATE_TEST_CASE_P(,
1499 ArcDefaulAppTest,
1500 ::testing::ValuesIn(kUnmanagedArcStates));
1501 INSTANTIATE_TEST_CASE_P(,
1502 ArcDefaulAppForManagedUserTest,
1503 ::testing::ValuesIn(kManagedArcStates));
1504 INSTANTIATE_TEST_CASE_P(,
1505 ArcPlayStoreAppTest,
1506 ::testing::ValuesIn(kUnmanagedArcStates));
1507 INSTANTIATE_TEST_CASE_P(,
1508 ArcAppModelBuilderRecreate,
1509 ::testing::ValuesIn(kUnmanagedArcStates));
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc ('k') | chrome/browser/ui/app_list/arc/arc_default_app_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698