Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: chrome/browser/ui/app_list/arc/arc_app_unittest.cc

Issue 2908483002: Reland "arc: Invalidate app icon on package update." (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 void TearDown() override { 186 void TearDown() override {
187 arc_test_.TearDown(); 187 arc_test_.TearDown();
188 ResetBuilder(); 188 ResetBuilder();
189 } 189 }
190 190
191 protected: 191 protected:
192 // Notifies that initial preparation is done, profile is ready and it is time 192 // Notifies that initial preparation is done, profile is ready and it is time
193 // to initialize ARC subsystem. 193 // to initialize ARC subsystem.
194 virtual void OnBeforeArcTestSetup() {} 194 virtual void OnBeforeArcTestSetup() {}
195 195
196 // Simulates ARC restart.
197 void RestartArc() {
khmel 2017/05/25 16:06:26 Moved restart code to helper to reuse.
198 arc_test()->TearDown();
199 ResetBuilder();
200
201 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting(
202 profile_.get());
203 arc_test()->SetUp(profile_.get());
204 CreateBuilder();
205 }
206
196 // Creates a new builder, destroying any existing one. 207 // Creates a new builder, destroying any existing one.
197 void CreateBuilder() { 208 void CreateBuilder() {
198 ResetBuilder(); // Destroy any existing builder in the correct order. 209 ResetBuilder(); // Destroy any existing builder in the correct order.
199 210
200 model_.reset(new app_list::AppListModel); 211 model_.reset(new app_list::AppListModel);
201 controller_.reset(new test::TestAppListControllerDelegate); 212 controller_.reset(new test::TestAppListControllerDelegate);
202 builder_.reset(new ArcAppModelBuilder(controller_.get())); 213 builder_.reset(new ArcAppModelBuilder(controller_.get()));
203 builder_->InitializeWithProfile(profile_.get(), model_.get()); 214 builder_->InitializeWithProfile(profile_.get(), model_.get());
204 } 215 }
205 216
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 // Send info about all fake apps except last. 1100 // Send info about all fake apps except last.
1090 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(), 1101 std::vector<arc::mojom::AppInfo> apps1(fake_apps().begin(),
1091 fake_apps().end() - 1); 1102 fake_apps().end() - 1);
1092 app_instance()->RefreshAppList(); 1103 app_instance()->RefreshAppList();
1093 app_instance()->SendRefreshAppList(apps1); 1104 app_instance()->SendRefreshAppList(apps1);
1094 // Model has refreshed apps. 1105 // Model has refreshed apps.
1095 ValidateHaveApps(apps1); 1106 ValidateHaveApps(apps1);
1096 EXPECT_EQ(apps1.size(), GetArcItemCount()); 1107 EXPECT_EQ(apps1.size(), GetArcItemCount());
1097 1108
1098 // Simulate restart. 1109 // Simulate restart.
1099 arc_test()->TearDown(); 1110 RestartArc();
1100 ResetBuilder();
1101
1102 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting(
1103 profile_.get());
1104 arc_test()->SetUp(profile_.get());
1105 CreateBuilder();
1106 1111
1107 // On restart new model contains last apps. 1112 // On restart new model contains last apps.
1108 ValidateHaveApps(apps1); 1113 ValidateHaveApps(apps1);
1109 EXPECT_EQ(apps1.size(), GetArcItemCount()); 1114 EXPECT_EQ(apps1.size(), GetArcItemCount());
1110 1115
1111 // Now refresh old apps with new one. 1116 // Now refresh old apps with new one.
1112 app_instance()->RefreshAppList(); 1117 app_instance()->RefreshAppList();
1113 app_instance()->SendRefreshAppList(fake_apps()); 1118 app_instance()->SendRefreshAppList(fake_apps());
1114 ValidateHaveApps(fake_apps()); 1119 ValidateHaveApps(fake_apps());
1115 EXPECT_EQ(fake_apps().size(), GetArcItemCount()); 1120 EXPECT_EQ(fake_apps().size(), GetArcItemCount());
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 // Validate loaded image. 1331 // Validate loaded image.
1327 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); 1332 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt());
1328 EXPECT_EQ(app_id, delegate.app_id()); 1333 EXPECT_EQ(app_id, delegate.app_id());
1329 ValidateIcon(delegate.image()); 1334 ValidateIcon(delegate.image());
1330 1335
1331 // No more updates are expected. 1336 // No more updates are expected.
1332 base::RunLoop().RunUntilIdle(); 1337 base::RunLoop().RunUntilIdle();
1333 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt()); 1338 EXPECT_EQ(1 + scale_factors.size(), delegate.update_image_cnt());
1334 } 1339 }
1335 1340
1341 TEST_P(ArcAppModelBuilderRecreate, IconInvalidation) {
khmel 2017/05/25 16:06:26 This is the actual fix. ArcAppModelBuilderRecreate
1342 std::vector<ui::ScaleFactor> supported_scale_factors;
1343 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
1344 supported_scale_factors.push_back(ui::SCALE_FACTOR_200P);
1345 ui::test::ScopedSetSupportedScaleFactors scoped_supported_scale_factors(
1346 supported_scale_factors);
1347
1348 ASSERT_FALSE(fake_apps().empty());
1349 std::vector<arc::mojom::AppInfo> apps = std::vector<arc::mojom::AppInfo>(
1350 fake_apps().begin(), fake_apps().begin() + 1);
1351
1352 const arc::mojom::AppInfo& app = apps[0];
1353 const std::string app_id = ArcAppTest::GetAppId(app);
1354
1355 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1356 ASSERT_NE(nullptr, prefs);
1357
1358 app_instance()->RefreshAppList();
1359 app_instance()->SendRefreshAppList(apps);
1360
1361 prefs->MaybeRequestIcon(app_id, ui::SCALE_FACTOR_100P);
1362
1363 std::string png_data;
1364 EXPECT_TRUE(app_instance()->GenerateAndSendIcon(
1365 app, arc::mojom::ScaleFactor::SCALE_FACTOR_100P, &png_data));
1366 WaitForIconUpdates(profile_.get(), app_id, 1);
1367
1368 // Simulate ARC restart.
1369 RestartArc();
1370
1371 prefs = ArcAppListPrefs::Get(profile_.get());
1372 ASSERT_NE(nullptr, prefs);
1373 app_instance()->RefreshAppList();
1374 app_instance()->SendRefreshAppList(apps);
1375
1376 // No icon update requests on restart. Icons were not invalidated.
1377 EXPECT_TRUE(app_instance()->icon_requests().empty());
1378
1379 // Send new apps for the package. This should invalidate app icons.
1380 app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps);
1381 base::RunLoop().RunUntilIdle();
1382
1383 // Requests to reload icons are issued for all supported scales.
1384 const std::vector<std::unique_ptr<arc::FakeAppInstance::IconRequest>>&
1385 icon_requests = app_instance()->icon_requests();
1386 ASSERT_EQ(2U, icon_requests.size());
1387 EXPECT_TRUE(icon_requests[0]->IsForApp(app));
1388 EXPECT_EQ(icon_requests[0]->scale_factor(), ui::SCALE_FACTOR_100P);
1389 EXPECT_TRUE(icon_requests[1]->IsForApp(app));
1390 EXPECT_EQ(icon_requests[1]->scale_factor(), ui::SCALE_FACTOR_200P);
1391
1392 EXPECT_TRUE(app_instance()->GenerateAndSendIcon(
1393 app, arc::mojom::ScaleFactor::SCALE_FACTOR_100P, &png_data));
1394 EXPECT_TRUE(app_instance()->GenerateAndSendIcon(
1395 app, arc::mojom::ScaleFactor::SCALE_FACTOR_200P, &png_data));
1396 WaitForIconUpdates(profile_.get(), app_id, 2);
1397
1398 // Simulate ARC restart again.
1399 RestartArc();
1400
1401 prefs = ArcAppListPrefs::Get(profile_.get());
1402 ASSERT_NE(nullptr, prefs);
1403 app_instance()->RefreshAppList();
1404 app_instance()->SendRefreshAppList(apps);
1405
1406 // No new icon update requests on restart. Icons were invalidated and updated.
1407 EXPECT_TRUE(app_instance()->icon_requests().empty());
1408 }
1409
1336 TEST_P(ArcAppModelBuilderTest, AppLauncher) { 1410 TEST_P(ArcAppModelBuilderTest, AppLauncher) {
1337 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile()); 1411 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile());
1338 ASSERT_NE(nullptr, prefs); 1412 ASSERT_NE(nullptr, prefs);
1339 1413
1340 // App1 is called in deferred mode, after refreshing apps. 1414 // App1 is called in deferred mode, after refreshing apps.
1341 // App2 is never called since app is not avaialble. 1415 // App2 is never called since app is not avaialble.
1342 // App3 is never called immediately because app is available already. 1416 // App3 is never called immediately because app is available already.
1343 const arc::mojom::AppInfo& app1 = fake_apps()[0]; 1417 const arc::mojom::AppInfo& app1 = fake_apps()[0];
1344 const arc::mojom::AppInfo& app2 = fake_apps()[1]; 1418 const arc::mojom::AppInfo& app2 = fake_apps()[1];
1345 const arc::mojom::AppInfo& app3 = fake_apps()[2]; 1419 const arc::mojom::AppInfo& app3 = fake_apps()[2];
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 // App should not appear now in the model but should be registered. 1472 // App should not appear now in the model but should be registered.
1399 EXPECT_FALSE(FindArcItem(app_id)); 1473 EXPECT_FALSE(FindArcItem(app_id));
1400 EXPECT_TRUE(prefs->IsRegistered(app_id)); 1474 EXPECT_TRUE(prefs->IsRegistered(app_id));
1401 } 1475 }
1402 1476
1403 TEST_P(ArcAppModelBuilderTest, ArcAppsAndShortcutsOnPackageChange) { 1477 TEST_P(ArcAppModelBuilderTest, ArcAppsAndShortcutsOnPackageChange) {
1404 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1478 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1405 ASSERT_NE(nullptr, prefs); 1479 ASSERT_NE(nullptr, prefs);
1406 1480
1407 std::vector<arc::mojom::AppInfo> apps = fake_apps(); 1481 std::vector<arc::mojom::AppInfo> apps = fake_apps();
1408 ASSERT_GE(3u, apps.size()); 1482 ASSERT_GE(apps.size(), 3U);
1409 apps[0].package_name = apps[2].package_name; 1483 apps[0].package_name = apps[2].package_name;
1410 apps[1].package_name = apps[2].package_name; 1484 apps[1].package_name = apps[2].package_name;
1411 1485
1412 std::vector<arc::mojom::ShortcutInfo> shortcuts = fake_shortcuts(); 1486 std::vector<arc::mojom::ShortcutInfo> shortcuts = fake_shortcuts();
1413 for (auto& shortcut : shortcuts) 1487 for (auto& shortcut : shortcuts)
1414 shortcut.package_name = apps[0].package_name; 1488 shortcut.package_name = apps[0].package_name;
1415 1489
1416 // Second app should be preserved after update. 1490 // Second app should be preserved after update.
1417 std::vector<arc::mojom::AppInfo> apps1(apps.begin(), apps.begin() + 2); 1491 std::vector<arc::mojom::AppInfo> apps1(apps.begin(), apps.begin() + 2);
1418 std::vector<arc::mojom::AppInfo> apps2(apps.begin() + 1, apps.begin() + 3); 1492 std::vector<arc::mojom::AppInfo> apps2(apps.begin() + 1, apps.begin() + 3);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 // TODO(victorhsieh): Opt-out on Persistent ARC is special. Skip until 1574 // TODO(victorhsieh): Opt-out on Persistent ARC is special. Skip until
1501 // implemented. 1575 // implemented.
1502 if (arc::ShouldArcAlwaysStart()) 1576 if (arc::ShouldArcAlwaysStart())
1503 return; 1577 return;
1504 arc::SetArcPlayStoreEnabledForProfile(profile(), false); 1578 arc::SetArcPlayStoreEnabledForProfile(profile(), false);
1505 all_apps = fake_default_apps(); 1579 all_apps = fake_default_apps();
1506 all_apps.erase(all_apps.begin()); 1580 all_apps.erase(all_apps.begin());
1507 ValidateHaveApps(all_apps); 1581 ValidateHaveApps(all_apps);
1508 1582
1509 // Sign-out and sign-in again. Removed default app should not appear. 1583 // Sign-out and sign-in again. Removed default app should not appear.
1510 arc_test()->TearDown(); 1584 RestartArc();
1511 ResetBuilder();
1512 ArcAppListPrefsFactory::GetInstance()->RecreateServiceInstanceForTesting(
1513 profile_.get());
1514 arc_test()->SetUp(profile_.get());
1515 CreateBuilder();
1516 1585
1517 // Prefs are changed. 1586 // Prefs are changed.
1518 prefs = ArcAppListPrefs::Get(profile_.get()); 1587 prefs = ArcAppListPrefs::Get(profile_.get());
1519 ASSERT_NE(nullptr, prefs); 1588 ASSERT_NE(nullptr, prefs);
1520 ValidateHaveApps(all_apps); 1589 ValidateHaveApps(all_apps);
1521 1590
1522 // Install deleted default app again. 1591 // Install deleted default app again.
1523 std::vector<arc::mojom::AppInfo> package_apps; 1592 std::vector<arc::mojom::AppInfo> package_apps;
1524 package_apps.push_back(fake_default_apps()[0]); 1593 package_apps.push_back(fake_default_apps()[0]);
1525 app_instance()->SendPackageAppListRefreshed( 1594 app_instance()->SendPackageAppListRefreshed(
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 ::testing::ValuesIn(kUnmanagedArcStates)); 1726 ::testing::ValuesIn(kUnmanagedArcStates));
1658 INSTANTIATE_TEST_CASE_P(, 1727 INSTANTIATE_TEST_CASE_P(,
1659 ArcDefaulAppForManagedUserTest, 1728 ArcDefaulAppForManagedUserTest,
1660 ::testing::ValuesIn(kManagedArcStates)); 1729 ::testing::ValuesIn(kManagedArcStates));
1661 INSTANTIATE_TEST_CASE_P(, 1730 INSTANTIATE_TEST_CASE_P(,
1662 ArcPlayStoreAppTest, 1731 ArcPlayStoreAppTest,
1663 ::testing::ValuesIn(kUnmanagedArcStates)); 1732 ::testing::ValuesIn(kUnmanagedArcStates));
1664 INSTANTIATE_TEST_CASE_P(, 1733 INSTANTIATE_TEST_CASE_P(,
1665 ArcAppModelBuilderRecreate, 1734 ArcAppModelBuilderRecreate,
1666 ::testing::ValuesIn(kUnmanagedArcStates)); 1735 ::testing::ValuesIn(kUnmanagedArcStates));
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_list_prefs.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698