Chromium Code Reviews| 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" |
| (...skipping 112 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after 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() {} | |
|
Luis Héctor Chávez
2016/11/22 17:14:14
nit: = default. Same below.
khmel
2016/11/22 18:43:05
Done.
| |
| 438 ~ArcAppModelBuilderRecreate() override {} | |
| 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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1031 EXPECT_FALSE(prefs->HasObserver(&launcher1)); | 1052 EXPECT_FALSE(prefs->HasObserver(&launcher1)); |
| 1032 EXPECT_TRUE(prefs->HasObserver(&launcher3)); | 1053 EXPECT_TRUE(prefs->HasObserver(&launcher3)); |
| 1033 | 1054 |
| 1034 ArcAppLauncher launcher2(profile(), id2, true); | 1055 ArcAppLauncher launcher2(profile(), id2, true); |
| 1035 EXPECT_TRUE(launcher2.app_launched()); | 1056 EXPECT_TRUE(launcher2.app_launched()); |
| 1036 EXPECT_FALSE(prefs->HasObserver(&launcher2)); | 1057 EXPECT_FALSE(prefs->HasObserver(&launcher2)); |
| 1037 ASSERT_EQ(2u, app_instance()->launch_requests().size()); | 1058 ASSERT_EQ(2u, app_instance()->launch_requests().size()); |
| 1038 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2)); | 1059 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2)); |
| 1039 } | 1060 } |
| 1040 | 1061 |
| 1062 // Validate that arc model contains expected elements on restart. | |
| 1063 TEST_F(ArcAppModelBuilderRecreate, AppModelRestart) { | |
| 1064 // No apps on fist initial start. | |
|
Luis Héctor Chávez
2016/11/22 17:14:14
nit: "No apps on first initial start." (also, firs
khmel
2016/11/22 18:43:05
Done.
| |
| 1065 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); | |
| 1066 | |
| 1067 // Send info about all fake apps except last. | |
| 1068 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(), | |
| 1069 fake_apps().end() - 1); | |
| 1070 app_instance()->RefreshAppList(); | |
| 1071 app_instance()->SendRefreshAppList(apps1); | |
| 1072 // Model has refreshed apps. | |
| 1073 ValidateHaveApps(apps1); | |
| 1074 EXPECT_EQ(apps1.size(), GetArcItemCount()); | |
| 1075 | |
| 1076 // Simulate restart. | |
| 1077 arc_test()->TearDown(); | |
| 1078 ResetBuilder(); | |
| 1079 | |
| 1080 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( | |
| 1081 profile_.get()); | |
| 1082 arc_test()->SetUp(profile_.get()); | |
| 1083 CreateBuilder(); | |
| 1084 | |
| 1085 // On restart new model contains last apps. | |
| 1086 ValidateHaveApps(apps1); | |
| 1087 EXPECT_EQ(apps1.size(), GetArcItemCount()); | |
| 1088 | |
| 1089 // Now refresh old apps with new one. | |
| 1090 app_instance()->RefreshAppList(); | |
| 1091 app_instance()->SendRefreshAppList(fake_apps()); | |
| 1092 ValidateHaveApps(fake_apps()); | |
| 1093 EXPECT_EQ(fake_apps().size(), GetArcItemCount()); | |
| 1094 } | |
| 1095 | |
| 1041 // Validates an app that have no launchable flag. | 1096 // Validates an app that have no launchable flag. |
| 1042 TEST_F(ArcAppModelBuilderTest, NonLaunchableApp) { | 1097 TEST_F(ArcAppModelBuilderTest, NonLaunchableApp) { |
| 1043 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 1098 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1044 ASSERT_NE(nullptr, prefs); | 1099 ASSERT_NE(nullptr, prefs); |
| 1045 | 1100 |
| 1046 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); | 1101 ValidateHaveApps(std::vector<arc::mojom::AppInfo>()); |
| 1047 app_instance()->RefreshAppList(); | 1102 app_instance()->RefreshAppList(); |
| 1048 // Send all except first. | 1103 // Send all except first. |
| 1049 std::vector<arc::mojom::AppInfo> apps(fake_apps().begin() + 1, | 1104 std::vector<arc::mojom::AppInfo> apps(fake_apps().begin() + 1, |
| 1050 fake_apps().end()); | 1105 fake_apps().end()); |
| (...skipping 97 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 |