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/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 // Default ARC, non-persistent and unmanaged | |
| 100 ARC_UNMANAGED, | |
|
hidehiko
2017/03/09 06:17:00
Please avoid using just "enabled" meaning PlayStor
khmel
2017/03/09 18:00:43
Thanks for good point! Done.
| |
| 101 // Persistent ARC and unmanaged | |
| 102 ARC_PERSISTENT_UNMANAGED, | |
| 103 // ARC non-persistent, managed and enabled | |
| 104 ARC_MANAGED_ENABLED, | |
| 105 // ARC non-persistent, managed and disabled | |
| 106 ARC_MANAGED_DISABLED, | |
| 107 // Persistent ARC managed and enabled | |
| 108 ARC_PERSISTENT_MANAGED_ENABLED, | |
| 109 // Persistent ARC managed and disabled | |
| 110 ARC_PERSISTENT_MANAGED_DISABLED, | |
| 111 }; | |
| 112 | |
| 113 constexpr ArcState kManagedArcStates[] = { | |
| 114 ArcState::ARC_MANAGED_ENABLED, ArcState::ARC_MANAGED_DISABLED, | |
| 115 ArcState::ARC_PERSISTENT_MANAGED_ENABLED, | |
| 116 ArcState::ARC_PERSISTENT_MANAGED_DISABLED, | |
| 117 }; | |
| 118 | |
| 119 constexpr ArcState kUnmanagedArcStates[] = { | |
| 120 ArcState::ARC_UNMANAGED, ArcState::ARC_PERSISTENT_UNMANAGED, | |
| 121 }; | |
| 122 | |
| 96 } // namespace | 123 } // namespace |
| 97 | 124 |
| 98 class ArcAppModelBuilderTest : public AppListTestBase, | 125 class ArcAppModelBuilderTest : public extensions::ExtensionServiceTestBase, |
|
khmel
2017/03/09 00:27:49
AppListTestBase has functionality to init profile
| |
| 99 public ::testing::WithParamInterface<bool> { | 126 public ::testing::WithParamInterface<ArcState> { |
| 100 public: | 127 public: |
| 101 ArcAppModelBuilderTest() = default; | 128 ArcAppModelBuilderTest() = default; |
| 102 ~ArcAppModelBuilderTest() override { | 129 ~ArcAppModelBuilderTest() override { |
| 103 // Release profile file in order to keep right sequence. | 130 // Release profile file in order to keep right sequence. |
| 104 profile_.reset(); | 131 profile_.reset(); |
| 105 } | 132 } |
| 106 | 133 |
| 107 void SetUp() override { | 134 void SetUp() override { |
| 108 if (GetParam()) | 135 switch (GetParam()) { |
| 109 arc::SetArcAlwaysStartForTesting(); | 136 case ArcState::ARC_PERSISTENT_UNMANAGED: |
| 110 AppListTestBase::SetUp(); | 137 case ArcState::ARC_PERSISTENT_MANAGED_ENABLED: |
| 138 case ArcState::ARC_PERSISTENT_MANAGED_DISABLED: | |
| 139 arc::SetArcAlwaysStartForTesting(); | |
| 140 break; | |
| 141 default: | |
| 142 break; | |
| 143 } | |
| 144 | |
| 145 extensions::ExtensionServiceTestBase::SetUp(); | |
| 146 InitializeExtensionService(ExtensionServiceInitParams()); | |
| 147 service_->Init(); | |
| 148 // ExtensionService needs a real I/O thread. | |
| 149 service_->SetFileTaskRunnerForTesting( | |
| 150 content::BrowserThread::GetBlockingPool() | |
| 151 ->GetSequencedTaskRunnerWithShutdownBehavior( | |
| 152 content::BrowserThread::GetBlockingPool() | |
| 153 ->GetNamedSequenceToken("ext_install-"), | |
| 154 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
| 155 | |
| 111 OnBeforeArcTestSetup(); | 156 OnBeforeArcTestSetup(); |
| 112 arc_test_.SetUp(profile_.get()); | 157 arc_test_.SetUp(profile_.get()); |
| 113 CreateBuilder(); | 158 CreateBuilder(); |
| 114 | 159 |
| 115 // Validating decoded content does not fit well for unit tests. | 160 // Validating decoded content does not fit well for unit tests. |
| 116 ArcAppIcon::DisableSafeDecodingForTesting(); | 161 ArcAppIcon::DisableSafeDecodingForTesting(); |
| 117 } | 162 } |
| 118 | 163 |
| 119 void TearDown() override { | 164 void TearDown() override { |
| 120 arc_test_.TearDown(); | 165 arc_test_.TearDown(); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 void AddPackage(const arc::mojom::ArcPackageInfo& package) { | 374 void AddPackage(const arc::mojom::ArcPackageInfo& package) { |
| 330 arc_test_.AddPackage(package); | 375 arc_test_.AddPackage(package); |
| 331 } | 376 } |
| 332 | 377 |
| 333 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { | 378 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { |
| 334 arc_test_.RemovePackage(package); | 379 arc_test_.RemovePackage(package); |
| 335 } | 380 } |
| 336 | 381 |
| 337 AppListControllerDelegate* controller() { return controller_.get(); } | 382 AppListControllerDelegate* controller() { return controller_.get(); } |
| 338 | 383 |
| 339 Profile* profile() { return profile_.get(); } | 384 TestingProfile* profile() { return profile_.get(); } |
| 340 | 385 |
| 341 ArcAppTest* arc_test() { return &arc_test_; } | 386 ArcAppTest* arc_test() { return &arc_test_; } |
| 342 | 387 |
| 343 const std::vector<arc::mojom::AppInfo>& fake_apps() const { | 388 const std::vector<arc::mojom::AppInfo>& fake_apps() const { |
| 344 return arc_test_.fake_apps(); | 389 return arc_test_.fake_apps(); |
| 345 } | 390 } |
| 346 | 391 |
| 347 const std::vector<arc::mojom::AppInfo>& fake_default_apps() const { | 392 const std::vector<arc::mojom::AppInfo>& fake_default_apps() const { |
| 348 return arc_test_.fake_default_apps(); | 393 return arc_test_.fake_default_apps(); |
| 349 } | 394 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 379 void OnBeforeArcTestSetup() override { | 424 void OnBeforeArcTestSetup() override { |
| 380 ArcDefaultAppList::UseTestAppsDirectory(); | 425 ArcDefaultAppList::UseTestAppsDirectory(); |
| 381 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( | 426 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( |
| 382 profile_.get(), nullptr); | 427 profile_.get(), nullptr); |
| 383 } | 428 } |
| 384 | 429 |
| 385 private: | 430 private: |
| 386 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); | 431 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); |
| 387 }; | 432 }; |
| 388 | 433 |
| 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 { | 434 class ArcPlayStoreAppTest : public ArcDefaulAppTest { |
| 410 public: | 435 public: |
| 411 ArcPlayStoreAppTest() = default; | 436 ArcPlayStoreAppTest() = default; |
| 412 ~ArcPlayStoreAppTest() override = default; | 437 ~ArcPlayStoreAppTest() override = default; |
| 413 | 438 |
| 414 protected: | 439 protected: |
| 415 // ArcAppModelBuilderTest: | 440 // ArcAppModelBuilderTest: |
| 416 void OnBeforeArcTestSetup() override { | 441 void OnBeforeArcTestSetup() override { |
| 417 ArcDefaulAppTest::OnBeforeArcTestSetup(); | 442 ArcDefaulAppTest::OnBeforeArcTestSetup(); |
| 418 | 443 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 434 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); | 459 extensions::ExtensionSystem::Get(profile_.get())->extension_service(); |
| 435 extension_service->AddExtension(arc_support_host_.get()); | 460 extension_service->AddExtension(arc_support_host_.get()); |
| 436 } | 461 } |
| 437 | 462 |
| 438 private: | 463 private: |
| 439 scoped_refptr<extensions::Extension> arc_support_host_; | 464 scoped_refptr<extensions::Extension> arc_support_host_; |
| 440 | 465 |
| 441 DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreAppTest); | 466 DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreAppTest); |
| 442 }; | 467 }; |
| 443 | 468 |
| 469 class ArcDefaulAppForManagedUserTest : public ArcPlayStoreAppTest { | |
| 470 public: | |
| 471 ArcDefaulAppForManagedUserTest() = default; | |
| 472 ~ArcDefaulAppForManagedUserTest() override = default; | |
| 473 | |
| 474 protected: | |
| 475 bool IsEnabledByPolicy() const { | |
| 476 switch (GetParam()) { | |
| 477 case ArcState::ARC_MANAGED_ENABLED: | |
| 478 case ArcState::ARC_PERSISTENT_MANAGED_ENABLED: | |
| 479 return true; | |
| 480 case ArcState::ARC_MANAGED_DISABLED: | |
| 481 case ArcState::ARC_PERSISTENT_MANAGED_DISABLED: | |
| 482 return false; | |
| 483 default: | |
| 484 NOTREACHED(); | |
| 485 return false; | |
| 486 } | |
| 487 } | |
| 488 | |
| 489 // ArcPlayStoreAppTest: | |
| 490 void OnBeforeArcTestSetup() override { | |
| 491 policy::ProfilePolicyConnector* const connector = | |
| 492 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile()); | |
| 493 connector->OverrideIsManagedForTesting(true); | |
| 494 profile()->GetTestingPrefService()->SetManagedPref( | |
| 495 prefs::kArcEnabled, new base::Value(IsEnabledByPolicy())); | |
| 496 | |
| 497 ArcPlayStoreAppTest::OnBeforeArcTestSetup(); | |
| 498 } | |
| 499 | |
| 500 private: | |
| 501 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppForManagedUserTest); | |
| 502 }; | |
| 503 | |
| 444 class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest { | 504 class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest { |
| 445 public: | 505 public: |
| 446 ArcAppModelBuilderRecreate() = default; | 506 ArcAppModelBuilderRecreate() = default; |
| 447 ~ArcAppModelBuilderRecreate() override = default; | 507 ~ArcAppModelBuilderRecreate() override = default; |
| 448 | 508 |
| 449 protected: | 509 protected: |
| 450 // ArcAppModelBuilderTest: | 510 // ArcAppModelBuilderTest: |
| 451 void OnBeforeArcTestSetup() override { | 511 void OnBeforeArcTestSetup() override { |
| 452 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( | 512 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( |
| 453 profile_.get(), nullptr); | 513 profile_.get(), nullptr); |
| (...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1370 TEST_P(ArcDefaulAppForManagedUserTest, DefaultAppsForManagedUser) { | 1430 TEST_P(ArcDefaulAppForManagedUserTest, DefaultAppsForManagedUser) { |
| 1371 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(profile_.get()); | 1431 const ArcAppListPrefs* const prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1372 ASSERT_TRUE(prefs); | 1432 ASSERT_TRUE(prefs); |
| 1373 | 1433 |
| 1374 // There is no default app for managed users except Play Store | 1434 // There is no default app for managed users except Play Store |
| 1375 for (const auto& app : fake_default_apps()) { | 1435 for (const auto& app : fake_default_apps()) { |
| 1376 const std::string app_id = ArcAppTest::GetAppId(app); | 1436 const std::string app_id = ArcAppTest::GetAppId(app); |
| 1377 EXPECT_FALSE(prefs->IsRegistered(app_id)); | 1437 EXPECT_FALSE(prefs->IsRegistered(app_id)); |
| 1378 EXPECT_FALSE(prefs->GetApp(app_id)); | 1438 EXPECT_FALSE(prefs->GetApp(app_id)); |
| 1379 } | 1439 } |
| 1440 | |
| 1441 // PlayStor exists for managed and enabled state. | |
| 1442 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = | |
| 1443 prefs->GetApp(arc::kPlayStoreAppId); | |
| 1444 if (IsEnabledByPolicy()) { | |
| 1445 ASSERT_TRUE(app_info); | |
| 1446 EXPECT_FALSE(app_info->ready); | |
| 1447 } else { | |
| 1448 EXPECT_FALSE(prefs->IsRegistered(arc::kPlayStoreAppId)); | |
| 1449 EXPECT_FALSE(app_info); | |
| 1450 } | |
| 1380 } | 1451 } |
| 1381 | 1452 |
| 1382 INSTANTIATE_TEST_CASE_P(, ArcAppModelBuilderTest, ::testing::Bool()); | 1453 INSTANTIATE_TEST_CASE_P(, |
| 1383 INSTANTIATE_TEST_CASE_P(, ArcDefaulAppTest, ::testing::Bool()); | 1454 ArcAppModelBuilderTest, |
| 1384 INSTANTIATE_TEST_CASE_P(, ArcDefaulAppForManagedUserTest, ::testing::Bool()); | 1455 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1385 INSTANTIATE_TEST_CASE_P(, ArcPlayStoreAppTest, ::testing::Bool()); | 1456 INSTANTIATE_TEST_CASE_P(, |
| 1386 INSTANTIATE_TEST_CASE_P(, ArcAppModelBuilderRecreate, ::testing::Bool()); | 1457 ArcDefaulAppTest, |
| 1458 ::testing::ValuesIn(kUnmanagedArcStates)); | |
| 1459 INSTANTIATE_TEST_CASE_P(, | |
| 1460 ArcDefaulAppForManagedUserTest, | |
| 1461 ::testing::ValuesIn(kManagedArcStates)); | |
| 1462 INSTANTIATE_TEST_CASE_P(, | |
| 1463 ArcPlayStoreAppTest, | |
| 1464 ::testing::ValuesIn(kUnmanagedArcStates)); | |
| 1465 INSTANTIATE_TEST_CASE_P(, | |
| 1466 ArcAppModelBuilderRecreate, | |
| 1467 ::testing::ValuesIn(kUnmanagedArcStates)); | |
| OLD | NEW |