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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 AppListControllerDelegate* controller() { return controller_.get(); } | 297 AppListControllerDelegate* controller() { return controller_.get(); } |
297 | 298 |
298 Profile* profile() { return profile_.get(); } | 299 Profile* profile() { return profile_.get(); } |
299 | 300 |
300 ArcAppTest* arc_test() { return &arc_test_; } | 301 ArcAppTest* arc_test() { return &arc_test_; } |
301 | 302 |
302 const std::vector<arc::mojom::AppInfo>& fake_apps() const { | 303 const std::vector<arc::mojom::AppInfo>& fake_apps() const { |
303 return arc_test_.fake_apps(); | 304 return arc_test_.fake_apps(); |
304 } | 305 } |
305 | 306 |
| 307 const std::vector<arc::mojom::AppInfo>& fake_default_apps() const { |
| 308 return arc_test_.fake_default_apps(); |
| 309 } |
| 310 |
306 const std::vector<arc::mojom::ArcPackageInfo>& fake_packages() const { | 311 const std::vector<arc::mojom::ArcPackageInfo>& fake_packages() const { |
307 return arc_test_.fake_packages(); | 312 return arc_test_.fake_packages(); |
308 } | 313 } |
309 | 314 |
310 const std::vector<arc::mojom::ShortcutInfo>& fake_shortcuts() const { | 315 const std::vector<arc::mojom::ShortcutInfo>& fake_shortcuts() const { |
311 return arc_test_.fake_shortcuts(); | 316 return arc_test_.fake_shortcuts(); |
312 } | 317 } |
313 | 318 |
314 arc::FakeAppInstance* app_instance() { | 319 arc::FakeAppInstance* app_instance() { |
315 return arc_test_.app_instance(); | 320 return arc_test_.app_instance(); |
316 } | 321 } |
317 | 322 |
318 private: | 323 private: |
319 ArcAppTest arc_test_; | 324 ArcAppTest arc_test_; |
320 std::unique_ptr<app_list::AppListModel> model_; | 325 std::unique_ptr<app_list::AppListModel> model_; |
321 std::unique_ptr<test::TestAppListControllerDelegate> controller_; | 326 std::unique_ptr<test::TestAppListControllerDelegate> controller_; |
322 std::unique_ptr<ArcAppModelBuilder> builder_; | 327 std::unique_ptr<ArcAppModelBuilder> builder_; |
323 | 328 |
324 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); | 329 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); |
325 }; | 330 }; |
326 | 331 |
| 332 class ArcDefaulAppTest : public ArcAppModelBuilderTest { |
| 333 public: |
| 334 ArcDefaulAppTest() {} |
| 335 ~ArcDefaulAppTest() override {} |
| 336 |
| 337 |
| 338 void SetUp() override { |
| 339 ArcDefaultAppList::UseTestAppsDirectory(); |
| 340 ArcAppModelBuilderTest::SetUp(); |
| 341 } |
| 342 |
| 343 private: |
| 344 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); |
| 345 }; |
| 346 |
327 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { | 347 TEST_F(ArcAppModelBuilderTest, ArcPackagePref) { |
328 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); | 348 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); |
329 app_instance()->SendRefreshPackageList(fake_packages()); | 349 app_instance()->SendRefreshPackageList(fake_packages()); |
330 ValidateHavePackages(fake_packages()); | 350 ValidateHavePackages(fake_packages()); |
331 | 351 |
332 arc::mojom::ArcPackageInfo package; | 352 arc::mojom::ArcPackageInfo package; |
333 package.package_name = kTestPackageName; | 353 package.package_name = kTestPackageName; |
334 package.package_version = 2; | 354 package.package_version = 2; |
335 package.last_backup_android_id = 2; | 355 package.last_backup_android_id = 2; |
336 package.last_backup_time = 2; | 356 package.last_backup_time = 2; |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 EXPECT_EQ(now_time, app_info_before->last_launch_time); | 981 EXPECT_EQ(now_time, app_info_before->last_launch_time); |
962 | 982 |
963 app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps2); | 983 app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps2); |
964 ValidateHaveApps(apps2); | 984 ValidateHaveApps(apps2); |
965 | 985 |
966 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_after = | 986 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_after = |
967 prefs->GetApp(app_id); | 987 prefs->GetApp(app_id); |
968 ASSERT_TRUE(app_info_after); | 988 ASSERT_TRUE(app_info_after); |
969 EXPECT_EQ(now_time, app_info_after->last_launch_time); | 989 EXPECT_EQ(now_time, app_info_after->last_launch_time); |
970 } | 990 } |
| 991 |
| 992 TEST_F(ArcDefaulAppTest, DefaultApps) { |
| 993 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 994 ASSERT_NE(nullptr, prefs); |
| 995 |
| 996 ValidateHaveApps(fake_default_apps()); |
| 997 |
| 998 // Start normal apps. We should have apps from 2 subsets. |
| 999 app_instance()->RefreshAppList(); |
| 1000 app_instance()->SendRefreshAppList(fake_apps()); |
| 1001 |
| 1002 std::vector<arc::mojom::AppInfo> all_apps = fake_default_apps(); |
| 1003 all_apps.insert(all_apps.end(), fake_apps().begin(), fake_apps().end()); |
| 1004 ValidateHaveApps(all_apps); |
| 1005 |
| 1006 // However default apps are still not ready. |
| 1007 for (const auto& default_app : fake_default_apps()) { |
| 1008 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp( |
| 1009 ArcAppTest::GetAppId(default_app)); |
| 1010 ASSERT_TRUE(app_info); |
| 1011 EXPECT_FALSE(app_info->ready); |
| 1012 } |
| 1013 |
| 1014 // Install default apps. |
| 1015 for (const auto& default_app : fake_default_apps()) { |
| 1016 std::vector<arc::mojom::AppInfo> package_apps; |
| 1017 package_apps.push_back(default_app); |
| 1018 app_instance()->SendPackageAppListRefreshed(default_app.package_name, |
| 1019 package_apps); |
| 1020 } |
| 1021 |
| 1022 // And now default apps are ready. |
| 1023 for (const auto& default_app : fake_default_apps()) { |
| 1024 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp( |
| 1025 ArcAppTest::GetAppId(default_app)); |
| 1026 ASSERT_TRUE(app_info); |
| 1027 EXPECT_TRUE(app_info->ready); |
| 1028 } |
| 1029 |
| 1030 // Uninstall first default package. Default app should go away. |
| 1031 app_instance()->SendPackageUninstalled(all_apps[0].package_name); |
| 1032 all_apps.erase(all_apps.begin()); |
| 1033 ValidateHaveApps(all_apps); |
| 1034 |
| 1035 // OptOut and default apps should exist minus first. |
| 1036 arc_test()->arc_auth_service()->DisableArc(); |
| 1037 all_apps = fake_default_apps(); |
| 1038 all_apps.erase(all_apps.begin()); |
| 1039 ValidateHaveApps(all_apps); |
| 1040 } |
OLD | NEW |