| 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/threading/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 21 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 22 #include "chrome/browser/chromeos/arc/arc_util.h" | 22 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 24 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 24 #include "chrome/browser/policy/profile_policy_connector.h" | 25 #include "chrome/browser/policy/profile_policy_connector.h" |
| 25 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 26 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 26 #include "chrome/browser/ui/app_list/app_list_test_util.h" | |
| 27 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" | 27 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" |
| 28 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" | 28 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" |
| 29 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" | 29 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" |
| 30 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" | 30 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" |
| 31 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 31 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 32 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" | 32 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" |
| 33 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h" | 33 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h" |
| 34 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" | 34 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" |
| 35 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 35 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 36 #include "chrome/browser/ui/app_list/arc/arc_default_app_list.h" | 36 #include "chrome/browser/ui/app_list/arc/arc_default_app_list.h" |
| 37 #include "chrome/browser/ui/app_list/arc/arc_package_syncable_service_factory.h" | 37 #include "chrome/browser/ui/app_list/arc/arc_package_syncable_service_factory.h" |
| 38 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" | 38 #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" |
| 39 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | 39 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" |
| 40 #include "chrome/common/pref_names.h" |
| 40 #include "chrome/test/base/testing_profile.h" | 41 #include "chrome/test/base/testing_profile.h" |
| 41 #include "components/arc/arc_util.h" | 42 #include "components/arc/arc_util.h" |
| 42 #include "components/arc/test/fake_app_instance.h" | 43 #include "components/arc/test/fake_app_instance.h" |
| 44 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 43 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" |
| 44 #include "extensions/browser/extension_system.h" | 46 #include "extensions/browser/extension_system.h" |
| 45 #include "extensions/common/extension.h" | 47 #include "extensions/common/extension.h" |
| 46 #include "extensions/common/manifest_constants.h" | 48 #include "extensions/common/manifest_constants.h" |
| 47 #include "testing/gtest/include/gtest/gtest.h" | 49 #include "testing/gtest/include/gtest/gtest.h" |
| 48 #include "ui/app_list/app_list_constants.h" | 50 #include "ui/app_list/app_list_constants.h" |
| 49 #include "ui/app_list/app_list_model.h" | 51 #include "ui/app_list/app_list_model.h" |
| 50 #include "ui/events/event_constants.h" | 52 #include "ui/events/event_constants.h" |
| 51 #include "ui/gfx/geometry/safe_integer_conversions.h" | 53 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 52 #include "ui/gfx/image/image_skia.h" | 54 #include "ui/gfx/image/image_skia.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 ui::ScaleFactor scale_factor) { | 88 ui::ScaleFactor scale_factor) { |
| 87 const base::FilePath icon_path = prefs->GetIconPath(app_id, scale_factor); | 89 const base::FilePath icon_path = prefs->GetIconPath(app_id, scale_factor); |
| 88 // Process pending tasks. This performs multiple thread hops, so we need | 90 // Process pending tasks. This performs multiple thread hops, so we need |
| 89 // to run it continuously until it is resolved. | 91 // to run it continuously until it is resolved. |
| 90 do { | 92 do { |
| 91 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 93 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 92 base::RunLoop().RunUntilIdle(); | 94 base::RunLoop().RunUntilIdle(); |
| 93 } while (!base::PathExists(icon_path)); | 95 } while (!base::PathExists(icon_path)); |
| 94 } | 96 } |
| 95 | 97 |
| 98 enum class ArcState { |
| 99 // By default, ARC is non-persistent and Play Store is unmanaged. |
| 100 ARC_PLAY_STORE_UNMANAGED, |
| 101 // ARC is persistent and Play Store is unmanaged |
| 102 ARC_PERSISTENT_PLAY_STORE_UNMANAGED, |
| 103 // ARC is non-persistent and Play Store is managed and enabled. |
| 104 ARC_PLAY_STORE_MANAGED_AND_ENABLED, |
| 105 // ARC is non-persistent and Play Store is managed and disabled. |
| 106 ARC_PLAY_STORE_MANAGED_AND_DISABLED, |
| 107 // ARC is persistent and Play Store is managed and enabled. |
| 108 ARC_PERSISTENT_PLAY_STORE_MANAGED_AND_ENABLED, |
| 109 // ARC is persistent and Play Store is managed and disabled. |
| 110 ARC_PERSISTENT_PLAY_STORE_MANAGED_AND_DISABLED, |
| 111 }; |
| 112 |
| 113 constexpr ArcState kManagedArcStates[] = { |
| 114 ArcState::ARC_PLAY_STORE_MANAGED_AND_ENABLED, |
| 115 ArcState::ARC_PLAY_STORE_MANAGED_AND_DISABLED, |
| 116 ArcState::ARC_PERSISTENT_PLAY_STORE_MANAGED_AND_ENABLED, |
| 117 ArcState::ARC_PERSISTENT_PLAY_STORE_MANAGED_AND_DISABLED, |
| 118 }; |
| 119 |
| 120 constexpr ArcState kUnmanagedArcStates[] = { |
| 121 ArcState::ARC_PLAY_STORE_UNMANAGED, |
| 122 ArcState::ARC_PERSISTENT_PLAY_STORE_UNMANAGED, |
| 123 }; |
| 124 |
| 96 } // namespace | 125 } // namespace |
| 97 | 126 |
| 98 class ArcAppModelBuilderTest : public AppListTestBase, | 127 class ArcAppModelBuilderTest : public extensions::ExtensionServiceTestBase, |
| 99 public ::testing::WithParamInterface<bool> { | 128 public ::testing::WithParamInterface<ArcState> { |
| 100 public: | 129 public: |
| 101 ArcAppModelBuilderTest() = default; | 130 ArcAppModelBuilderTest() = default; |
| 102 ~ArcAppModelBuilderTest() override { | 131 ~ArcAppModelBuilderTest() override { |
| 103 // Release profile file in order to keep right sequence. | 132 // Release profile file in order to keep right sequence. |
| 104 profile_.reset(); | 133 profile_.reset(); |
| 105 } | 134 } |
| 106 | 135 |
| 107 void SetUp() override { | 136 void SetUp() override { |
| 108 if (GetParam()) | 137 switch (GetParam()) { |
| 109 arc::SetArcAlwaysStartForTesting(); | 138 case ArcState::ARC_PERSISTENT_PLAY_STORE_UNMANAGED: |
| 110 AppListTestBase::SetUp(); | 139 case ArcState::ARC_PERSISTENT_PLAY_STORE_MANAGED_AND_ENABLED: |
| 140 case ArcState::ARC_PERSISTENT_PLAY_STORE_MANAGED_AND_DISABLED: |
| 141 arc::SetArcAlwaysStartForTesting(); |
| 142 break; |
| 143 default: |
| 144 break; |
| 145 } |
| 146 |
| 147 extensions::ExtensionServiceTestBase::SetUp(); |
| 148 InitializeExtensionService(ExtensionServiceInitParams()); |
| 149 service_->Init(); |
| 150 // ExtensionService needs a real I/O thread. |
| 151 service_->SetFileTaskRunnerForTesting( |
| 152 content::BrowserThread::GetBlockingPool() |
| 153 ->GetSequencedTaskRunnerWithShutdownBehavior( |
| 154 content::BrowserThread::GetBlockingPool() |
| 155 ->GetNamedSequenceToken("ext_install-"), |
| 156 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 157 |
| 111 OnBeforeArcTestSetup(); | 158 OnBeforeArcTestSetup(); |
| 112 arc_test_.SetUp(profile_.get()); | 159 arc_test_.SetUp(profile_.get()); |
| 113 CreateBuilder(); | 160 CreateBuilder(); |
| 114 | 161 |
| 115 // Validating decoded content does not fit well for unit tests. | 162 // Validating decoded content does not fit well for unit tests. |
| 116 ArcAppIcon::DisableSafeDecodingForTesting(); | 163 ArcAppIcon::DisableSafeDecodingForTesting(); |
| 117 } | 164 } |
| 118 | 165 |
| 119 void TearDown() override { | 166 void TearDown() override { |
| 120 arc_test_.TearDown(); | 167 arc_test_.TearDown(); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 void AddPackage(const arc::mojom::ArcPackageInfo& package) { | 376 void AddPackage(const arc::mojom::ArcPackageInfo& package) { |
| 330 arc_test_.AddPackage(package); | 377 arc_test_.AddPackage(package); |
| 331 } | 378 } |
| 332 | 379 |
| 333 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { | 380 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { |
| 334 arc_test_.RemovePackage(package); | 381 arc_test_.RemovePackage(package); |
| 335 } | 382 } |
| 336 | 383 |
| 337 AppListControllerDelegate* controller() { return controller_.get(); } | 384 AppListControllerDelegate* controller() { return controller_.get(); } |
| 338 | 385 |
| 339 Profile* profile() { return profile_.get(); } | 386 TestingProfile* profile() { return profile_.get(); } |
| 340 | 387 |
| 341 ArcAppTest* arc_test() { return &arc_test_; } | 388 ArcAppTest* arc_test() { return &arc_test_; } |
| 342 | 389 |
| 343 const std::vector<arc::mojom::AppInfo>& fake_apps() const { | 390 const std::vector<arc::mojom::AppInfo>& fake_apps() const { |
| 344 return arc_test_.fake_apps(); | 391 return arc_test_.fake_apps(); |
| 345 } | 392 } |
| 346 | 393 |
| 347 const std::vector<arc::mojom::AppInfo>& fake_default_apps() const { | 394 const std::vector<arc::mojom::AppInfo>& fake_default_apps() const { |
| 348 return arc_test_.fake_default_apps(); | 395 return arc_test_.fake_default_apps(); |
| 349 } | 396 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 379 void OnBeforeArcTestSetup() override { | 426 void OnBeforeArcTestSetup() override { |
| 380 ArcDefaultAppList::UseTestAppsDirectory(); | 427 ArcDefaultAppList::UseTestAppsDirectory(); |
| 381 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( | 428 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( |
| 382 profile_.get(), nullptr); | 429 profile_.get(), nullptr); |
| 383 } | 430 } |
| 384 | 431 |
| 385 private: | 432 private: |
| 386 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); | 433 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); |
| 387 }; | 434 }; |
| 388 | 435 |
| 389 class ArcDefaulAppForManagedUserTest : public ArcDefaulAppTest { | |
| 390 public: | |
| 391 ArcDefaulAppForManagedUserTest() = default; | |
| 392 ~ArcDefaulAppForManagedUserTest() override = default; | |
| 393 | |
| 394 protected: | |
| 395 // ArcAppModelBuilderTest: | |
| 396 void OnBeforeArcTestSetup() override { | |
| 397 ArcDefaulAppTest::OnBeforeArcTestSetup(); | |
| 398 | |
| 399 policy::ProfilePolicyConnector* const connector = | |
| 400 policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | |
| 401 profile()); | |
| 402 connector->OverrideIsManagedForTesting(true); | |
| 403 } | |
| 404 | |
| 405 private: | |
| 406 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppForManagedUserTest); | |
| 407 }; | |
| 408 | |
| 409 class ArcPlayStoreAppTest : public ArcDefaulAppTest { | 436 class ArcPlayStoreAppTest : public ArcDefaulAppTest { |
| 410 public: | 437 public: |
| 411 ArcPlayStoreAppTest() = default; | 438 ArcPlayStoreAppTest() = default; |
| 412 ~ArcPlayStoreAppTest() override = default; | 439 ~ArcPlayStoreAppTest() override = default; |
| 413 | 440 |
| 414 protected: | 441 protected: |
| 415 // ArcAppModelBuilderTest: | 442 // ArcAppModelBuilderTest: |
| 416 void OnBeforeArcTestSetup() override { | 443 void OnBeforeArcTestSetup() override { |
| 417 ArcDefaulAppTest::OnBeforeArcTestSetup(); | 444 ArcDefaulAppTest::OnBeforeArcTestSetup(); |
| 418 | 445 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 434 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); | 461 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); |
| 435 extension_service->AddExtension(arc_support_host_.get()); | 462 extension_service->AddExtension(arc_support_host_.get()); |
| 436 } | 463 } |
| 437 | 464 |
| 438 private: | 465 private: |
| 439 scoped_refptr<extensions::Extension> arc_support_host_; | 466 scoped_refptr<extensions::Extension> arc_support_host_; |
| 440 | 467 |
| 441 DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreAppTest); | 468 DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreAppTest); |
| 442 }; | 469 }; |
| 443 | 470 |
| 471 class ArcDefaulAppForManagedUserTest : public ArcPlayStoreAppTest { |
| 472 public: |
| 473 ArcDefaulAppForManagedUserTest() = default; |
| 474 ~ArcDefaulAppForManagedUserTest() override = default; |
| 475 |
| 476 protected: |
| 477 bool IsEnabledByPolicy() const { |
| 478 switch (GetParam()) { |
| 479 case ArcState::ARC_PLAY_STORE_MANAGED_AND_ENABLED: |
| 480 case ArcState::ARC_PERSISTENT_PLAY_STORE_MANAGED_AND_ENABLED: |
| 481 return true; |
| 482 case ArcState::ARC_PLAY_STORE_MANAGED_AND_DISABLED: |
| 483 case ArcState::ARC_PERSISTENT_PLAY_STORE_MANAGED_AND_DISABLED: |
| 484 return false; |
| 485 default: |
| 486 NOTREACHED(); |
| 487 return false; |
| 488 } |
| 489 } |
| 490 |
| 491 // ArcPlayStoreAppTest: |
| 492 void OnBeforeArcTestSetup() override { |
| 493 policy::ProfilePolicyConnector* const connector = |
| 494 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile()); |
| 495 connector->OverrideIsManagedForTesting(true); |
| 496 profile()->GetTestingPrefService()->SetManagedPref( |
| 497 prefs::kArcEnabled, new base::Value(IsEnabledByPolicy())); |
| 498 |
| 499 ArcPlayStoreAppTest::OnBeforeArcTestSetup(); |
| 500 } |
| 501 |
| 502 private: |
| 503 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppForManagedUserTest); |
| 504 }; |
| 505 |
| 444 class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest { | 506 class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest { |
| 445 public: | 507 public: |
| 446 ArcAppModelBuilderRecreate() = default; | 508 ArcAppModelBuilderRecreate() = default; |
| 447 ~ArcAppModelBuilderRecreate() override = default; | 509 ~ArcAppModelBuilderRecreate() override = default; |
| 448 | 510 |
| 449 protected: | 511 protected: |
| 450 // ArcAppModelBuilderTest: | 512 // ArcAppModelBuilderTest: |
| 451 void OnBeforeArcTestSetup() override { | 513 void OnBeforeArcTestSetup() override { |
| 452 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( | 514 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( |
| 453 profile_.get(), nullptr); | 515 profile_.get(), nullptr); |
| (...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 TEST_P(ArcDefaulAppForManagedUserTest, DefaultAppsForManagedUser) { | 1432 TEST_P(ArcDefaulAppForManagedUserTest, DefaultAppsForManagedUser) { |
| 1371 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(profile_.get()); | 1433 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1372 ASSERT_TRUE(prefs); | 1434 ASSERT_TRUE(prefs); |
| 1373 | 1435 |
| 1374 // There is no default app for managed users except Play Store | 1436 // There is no default app for managed users except Play Store |
| 1375 for (const auto& app : fake_default_apps()) { | 1437 for (const auto& app : fake_default_apps()) { |
| 1376 const std::string app_id = ArcAppTest::GetAppId(app); | 1438 const std::string app_id = ArcAppTest::GetAppId(app); |
| 1377 EXPECT_FALSE(prefs->IsRegistered(app_id)); | 1439 EXPECT_FALSE(prefs->IsRegistered(app_id)); |
| 1378 EXPECT_FALSE(prefs->GetApp(app_id)); | 1440 EXPECT_FALSE(prefs->GetApp(app_id)); |
| 1379 } | 1441 } |
| 1442 |
| 1443 // PlayStor exists for managed and enabled state. |
| 1444 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = |
| 1445 prefs->GetApp(arc::kPlayStoreAppId); |
| 1446 if (IsEnabledByPolicy()) { |
| 1447 ASSERT_TRUE(app_info); |
| 1448 EXPECT_FALSE(app_info->ready); |
| 1449 } else { |
| 1450 EXPECT_FALSE(prefs->IsRegistered(arc::kPlayStoreAppId)); |
| 1451 EXPECT_FALSE(app_info); |
| 1452 } |
| 1380 } | 1453 } |
| 1381 | 1454 |
| 1382 INSTANTIATE_TEST_CASE_P(, ArcAppModelBuilderTest, ::testing::Bool()); | 1455 INSTANTIATE_TEST_CASE_P(, |
| 1383 INSTANTIATE_TEST_CASE_P(, ArcDefaulAppTest, ::testing::Bool()); | 1456 ArcAppModelBuilderTest, |
| 1384 INSTANTIATE_TEST_CASE_P(, ArcDefaulAppForManagedUserTest, ::testing::Bool()); | 1457 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1385 INSTANTIATE_TEST_CASE_P(, ArcPlayStoreAppTest, ::testing::Bool()); | 1458 INSTANTIATE_TEST_CASE_P(, |
| 1386 INSTANTIATE_TEST_CASE_P(, ArcAppModelBuilderRecreate, ::testing::Bool()); | 1459 ArcDefaulAppTest, |
| 1460 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1461 INSTANTIATE_TEST_CASE_P(, |
| 1462 ArcDefaulAppForManagedUserTest, |
| 1463 ::testing::ValuesIn(kManagedArcStates)); |
| 1464 INSTANTIATE_TEST_CASE_P(, |
| 1465 ArcPlayStoreAppTest, |
| 1466 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1467 INSTANTIATE_TEST_CASE_P(, |
| 1468 ArcAppModelBuilderRecreate, |
| 1469 ::testing::ValuesIn(kUnmanagedArcStates)); |
| OLD | NEW |