Chromium Code Reviews| Index: chrome/browser/ui/app_list/arc/arc_app_unittest.cc |
| diff --git a/chrome/browser/ui/app_list/arc/arc_app_unittest.cc b/chrome/browser/ui/app_list/arc/arc_app_unittest.cc |
| index 5ac7764dd1dde8a1b9c2fb9eb20bb4bbfcc7556e..28c42b557adfc8940e1d0bf6c6471075316a5f85 100644 |
| --- a/chrome/browser/ui/app_list/arc/arc_app_unittest.cc |
| +++ b/chrome/browser/ui/app_list/arc/arc_app_unittest.cc |
| @@ -193,6 +193,17 @@ class ArcAppModelBuilderTest : public extensions::ExtensionServiceTestBase, |
| // to initialize ARC subsystem. |
| virtual void OnBeforeArcTestSetup() {} |
| + // Simulates ARC restart. |
| + void RestartArc() { |
|
khmel
2017/05/25 16:06:26
Moved restart code to helper to reuse.
|
| + arc_test()->TearDown(); |
| + ResetBuilder(); |
| + |
| + ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( |
| + profile_.get()); |
| + arc_test()->SetUp(profile_.get()); |
| + CreateBuilder(); |
| + } |
| + |
| // Creates a new builder, destroying any existing one. |
| void CreateBuilder() { |
| ResetBuilder(); // Destroy any existing builder in the correct order. |
| @@ -1096,13 +1107,7 @@ TEST_P(ArcAppModelBuilderRecreate, AppModelRestart) { |
| EXPECT_EQ(apps1.size(), GetArcItemCount()); |
| // Simulate restart. |
| - arc_test()->TearDown(); |
| - ResetBuilder(); |
| - |
| - ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( |
| - profile_.get()); |
| - arc_test()->SetUp(profile_.get()); |
| - CreateBuilder(); |
| + RestartArc(); |
| // On restart new model contains last apps. |
| ValidateHaveApps(apps1); |
| @@ -1333,6 +1338,75 @@ TEST_P(ArcAppModelBuilderTest, IconLoader) { |
| EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); |
| } |
| +TEST_P(ArcAppModelBuilderRecreate, IconInvalidation) { |
|
khmel
2017/05/25 16:06:26
This is the actual fix. ArcAppModelBuilderRecreate
|
| + std::vector<ui::ScaleFactor> supported_scale_factors; |
| + supported_scale_factors.push_back(ui::SCALE_FACTOR_100P); |
| + supported_scale_factors.push_back(ui::SCALE_FACTOR_200P); |
| + ui::test::ScopedSetSupportedScaleFactors scoped_supported_scale_factors( |
| + supported_scale_factors); |
| + |
| + ASSERT_FALSE(fake_apps().empty()); |
| + std::vector<arc::mojom::AppInfo> apps = std::vector<arc::mojom::AppInfo>( |
| + fake_apps().begin(), fake_apps().begin() + 1); |
| + |
| + const arc::mojom::AppInfo& app = apps[0]; |
| + const std::string app_id = ArcAppTest::GetAppId(app); |
| + |
| + ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| + ASSERT_NE(nullptr, prefs); |
| + |
| + app_instance()->RefreshAppList(); |
| + app_instance()->SendRefreshAppList(apps); |
| + |
| + prefs->MaybeRequestIcon(app_id, ui::SCALE_FACTOR_100P); |
| + |
| + std::string png_data; |
| + EXPECT_TRUE(app_instance()->GenerateAndSendIcon( |
| + app, arc::mojom::ScaleFactor::SCALE_FACTOR_100P, &png_data)); |
| + WaitForIconUpdates(profile_.get(), app_id, 1); |
| + |
| + // Simulate ARC restart. |
| + RestartArc(); |
| + |
| + prefs = ArcAppListPrefs::Get(profile_.get()); |
| + ASSERT_NE(nullptr, prefs); |
| + app_instance()->RefreshAppList(); |
| + app_instance()->SendRefreshAppList(apps); |
| + |
| + // No icon update requests on restart. Icons were not invalidated. |
| + EXPECT_TRUE(app_instance()->icon_requests().empty()); |
| + |
| + // Send new apps for the package. This should invalidate app icons. |
| + app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + // Requests to reload icons are issued for all supported scales. |
| + const std::vector<std::unique_ptr<arc::FakeAppInstance::IconRequest>>& |
| + icon_requests = app_instance()->icon_requests(); |
| + ASSERT_EQ(2U, icon_requests.size()); |
| + EXPECT_TRUE(icon_requests[0]->IsForApp(app)); |
| + EXPECT_EQ(icon_requests[0]->scale_factor(), ui::SCALE_FACTOR_100P); |
| + EXPECT_TRUE(icon_requests[1]->IsForApp(app)); |
| + EXPECT_EQ(icon_requests[1]->scale_factor(), ui::SCALE_FACTOR_200P); |
| + |
| + EXPECT_TRUE(app_instance()->GenerateAndSendIcon( |
| + app, arc::mojom::ScaleFactor::SCALE_FACTOR_100P, &png_data)); |
| + EXPECT_TRUE(app_instance()->GenerateAndSendIcon( |
| + app, arc::mojom::ScaleFactor::SCALE_FACTOR_200P, &png_data)); |
| + WaitForIconUpdates(profile_.get(), app_id, 2); |
| + |
| + // Simulate ARC restart again. |
| + RestartArc(); |
| + |
| + prefs = ArcAppListPrefs::Get(profile_.get()); |
| + ASSERT_NE(nullptr, prefs); |
| + app_instance()->RefreshAppList(); |
| + app_instance()->SendRefreshAppList(apps); |
| + |
| + // No new icon update requests on restart. Icons were invalidated and updated. |
| + EXPECT_TRUE(app_instance()->icon_requests().empty()); |
| +} |
| + |
| TEST_P(ArcAppModelBuilderTest, AppLauncher) { |
| ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); |
| ASSERT_NE(nullptr, prefs); |
| @@ -1405,7 +1479,7 @@ TEST_P(ArcAppModelBuilderTest, ArcAppsAndShortcutsOnPackageChange) { |
| ASSERT_NE(nullptr, prefs); |
| std::vector<arc::mojom::AppInfo> apps = fake_apps(); |
| - ASSERT_GE(3u, apps.size()); |
| + ASSERT_GE(apps.size(), 3U); |
| apps[0].package_name = apps[2].package_name; |
| apps[1].package_name = apps[2].package_name; |
| @@ -1507,12 +1581,7 @@ TEST_P(ArcDefaulAppTest, DefaultApps) { |
| ValidateHaveApps(all_apps); |
| // Sign-out and sign-in again. Removed default app should not appear. |
| - arc_test()->TearDown(); |
| - ResetBuilder(); |
| - ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting( |
| - profile_.get()); |
| - arc_test()->SetUp(profile_.get()); |
| - CreateBuilder(); |
| + RestartArc(); |
| // Prefs are changed. |
| prefs = ArcAppListPrefs::Get(profile_.get()); |