| 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(IsWaitDefaultAppsNeeded()); |
| 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 IsWaitDefaultAppsNeeded() const { return true; } |
| 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 IsWaitDefaultAppsNeeded() 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 Loading... |
| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); |
| 1369 EXPECT_EQ(oem_states[app_id], prefs->IsOem(app_id)); | 1386 EXPECT_EQ(oem_states[app_id], prefs->IsOem(app_id)); |
| 1370 } | 1387 } |
| 1371 } | 1388 } |
| 1372 | 1389 |
| 1390 TEST_P(ArcAppLauncherForDefaulAppTest, AppLauncherForDefaultApps) { |
| 1391 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1392 ASSERT_NE(nullptr, prefs); |
| 1393 |
| 1394 ASSERT_GE(fake_default_apps().size(), 2U); |
| 1395 const arc::mojom::AppInfo& app1 = fake_default_apps()[0]; |
| 1396 const arc::mojom::AppInfo& app2 = fake_default_apps()[1]; |
| 1397 const std::string id1 = ArcAppTest::GetAppId(app1); |
| 1398 const std::string id2 = ArcAppTest::GetAppId(app2); |
| 1399 |
| 1400 // Launch when app is registered and ready. |
| 1401 ArcAppLauncher launcher1(profile(), id1, true, false); |
| 1402 // Launch when app is registered. |
| 1403 ArcAppLauncher launcher2(profile(), id2, true, true); |
| 1404 |
| 1405 EXPECT_FALSE(launcher1.app_launched()); |
| 1406 EXPECT_FALSE(launcher2.app_launched()); |
| 1407 |
| 1408 arc_test()->WaitForDefaultApps(); |
| 1409 |
| 1410 // Only second app is expected to be launched. |
| 1411 EXPECT_FALSE(launcher1.app_launched()); |
| 1412 EXPECT_TRUE(launcher2.app_launched()); |
| 1413 |
| 1414 app_instance()->RefreshAppList(); |
| 1415 app_instance()->SendRefreshAppList(fake_default_apps()); |
| 1416 // Default apps are ready now and it is expected that first app was launched |
| 1417 // now. |
| 1418 EXPECT_TRUE(launcher1.app_launched()); |
| 1419 } |
| 1420 |
| 1373 TEST_P(ArcDefaulAppTest, DefaultAppsNotAvailable) { | 1421 TEST_P(ArcDefaulAppTest, DefaultAppsNotAvailable) { |
| 1374 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 1422 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
| 1375 ASSERT_NE(nullptr, prefs); | 1423 ASSERT_NE(nullptr, prefs); |
| 1376 | 1424 |
| 1377 ValidateHaveApps(fake_default_apps()); | 1425 ValidateHaveApps(fake_default_apps()); |
| 1378 | 1426 |
| 1379 const std::vector<arc::mojom::AppInfo> empty_app_list; | 1427 const std::vector<arc::mojom::AppInfo> empty_app_list; |
| 1380 | 1428 |
| 1381 app_instance()->RefreshAppList(); | 1429 app_instance()->RefreshAppList(); |
| 1382 app_instance()->SendRefreshAppList(empty_app_list); | 1430 app_instance()->SendRefreshAppList(empty_app_list); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1452 } | 1500 } |
| 1453 } | 1501 } |
| 1454 | 1502 |
| 1455 INSTANTIATE_TEST_CASE_P(, | 1503 INSTANTIATE_TEST_CASE_P(, |
| 1456 ArcAppModelBuilderTest, | 1504 ArcAppModelBuilderTest, |
| 1457 ::testing::ValuesIn(kUnmanagedArcStates)); | 1505 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1458 INSTANTIATE_TEST_CASE_P(, | 1506 INSTANTIATE_TEST_CASE_P(, |
| 1459 ArcDefaulAppTest, | 1507 ArcDefaulAppTest, |
| 1460 ::testing::ValuesIn(kUnmanagedArcStates)); | 1508 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1461 INSTANTIATE_TEST_CASE_P(, | 1509 INSTANTIATE_TEST_CASE_P(, |
| 1510 ArcAppLauncherForDefaulAppTest, |
| 1511 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1512 INSTANTIATE_TEST_CASE_P(, |
| 1462 ArcDefaulAppForManagedUserTest, | 1513 ArcDefaulAppForManagedUserTest, |
| 1463 ::testing::ValuesIn(kManagedArcStates)); | 1514 ::testing::ValuesIn(kManagedArcStates)); |
| 1464 INSTANTIATE_TEST_CASE_P(, | 1515 INSTANTIATE_TEST_CASE_P(, |
| 1465 ArcPlayStoreAppTest, | 1516 ArcPlayStoreAppTest, |
| 1466 ::testing::ValuesIn(kUnmanagedArcStates)); | 1517 ::testing::ValuesIn(kUnmanagedArcStates)); |
| 1467 INSTANTIATE_TEST_CASE_P(, | 1518 INSTANTIATE_TEST_CASE_P(, |
| 1468 ArcAppModelBuilderRecreate, | 1519 ArcAppModelBuilderRecreate, |
| 1469 ::testing::ValuesIn(kUnmanagedArcStates)); | 1520 ::testing::ValuesIn(kUnmanagedArcStates)); |
| OLD | NEW |