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 "chrome/browser/ui/app_list/app_list_test_util.h" | 19 #include "chrome/browser/ui/app_list/app_list_test_util.h" |
20 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" | 20 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" |
21 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" | 21 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" |
22 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" | 22 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" |
23 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" | 23 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" |
24 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 24 #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" | 25 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h" |
26 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" | 26 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" |
27 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 27 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 28 #include "chrome/browser/ui/app_list/arc/arc_default_app_list.h" |
28 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" | 29 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" |
29 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
30 #include "components/arc/test/fake_app_instance.h" | 31 #include "components/arc/test/fake_app_instance.h" |
31 #include "components/arc/test/fake_arc_bridge_service.h" | 32 #include "components/arc/test/fake_arc_bridge_service.h" |
32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
34 #include "ui/app_list/app_list_constants.h" | 35 #include "ui/app_list/app_list_constants.h" |
35 #include "ui/app_list/app_list_model.h" | 36 #include "ui/app_list/app_list_model.h" |
36 #include "ui/gfx/geometry/safe_integer_conversions.h" | 37 #include "ui/gfx/geometry/safe_integer_conversions.h" |
37 #include "ui/gfx/image/image_skia.h" | 38 #include "ui/gfx/image/image_skia.h" |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 AppListControllerDelegate* controller() { return controller_.get(); } | 312 AppListControllerDelegate* controller() { return controller_.get(); } |
312 | 313 |
313 Profile* profile() { return profile_.get(); } | 314 Profile* profile() { return profile_.get(); } |
314 | 315 |
315 ArcAppTest* arc_test() { return &arc_test_; } | 316 ArcAppTest* arc_test() { return &arc_test_; } |
316 | 317 |
317 const std::vector<arc::mojom::AppInfo>& fake_apps() const { | 318 const std::vector<arc::mojom::AppInfo>& fake_apps() const { |
318 return arc_test_.fake_apps(); | 319 return arc_test_.fake_apps(); |
319 } | 320 } |
320 | 321 |
| 322 const std::vector<arc::mojom::AppInfo>& fake_default_apps() const { |
| 323 return arc_test_.fake_default_apps(); |
| 324 } |
| 325 |
321 const std::vector<arc::mojom::ArcPackageInfo>& fake_packages() const { | 326 const std::vector<arc::mojom::ArcPackageInfo>& fake_packages() const { |
322 return arc_test_.fake_packages(); | 327 return arc_test_.fake_packages(); |
323 } | 328 } |
324 | 329 |
325 const std::vector<arc::mojom::ShortcutInfo>& fake_shortcuts() const { | 330 const std::vector<arc::mojom::ShortcutInfo>& fake_shortcuts() const { |
326 return arc_test_.fake_shortcuts(); | 331 return arc_test_.fake_shortcuts(); |
327 } | 332 } |
328 | 333 |
329 arc::FakeAppInstance* app_instance() { | 334 arc::FakeAppInstance* app_instance() { |
330 return arc_test_.app_instance(); | 335 return arc_test_.app_instance(); |
331 } | 336 } |
332 | 337 |
333 private: | 338 private: |
334 ArcAppTest arc_test_; | 339 ArcAppTest arc_test_; |
335 std::unique_ptr<app_list::AppListModel> model_; | 340 std::unique_ptr<app_list::AppListModel> model_; |
336 std::unique_ptr<test::TestAppListControllerDelegate> controller_; | 341 std::unique_ptr<test::TestAppListControllerDelegate> controller_; |
337 std::unique_ptr<ArcAppModelBuilder> builder_; | 342 std::unique_ptr<ArcAppModelBuilder> builder_; |
338 | 343 |
339 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); | 344 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); |
340 }; | 345 }; |
341 | 346 |
| 347 class ArcDefaulAppTest : public ArcAppModelBuilderTest { |
| 348 public: |
| 349 ArcDefaulAppTest() {} |
| 350 ~ArcDefaulAppTest() override {} |
| 351 |
| 352 |
| 353 void SetUp() override { |
| 354 ArcDefaultAppList::UseTestAppsDirectory(); |
| 355 ArcAppModelBuilderTest::SetUp(); |
| 356 } |
| 357 |
| 358 private: |
| 359 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); |
| 360 }; |
| 361 |
342 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { | 362 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { |
343 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); | 363 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); |
344 app_instance()->SendRefreshPackageList(fake_packages()); | 364 app_instance()->SendRefreshPackageList(fake_packages()); |
345 ValidateHavePackages(fake_packages()); | 365 ValidateHavePackages(fake_packages()); |
346 | 366 |
347 arc::mojom::ArcPackageInfo package; | 367 arc::mojom::ArcPackageInfo package; |
348 package.package_name = kTestPackageName; | 368 package.package_name = kTestPackageName; |
349 package.package_version = 2; | 369 package.package_version = 2; |
350 package.last_backup_android_id = 2; | 370 package.last_backup_android_id = 2; |
351 package.last_backup_time = 2; | 371 package.last_backup_time = 2; |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 EXPECT_EQ(now_time, app_info_before->last_launch_time); | 980 EXPECT_EQ(now_time, app_info_before->last_launch_time); |
961 | 981 |
962 app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps2); | 982 app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps2); |
963 ValidateHaveApps(apps2); | 983 ValidateHaveApps(apps2); |
964 | 984 |
965 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_after = | 985 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_after = |
966 prefs->GetApp(app_id); | 986 prefs->GetApp(app_id); |
967 ASSERT_TRUE(app_info_after); | 987 ASSERT_TRUE(app_info_after); |
968 EXPECT_EQ(now_time, app_info_after->last_launch_time); | 988 EXPECT_EQ(now_time, app_info_after->last_launch_time); |
969 } | 989 } |
| 990 |
| 991 TEST_F(ArcDefaulAppTest, DefaultApps) { |
| 992 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 993 ASSERT_NE(nullptr, prefs); |
| 994 |
| 995 ValidateHaveApps(fake_default_apps()); |
| 996 |
| 997 // Start normal apps. We should have apps from 2 subsets. |
| 998 app_instance()->RefreshAppList(); |
| 999 app_instance()->SendRefreshAppList(fake_apps()); |
| 1000 |
| 1001 std::vector<arc::mojom::AppInfo> all_apps = fake_default_apps(); |
| 1002 all_apps.insert(all_apps.end(), fake_apps().begin(), fake_apps().end()); |
| 1003 ValidateHaveApps(all_apps); |
| 1004 |
| 1005 // However default apps are still not ready. |
| 1006 for (const auto& default_app : fake_default_apps()) { |
| 1007 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp( |
| 1008 ArcAppTest::GetAppId(default_app)); |
| 1009 ASSERT_TRUE(app_info); |
| 1010 EXPECT_FALSE(app_info->ready); |
| 1011 } |
| 1012 |
| 1013 // Install default apps. |
| 1014 for (const auto& default_app : fake_default_apps()) { |
| 1015 std::vector<arc::mojom::AppInfo> package_apps; |
| 1016 package_apps.push_back(default_app); |
| 1017 app_instance()->SendPackageAppListRefreshed(default_app.package_name, |
| 1018 package_apps); |
| 1019 } |
| 1020 |
| 1021 // And now default apps are ready. |
| 1022 for (const auto& default_app : fake_default_apps()) { |
| 1023 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp( |
| 1024 ArcAppTest::GetAppId(default_app)); |
| 1025 ASSERT_TRUE(app_info); |
| 1026 EXPECT_TRUE(app_info->ready); |
| 1027 } |
| 1028 |
| 1029 // Uninstall first default package. Default app should go away. |
| 1030 app_instance()->SendPackageUninstalled(all_apps[0].package_name); |
| 1031 all_apps.erase(all_apps.begin()); |
| 1032 ValidateHaveApps(all_apps); |
| 1033 |
| 1034 // OptOut and default apps should exist minus first. |
| 1035 arc_test()->arc_auth_service()->DisableArc(); |
| 1036 all_apps = fake_default_apps(); |
| 1037 all_apps.erase(all_apps.begin()); |
| 1038 ValidateHaveApps(all_apps); |
| 1039 } |
OLD | NEW |