| 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 <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/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 20 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 21 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
| 22 #include "chrome/browser/policy/profile_policy_connector.h" | 22 #include "chrome/browser/policy/profile_policy_connector.h" |
| 23 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 23 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 24 #include "chrome/browser/ui/app_list/app_list_test_util.h" | 24 #include "chrome/browser/ui/app_list/app_list_test_util.h" |
| 25 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" | 25 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" |
| 26 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" | 26 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" |
| 27 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" | 27 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" |
| 28 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" | 28 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" |
| 29 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 29 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 30 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" |
| 30 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h" | 31 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h" |
| 31 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" | 32 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" |
| 32 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 33 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 33 #include "chrome/browser/ui/app_list/arc/arc_default_app_list.h" | 34 #include "chrome/browser/ui/app_list/arc/arc_default_app_list.h" |
| 35 #include "chrome/browser/ui/app_list/arc/arc_package_syncable_service_factory.h" |
| 34 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" | 36 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" |
| 35 #include "chrome/test/base/testing_profile.h" | 37 #include "chrome/test/base/testing_profile.h" |
| 36 #include "components/arc/test/fake_app_instance.h" | 38 #include "components/arc/test/fake_app_instance.h" |
| 37 #include "components/arc/test/fake_arc_bridge_service.h" | 39 #include "components/arc/test/fake_arc_bridge_service.h" |
| 38 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 39 #include "extensions/browser/extension_system.h" | 41 #include "extensions/browser/extension_system.h" |
| 40 #include "extensions/common/extension.h" | 42 #include "extensions/common/extension.h" |
| 41 #include "extensions/common/manifest_constants.h" | 43 #include "extensions/common/manifest_constants.h" |
| 42 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 43 #include "ui/app_list/app_list_constants.h" | 45 #include "ui/app_list/app_list_constants.h" |
| 44 #include "ui/app_list/app_list_model.h" | 46 #include "ui/app_list/app_list_model.h" |
| 45 #include "ui/gfx/geometry/safe_integer_conversions.h" | 47 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 46 #include "ui/gfx/image/image_skia.h" | 48 #include "ui/gfx/image/image_skia.h" |
| 47 | 49 |
| 48 namespace { | 50 namespace { |
| 49 | 51 |
| 50 constexpr char kTestPackageName[] = "fake.package.name2"; | 52 constexpr char kTestPackageName[] = "fake.package.name2"; |
| 51 | 53 |
| 52 class FakeAppIconLoaderDelegate : public AppIconLoaderDelegate { | 54 class FakeAppIconLoaderDelegate : public AppIconLoaderDelegate { |
| 53 public: | 55 public: |
| 54 FakeAppIconLoaderDelegate() {} | 56 FakeAppIconLoaderDelegate() = default; |
| 55 ~FakeAppIconLoaderDelegate() override {} | 57 ~FakeAppIconLoaderDelegate() override = default; |
| 56 | 58 |
| 57 void OnAppImageUpdated(const std::string& app_id, | 59 void OnAppImageUpdated(const std::string& app_id, |
| 58 const gfx::ImageSkia& image) override { | 60 const gfx::ImageSkia& image) override { |
| 59 app_id_ = app_id; | 61 app_id_ = app_id; |
| 60 image_ = image; | 62 image_ = image; |
| 61 ++update_image_cnt_; | 63 ++update_image_cnt_; |
| 62 } | 64 } |
| 63 | 65 |
| 64 size_t update_image_cnt() const { return update_image_cnt_; } | 66 size_t update_image_cnt() const { return update_image_cnt_; } |
| 65 | 67 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 84 do { | 86 do { |
| 85 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 87 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 86 base::RunLoop().RunUntilIdle(); | 88 base::RunLoop().RunUntilIdle(); |
| 87 } while (!base::PathExists(icon_path)); | 89 } while (!base::PathExists(icon_path)); |
| 88 } | 90 } |
| 89 | 91 |
| 90 } // namespace | 92 } // namespace |
| 91 | 93 |
| 92 class ArcAppModelBuilderTest : public AppListTestBase { | 94 class ArcAppModelBuilderTest : public AppListTestBase { |
| 93 public: | 95 public: |
| 94 ArcAppModelBuilderTest() {} | 96 ArcAppModelBuilderTest() = default; |
| 95 ~ArcAppModelBuilderTest() override { | 97 ~ArcAppModelBuilderTest() override { |
| 96 // Release profile file in order to keep right sequence. | 98 // Release profile file in order to keep right sequence. |
| 97 profile_.reset(); | 99 profile_.reset(); |
| 98 } | 100 } |
| 99 | 101 |
| 100 void SetUp() override { | 102 void SetUp() override { |
| 101 AppListTestBase::SetUp(); | 103 AppListTestBase::SetUp(); |
| 102 OnBeforeArcTestSetup(); | 104 OnBeforeArcTestSetup(); |
| 103 arc_test_.SetUp(profile_.get()); | 105 arc_test_.SetUp(profile_.get()); |
| 104 CreateBuilder(); | 106 CreateBuilder(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 break; | 158 break; |
| 157 } | 159 } |
| 158 } | 160 } |
| 159 } | 161 } |
| 160 EXPECT_NE(nullptr, arc_item); | 162 EXPECT_NE(nullptr, arc_item); |
| 161 return arc_item; | 163 return arc_item; |
| 162 } | 164 } |
| 163 | 165 |
| 164 ArcAppItem* FindArcItem(const std::string& id) const { | 166 ArcAppItem* FindArcItem(const std::string& id) const { |
| 165 const size_t count = GetArcItemCount(); | 167 const size_t count = GetArcItemCount(); |
| 168 ArcAppItem* found_item = nullptr; |
| 166 for (size_t i = 0; i < count; ++i) { | 169 for (size_t i = 0; i < count; ++i) { |
| 167 ArcAppItem* item = GetArcItem(i); | 170 ArcAppItem* item = GetArcItem(i); |
| 168 if (item && item->id() == id) | 171 if (item && item->id() == id) { |
| 169 return item; | 172 DCHECK(!found_item); |
| 173 found_item = item; |
| 174 } |
| 170 } | 175 } |
| 171 return nullptr; | 176 return found_item; |
| 172 } | 177 } |
| 173 | 178 |
| 174 // Validate that prefs and model have right content. | 179 // Validate that prefs and model have right content. |
| 175 void ValidateHaveApps(const std::vector<arc::mojom::AppInfo> apps) { | 180 void ValidateHaveApps(const std::vector<arc::mojom::AppInfo> apps) { |
| 176 ValidateHaveAppsAndShortcuts(apps, std::vector<arc::mojom::ShortcutInfo>()); | 181 ValidateHaveAppsAndShortcuts(apps, std::vector<arc::mojom::ShortcutInfo>()); |
| 177 } | 182 } |
| 178 | 183 |
| 179 void ValidateHaveShortcuts( | 184 void ValidateHaveShortcuts( |
| 180 const std::vector<arc::mojom::ShortcutInfo> shortcuts) { | 185 const std::vector<arc::mojom::ShortcutInfo> shortcuts) { |
| 181 ValidateHaveAppsAndShortcuts(std::vector<arc::mojom::AppInfo>(), shortcuts); | 186 ValidateHaveAppsAndShortcuts(std::vector<arc::mojom::AppInfo>(), shortcuts); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 ArcAppTest arc_test_; | 357 ArcAppTest arc_test_; |
| 353 std::unique_ptr<app_list::AppListModel> model_; | 358 std::unique_ptr<app_list::AppListModel> model_; |
| 354 std::unique_ptr<test::TestAppListControllerDelegate> controller_; | 359 std::unique_ptr<test::TestAppListControllerDelegate> controller_; |
| 355 std::unique_ptr<ArcAppModelBuilder> builder_; | 360 std::unique_ptr<ArcAppModelBuilder> builder_; |
| 356 | 361 |
| 357 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); | 362 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); |
| 358 }; | 363 }; |
| 359 | 364 |
| 360 class ArcDefaulAppTest : public ArcAppModelBuilderTest { | 365 class ArcDefaulAppTest : public ArcAppModelBuilderTest { |
| 361 public: | 366 public: |
| 362 ArcDefaulAppTest() {} | 367 ArcDefaulAppTest() = default; |
| 363 ~ArcDefaulAppTest() override {} | 368 ~ArcDefaulAppTest() override = default; |
| 364 | 369 |
| 365 protected: | 370 protected: |
| 366 // ArcAppModelBuilderTest: | 371 // ArcAppModelBuilderTest: |
| 367 void OnBeforeArcTestSetup() override { | 372 void OnBeforeArcTestSetup() override { |
| 368 ArcDefaultAppList::UseTestAppsDirectory(); | 373 ArcDefaultAppList::UseTestAppsDirectory(); |
| 369 } | 374 } |
| 370 | 375 |
| 371 private: | 376 private: |
| 372 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); | 377 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); |
| 373 }; | 378 }; |
| 374 | 379 |
| 375 class ArcDefaulAppForManagedUserTest : public ArcDefaulAppTest { | 380 class ArcDefaulAppForManagedUserTest : public ArcDefaulAppTest { |
| 376 public: | 381 public: |
| 377 ArcDefaulAppForManagedUserTest() {} | 382 ArcDefaulAppForManagedUserTest() = default; |
| 378 ~ArcDefaulAppForManagedUserTest() override {} | 383 ~ArcDefaulAppForManagedUserTest() override = default; |
| 379 | 384 |
| 380 protected: | 385 protected: |
| 381 // ArcAppModelBuilderTest: | 386 // ArcAppModelBuilderTest: |
| 382 void OnBeforeArcTestSetup() override { | 387 void OnBeforeArcTestSetup() override { |
| 383 ArcDefaulAppTest::OnBeforeArcTestSetup(); | 388 ArcDefaulAppTest::OnBeforeArcTestSetup(); |
| 384 | 389 |
| 385 policy::ProfilePolicyConnector* const connector = | 390 policy::ProfilePolicyConnector* const connector = |
| 386 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | 391 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
| 387 profile()); | 392 profile()); |
| 388 connector->OverrideIsManagedForTesting(true); | 393 connector->OverrideIsManagedForTesting(true); |
| 389 } | 394 } |
| 390 | 395 |
| 391 private: | 396 private: |
| 392 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppForManagedUserTest); | 397 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppForManagedUserTest); |
| 393 }; | 398 }; |
| 394 | 399 |
| 395 class ArcPlayStoreAppTest : public ArcDefaulAppTest { | 400 class ArcPlayStoreAppTest : public ArcDefaulAppTest { |
| 396 public: | 401 public: |
| 397 ArcPlayStoreAppTest() {} | 402 ArcPlayStoreAppTest() = default; |
| 398 ~ArcPlayStoreAppTest() override {} | 403 ~ArcPlayStoreAppTest() override = default; |
| 399 | 404 |
| 400 protected: | 405 protected: |
| 401 // ArcAppModelBuilderTest: | 406 // ArcAppModelBuilderTest: |
| 402 void OnBeforeArcTestSetup() override { | 407 void OnBeforeArcTestSetup() override { |
| 403 ArcDefaulAppTest::OnBeforeArcTestSetup(); | 408 ArcDefaulAppTest::OnBeforeArcTestSetup(); |
| 404 | 409 |
| 405 base::DictionaryValue manifest; | 410 base::DictionaryValue manifest; |
| 406 manifest.SetString(extensions::manifest_keys::kName, | 411 manifest.SetString(extensions::manifest_keys::kName, |
| 407 "Play Store"); | 412 "Play Store"); |
| 408 manifest.SetString(extensions::manifest_keys::kVersion, "1"); | 413 manifest.SetString(extensions::manifest_keys::kVersion, "1"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 420 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); | 425 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); |
| 421 extension_service->AddExtension(arc_support_host_.get()); | 426 extension_service->AddExtension(arc_support_host_.get()); |
| 422 } | 427 } |
| 423 | 428 |
| 424 private: | 429 private: |
| 425 scoped_refptr<extensions::Extension> arc_support_host_; | 430 scoped_refptr<extensions::Extension> arc_support_host_; |
| 426 | 431 |
| 427 DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreAppTest); | 432 DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreAppTest); |
| 428 }; | 433 }; |
| 429 | 434 |
| 435 class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest { |
| 436 public: |
| 437 ArcAppModelBuilderRecreate() = default; |
| 438 ~ArcAppModelBuilderRecreate() override = default; |
| 439 |
| 440 protected: |
| 441 // ArcAppModelBuilderTest: |
| 442 void OnBeforeArcTestSetup() override { |
| 443 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( |
| 444 profile_.get(), nullptr); |
| 445 } |
| 446 |
| 447 private: |
| 448 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderRecreate); |
| 449 }; |
| 450 |
| 430 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { | 451 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { |
| 431 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); | 452 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); |
| 432 app_instance()->SendRefreshPackageList(fake_packages()); | 453 app_instance()->SendRefreshPackageList(fake_packages()); |
| 433 ValidateHavePackages(fake_packages()); | 454 ValidateHavePackages(fake_packages()); |
| 434 | 455 |
| 435 arc::mojom::ArcPackageInfo package; | 456 arc::mojom::ArcPackageInfo package; |
| 436 package.package_name = kTestPackageName; | 457 package.package_name = kTestPackageName; |
| 437 package.package_version = 2; | 458 package.package_version = 2; |
| 438 package.last_backup_android_id = 2; | 459 package.last_backup_android_id = 2; |
| 439 package.last_backup_time = 2; | 460 package.last_backup_time = 2; |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 base::Time time_before = base::Time::Now(); | 928 base::Time time_before = base::Time::Now(); |
| 908 arc::LaunchApp(profile(), id2); | 929 arc::LaunchApp(profile(), id2); |
| 909 base::Time time_after = base::Time::Now(); | 930 base::Time time_after = base::Time::Now(); |
| 910 | 931 |
| 911 app_info = prefs->GetApp(id2); | 932 app_info = prefs->GetApp(id2); |
| 912 ASSERT_NE(nullptr, app_info.get()); | 933 ASSERT_NE(nullptr, app_info.get()); |
| 913 ASSERT_LE(time_before, app_info->last_launch_time); | 934 ASSERT_LE(time_before, app_info->last_launch_time); |
| 914 ASSERT_GE(time_after, app_info->last_launch_time); | 935 ASSERT_GE(time_after, app_info->last_launch_time); |
| 915 } | 936 } |
| 916 | 937 |
| 938 // Validate that arc model contains expected elements on restart. |
| 939 TEST_F(ArcAppModelBuilderRecreate, AppModelRestart) { |
| 940 // No apps on initial start. |
| 941 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); |
| 942 |
| 943 // Send info about all fake apps except last. |
| 944 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(), |
| 945 fake_apps().end() - 1); |
| 946 app_instance()->RefreshAppList(); |
| 947 app_instance()->SendRefreshAppList(apps1); |
| 948 // Model has refreshed apps. |
| 949 ValidateHaveApps(apps1); |
| 950 EXPECT_EQ(apps1.size(), GetArcItemCount()); |
| 951 |
| 952 // Simulate restart. |
| 953 arc_test()->TearDown(); |
| 954 ResetBuilder(); |
| 955 |
| 956 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( |
| 957 profile_.get()); |
| 958 arc_test()->SetUp(profile_.get()); |
| 959 CreateBuilder(); |
| 960 |
| 961 // On restart new model contains last apps. |
| 962 ValidateHaveApps(apps1); |
| 963 EXPECT_EQ(apps1.size(), GetArcItemCount()); |
| 964 |
| 965 // Now refresh old apps with new one. |
| 966 app_instance()->RefreshAppList(); |
| 967 app_instance()->SendRefreshAppList(fake_apps()); |
| 968 ValidateHaveApps(fake_apps()); |
| 969 EXPECT_EQ(fake_apps().size(), GetArcItemCount()); |
| 970 } |
| 971 |
| 917 TEST_F(ArcPlayStoreAppTest, PlayStore) { | 972 TEST_F(ArcPlayStoreAppTest, PlayStore) { |
| 918 // Make sure PlayStore is available. | 973 // Make sure PlayStore is available. |
| 919 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 974 ASSERT_TRUE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 920 | 975 |
| 921 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 976 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 922 ASSERT_TRUE(prefs); | 977 ASSERT_TRUE(prefs); |
| 923 | 978 |
| 924 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp( | 979 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp( |
| 925 arc::kPlayStoreAppId); | 980 arc::kPlayStoreAppId); |
| 926 ASSERT_TRUE(app_info); | 981 ASSERT_TRUE(app_info); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(profile_.get()); | 1203 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1149 ASSERT_TRUE(prefs); | 1204 ASSERT_TRUE(prefs); |
| 1150 | 1205 |
| 1151 // There is no default app for managed users except Play Store | 1206 // There is no default app for managed users except Play Store |
| 1152 for (const auto& app : fake_default_apps()) { | 1207 for (const auto& app : fake_default_apps()) { |
| 1153 const std::string app_id = ArcAppTest::GetAppId(app); | 1208 const std::string app_id = ArcAppTest::GetAppId(app); |
| 1154 EXPECT_FALSE(prefs->IsRegistered(app_id)); | 1209 EXPECT_FALSE(prefs->IsRegistered(app_id)); |
| 1155 EXPECT_FALSE(prefs->GetApp(app_id)); | 1210 EXPECT_FALSE(prefs->GetApp(app_id)); |
| 1156 } | 1211 } |
| 1157 } | 1212 } |
| OLD | NEW |