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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 // Removes icon request record and allowd re-sending icon request. | 376 // Removes icon request record and allowd re-sending icon request. |
377 void MaybeRemoveIconRequestRecord(const std::string& app_id) { | 377 void MaybeRemoveIconRequestRecord(const std::string& app_id) { |
378 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 378 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
379 ASSERT_NE(nullptr, prefs); | 379 ASSERT_NE(nullptr, prefs); |
380 | 380 |
381 prefs->MaybeRemoveIconRequestRecord(app_id); | 381 prefs->MaybeRemoveIconRequestRecord(app_id); |
382 } | 382 } |
383 | 383 |
384 void AddPackage(const arc::mojom::ArcPackageInfo& package) { | 384 void AddPackage(const arc::mojom::ArcPackageInfo& package) { |
385 arc_test_.AddPackage(package); | 385 arc_test_.AddPackage(package); |
386 app_instance()->SendPackageAdded(package); | |
386 } | 387 } |
387 | 388 |
388 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { | 389 void RemovePackage(const arc::mojom::ArcPackageInfo& package) { |
389 arc_test_.RemovePackage(package); | 390 arc_test_.RemovePackage(package); |
391 app_instance()->SendPackageUninstalled(package.package_name); | |
390 } | 392 } |
391 | 393 |
392 AppListControllerDelegate* controller() { return controller_.get(); } | 394 AppListControllerDelegate* controller() { return controller_.get(); } |
393 | 395 |
394 TestingProfile* profile() { return profile_.get(); } | 396 TestingProfile* profile() { return profile_.get(); } |
395 | 397 |
396 ArcAppTest* arc_test() { return &arc_test_; } | 398 ArcAppTest* arc_test() { return &arc_test_; } |
397 | 399 |
398 const std::vector<arc::mojom::AppInfo>& fake_apps() const { | 400 const std::vector<arc::mojom::AppInfo>& fake_apps() const { |
399 return arc_test_.fake_apps(); | 401 return arc_test_.fake_apps(); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 ValidateHavePackages(fake_packages()); | 552 ValidateHavePackages(fake_packages()); |
551 | 553 |
552 arc::mojom::ArcPackageInfo package; | 554 arc::mojom::ArcPackageInfo package; |
553 package.package_name = kTestPackageName; | 555 package.package_name = kTestPackageName; |
554 package.package_version = 2; | 556 package.package_version = 2; |
555 package.last_backup_android_id = 2; | 557 package.last_backup_android_id = 2; |
556 package.last_backup_time = 2; | 558 package.last_backup_time = 2; |
557 package.sync = true; | 559 package.sync = true; |
558 | 560 |
559 RemovePackage(package); | 561 RemovePackage(package); |
560 app_instance()->SendPackageUninstalled(package.package_name); | |
561 ValidateHavePackages(fake_packages()); | 562 ValidateHavePackages(fake_packages()); |
562 | 563 |
563 AddPackage(package); | 564 AddPackage(package); |
564 app_instance()->SendPackageAdded(package); | |
565 ValidateHavePackages(fake_packages()); | 565 ValidateHavePackages(fake_packages()); |
566 } | 566 } |
567 | 567 |
568 TEST_P(ArcAppModelBuilderTest, RefreshAllOnReady) { | 568 TEST_P(ArcAppModelBuilderTest, RefreshAllOnReady) { |
569 // There should already have been one call, when the interface was | 569 // There should already have been one call, when the interface was |
570 // registered. | 570 // registered. |
571 EXPECT_EQ(1, app_instance()->refresh_app_list_count()); | 571 EXPECT_EQ(1, app_instance()->refresh_app_list_count()); |
572 app_instance()->RefreshAppList(); | 572 app_instance()->RefreshAppList(); |
573 EXPECT_EQ(2, app_instance()->refresh_app_list_count()); | 573 EXPECT_EQ(2, app_instance()->refresh_app_list_count()); |
574 } | 574 } |
(...skipping 10 matching lines...) Expand all Loading... | |
585 | 585 |
586 std::vector<arc::mojom::ShortcutInfo> shortcuts = fake_shortcuts(); | 586 std::vector<arc::mojom::ShortcutInfo> shortcuts = fake_shortcuts(); |
587 ASSERT_GE(shortcuts.size(), 2U); | 587 ASSERT_GE(shortcuts.size(), 2U); |
588 | 588 |
589 // Adding package is requred to safely call SendPackageUninstalled. | 589 // Adding package is requred to safely call SendPackageUninstalled. |
590 arc::mojom::ArcPackageInfo package; | 590 arc::mojom::ArcPackageInfo package; |
591 package.package_name = shortcuts[1].package_name; | 591 package.package_name = shortcuts[1].package_name; |
592 package.package_version = 1; | 592 package.package_version = 1; |
593 package.sync = true; | 593 package.sync = true; |
594 AddPackage(package); | 594 AddPackage(package); |
595 app_instance()->SendPackageAdded(package); | |
596 | 595 |
597 app_instance()->SendInstallShortcuts(shortcuts); | 596 app_instance()->SendInstallShortcuts(shortcuts); |
598 ValidateHaveShortcuts(shortcuts); | 597 ValidateHaveShortcuts(shortcuts); |
599 | 598 |
600 // Uninstall first shortcut and validate it was removed. | 599 // Uninstall first shortcut and validate it was removed. |
601 const std::string package_name = shortcuts[0].package_name; | 600 const std::string package_name = shortcuts[0].package_name; |
602 const std::string intent_uri = shortcuts[0].intent_uri; | 601 const std::string intent_uri = shortcuts[0].intent_uri; |
603 shortcuts.erase(shortcuts.begin()); | 602 shortcuts.erase(shortcuts.begin()); |
604 app_instance()->SendUninstallShortcut(package_name, intent_uri); | 603 app_instance()->SendUninstallShortcut(package_name, intent_uri); |
605 ValidateHaveShortcuts(shortcuts); | 604 ValidateHaveShortcuts(shortcuts); |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1357 const std::string app_id = ArcAppTest::GetAppId(fake_apps()[0]); | 1356 const std::string app_id = ArcAppTest::GetAppId(fake_apps()[0]); |
1358 | 1357 |
1359 EXPECT_FALSE(prefs->IsRegistered(app_id)); | 1358 EXPECT_FALSE(prefs->IsRegistered(app_id)); |
1360 EXPECT_FALSE(FindArcItem(app_id)); | 1359 EXPECT_FALSE(FindArcItem(app_id)); |
1361 app_instance()->SendTaskCreated(0, fake_apps()[0], std::string()); | 1360 app_instance()->SendTaskCreated(0, fake_apps()[0], std::string()); |
1362 // App should not appear now in the model but should be registered. | 1361 // App should not appear now in the model but should be registered. |
1363 EXPECT_FALSE(FindArcItem(app_id)); | 1362 EXPECT_FALSE(FindArcItem(app_id)); |
1364 EXPECT_TRUE(prefs->IsRegistered(app_id)); | 1363 EXPECT_TRUE(prefs->IsRegistered(app_id)); |
1365 } | 1364 } |
1366 | 1365 |
1367 TEST_P(ArcAppModelBuilderTest, ArcAppsOnPackageUpdated) { | 1366 TEST_P(ArcAppModelBuilderTest, ArcAppsAndShortcutsOnPackageChange) { |
1368 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 1367 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
1369 ASSERT_NE(nullptr, prefs); | 1368 ASSERT_NE(nullptr, prefs); |
1370 | 1369 |
1371 std::vector<arc::mojom::AppInfo> apps = fake_apps(); | 1370 std::vector<arc::mojom::AppInfo> apps = fake_apps(); |
1372 ASSERT_GE(3u, apps.size()); | 1371 ASSERT_GE(3u, apps.size()); |
1373 apps[0].package_name = apps[2].package_name; | 1372 apps[0].package_name = apps[2].package_name; |
1374 apps[1].package_name = apps[2].package_name; | 1373 apps[1].package_name = apps[2].package_name; |
1374 | |
1375 std::vector<arc::mojom::ShortcutInfo> shortcuts = fake_shortcuts(); | |
1376 for (auto& shortcut : shortcuts) | |
1377 shortcut.package_name = apps[0].package_name; | |
1378 | |
1375 // Second app should be preserved after update. | 1379 // Second app should be preserved after update. |
1376 std::vector<arc::mojom::AppInfo> apps1(apps.begin(), apps.begin() + 2); | 1380 std::vector<arc::mojom::AppInfo> apps1(apps.begin(), apps.begin() + 2); |
1377 std::vector<arc::mojom::AppInfo> apps2(apps.begin() + 1, apps.begin() + 3); | 1381 std::vector<arc::mojom::AppInfo> apps2(apps.begin() + 1, apps.begin() + 3); |
1378 | 1382 |
1383 // Adding package is requred to safely call SendPackageUninstalled. | |
xiyuan
2017/05/04 23:15:33
nit: requred -> required
khmel
2017/05/04 23:18:03
Done.
| |
1384 arc::mojom::ArcPackageInfo package; | |
1385 package.package_name = apps[0].package_name; | |
1386 package.package_version = 1; | |
1387 package.sync = true; | |
1388 AddPackage(package); | |
1389 | |
1379 app_instance()->RefreshAppList(); | 1390 app_instance()->RefreshAppList(); |
1380 app_instance()->SendRefreshAppList(apps1); | 1391 app_instance()->SendRefreshAppList(apps1); |
1381 ValidateHaveApps(apps1); | 1392 app_instance()->SendInstallShortcuts(shortcuts); |
1393 | |
1394 ValidateHaveAppsAndShortcuts(apps1, shortcuts); | |
1382 | 1395 |
1383 const std::string app_id = ArcAppTest::GetAppId(apps[1]); | 1396 const std::string app_id = ArcAppTest::GetAppId(apps[1]); |
1384 const base::Time now_time = base::Time::Now(); | 1397 const base::Time now_time = base::Time::Now(); |
1385 prefs->SetLastLaunchTime(app_id, now_time); | 1398 prefs->SetLastLaunchTime(app_id, now_time); |
1386 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_before = | 1399 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_before = |
1387 prefs->GetApp(app_id); | 1400 prefs->GetApp(app_id); |
1388 ASSERT_TRUE(app_info_before); | 1401 ASSERT_TRUE(app_info_before); |
1389 EXPECT_EQ(now_time, app_info_before->last_launch_time); | 1402 EXPECT_EQ(now_time, app_info_before->last_launch_time); |
1390 | 1403 |
1391 app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps2); | 1404 app_instance()->SendPackageAppListRefreshed(apps[0].package_name, apps2); |
1392 ValidateHaveApps(apps2); | 1405 ValidateHaveAppsAndShortcuts(apps2, shortcuts); |
1393 | 1406 |
1394 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_after = | 1407 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_after = |
1395 prefs->GetApp(app_id); | 1408 prefs->GetApp(app_id); |
1396 ASSERT_TRUE(app_info_after); | 1409 ASSERT_TRUE(app_info_after); |
1397 EXPECT_EQ(now_time, app_info_after->last_launch_time); | 1410 EXPECT_EQ(now_time, app_info_after->last_launch_time); |
1411 | |
1412 RemovePackage(package); | |
1413 ValidateHaveAppsAndShortcuts(std::vector<arc::mojom::AppInfo>(), | |
1414 std::vector<arc::mojom::ShortcutInfo>()); | |
1398 } | 1415 } |
1399 | 1416 |
1400 TEST_P(ArcDefaulAppTest, DefaultApps) { | 1417 TEST_P(ArcDefaulAppTest, DefaultApps) { |
1401 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); | 1418 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_.get()); |
1402 ASSERT_NE(nullptr, prefs); | 1419 ASSERT_NE(nullptr, prefs); |
1403 | 1420 |
1404 ValidateHaveApps(fake_default_apps()); | 1421 ValidateHaveApps(fake_default_apps()); |
1405 | 1422 |
1406 // Start normal apps. We should have apps from 2 subsets. | 1423 // Start normal apps. We should have apps from 2 subsets. |
1407 app_instance()->RefreshAppList(); | 1424 app_instance()->RefreshAppList(); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1603 ::testing::ValuesIn(kUnmanagedArcStates)); | 1620 ::testing::ValuesIn(kUnmanagedArcStates)); |
1604 INSTANTIATE_TEST_CASE_P(, | 1621 INSTANTIATE_TEST_CASE_P(, |
1605 ArcDefaulAppForManagedUserTest, | 1622 ArcDefaulAppForManagedUserTest, |
1606 ::testing::ValuesIn(kManagedArcStates)); | 1623 ::testing::ValuesIn(kManagedArcStates)); |
1607 INSTANTIATE_TEST_CASE_P(, | 1624 INSTANTIATE_TEST_CASE_P(, |
1608 ArcPlayStoreAppTest, | 1625 ArcPlayStoreAppTest, |
1609 ::testing::ValuesIn(kUnmanagedArcStates)); | 1626 ::testing::ValuesIn(kUnmanagedArcStates)); |
1610 INSTANTIATE_TEST_CASE_P(, | 1627 INSTANTIATE_TEST_CASE_P(, |
1611 ArcAppModelBuilderRecreate, | 1628 ArcAppModelBuilderRecreate, |
1612 ::testing::ValuesIn(kUnmanagedArcStates)); | 1629 ::testing::ValuesIn(kUnmanagedArcStates)); |
OLD | NEW |