| OLD | NEW |
| 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 <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.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/values.h" |
| 20 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 21 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/ui/app_list/app_list_test_util.h" | 22 #include "chrome/browser/ui/app_list/app_list_test_util.h" |
| 20 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" | 23 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" |
| 21 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" | 24 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" |
| 22 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" | 25 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" |
| 23 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" | 26 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" |
| 24 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 27 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 25 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h" | 28 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h" |
| 26 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" | 29 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" |
| 27 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 30 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 28 #include "chrome/browser/ui/app_list/arc/arc_default_app_list.h" | 31 #include "chrome/browser/ui/app_list/arc/arc_default_app_list.h" |
| 29 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" | 32 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" |
| 30 #include "chrome/test/base/testing_profile.h" | 33 #include "chrome/test/base/testing_profile.h" |
| 31 #include "components/arc/test/fake_app_instance.h" | 34 #include "components/arc/test/fake_app_instance.h" |
| 32 #include "components/arc/test/fake_arc_bridge_service.h" | 35 #include "components/arc/test/fake_arc_bridge_service.h" |
| 33 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 37 #include "extensions/browser/extension_system.h" |
| 38 #include "extensions/common/extension.h" |
| 39 #include "extensions/common/manifest_constants.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "ui/app_list/app_list_constants.h" | 41 #include "ui/app_list/app_list_constants.h" |
| 36 #include "ui/app_list/app_list_model.h" | 42 #include "ui/app_list/app_list_model.h" |
| 37 #include "ui/gfx/geometry/safe_integer_conversions.h" | 43 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 38 #include "ui/gfx/image/image_skia.h" | 44 #include "ui/gfx/image/image_skia.h" |
| 39 | 45 |
| 40 namespace { | 46 namespace { |
| 41 | 47 |
| 42 constexpr char kTestPackageName[] = "fake.package.name2"; | 48 constexpr char kTestPackageName[] = "fake.package.name2"; |
| 43 | 49 |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 343 |
| 338 void SetUp() override { | 344 void SetUp() override { |
| 339 ArcDefaultAppList::UseTestAppsDirectory(); | 345 ArcDefaultAppList::UseTestAppsDirectory(); |
| 340 ArcAppModelBuilderTest::SetUp(); | 346 ArcAppModelBuilderTest::SetUp(); |
| 341 } | 347 } |
| 342 | 348 |
| 343 private: | 349 private: |
| 344 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); | 350 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); |
| 345 }; | 351 }; |
| 346 | 352 |
| 353 class ArcPlayStoreAppTest : public ArcAppModelBuilderTest { |
| 354 public: |
| 355 ArcPlayStoreAppTest() {} |
| 356 ~ArcPlayStoreAppTest() override {} |
| 357 |
| 358 |
| 359 void SetUp() override { |
| 360 AppListTestBase::SetUp(); |
| 361 CreateArcHost(); |
| 362 arc_test()->SetUp(profile_.get()); |
| 363 CreateBuilder(); |
| 364 } |
| 365 |
| 366 private: |
| 367 void CreateArcHost() { |
| 368 base::DictionaryValue manifest; |
| 369 manifest.SetString(extensions::manifest_keys::kName, |
| 370 "Play Store"); |
| 371 manifest.SetString(extensions::manifest_keys::kVersion, "1"); |
| 372 manifest.SetString(extensions::manifest_keys::kDescription, |
| 373 "Play Store for testing"); |
| 374 |
| 375 std::string error; |
| 376 arc_support_host_ = extensions::Extension::Create( |
| 377 base::FilePath(), |
| 378 extensions::Manifest::UNPACKED, |
| 379 manifest, extensions::Extension::NO_FLAGS, |
| 380 ArcSupportHost::kHostAppId, &error); |
| 381 |
| 382 ExtensionService* extension_service = |
| 383 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); |
| 384 extension_service->AddExtension(arc_support_host_.get()); |
| 385 } |
| 386 |
| 387 scoped_refptr<extensions::Extension> arc_support_host_; |
| 388 |
| 389 DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreAppTest); |
| 390 }; |
| 391 |
| 392 |
| 347 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { | 393 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { |
| 348 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); | 394 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); |
| 349 app_instance()->SendRefreshPackageList(fake_packages()); | 395 app_instance()->SendRefreshPackageList(fake_packages()); |
| 350 ValidateHavePackages(fake_packages()); | 396 ValidateHavePackages(fake_packages()); |
| 351 | 397 |
| 352 arc::mojom::ArcPackageInfo package; | 398 arc::mojom::ArcPackageInfo package; |
| 353 package.package_name = kTestPackageName; | 399 package.package_name = kTestPackageName; |
| 354 package.package_version = 2; | 400 package.package_version = 2; |
| 355 package.last_backup_android_id = 2; | 401 package.last_backup_android_id = 2; |
| 356 package.last_backup_time = 2; | 402 package.last_backup_time = 2; |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 base::Time time_before = base::Time::Now(); | 880 base::Time time_before = base::Time::Now(); |
| 835 arc::LaunchApp(profile(), id2); | 881 arc::LaunchApp(profile(), id2); |
| 836 base::Time time_after = base::Time::Now(); | 882 base::Time time_after = base::Time::Now(); |
| 837 | 883 |
| 838 app_info = prefs->GetApp(id2); | 884 app_info = prefs->GetApp(id2); |
| 839 ASSERT_NE(nullptr, app_info.get()); | 885 ASSERT_NE(nullptr, app_info.get()); |
| 840 ASSERT_LE(time_before, app_info->last_launch_time); | 886 ASSERT_LE(time_before, app_info->last_launch_time); |
| 841 ASSERT_GE(time_after, app_info->last_launch_time); | 887 ASSERT_GE(time_after, app_info->last_launch_time); |
| 842 } | 888 } |
| 843 | 889 |
| 844 TEST_F(ArcAppModelBuilderTest, IconLoader) { | 890 TEST_F(ArcPlayStoreAppTest, PlayStore) { |
| 891 // Make sure PlayStore is available. |
| 892 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 893 |
| 894 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 895 ASSERT_TRUE(prefs); |
| 896 |
| 897 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp( |
| 898 arc::kPlayStoreAppId); |
| 899 ASSERT_TRUE(app_info); |
| 900 EXPECT_FALSE(app_info->ready); |
| 901 |
| 902 arc::mojom::AppInfo app; |
| 903 std::vector<arc::mojom::AppInfo> apps; |
| 904 app.name = "Play Store"; |
| 905 app.package_name = arc::kPlayStorePackage; |
| 906 app.activity = arc::kPlayStoreActivity; |
| 907 app.sticky = false; |
| 908 apps.push_back(app); |
| 909 |
| 910 app_instance()->RefreshAppList(); |
| 911 app_instance()->SendRefreshAppList(apps); |
| 912 |
| 913 app_info = prefs->GetApp(arc::kPlayStoreAppId); |
| 914 ASSERT_TRUE(app_info); |
| 915 EXPECT_TRUE(app_info->ready); |
| 916 |
| 917 arc_test()->arc_auth_service()->DisableArc(); |
| 918 |
| 919 app_info = prefs->GetApp(arc::kPlayStoreAppId); |
| 920 ASSERT_TRUE(app_info); |
| 921 EXPECT_FALSE(app_info->ready); |
| 922 |
| 923 arc::LaunchApp(profile(), arc::kPlayStoreAppId); |
| 924 EXPECT_TRUE(arc_test()->arc_auth_service()->IsArcEnabled()); |
| 925 } |
| 926 |
| 927 // TODO(crbug.com/628425) -- reenable once this test is less flaky. |
| 928 TEST_F(ArcAppModelBuilderTest, DISABLED_IconLoader) { |
| 845 // Validating decoded content does not fit well for unit tests. | 929 // Validating decoded content does not fit well for unit tests. |
| 846 ArcAppIcon::DisableSafeDecodingForTesting(); | 930 ArcAppIcon::DisableSafeDecodingForTesting(); |
| 847 | |
| 848 const arc::mojom::AppInfo& app = fake_apps()[0]; | 931 const arc::mojom::AppInfo& app = fake_apps()[0]; |
| 849 const std::string app_id = ArcAppTest::GetAppId(app); | 932 const std::string app_id = ArcAppTest::GetAppId(app); |
| 850 | 933 |
| 851 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 934 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 852 ASSERT_NE(nullptr, prefs); | 935 ASSERT_NE(nullptr, prefs); |
| 853 | 936 |
| 854 app_instance()->RefreshAppList(); | 937 app_instance()->RefreshAppList(); |
| 855 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( | 938 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( |
| 856 fake_apps().begin(), fake_apps().begin() + 1)); | 939 fake_apps().begin(), fake_apps().begin() + 1)); |
| 857 | 940 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 app_instance()->SendPackageUninstalled(all_apps[0].package_name); | 1114 app_instance()->SendPackageUninstalled(all_apps[0].package_name); |
| 1032 all_apps.erase(all_apps.begin()); | 1115 all_apps.erase(all_apps.begin()); |
| 1033 ValidateHaveApps(all_apps); | 1116 ValidateHaveApps(all_apps); |
| 1034 | 1117 |
| 1035 // OptOut and default apps should exist minus first. | 1118 // OptOut and default apps should exist minus first. |
| 1036 arc_test()->arc_auth_service()->DisableArc(); | 1119 arc_test()->arc_auth_service()->DisableArc(); |
| 1037 all_apps = fake_default_apps(); | 1120 all_apps = fake_default_apps(); |
| 1038 all_apps.erase(all_apps.begin()); | 1121 all_apps.erase(all_apps.begin()); |
| 1039 ValidateHaveApps(all_apps); | 1122 ValidateHaveApps(all_apps); |
| 1040 } | 1123 } |
| OLD | NEW |