| 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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 358 |
| 353 void SetUp() override { | 359 void SetUp() override { |
| 354 ArcDefaultAppList::UseTestAppsDirectory(); | 360 ArcDefaultAppList::UseTestAppsDirectory(); |
| 355 ArcAppModelBuilderTest::SetUp(); | 361 ArcAppModelBuilderTest::SetUp(); |
| 356 } | 362 } |
| 357 | 363 |
| 358 private: | 364 private: |
| 359 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); | 365 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); |
| 360 }; | 366 }; |
| 361 | 367 |
| 368 class ArcPlayStoreAppTest : public ArcAppModelBuilderTest { |
| 369 public: |
| 370 ArcPlayStoreAppTest() {} |
| 371 ~ArcPlayStoreAppTest() override {} |
| 372 |
| 373 |
| 374 void SetUp() override { |
| 375 AppListTestBase::SetUp(); |
| 376 CreateArcHost(); |
| 377 arc_test()->SetUp(profile_.get()); |
| 378 CreateBuilder(); |
| 379 } |
| 380 |
| 381 private: |
| 382 void CreateArcHost() { |
| 383 base::DictionaryValue manifest; |
| 384 manifest.SetString(extensions::manifest_keys::kName, |
| 385 "Play Store"); |
| 386 manifest.SetString(extensions::manifest_keys::kVersion, "1"); |
| 387 manifest.SetString(extensions::manifest_keys::kDescription, |
| 388 "Play Store for testing"); |
| 389 |
| 390 std::string error; |
| 391 arc_support_host_ = extensions::Extension::Create( |
| 392 base::FilePath(), |
| 393 extensions::Manifest::UNPACKED, |
| 394 manifest, extensions::Extension::NO_FLAGS, |
| 395 ArcSupportHost::kHostAppId, &error); |
| 396 |
| 397 ExtensionService* extension_service = |
| 398 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); |
| 399 extension_service->AddExtension(arc_support_host_.get()); |
| 400 } |
| 401 |
| 402 scoped_refptr<extensions::Extension> arc_support_host_; |
| 403 |
| 404 DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreAppTest); |
| 405 }; |
| 406 |
| 407 |
| 362 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { | 408 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { |
| 363 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); | 409 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); |
| 364 app_instance()->SendRefreshPackageList(fake_packages()); | 410 app_instance()->SendRefreshPackageList(fake_packages()); |
| 365 ValidateHavePackages(fake_packages()); | 411 ValidateHavePackages(fake_packages()); |
| 366 | 412 |
| 367 arc::mojom::ArcPackageInfo package; | 413 arc::mojom::ArcPackageInfo package; |
| 368 package.package_name = kTestPackageName; | 414 package.package_name = kTestPackageName; |
| 369 package.package_version = 2; | 415 package.package_version = 2; |
| 370 package.last_backup_android_id = 2; | 416 package.last_backup_android_id = 2; |
| 371 package.last_backup_time = 2; | 417 package.last_backup_time = 2; |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 base::Time time_before = base::Time::Now(); | 884 base::Time time_before = base::Time::Now(); |
| 839 arc::LaunchApp(profile(), id2); | 885 arc::LaunchApp(profile(), id2); |
| 840 base::Time time_after = base::Time::Now(); | 886 base::Time time_after = base::Time::Now(); |
| 841 | 887 |
| 842 app_info = prefs->GetApp(id2); | 888 app_info = prefs->GetApp(id2); |
| 843 ASSERT_NE(nullptr, app_info.get()); | 889 ASSERT_NE(nullptr, app_info.get()); |
| 844 ASSERT_LE(time_before, app_info->last_launch_time); | 890 ASSERT_LE(time_before, app_info->last_launch_time); |
| 845 ASSERT_GE(time_after, app_info->last_launch_time); | 891 ASSERT_GE(time_after, app_info->last_launch_time); |
| 846 } | 892 } |
| 847 | 893 |
| 894 TEST_F(ArcPlayStoreAppTest, PlayStore) { |
| 895 // Make sure PlayStore is available. |
| 896 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 897 |
| 898 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 899 ASSERT_TRUE(prefs); |
| 900 |
| 901 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp( |
| 902 arc::kPlayStoreAppId); |
| 903 ASSERT_TRUE(app_info); |
| 904 EXPECT_FALSE(app_info->ready); |
| 905 |
| 906 arc::mojom::AppInfo app; |
| 907 std::vector<arc::mojom::AppInfo> apps; |
| 908 app.name = "Play Store"; |
| 909 app.package_name = arc::kPlayStorePackage; |
| 910 app.activity = arc::kPlayStoreActivity; |
| 911 app.sticky = false; |
| 912 apps.push_back(app); |
| 913 |
| 914 app_instance()->RefreshAppList(); |
| 915 app_instance()->SendRefreshAppList(apps); |
| 916 |
| 917 app_info = prefs->GetApp(arc::kPlayStoreAppId); |
| 918 ASSERT_TRUE(app_info); |
| 919 EXPECT_TRUE(app_info->ready); |
| 920 |
| 921 arc_test()->arc_auth_service()->DisableArc(); |
| 922 |
| 923 app_info = prefs->GetApp(arc::kPlayStoreAppId); |
| 924 ASSERT_TRUE(app_info); |
| 925 EXPECT_FALSE(app_info->ready); |
| 926 |
| 927 arc::LaunchApp(profile(), arc::kPlayStoreAppId); |
| 928 EXPECT_TRUE(arc_test()->arc_auth_service()->IsArcEnabled()); |
| 929 } |
| 930 |
| 848 // TODO(crbug.com/628425) -- reenable once this test is less flaky. | 931 // TODO(crbug.com/628425) -- reenable once this test is less flaky. |
| 849 TEST_F(ArcAppModelBuilderTest, DISABLED_IconLoader) { | 932 TEST_F(ArcAppModelBuilderTest, DISABLED_IconLoader) { |
| 850 const arc::mojom::AppInfo& app = fake_apps()[0]; | 933 const arc::mojom::AppInfo& app = fake_apps()[0]; |
| 851 const std::string app_id = ArcAppTest::GetAppId(app); | 934 const std::string app_id = ArcAppTest::GetAppId(app); |
| 852 | 935 |
| 853 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 936 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 854 ASSERT_NE(nullptr, prefs); | 937 ASSERT_NE(nullptr, prefs); |
| 855 | 938 |
| 856 app_instance()->RefreshAppList(); | 939 app_instance()->RefreshAppList(); |
| 857 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( | 940 app_instance()->SendRefreshAppList(std::vector<arc::mojom::AppInfo>( |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 app_instance()->SendPackageUninstalled(all_apps[0].package_name); | 1113 app_instance()->SendPackageUninstalled(all_apps[0].package_name); |
| 1031 all_apps.erase(all_apps.begin()); | 1114 all_apps.erase(all_apps.begin()); |
| 1032 ValidateHaveApps(all_apps); | 1115 ValidateHaveApps(all_apps); |
| 1033 | 1116 |
| 1034 // OptOut and default apps should exist minus first. | 1117 // OptOut and default apps should exist minus first. |
| 1035 arc_test()->arc_auth_service()->DisableArc(); | 1118 arc_test()->arc_auth_service()->DisableArc(); |
| 1036 all_apps = fake_default_apps(); | 1119 all_apps = fake_default_apps(); |
| 1037 all_apps.erase(all_apps.begin()); | 1120 all_apps.erase(all_apps.begin()); |
| 1038 ValidateHaveApps(all_apps); | 1121 ValidateHaveApps(all_apps); |
| 1039 } | 1122 } |
| OLD | NEW |