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> |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 | 439 |
| 440 private: | 440 private: |
| 441 ArcAppTest arc_test_; | 441 ArcAppTest arc_test_; |
| 442 std::unique_ptr<app_list::AppListModel> model_; | 442 std::unique_ptr<app_list::AppListModel> model_; |
| 443 std::unique_ptr<test::TestAppListControllerDelegate> controller_; | 443 std::unique_ptr<test::TestAppListControllerDelegate> controller_; |
| 444 std::unique_ptr<ArcAppModelBuilder> builder_; | 444 std::unique_ptr<ArcAppModelBuilder> builder_; |
| 445 | 445 |
| 446 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); | 446 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderTest); |
| 447 }; | 447 }; |
| 448 | 448 |
| 449 class ArcDefaulAppTest : public ArcAppModelBuilderTest { | 449 class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest { |
| 450 public: | |
| 451 ArcAppModelBuilderRecreate() = default; | |
| 452 ~ArcAppModelBuilderRecreate() override = default; | |
| 453 | |
| 454 protected: | |
| 455 // Simulates ARC restart. | |
| 456 void RestartArc() { | |
|
khmel
2017/05/25 16:15:55
Moved Restart here where this operation is safe to
| |
| 457 arc_test()->TearDown(); | |
| 458 ResetBuilder(); | |
| 459 | |
| 460 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( | |
| 461 profile_.get()); | |
| 462 arc_test()->SetUp(profile_.get()); | |
| 463 CreateBuilder(); | |
| 464 } | |
| 465 | |
| 466 // ArcAppModelBuilderTest: | |
| 467 void OnBeforeArcTestSetup() override { | |
| 468 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( | |
| 469 profile_.get(), nullptr); | |
| 470 } | |
| 471 | |
| 472 private: | |
| 473 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderRecreate); | |
| 474 }; | |
| 475 | |
| 476 class ArcDefaulAppTest : public ArcAppModelBuilderRecreate { | |
|
khmel
2017/05/25 16:15:55
Now ArcDefaulAppTest has base class ArcAppModelBu
| |
| 450 public: | 477 public: |
| 451 ArcDefaulAppTest() = default; | 478 ArcDefaulAppTest() = default; |
| 452 ~ArcDefaulAppTest() override = default; | 479 ~ArcDefaulAppTest() override = default; |
| 453 | 480 |
| 454 protected: | 481 protected: |
| 455 // ArcAppModelBuilderTest: | 482 // ArcAppModelBuilderTest: |
| 456 void OnBeforeArcTestSetup() override { | 483 void OnBeforeArcTestSetup() override { |
| 457 ArcDefaultAppList::UseTestAppsDirectory(); | 484 ArcDefaultAppList::UseTestAppsDirectory(); |
| 458 arc_test()->set_wait_default_apps(IsWaitDefaultAppsNeeded()); | 485 arc_test()->set_wait_default_apps(IsWaitDefaultAppsNeeded()); |
| 459 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( | 486 ArcAppModelBuilderRecreate::OnBeforeArcTestSetup(); |
| 460 profile_.get(), nullptr); | |
| 461 } | 487 } |
| 462 | 488 |
| 463 // Returns true if test needs to wait for default apps on setup. | 489 // Returns true if test needs to wait for default apps on setup. |
| 464 virtual bool IsWaitDefaultAppsNeeded() const { return true; } | 490 virtual bool IsWaitDefaultAppsNeeded() const { return true; } |
| 465 | 491 |
| 466 private: | 492 private: |
| 467 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); | 493 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); |
| 468 }; | 494 }; |
| 469 | 495 |
| 470 class ArcAppLauncherForDefaulAppTest : public ArcDefaulAppTest { | 496 class ArcAppLauncherForDefaulAppTest : public ArcDefaulAppTest { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 profile()->GetTestingPrefService()->SetManagedPref( | 567 profile()->GetTestingPrefService()->SetManagedPref( |
| 542 prefs::kArcEnabled, base::MakeUnique<base::Value>(IsEnabledByPolicy())); | 568 prefs::kArcEnabled, base::MakeUnique<base::Value>(IsEnabledByPolicy())); |
| 543 | 569 |
| 544 ArcPlayStoreAppTest::OnBeforeArcTestSetup(); | 570 ArcPlayStoreAppTest::OnBeforeArcTestSetup(); |
| 545 } | 571 } |
| 546 | 572 |
| 547 private: | 573 private: |
| 548 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppForManagedUserTest); | 574 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppForManagedUserTest); |
| 549 }; | 575 }; |
| 550 | 576 |
| 551 class ArcAppModelBuilderRecreate : public ArcAppModelBuilderTest { | |
| 552 public: | |
| 553 ArcAppModelBuilderRecreate() = default; | |
| 554 ~ArcAppModelBuilderRecreate() override = default; | |
| 555 | |
| 556 protected: | |
| 557 // ArcAppModelBuilderTest: | |
| 558 void OnBeforeArcTestSetup() override { | |
| 559 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( | |
| 560 profile_.get(), nullptr); | |
| 561 } | |
| 562 | |
| 563 private: | |
| 564 DISALLOW_COPY_AND_ASSIGN(ArcAppModelBuilderRecreate); | |
| 565 }; | |
| 566 | |
| 567 TEST_P(ArcAppModelBuilderTest, ArcPackagePref) { | 577 TEST_P(ArcAppModelBuilderTest, ArcPackagePref) { |
| 568 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); | 578 ValidateHavePackages(std::vector<arc::mojom::ArcPackageInfo>()); |
| 569 app_instance()->SendRefreshPackageList(fake_packages()); | 579 app_instance()->SendRefreshPackageList(fake_packages()); |
| 570 ValidateHavePackages(fake_packages()); | 580 ValidateHavePackages(fake_packages()); |
| 571 | 581 |
| 572 arc::mojom::ArcPackageInfo package; | 582 arc::mojom::ArcPackageInfo package; |
| 573 package.package_name = kTestPackageName; | 583 package.package_name = kTestPackageName; |
| 574 package.package_version = 2; | 584 package.package_version = 2; |
| 575 package.last_backup_android_id = 2; | 585 package.last_backup_android_id = 2; |
| 576 package.last_backup_time = 2; | 586 package.last_backup_time = 2; |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1089 // Send info about all fake apps except last. | 1099 // Send info about all fake apps except last. |
| 1090 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(), | 1100 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(), |
| 1091 fake_apps().end() - 1); | 1101 fake_apps().end() - 1); |
| 1092 app_instance()->RefreshAppList(); | 1102 app_instance()->RefreshAppList(); |
| 1093 app_instance()->SendRefreshAppList(apps1); | 1103 app_instance()->SendRefreshAppList(apps1); |
| 1094 // Model has refreshed apps. | 1104 // Model has refreshed apps. |
| 1095 ValidateHaveApps(apps1); | 1105 ValidateHaveApps(apps1); |
| 1096 EXPECT_EQ(apps1.size(), GetArcItemCount()); | 1106 EXPECT_EQ(apps1.size(), GetArcItemCount()); |
| 1097 | 1107 |
| 1098 // Simulate restart. | 1108 // Simulate restart. |
| 1099 arc_test()->TearDown(); | 1109 RestartArc(); |
| 1100 ResetBuilder(); | |
| 1101 | |
| 1102 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( | |
| 1103 profile_.get()); | |
| 1104 arc_test()->SetUp(profile_.get()); | |
| 1105 CreateBuilder(); | |
| 1106 | 1110 |
| 1107 // On restart new model contains last apps. | 1111 // On restart new model contains last apps. |
| 1108 ValidateHaveApps(apps1); | 1112 ValidateHaveApps(apps1); |
| 1109 EXPECT_EQ(apps1.size(), GetArcItemCount()); | 1113 EXPECT_EQ(apps1.size(), GetArcItemCount()); |
| 1110 | 1114 |
| 1111 // Now refresh old apps with new one. | 1115 // Now refresh old apps with new one. |
| 1112 app_instance()->RefreshAppList(); | 1116 app_instance()->RefreshAppList(); |
| 1113 app_instance()->SendRefreshAppList(fake_apps()); | 1117 app_instance()->SendRefreshAppList(fake_apps()); |
| 1114 ValidateHaveApps(fake_apps()); | 1118 ValidateHaveApps(fake_apps()); |
| 1115 EXPECT_EQ(fake_apps().size(), GetArcItemCount()); | 1119 EXPECT_EQ(fake_apps().size(), GetArcItemCount()); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1326 // Validate loaded image. | 1330 // Validate loaded image. |
| 1327 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); | 1331 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); |
| 1328 EXPECT_EQ(app_id, delegate.app_id()); | 1332 EXPECT_EQ(app_id, delegate.app_id()); |
| 1329 ValidateIcon(delegate.image()); | 1333 ValidateIcon(delegate.image()); |
| 1330 | 1334 |
| 1331 // No more updates are expected. | 1335 // No more updates are expected. |
| 1332 base::RunLoop().RunUntilIdle(); | 1336 base::RunLoop().RunUntilIdle(); |
| 1333 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); | 1337 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); |
| 1334 } | 1338 } |
| 1335 | 1339 |
| 1340 TEST_P(ArcAppModelBuilderRecreate, IconInvalidation) { | |
| 1341 std::vector<ui::ScaleFactor> supported_scale_factors; | |
| 1342 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P); | |
| 1343 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P); | |
| 1344 ui::test::ScopedSetSupportedScaleFactors scoped_supported_scale_factors( | |
| 1345 supported_scale_factors); | |
| 1346 | |
| 1347 ASSERT_FALSE(fake_apps().empty()); | |
| 1348 std::vector<arc::mojom::AppInfo> apps = std::vector<arc::mojom::AppInfo>( | |
| 1349 fake_apps().begin(), fake_apps().begin() + 1); | |
| 1350 | |
| 1351 const arc::mojom::AppInfo& app = apps[0]; | |
| 1352 const std::string app_id = ArcAppTest::GetAppId(app); | |
| 1353 | |
| 1354 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | |
| 1355 ASSERT_NE(nullptr, prefs); | |
| 1356 | |
| 1357 app_instance()->RefreshAppList(); | |
| 1358 app_instance()->SendRefreshAppList(apps); | |
| 1359 | |
| 1360 prefs->MaybeRequestIcon(app_id, ui::SCALE_FACTOR_100P); | |
| 1361 | |
| 1362 std::string png_data; | |
| 1363 EXPECT_TRUE(app_instance()->GenerateAndSendIcon( | |
| 1364 app, arc::mojom::ScaleFactor::SCALE_FACTOR_100P, &png_data)); | |
| 1365 WaitForIconUpdates(profile_.get(), app_id, 1); | |
| 1366 | |
| 1367 // Simulate ARC restart. | |
| 1368 RestartArc(); | |
| 1369 | |
| 1370 prefs = ArcAppListPrefs::Get(profile_.get()); | |
| 1371 ASSERT_NE(nullptr, prefs); | |
| 1372 app_instance()->RefreshAppList(); | |
| 1373 app_instance()->SendRefreshAppList(apps); | |
| 1374 | |
| 1375 // No icon update requests on restart. Icons were not invalidated. | |
| 1376 EXPECT_TRUE(app_instance()->icon_requests().empty()); | |
| 1377 | |
| 1378 // Send new apps for the package. This should invalidate app icons. | |
| 1379 app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps); | |
| 1380 base::RunLoop().RunUntilIdle(); | |
| 1381 | |
| 1382 // Requests to reload icons are issued for all supported scales. | |
| 1383 const std::vector<std::unique_ptr<arc::FakeAppInstance::IconRequest>>& | |
| 1384 icon_requests = app_instance()->icon_requests(); | |
| 1385 ASSERT_EQ(2U, icon_requests.size()); | |
| 1386 EXPECT_TRUE(icon_requests[0]->IsForApp(app)); | |
| 1387 EXPECT_EQ(icon_requests[0]->scale_factor(), ui::SCALE_FACTOR_100P); | |
| 1388 EXPECT_TRUE(icon_requests[1]->IsForApp(app)); | |
| 1389 EXPECT_EQ(icon_requests[1]->scale_factor(), ui::SCALE_FACTOR_200P); | |
| 1390 | |
| 1391 EXPECT_TRUE(app_instance()->GenerateAndSendIcon( | |
| 1392 app, arc::mojom::ScaleFactor::SCALE_FACTOR_100P, &png_data)); | |
| 1393 EXPECT_TRUE(app_instance()->GenerateAndSendIcon( | |
| 1394 app, arc::mojom::ScaleFactor::SCALE_FACTOR_200P, &png_data)); | |
| 1395 WaitForIconUpdates(profile_.get(), app_id, 2); | |
| 1396 | |
| 1397 // Simulate ARC restart again. | |
| 1398 RestartArc(); | |
| 1399 | |
| 1400 prefs = ArcAppListPrefs::Get(profile_.get()); | |
| 1401 ASSERT_NE(nullptr, prefs); | |
| 1402 app_instance()->RefreshAppList(); | |
| 1403 app_instance()->SendRefreshAppList(apps); | |
| 1404 | |
| 1405 // No new icon update requests on restart. Icons were invalidated and updated. | |
| 1406 EXPECT_TRUE(app_instance()->icon_requests().empty()); | |
| 1407 } | |
| 1408 | |
| 1336 TEST_P(ArcAppModelBuilderTest, AppLauncher) { | 1409 TEST_P(ArcAppModelBuilderTest, AppLauncher) { |
| 1337 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); | 1410 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); |
| 1338 ASSERT_NE(nullptr, prefs); | 1411 ASSERT_NE(nullptr, prefs); |
| 1339 | 1412 |
| 1340 // App1 is called in deferred mode, after refreshing apps. | 1413 // App1 is called in deferred mode, after refreshing apps. |
| 1341 // App2 is never called since app is not avaialble. | 1414 // App2 is never called since app is not avaialble. |
| 1342 // App3 is never called immediately because app is available already. | 1415 // App3 is never called immediately because app is available already. |
| 1343 const arc::mojom::AppInfo& app1 = fake_apps()[0]; | 1416 const arc::mojom::AppInfo& app1 = fake_apps()[0]; |
| 1344 const arc::mojom::AppInfo& app2 = fake_apps()[1]; | 1417 const arc::mojom::AppInfo& app2 = fake_apps()[1]; |
| 1345 const arc::mojom::AppInfo& app3 = fake_apps()[2]; | 1418 const arc::mojom::AppInfo& app3 = fake_apps()[2]; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1398 // App should not appear now in the model but should be registered. | 1471 // App should not appear now in the model but should be registered. |
| 1399 EXPECT_FALSE(FindArcItem(app_id)); | 1472 EXPECT_FALSE(FindArcItem(app_id)); |
| 1400 EXPECT_TRUE(prefs->IsRegistered(app_id)); | 1473 EXPECT_TRUE(prefs->IsRegistered(app_id)); |
| 1401 } | 1474 } |
| 1402 | 1475 |
| 1403 TEST_P(ArcAppModelBuilderTest, ArcAppsAndShortcutsOnPackageChange) { | 1476 TEST_P(ArcAppModelBuilderTest, ArcAppsAndShortcutsOnPackageChange) { |
| 1404 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 1477 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1405 ASSERT_NE(nullptr, prefs); | 1478 ASSERT_NE(nullptr, prefs); |
| 1406 | 1479 |
| 1407 std::vector<arc::mojom::AppInfo> apps = fake_apps(); | 1480 std::vector<arc::mojom::AppInfo> apps = fake_apps(); |
| 1408 ASSERT_GE(3u, apps.size()); | 1481 ASSERT_GE(apps.size(), 3U); |
| 1409 apps[0].package_name = apps[2].package_name; | 1482 apps[0].package_name = apps[2].package_name; |
| 1410 apps[1].package_name = apps[2].package_name; | 1483 apps[1].package_name = apps[2].package_name; |
| 1411 | 1484 |
| 1412 std::vector<arc::mojom::ShortcutInfo> shortcuts = fake_shortcuts(); | 1485 std::vector<arc::mojom::ShortcutInfo> shortcuts = fake_shortcuts(); |
| 1413 for (auto& shortcut : shortcuts) | 1486 for (auto& shortcut : shortcuts) |
| 1414 shortcut.package_name = apps[0].package_name; | 1487 shortcut.package_name = apps[0].package_name; |
| 1415 | 1488 |
| 1416 // Second app should be preserved after update. | 1489 // Second app should be preserved after update. |
| 1417 std::vector<arc::mojom::AppInfo> apps1(apps.begin(), apps.begin() + 2); | 1490 std::vector<arc::mojom::AppInfo> apps1(apps.begin(), apps.begin() + 2); |
| 1418 std::vector<arc::mojom::AppInfo> apps2(apps.begin() + 1, apps.begin() + 3); | 1491 std::vector<arc::mojom::AppInfo> apps2(apps.begin() + 1, apps.begin() + 3); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1500 // TODO(victorhsieh): Opt-out on Persistent ARC is special. Skip until | 1573 // TODO(victorhsieh): Opt-out on Persistent ARC is special. Skip until |
| 1501 // implemented. | 1574 // implemented. |
| 1502 if (arc::ShouldArcAlwaysStart()) | 1575 if (arc::ShouldArcAlwaysStart()) |
| 1503 return; | 1576 return; |
| 1504 arc::SetArcPlayStoreEnabledForProfile(profile(), false); | 1577 arc::SetArcPlayStoreEnabledForProfile(profile(), false); |
| 1505 all_apps = fake_default_apps(); | 1578 all_apps = fake_default_apps(); |
| 1506 all_apps.erase(all_apps.begin()); | 1579 all_apps.erase(all_apps.begin()); |
| 1507 ValidateHaveApps(all_apps); | 1580 ValidateHaveApps(all_apps); |
| 1508 | 1581 |
| 1509 // Sign-out and sign-in again. Removed default app should not appear. | 1582 // Sign-out and sign-in again. Removed default app should not appear. |
| 1510 arc_test()->TearDown(); | 1583 RestartArc(); |
| 1511 ResetBuilder(); | |
| 1512 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( | |
| 1513 profile_.get()); | |
| 1514 arc_test()->SetUp(profile_.get()); | |
| 1515 CreateBuilder(); | |
| 1516 | 1584 |
| 1517 // Prefs are changed. | 1585 // Prefs are changed. |
| 1518 prefs = ArcAppListPrefs::Get(profile_.get()); | 1586 prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1519 ASSERT_NE(nullptr, prefs); | 1587 ASSERT_NE(nullptr, prefs); |
| 1520 ValidateHaveApps(all_apps); | 1588 ValidateHaveApps(all_apps); |
| 1521 | 1589 |
| 1522 // Install deleted default app again. | 1590 // Install deleted default app again. |
| 1523 std::vector<arc::mojom::AppInfo> package_apps; | 1591 std::vector<arc::mojom::AppInfo> package_apps; |
| 1524 package_apps.push_back(fake_default_apps()[0]); | 1592 package_apps.push_back(fake_default_apps()[0]); |
| 1525 app_instance()->SendPackageAppListRefreshed( | 1593 app_instance()->SendPackageAppListRefreshed( |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1657 ::testing::ValuesIn(kUnmanagedArcStates)); | 1725 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1658 INSTANTIATE_TEST_CASE_P(, | 1726 INSTANTIATE_TEST_CASE_P(, |
| 1659 ArcDefaulAppForManagedUserTest, | 1727 ArcDefaulAppForManagedUserTest, |
| 1660 ::testing::ValuesIn(kManagedArcStates)); | 1728 ::testing::ValuesIn(kManagedArcStates)); |
| 1661 INSTANTIATE_TEST_CASE_P(, | 1729 INSTANTIATE_TEST_CASE_P(, |
| 1662 ArcPlayStoreAppTest, | 1730 ArcPlayStoreAppTest, |
| 1663 ::testing::ValuesIn(kUnmanagedArcStates)); | 1731 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1664 INSTANTIATE_TEST_CASE_P(, | 1732 INSTANTIATE_TEST_CASE_P(, |
| 1665 ArcAppModelBuilderRecreate, | 1733 ArcAppModelBuilderRecreate, |
| 1666 ::testing::ValuesIn(kUnmanagedArcStates)); | 1734 ::testing::ValuesIn(kUnmanagedArcStates)); |
| OLD | NEW |