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

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

Issue 2751913004: arc: Fix race conditon when Play Store is started too early. (Closed)
Patch Set: adressed Hidehiko's comments Created 3 years, 9 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
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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 418
419 class ArcDefaulAppTest : public ArcAppModelBuilderTest { 419 class ArcDefaulAppTest : public ArcAppModelBuilderTest {
420 public: 420 public:
421 ArcDefaulAppTest() = default; 421 ArcDefaulAppTest() = default;
422 ~ArcDefaulAppTest() override = default; 422 ~ArcDefaulAppTest() override = default;
423 423
424 protected: 424 protected:
425 // ArcAppModelBuilderTest: 425 // ArcAppModelBuilderTest:
426 void OnBeforeArcTestSetup() override { 426 void OnBeforeArcTestSetup() override {
427 ArcDefaultAppList::UseTestAppsDirectory(); 427 ArcDefaultAppList::UseTestAppsDirectory();
428 arc_test()->set_wait_default_apps(IsNeedWaitDefaultApps());
428 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory( 429 arc::ArcPackageSyncableServiceFactory::GetInstance()->SetTestingFactory(
429 profile_.get(), nullptr); 430 profile_.get(), nullptr);
430 } 431 }
431 432
433 // Returns true if test needs to wait for default apps on setup.
434 virtual bool IsNeedWaitDefaultApps() const { return true; }
hidehiko 2017/03/16 16:23:19 nit: IsWaitDefaultAppsNeeded() looks more common p
khmel 2017/03/16 16:38:47 Done.
435
432 private: 436 private:
433 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest); 437 DISALLOW_COPY_AND_ASSIGN(ArcDefaulAppTest);
434 }; 438 };
435 439
440 class ArcAppLauncherForDefaulAppTest : public ArcDefaulAppTest {
441 public:
442 ArcAppLauncherForDefaulAppTest() = default;
443 ~ArcAppLauncherForDefaulAppTest() override = default;
444
445 protected:
446 // ArcDefaulAppTest:
447 bool IsNeedWaitDefaultApps() const override { return false; }
448
449 private:
450 DISALLOW_COPY_AND_ASSIGN(ArcAppLauncherForDefaulAppTest);
451 };
452
436 class ArcPlayStoreAppTest : public ArcDefaulAppTest { 453 class ArcPlayStoreAppTest : public ArcDefaulAppTest {
437 public: 454 public:
438 ArcPlayStoreAppTest() = default; 455 ArcPlayStoreAppTest() = default;
439 ~ArcPlayStoreAppTest() override = default; 456 ~ArcPlayStoreAppTest() override = default;
440 457
441 protected: 458 protected:
442 // ArcAppModelBuilderTest: 459 // ArcAppModelBuilderTest:
443 void OnBeforeArcTestSetup() override { 460 void OnBeforeArcTestSetup() override {
444 ArcDefaulAppTest::OnBeforeArcTestSetup(); 461 ArcDefaulAppTest::OnBeforeArcTestSetup();
445 462
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 // App1 is called in deferred mode, after refreshing apps. 1212 // App1 is called in deferred mode, after refreshing apps.
1196 // App2 is never called since app is not avaialble. 1213 // App2 is never called since app is not avaialble.
1197 // App3 is never called immediately because app is available already. 1214 // App3 is never called immediately because app is available already.
1198 const arc::mojom::AppInfo& app1 = fake_apps()[0]; 1215 const arc::mojom::AppInfo& app1 = fake_apps()[0];
1199 const arc::mojom::AppInfo& app2 = fake_apps()[1]; 1216 const arc::mojom::AppInfo& app2 = fake_apps()[1];
1200 const arc::mojom::AppInfo& app3 = fake_apps()[2]; 1217 const arc::mojom::AppInfo& app3 = fake_apps()[2];
1201 const std::string id1 = ArcAppTest::GetAppId(app1); 1218 const std::string id1 = ArcAppTest::GetAppId(app1);
1202 const std::string id2 = ArcAppTest::GetAppId(app2); 1219 const std::string id2 = ArcAppTest::GetAppId(app2);
1203 const std::string id3 = ArcAppTest::GetAppId(app3); 1220 const std::string id3 = ArcAppTest::GetAppId(app3);
1204 1221
1205 ArcAppLauncher launcher1(profile(), id1, true); 1222 ArcAppLauncher launcher1(profile(), id1, true, false);
1206 EXPECT_FALSE(launcher1.app_launched()); 1223 EXPECT_FALSE(launcher1.app_launched());
1207 EXPECT_TRUE(prefs->HasObserver(&launcher1)); 1224 EXPECT_TRUE(prefs->HasObserver(&launcher1));
1208 1225
1209 ArcAppLauncher launcher3(profile(), id3, true); 1226 ArcAppLauncher launcher3(profile(), id3, true, false);
1210 EXPECT_FALSE(launcher1.app_launched()); 1227 EXPECT_FALSE(launcher1.app_launched());
1211 EXPECT_TRUE(prefs->HasObserver(&launcher1)); 1228 EXPECT_TRUE(prefs->HasObserver(&launcher1));
1212 EXPECT_FALSE(launcher3.app_launched()); 1229 EXPECT_FALSE(launcher3.app_launched());
1213 EXPECT_TRUE(prefs->HasObserver(&launcher3)); 1230 EXPECT_TRUE(prefs->HasObserver(&launcher3));
1214 1231
1215 EXPECT_EQ(0u, app_instance()->launch_requests().size()); 1232 EXPECT_EQ(0u, app_instance()->launch_requests().size());
1216 1233
1217 std::vector<arc::mojom::AppInfo> apps(fake_apps().begin(), 1234 std::vector<arc::mojom::AppInfo> apps(fake_apps().begin(),
1218 fake_apps().begin() + 2); 1235 fake_apps().begin() + 2);
1219 app_instance()->SendRefreshAppList(apps); 1236 app_instance()->SendRefreshAppList(apps);
1220 1237
1221 EXPECT_TRUE(launcher1.app_launched()); 1238 EXPECT_TRUE(launcher1.app_launched());
1222 ASSERT_EQ(1u, app_instance()->launch_requests().size()); 1239 ASSERT_EQ(1u, app_instance()->launch_requests().size());
1223 EXPECT_TRUE(app_instance()->launch_requests()[0]->IsForApp(app1)); 1240 EXPECT_TRUE(app_instance()->launch_requests()[0]->IsForApp(app1));
1224 EXPECT_FALSE(launcher3.app_launched()); 1241 EXPECT_FALSE(launcher3.app_launched());
1225 EXPECT_FALSE(prefs->HasObserver(&launcher1)); 1242 EXPECT_FALSE(prefs->HasObserver(&launcher1));
1226 EXPECT_TRUE(prefs->HasObserver(&launcher3)); 1243 EXPECT_TRUE(prefs->HasObserver(&launcher3));
1227 1244
1228 ArcAppLauncher launcher2(profile(), id2, true); 1245 ArcAppLauncher launcher2(profile(), id2, true, false);
1229 EXPECT_TRUE(launcher2.app_launched()); 1246 EXPECT_TRUE(launcher2.app_launched());
1230 EXPECT_FALSE(prefs->HasObserver(&launcher2)); 1247 EXPECT_FALSE(prefs->HasObserver(&launcher2));
1231 ASSERT_EQ(2u, app_instance()->launch_requests().size()); 1248 ASSERT_EQ(2u, app_instance()->launch_requests().size());
1232 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2)); 1249 EXPECT_TRUE(app_instance()->launch_requests()[1]->IsForApp(app2));
1233 } 1250 }
1234 1251
1235 // Validates an app that have no launchable flag. 1252 // Validates an app that have no launchable flag.
1236 TEST_P(ArcAppModelBuilderTest, NonLaunchableApp) { 1253 TEST_P(ArcAppModelBuilderTest, NonLaunchableApp) {
1237 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1254 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1238 ASSERT_NE(nullptr, prefs); 1255 ASSERT_NE(nullptr, prefs);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 // Install deleted default app again. 1376 // Install deleted default app again.
1360 std::vector<arc::mojom::AppInfo> package_apps; 1377 std::vector<arc::mojom::AppInfo> package_apps;
1361 package_apps.push_back(fake_default_apps()[0]); 1378 package_apps.push_back(fake_default_apps()[0]);
1362 app_instance()->SendPackageAppListRefreshed( 1379 app_instance()->SendPackageAppListRefreshed(
1363 fake_default_apps()[0].package_name, package_apps); 1380 fake_default_apps()[0].package_name, package_apps);
1364 ValidateHaveApps(fake_default_apps()); 1381 ValidateHaveApps(fake_default_apps());
1365 1382
1366 // Validate that OEM state is preserved. 1383 // Validate that OEM state is preserved.
1367 for (const auto& default_app : fake_default_apps()) { 1384 for (const auto& default_app : fake_default_apps()) {
1368 const std::string app_id = ArcAppTest::GetAppId(default_app); 1385 const std::string app_id = ArcAppTest::GetAppId(default_app);
1386 printf("#### %s %d %d\n", app_id.c_str(), oem_states[app_id],
hidehiko 2017/03/16 16:23:19 Looks debugging purpose? Could you remove?
khmel 2017/03/16 16:38:47 Hmm, why git cl upload did not catch this? Done
1387 prefs->IsOem(app_id));
1369 EXPECT_EQ(oem_states[app_id], prefs->IsOem(app_id)); 1388 EXPECT_EQ(oem_states[app_id], prefs->IsOem(app_id));
1370 } 1389 }
1371 } 1390 }
1372 1391
1392 TEST_P(ArcAppLauncherForDefaulAppTest, AppLauncherForDefaultApps) {
1393 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1394 ASSERT_NE(nullptr, prefs);
1395
1396 ASSERT_GE(fake_default_apps().size(), 2U);
1397 const arc::mojom::AppInfo& app1 = fake_default_apps()[0];
1398 const arc::mojom::AppInfo& app2 = fake_default_apps()[1];
1399 const std::string id1 = ArcAppTest::GetAppId(app1);
1400 const std::string id2 = ArcAppTest::GetAppId(app2);
1401
1402 // Launch when app is registered and ready.
1403 ArcAppLauncher launcher1(profile(), id1, true, false);
1404 // Launch when app is registered.
1405 ArcAppLauncher launcher2(profile(), id2, true, true);
1406
1407 EXPECT_FALSE(launcher1.app_launched());
1408 EXPECT_FALSE(launcher2.app_launched());
1409
1410 arc_test()->WaitForDefaultApps();
1411
1412 // Only second app is expected to be launched.
1413 EXPECT_FALSE(launcher1.app_launched());
1414 EXPECT_TRUE(launcher2.app_launched());
1415
1416 app_instance()->RefreshAppList();
1417 app_instance()->SendRefreshAppList(fake_default_apps());
1418 // Default apps are ready now and it is expected that first app was launched
1419 // now.
1420 EXPECT_TRUE(launcher1.app_launched());
1421 }
1422
1373 TEST_P(ArcDefaulAppTest, DefaultAppsNotAvailable) { 1423 TEST_P(ArcDefaulAppTest, DefaultAppsNotAvailable) {
1374 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); 1424 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get());
1375 ASSERT_NE(nullptr, prefs); 1425 ASSERT_NE(nullptr, prefs);
1376 1426
1377 ValidateHaveApps(fake_default_apps()); 1427 ValidateHaveApps(fake_default_apps());
1378 1428
1379 const std::vector<arc::mojom::AppInfo> empty_app_list; 1429 const std::vector<arc::mojom::AppInfo> empty_app_list;
1380 1430
1381 app_instance()->RefreshAppList(); 1431 app_instance()->RefreshAppList();
1382 app_instance()->SendRefreshAppList(empty_app_list); 1432 app_instance()->SendRefreshAppList(empty_app_list);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 } 1502 }
1453 } 1503 }
1454 1504
1455 INSTANTIATE_TEST_CASE_P(, 1505 INSTANTIATE_TEST_CASE_P(,
1456 ArcAppModelBuilderTest, 1506 ArcAppModelBuilderTest,
1457 ::testing::ValuesIn(kUnmanagedArcStates)); 1507 ::testing::ValuesIn(kUnmanagedArcStates));
1458 INSTANTIATE_TEST_CASE_P(, 1508 INSTANTIATE_TEST_CASE_P(,
1459 ArcDefaulAppTest, 1509 ArcDefaulAppTest,
1460 ::testing::ValuesIn(kUnmanagedArcStates)); 1510 ::testing::ValuesIn(kUnmanagedArcStates));
1461 INSTANTIATE_TEST_CASE_P(, 1511 INSTANTIATE_TEST_CASE_P(,
1512 ArcAppLauncherForDefaulAppTest,
1513 ::testing::ValuesIn(kUnmanagedArcStates));
1514 INSTANTIATE_TEST_CASE_P(,
1462 ArcDefaulAppForManagedUserTest, 1515 ArcDefaulAppForManagedUserTest,
1463 ::testing::ValuesIn(kManagedArcStates)); 1516 ::testing::ValuesIn(kManagedArcStates));
1464 INSTANTIATE_TEST_CASE_P(, 1517 INSTANTIATE_TEST_CASE_P(,
1465 ArcPlayStoreAppTest, 1518 ArcPlayStoreAppTest,
1466 ::testing::ValuesIn(kUnmanagedArcStates)); 1519 ::testing::ValuesIn(kUnmanagedArcStates));
1467 INSTANTIATE_TEST_CASE_P(, 1520 INSTANTIATE_TEST_CASE_P(,
1468 ArcAppModelBuilderRecreate, 1521 ArcAppModelBuilderRecreate,
1469 ::testing::ValuesIn(kUnmanagedArcStates)); 1522 ::testing::ValuesIn(kUnmanagedArcStates));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698