1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/apps/app_service/publishers/arc_apps.h"
#include <algorithm>
#include <functional>
#include <memory>
#include <utility>
#include <variant>
#include "ash/constants/ash_features.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/app_service/app_service_test.h"
#include "chrome/browser/apps/app_service/launch_result_type.h"
#include "chrome/browser/apps/app_service/promise_apps/promise_app.h"
#include "chrome/browser/apps/app_service/promise_apps/promise_app_registry_cache.h"
#include "chrome/browser/apps/app_service/promise_apps/promise_app_service.h"
#include "chrome/browser/apps/app_service/publishers/arc_apps_factory.h"
#include "chrome/browser/ash/app_list/arc/arc_app_list_prefs.h"
#include "chrome/browser/ash/app_list/arc/arc_app_test.h"
#include "chrome/browser/ash/app_list/arc/arc_app_utils.h"
#include "chrome/browser/ash/app_list/arc/intent.h"
#include "chrome/browser/ash/apps/apk_web_app_service.h"
#include "chrome/browser/ash/arc/fileapi/arc_file_system_bridge.h"
#include "chrome/browser/ash/file_manager/path_util.h"
#include "chrome/browser/ash/system_web_apps/system_web_app_manager.h"
#include "chrome/browser/policy/system_features_disable_list_policy_handler.h"
#include "chrome/browser/web_applications/policy/web_app_policy_manager.h"
#include "chrome/browser/web_applications/test/fake_web_app_provider.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chromeos/ash/experiences/arc/app/arc_app_constants.h"
#include "chromeos/ash/experiences/arc/arc_features.h"
#include "chromeos/ash/experiences/arc/arc_prefs.h"
#include "chromeos/ash/experiences/arc/arc_util.h"
#include "chromeos/ash/experiences/arc/intent_helper/arc_intent_helper_bridge.h"
#include "chromeos/ash/experiences/arc/intent_helper/intent_constants.h"
#include "chromeos/ash/experiences/arc/intent_helper/intent_filter.h"
#include "chromeos/ash/experiences/arc/mojom/app.mojom.h"
#include "chromeos/ash/experiences/arc/mojom/intent_helper.mojom.h"
#include "chromeos/ash/experiences/arc/session/arc_bridge_service.h"
#include "chromeos/ash/experiences/arc/session/arc_service_manager.h"
#include "chromeos/ash/experiences/arc/test/connection_holder_util.h"
#include "chromeos/ash/experiences/arc/test/fake_app_instance.h"
#include "chromeos/ash/experiences/arc/test/fake_file_system_instance.h"
#include "chromeos/ash/experiences/arc/test/fake_intent_helper_instance.h"
#include "chromeos/ash/experiences/system_web_apps/types/system_web_app_delegate_map.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/services/app_service/public/cpp/app_types.h"
#include "components/services/app_service/public/cpp/intent_filter_util.h"
#include "components/services/app_service/public/cpp/intent_util.h"
#include "components/services/app_service/public/cpp/permission.h"
#include "components/services/app_service/public/cpp/preferred_apps_list_handle.h"
#include "content/public/test/browser_task_environment.h"
#include "storage/browser/file_system/external_mount_points.h"
#include "storage/browser/file_system/file_system_url.h"
#include "storage/common/file_system/file_system_mount_option.h"
#include "storage/common/file_system/file_system_types.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kTestPackageName[] = "com.example.this";
const apps::PackageId kTestPackageId(apps::PackageType::kArc,
"com.example.this");
std::vector<arc::IntentFilter> CreateFilterList(
const std::string& package_name,
const std::vector<std::string>& authorities) {
std::vector<arc::IntentFilter::AuthorityEntry> filter_authorities;
for (const std::string& authority : authorities) {
filter_authorities.emplace_back(authority, 0);
}
std::vector<arc::IntentFilter::PatternMatcher> patterns;
patterns.emplace_back("/", arc::PatternType::kPrefix);
auto filter = arc::IntentFilter(package_name, {arc::kIntentActionView},
std::move(filter_authorities),
std::move(patterns), {"https"}, {});
std::vector<arc::IntentFilter> filters;
filters.push_back(std::move(filter));
return filters;
}
apps::IntentFilters CreateIntentFilters(
const std::vector<std::string>& authorities) {
apps::IntentFilters filters;
apps::IntentFilterPtr filter = std::make_unique<apps::IntentFilter>();
apps::ConditionValues values1;
values1.push_back(std::make_unique<apps::ConditionValue>(
apps_util::kIntentActionView, apps::PatternMatchType::kLiteral));
filter->conditions.push_back(std::make_unique<apps::Condition>(
apps::ConditionType::kAction, std::move(values1)));
apps::ConditionValues values2;
values2.push_back(std::make_unique<apps::ConditionValue>(
"https", apps::PatternMatchType::kLiteral));
filter->conditions.push_back(std::make_unique<apps::Condition>(
apps::ConditionType::kScheme, std::move(values2)));
apps::ConditionValues values;
for (const std::string& authority : authorities) {
values.push_back(std::make_unique<apps::ConditionValue>(
authority, apps::PatternMatchType::kLiteral));
}
filter->conditions.push_back(std::make_unique<apps::Condition>(
apps::ConditionType::kAuthority, std::move(values)));
apps::ConditionValues values3;
values3.push_back(std::make_unique<apps::ConditionValue>(
"/", apps::PatternMatchType::kPrefix));
filter->conditions.push_back(std::make_unique<apps::Condition>(
apps::ConditionType::kPath, std::move(values3)));
filters.push_back(std::move(filter));
return filters;
}
// Returns a FileSystemURL, encoded as a GURL, that points to a file in the
// Downloads directory.
GURL FileInDownloads(Profile* profile, base::FilePath file) {
url::Origin origin = file_manager::util::GetFilesAppOrigin();
std::string mount_point_name =
file_manager::util::GetDownloadsMountPointName(profile);
storage::ExternalMountPoints* mount_points =
storage::ExternalMountPoints::GetSystemInstance();
mount_points->RegisterFileSystem(
mount_point_name, storage::kFileSystemTypeLocal,
storage::FileSystemMountOption(),
file_manager::util::GetDownloadsFolderForProfile(profile));
return mount_points
->CreateExternalFileSystemURL(blink::StorageKey::CreateFirstParty(origin),
mount_point_name, file)
.ToGURL();
}
std::vector<arc::mojom::AppInfoPtr> GetArcSettingsAppInfo() {
std::vector<arc::mojom::AppInfoPtr> apps;
arc::mojom::AppInfoPtr app(arc::mojom::AppInfo::New());
app->name = "settings";
app->package_name = "com.android.settings";
app->activity = "com.android.settings.Settings";
app->sticky = false;
apps.push_back(std::move(app));
return apps;
}
} // namespace
class ArcAppsPublisherTest : public testing::Test {
public:
ArcAppsPublisherTest()
: local_state_(std::make_unique<ScopedTestingLocalState>(
TestingBrowserProcess::GetGlobal())) {}
void SetUp() override {
testing::Test::SetUp();
profile_ = MakeProfile();
// Do not destroy the ArcServiceManager during TearDown, so that Arc
// KeyedServices can be correctly destroyed during profile shutdown.
arc_test_.set_persist_service_manager(true);
// We will manually start ArcApps after setting up IntentHelper, this allows
// ArcApps to observe the correct IntentHelper during initialization.
arc_test_.set_start_app_service_publisher(false);
// We want to use the real ArcIntentHelper KeyedService so that it's the
// same object that ArcApps uses.
arc_test_.set_initialize_real_intent_helper_bridge(true);
arc_test_.SetUp(profile());
auto* arc_bridge_service =
arc_test_.arc_service_manager()->arc_bridge_service();
intent_helper_ =
arc::ArcIntentHelperBridge::GetForBrowserContext(profile());
arc_file_system_bridge_ = std::make_unique<arc::ArcFileSystemBridge>(
profile(), arc_bridge_service);
auto web_app_policy_manager =
std::make_unique<web_app::WebAppPolicyManager>(profile());
web_app_policy_manager->SetSystemWebAppDelegateMap(&system_apps_);
auto* provider = web_app::FakeWebAppProvider::Get(profile());
provider->SetWebAppPolicyManager(std::move(web_app_policy_manager));
web_app::test::AwaitStartWebAppProviderAndSubsystems(profile());
app_service_test_.SetUp(profile_.get());
apps::ArcAppsFactory::GetForProfile(profile());
// Ensure that the PreferredAppsList is fully initialized before running the
// test.
task_environment_.RunUntilIdle();
}
void TearDown() override {
arc_test_.StopArcInstance();
apps::ArcAppsFactory::GetInstance()->ShutDownForTesting(profile());
arc_test_.TearDown();
}
virtual std::unique_ptr<TestingProfile> MakeProfile() {
return std::make_unique<TestingProfile>();
}
void VerifyIntentFilters(const std::string& app_id,
const std::vector<std::string>& authorities) {
apps::IntentFilters source = CreateIntentFilters(authorities);
apps::IntentFilters target;
apps::AppServiceProxyFactory::GetForProfile(profile())
->AppRegistryCache()
.ForOneApp(app_id, [&target](const apps::AppUpdate& update) {
target = update.IntentFilters();
});
EXPECT_EQ(source.size(), target.size());
for (size_t i = 0; i < source.size(); i++) {
EXPECT_EQ(*source[i], *target[i]);
}
}
void SetUpFileSystemInstance() {
auto* arc_bridge_service =
arc_test()->arc_service_manager()->arc_bridge_service();
file_system_instance_ = std::make_unique<arc::FakeFileSystemInstance>();
arc_bridge_service->file_system()->SetInstance(file_system_instance());
arc::WaitForInstanceReady(arc_bridge_service->file_system());
}
TestingProfile* profile() { return profile_.get(); }
apps::AppServiceProxy* app_service_proxy() {
return apps::AppServiceProxyFactory::GetForProfile(profile());
}
arc::ArcIntentHelperBridge* intent_helper() { return intent_helper_; }
arc::FakeIntentHelperInstance* intent_helper_instance() {
return arc_test_.intent_helper_instance();
}
arc::FakeFileSystemInstance* file_system_instance() {
return file_system_instance_.get();
}
ArcAppTest* arc_test() { return &arc_test_; }
apps::PreferredAppsListHandle& preferred_apps() {
return apps::AppServiceProxyFactory::GetForProfile(profile())
->PreferredAppsList();
}
std::vector<arc::mojom::SupportedLinksPackagePtr> CreateSupportedLinks(
const std::string& package_name) {
std::vector<arc::mojom::SupportedLinksPackagePtr> result;
auto link = arc::mojom::SupportedLinksPackage::New();
link->package_name = package_name;
result.push_back(std::move(link));
return result;
}
protected:
std::unique_ptr<ScopedTestingLocalState> local_state_;
private:
content::BrowserTaskEnvironment task_environment_;
ash::SystemWebAppDelegateMap system_apps_;
ArcAppTest arc_test_;
std::unique_ptr<TestingProfile> profile_;
apps::AppServiceTest app_service_test_;
raw_ptr<arc::ArcIntentHelperBridge, DanglingUntriaged> intent_helper_;
std::unique_ptr<arc::FakeFileSystemInstance> file_system_instance_;
std::unique_ptr<arc::ArcFileSystemBridge> arc_file_system_bridge_;
};
// Verifies that a call to set the supported links preference from the ARC
// system doesn't change the setting in app service.
TEST_F(ArcAppsPublisherTest, SetSupportedLinksFromArcSystem) {
constexpr char kTestAuthority[] = "www.example.com";
const auto& fake_apps = arc_test()->fake_apps();
std::string package_name = fake_apps[0]->package_name;
std::string app_id = ArcAppListPrefs::GetAppId(fake_apps[0]->package_name,
fake_apps[0]->activity);
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
// Update intent filters and supported links for the app, as if it was just
// installed.
intent_helper()->OnIntentFiltersUpdatedForPackage(
package_name, CreateFilterList(package_name, {kTestAuthority}));
VerifyIntentFilters(app_id, {kTestAuthority});
intent_helper()->OnSupportedLinksChanged(
CreateSupportedLinks(package_name), {},
arc::mojom::SupportedLinkChangeSource::kArcSystem);
ASSERT_EQ(std::nullopt, preferred_apps().FindPreferredAppForUrl(
GURL("https://www.example.com/foo")));
}
// Verifies that a call to set the supported links preference from App Service
// syncs the setting to ARC.
TEST_F(ArcAppsPublisherTest, SetSupportedLinksFromAppService) {
constexpr char kTestAuthority[] = "www.example.com";
const auto& fake_apps = arc_test()->fake_apps();
std::string package_name = fake_apps[0]->package_name;
std::string app_id = ArcAppListPrefs::GetAppId(fake_apps[0]->package_name,
fake_apps[0]->activity);
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
intent_helper()->OnIntentFiltersUpdatedForPackage(
package_name, CreateFilterList(package_name, {kTestAuthority}));
VerifyIntentFilters(app_id, {kTestAuthority});
apps::AppServiceProxyFactory::GetForProfile(profile())
->SetSupportedLinksPreference(app_id);
ASSERT_TRUE(
intent_helper_instance()->verified_links().find(package_name)->second);
}
// Verifies that the ARC system can still update preferred intent filters for
// apps which are already preferred.
TEST_F(ArcAppsPublisherTest, SetSupportedLinksAllowsUpdates) {
constexpr char kTestAuthority[] = "www.example.com";
constexpr char kTestAuthority2[] = "www.newexample.com";
const auto& fake_apps = arc_test()->fake_apps();
std::string package_name = fake_apps[0]->package_name;
std::string app_id = ArcAppListPrefs::GetAppId(fake_apps[0]->package_name,
fake_apps[0]->activity);
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
// Update intent filters and supported links for the app, as if it was just
// installed.
intent_helper()->OnIntentFiltersUpdatedForPackage(
package_name, CreateFilterList(package_name, {kTestAuthority}));
VerifyIntentFilters(app_id, {kTestAuthority});
// Set a user preference for the app.
apps::AppServiceProxyFactory::GetForProfile(profile())
->SetSupportedLinksPreference(app_id);
// Update filters with a new authority added.
intent_helper()->OnIntentFiltersUpdatedForPackage(
package_name,
CreateFilterList(package_name, {kTestAuthority, kTestAuthority2}));
VerifyIntentFilters(app_id, {kTestAuthority, kTestAuthority2});
intent_helper()->OnSupportedLinksChanged(
CreateSupportedLinks(package_name), {},
arc::mojom::SupportedLinkChangeSource::kArcSystem);
// Verify that the user preference has been extended to the new filter.
ASSERT_EQ(app_id, preferred_apps().FindPreferredAppForUrl(
GURL("https://www.newexample.com/foo")));
}
// Verifies that the user can set an app as preferred through ARC settings.
TEST_F(ArcAppsPublisherTest, SetSupportedLinksAllowsUserChanges) {
constexpr char kTestAuthority[] = "www.example.com";
const auto& fake_apps = arc_test()->fake_apps();
std::string package_name = fake_apps[0]->package_name;
std::string app_id = ArcAppListPrefs::GetAppId(fake_apps[0]->package_name,
fake_apps[0]->activity);
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
// Update intent filters and supported links for the app, as if it was just
// installed.
intent_helper()->OnIntentFiltersUpdatedForPackage(
package_name, CreateFilterList(package_name, {kTestAuthority}));
intent_helper()->OnSupportedLinksChanged(
CreateSupportedLinks(package_name), {},
arc::mojom::SupportedLinkChangeSource::kUserPreference);
ASSERT_EQ(app_id, preferred_apps().FindPreferredAppForUrl(
GURL("https://www.example.com/foo")));
}
// Verifies that the Play Store app can be set as preferred by the system.
TEST_F(ArcAppsPublisherTest, SetSupportedLinksAllowsPlayStoreDefault) {
constexpr char kTestAuthority[] = "play.google.com";
std::vector<arc::mojom::AppInfoPtr> apps;
apps.push_back(arc::mojom::AppInfo::New("Play Store", arc::kPlayStorePackage,
arc::kPlayStoreActivity));
arc_test()->app_instance()->SendRefreshAppList(apps);
// Update intent filters and supported links for the app, as if it was just
// installed.
intent_helper()->OnIntentFiltersUpdatedForPackage(
arc::kPlayStorePackage,
CreateFilterList(arc::kPlayStorePackage, {kTestAuthority}));
intent_helper()->OnSupportedLinksChanged(
CreateSupportedLinks(arc::kPlayStorePackage), {},
arc::mojom::SupportedLinkChangeSource::kArcSystem);
ASSERT_EQ(arc::kPlayStoreAppId, preferred_apps().FindPreferredAppForUrl(
GURL("https://play.google.com/foo")));
}
// Verifies that disabling OS settings by SystemFeaturesDisableList policy will
// disable ARC settings as well. Clearing the policy should re-enable ARC
// settings.
TEST_F(ArcAppsPublisherTest, DisableOSSettingArcSettings) {
arc_test()->app_instance()->SendRefreshAppList(GetArcSettingsAppInfo());
// Change SystemFeaturesDisableList policy to disable OS Setting.
{
ScopedListPrefUpdate update(
local_state_->Get(), policy::policy_prefs::kSystemFeaturesDisableList);
update->Append(static_cast<int>(policy::SystemFeature::kOsSettings));
}
// Verify that ARC settings readiness is set to disabled by policy.
bool found = app_service_proxy()->AppRegistryCache().ForOneApp(
arc::kSettingsAppId, [](const apps::AppUpdate& update) {
EXPECT_EQ(update.Readiness(), apps::Readiness::kDisabledByPolicy);
});
ASSERT_TRUE(found);
// Clear SystemFeaturesDisableList policy.
{
ScopedListPrefUpdate update(
local_state_->Get(), policy::policy_prefs::kSystemFeaturesDisableList);
update->clear();
}
// Verify that ARC settings readiness is set to ready.
found = false;
found = app_service_proxy()->AppRegistryCache().ForOneApp(
arc::kSettingsAppId, [](const apps::AppUpdate& update) {
EXPECT_EQ(update.Readiness(), apps::Readiness::kReady);
});
ASSERT_TRUE(found);
}
// Verifies that disabling OS settings by SystemFeaturesDisableList policy and
// re-enabling does not remove the local settings block.
TEST_F(ArcAppsPublisherTest, DisableAndBlockOSSettingArcSettings) {
arc_test()->app_instance()->SendRefreshAppList(GetArcSettingsAppInfo());
// Change SystemFeaturesDisableList policy to disable OS Setting.
{
ScopedListPrefUpdate update(
local_state_->Get(), policy::policy_prefs::kSystemFeaturesDisableList);
update->Append(static_cast<int>(policy::SystemFeature::kOsSettings));
}
// Verify that ARC settings readiness is set to disabled by policy.
bool found = app_service_proxy()->AppRegistryCache().ForOneApp(
arc::kSettingsAppId, [](const apps::AppUpdate& update) {
EXPECT_EQ(update.Readiness(), apps::Readiness::kDisabledByPolicy);
});
ASSERT_TRUE(found);
// Blocks the ARC settings app. It stays in kDisabledByPolicy.
app_service_proxy()->BlockApps({arc::kSettingsAppId});
found = app_service_proxy()->AppRegistryCache().ForOneApp(
arc::kSettingsAppId, [](const apps::AppUpdate& update) {
EXPECT_EQ(update.Readiness(), apps::Readiness::kDisabledByPolicy);
});
ASSERT_TRUE(found);
// Clear SystemFeaturesDisableList policy.
{
ScopedListPrefUpdate update(
local_state_->Get(), policy::policy_prefs::kSystemFeaturesDisableList);
update->clear();
}
// ARC settings should be in kDisabledByLocalSettings.
found = app_service_proxy()->AppRegistryCache().ForOneApp(
arc::kSettingsAppId, [](const apps::AppUpdate& update) {
EXPECT_EQ(update.Readiness(),
apps::Readiness::kDisabledByLocalSettings);
});
ASSERT_TRUE(found);
// Unblocks the app.
app_service_proxy()->UnblockApps({arc::kSettingsAppId});
// Verify that ARC settings readiness is set to ready.
found = app_service_proxy()->AppRegistryCache().ForOneApp(
arc::kSettingsAppId, [](const apps::AppUpdate& update) {
EXPECT_EQ(update.Readiness(), apps::Readiness::kReady);
});
ASSERT_TRUE(found);
}
class ArcAppsPublisherManagedProfileTest : public ArcAppsPublisherTest {
public:
std::unique_ptr<TestingProfile> MakeProfile() override {
TestingProfile::Builder builder;
builder.OverridePolicyConnectorIsManagedForTesting(true);
return builder.Build();
}
};
// Verifies that a call to set the default supported links preference from the
// ARC system changes the app service setting, for a managed profile.
TEST_F(ArcAppsPublisherManagedProfileTest, SetSupportedLinksByDefault) {
constexpr char kTestAuthority[] = "www.example.com";
const auto& fake_apps = arc_test()->fake_apps();
std::string package_name = fake_apps[0]->package_name;
std::string app_id = ArcAppListPrefs::GetAppId(fake_apps[0]->package_name,
fake_apps[0]->activity);
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
// Update intent filters and supported links for the app, as if it was just
// installed.
intent_helper()->OnIntentFiltersUpdatedForPackage(
package_name, CreateFilterList(package_name, {kTestAuthority}));
VerifyIntentFilters(app_id, {kTestAuthority});
intent_helper()->OnSupportedLinksChanged(
CreateSupportedLinks(package_name), {},
arc::mojom::SupportedLinkChangeSource::kArcSystem);
ASSERT_EQ(app_id, preferred_apps().FindPreferredAppForUrl(
GURL("https://www.example.com/foo")));
}
// Verifies that a call to set the default supported links preference from the
// ARC system is ignored if the policy ArcOpenLinksInBrowserByDefault for
// a managed profile is set to true.
TEST_F(ArcAppsPublisherManagedProfileTest, SetSupportedLinksDisabledByPolicy) {
constexpr char kTestAuthority[] = "www.example.com";
const auto& fake_apps = arc_test()->fake_apps();
std::string package_name = fake_apps[0]->package_name;
std::string app_id = ArcAppListPrefs::GetAppId(fake_apps[0]->package_name,
fake_apps[0]->activity);
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
profile()->GetPrefs()->SetBoolean(arc::prefs::kArcOpenLinksInBrowserByDefault,
true);
// Update intent filters and supported links for the app, as if it was just
// installed.
intent_helper()->OnIntentFiltersUpdatedForPackage(
package_name, CreateFilterList(package_name, {kTestAuthority}));
VerifyIntentFilters(app_id, {kTestAuthority});
intent_helper()->OnSupportedLinksChanged(
CreateSupportedLinks(package_name), {},
arc::mojom::SupportedLinkChangeSource::kArcSystem);
ASSERT_EQ(std::nullopt, preferred_apps().FindPreferredAppForUrl(
GURL("https://www.example.com/foo")));
}
TEST_F(ArcAppsPublisherManagedProfileTest,
SetSupportedLinksIgnoresWorkspaceInstall) {
constexpr char kTestAuthority[] = "drive.google.com";
std::string package_name = "com.google.android.apps.docs";
std::string activity_name = base::StrCat({package_name, ".MainActivity"});
std::string app_id = ArcAppListPrefs::GetAppId(package_name, activity_name);
arc::mojom::AppInfoPtr app =
arc::mojom::AppInfo::New("Google Drive", package_name, activity_name);
std::vector<arc::mojom::AppInfoPtr> app_list;
app_list.push_back(std::move(app));
arc_test()->app_instance()->SendRefreshAppList(std::move(app_list));
// Update intent filters and supported links for the app, as if it was just
// installed.
intent_helper()->OnIntentFiltersUpdatedForPackage(
package_name, CreateFilterList(package_name, {kTestAuthority}));
VerifyIntentFilters(app_id, {kTestAuthority});
intent_helper()->OnSupportedLinksChanged(
CreateSupportedLinks(package_name), {},
arc::mojom::SupportedLinkChangeSource::kArcSystem);
ASSERT_EQ(std::nullopt, preferred_apps().FindPreferredAppForUrl(
GURL("https://drive.google.com/foo")));
}
TEST_F(ArcAppsPublisherManagedProfileTest,
SetSupportedLinksAllowsWorkspaceUserChange) {
constexpr char kTestAuthority[] = "docs.google.com";
std::string package_name = "com.google.android.apps.docs.editor.docs";
std::string activity_name = base::StrCat({package_name, ".MainActivity"});
std::string app_id = ArcAppListPrefs::GetAppId(package_name, activity_name);
arc::mojom::AppInfoPtr app =
arc::mojom::AppInfo::New("Google Docs", package_name, activity_name);
std::vector<arc::mojom::AppInfoPtr> app_list;
app_list.push_back(std::move(app));
arc_test()->app_instance()->SendRefreshAppList(std::move(app_list));
intent_helper()->OnIntentFiltersUpdatedForPackage(
package_name, CreateFilterList(package_name, {kTestAuthority}));
intent_helper()->OnSupportedLinksChanged(
CreateSupportedLinks(package_name), {},
arc::mojom::SupportedLinkChangeSource::kUserPreference);
ASSERT_EQ(app_id, preferred_apps().FindPreferredAppForUrl(
GURL("https://docs.google.com/document/")));
}
TEST_F(ArcAppsPublisherManagedProfileTest,
SetSupportedLinksAllowsWorkspaceUpdate) {
constexpr char kDriveAuthority[] = "drive.google.com";
constexpr char kDocsAuthority[] = "docs.google.com";
std::string package_name = "com.google.android.apps.docs";
std::string activity_name = base::StrCat({package_name, ".MainActivity"});
std::string app_id = ArcAppListPrefs::GetAppId(package_name, activity_name);
arc::mojom::AppInfoPtr app =
arc::mojom::AppInfo::New("Google Drive", package_name, activity_name);
std::vector<arc::mojom::AppInfoPtr> app_list;
app_list.push_back(std::move(app));
arc_test()->app_instance()->SendRefreshAppList(std::move(app_list));
intent_helper()->OnIntentFiltersUpdatedForPackage(
package_name, CreateFilterList(package_name, {kDriveAuthority}));
apps::AppServiceProxyFactory::GetForProfile(profile())
->SetSupportedLinksPreference(app_id);
ASSERT_EQ(app_id, preferred_apps().FindPreferredAppForUrl(
GURL("https://drive.google.com/foo")));
// Simulate the app being updated to add a new intent filter.
intent_helper()->OnIntentFiltersUpdatedForPackage(
package_name,
CreateFilterList(package_name, {kDriveAuthority, kDocsAuthority}));
intent_helper()->OnSupportedLinksChanged(
CreateSupportedLinks(package_name), {},
arc::mojom::SupportedLinkChangeSource::kArcSystem);
// Verify that the new intent filter is also marked as preferred.
ASSERT_EQ(app_id, preferred_apps().FindPreferredAppForUrl(
GURL("https://docs.google.com/document")));
}
// Verifies that ARC permissions are published to App Service correctly.
TEST_F(ArcAppsPublisherTest, PublishPermission) {
constexpr char kPackageName[] = "com.test.package";
constexpr char kActivityName[] = "com.test.package.activity";
const std::string kAppId =
ArcAppListPrefs::GetAppId(kPackageName, kActivityName);
std::vector<arc::mojom::AppInfoPtr> apps;
apps.push_back(
arc::mojom::AppInfo::New("Fake app", kPackageName, kActivityName));
arc_test()->app_instance()->SendRefreshAppList(apps);
std::vector<arc::mojom::ArcPackageInfoPtr> packages;
auto package = arc::mojom::ArcPackageInfo::New(
kPackageName, /*package_version=*/1, /*last_backup_android_id=*/1,
/*last_backup_time=*/1, /*sync=*/true);
base::flat_map<arc::mojom::AppPermission, arc::mojom::PermissionStatePtr>
permissions;
permissions.emplace(arc::mojom::AppPermission::CAMERA,
arc::mojom::PermissionState::New(
/*granted=*/true, /*managed=*/false,
/*details=*/std::nullopt, /*one_time=*/true));
permissions.emplace(
arc::mojom::AppPermission::LOCATION,
arc::mojom::PermissionState::New(/*granted=*/true, /*managed=*/true,
/*details=*/"While in use"));
package->permission_states = std::move(permissions);
packages.push_back(std::move(package));
arc_test()->app_instance()->SendRefreshPackageList(std::move(packages));
apps::Permissions result;
bool found = app_service_proxy()->AppRegistryCache().ForOneApp(
kAppId, [&result](const apps::AppUpdate& update) {
result = ClonePermissions(update.Permissions());
});
ASSERT_TRUE(found);
EXPECT_EQ(result.size(), 2ul);
// Sort permissions by permission type.
std::ranges::sort(result, std::less<>(), &apps::Permission::permission_type);
EXPECT_EQ(result[0]->permission_type, apps::PermissionType::kCamera);
EXPECT_EQ(std::get<apps::TriState>(result[0]->value), apps::TriState::kAsk);
EXPECT_FALSE(result[0]->is_managed);
EXPECT_EQ(result[0]->details, std::nullopt);
EXPECT_EQ(result[1]->permission_type, apps::PermissionType::kLocation);
EXPECT_TRUE(result[1]->IsPermissionEnabled());
EXPECT_TRUE(result[1]->is_managed);
EXPECT_EQ(result[1]->details, "While in use");
}
TEST_F(ArcAppsPublisherTest,
LaunchAppWithIntent_EditIntent_SendsOpenUrlRequest) {
SetUpFileSystemInstance();
auto intent = apps_util::MakeEditIntent(
FileInDownloads(profile(), base::FilePath("test.txt")), "text/plain");
const auto& fake_apps = arc_test()->fake_apps();
std::string package_name = fake_apps[0]->package_name;
std::string app_id = ArcAppListPrefs::GetAppId(fake_apps[0]->package_name,
fake_apps[0]->activity);
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
std::optional<apps::State> result;
app_service_proxy()->LaunchAppWithIntent(
app_id, 0, std::move(intent), apps::LaunchSource::kFromFileManager,
/*window_info=*/nullptr,
base::BindLambdaForTesting(
[&result](apps::LaunchResult&& callback_result) {
result = callback_result.state;
}));
ASSERT_EQ(apps::State::kSuccess, result.value_or(apps::State::kFailed));
ASSERT_EQ(file_system_instance()->handledUrlRequests().size(), 1u);
auto& url_request = file_system_instance()->handledUrlRequests()[0];
ASSERT_EQ(url_request->action_type, arc::mojom::ActionType::EDIT);
ASSERT_EQ(url_request->urls.size(), 1u);
ASSERT_EQ(url_request->urls[0]->mime_type, "text/plain");
ASSERT_TRUE(
base::EndsWith(url_request->urls[0]->content_url.spec(), "test.txt"));
}
TEST_F(ArcAppsPublisherTest,
LaunchAppWithIntent_EditIntent_NoArcFileSystem_ReturnsFalse) {
// Do not start up ArcFileSystem, to simulate the intent being sent before ARC
// starts.
auto intent = apps_util::MakeEditIntent(
FileInDownloads(profile(), base::FilePath("test.txt")), "text/plain");
const auto& fake_apps = arc_test()->fake_apps();
std::string package_name = fake_apps[0]->package_name;
std::string app_id = ArcAppListPrefs::GetAppId(fake_apps[0]->package_name,
fake_apps[0]->activity);
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
std::optional<apps::State> result;
app_service_proxy()->LaunchAppWithIntent(
app_id, 0, std::move(intent), apps::LaunchSource::kFromFileManager,
/*window_info=*/nullptr,
base::BindLambdaForTesting(
[&result](apps::LaunchResult&& callback_result) {
result = callback_result.state;
}));
ASSERT_EQ(apps::State::kFailed, result.value_or(apps::State::kSuccess));
}
TEST_F(
ArcAppsPublisherTest,
LaunchAppWithIntent_ViewFileIntent_SendsOpenUrlRequestWithIndividualFileMimeTypes) {
SetUpFileSystemInstance();
auto file1 = std::make_unique<apps::IntentFile>(
FileInDownloads(profile(), base::FilePath("test1.png")));
file1->mime_type = "image/png";
auto file2 = std::make_unique<apps::IntentFile>(
FileInDownloads(profile(), base::FilePath("test2.jpeg")));
file2->mime_type = "image/jpeg";
std::vector<apps::IntentFilePtr> files;
files.push_back(std::move(file1));
files.push_back(std::move(file2));
auto intent = std::make_unique<apps::Intent>(apps_util::kIntentActionView,
std::move(files));
const auto& fake_apps = arc_test()->fake_apps();
std::string package_name = fake_apps[0]->package_name;
std::string app_id = ArcAppListPrefs::GetAppId(fake_apps[0]->package_name,
fake_apps[0]->activity);
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
std::optional<apps::State> result;
app_service_proxy()->LaunchAppWithIntent(
app_id, 0, std::move(intent), apps::LaunchSource::kFromFileManager,
/*window_info=*/nullptr,
base::BindLambdaForTesting(
[&result](apps::LaunchResult&& callback_result) {
result = callback_result.state;
}));
ASSERT_EQ(apps::State::kSuccess, result.value_or(apps::State::kFailed));
ASSERT_EQ(file_system_instance()->handledUrlRequests().size(), 1u);
auto& url_request = file_system_instance()->handledUrlRequests()[0];
ASSERT_EQ(url_request->action_type, arc::mojom::ActionType::VIEW);
ASSERT_EQ(url_request->urls.size(), 2u);
ASSERT_EQ(url_request->urls[0]->mime_type, "image/png");
ASSERT_EQ(url_request->urls[1]->mime_type, "image/jpeg");
ASSERT_TRUE(
base::EndsWith(url_request->urls[0]->content_url.spec(), "test1.png"));
ASSERT_TRUE(
base::EndsWith(url_request->urls[1]->content_url.spec(), "test2.jpeg"));
}
TEST_F(ArcAppsPublisherTest,
LaunchAppWithIntent_ShareFileIntent_SendsOpenUrlRequest) {
SetUpFileSystemInstance();
std::string mime_type = "image/jpeg";
std::string file_name = "test.jpeg";
GURL url = FileInDownloads(profile(), base::FilePath(file_name));
auto intent = apps_util::MakeShareIntent({url}, {mime_type});
const auto& fake_apps = arc_test()->fake_apps();
std::string package_name = fake_apps[0]->package_name;
std::string app_id = ArcAppListPrefs::GetAppId(fake_apps[0]->package_name,
fake_apps[0]->activity);
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
std::optional<apps::State> result;
app_service_proxy()->LaunchAppWithIntent(
app_id, 0, std::move(intent), apps::LaunchSource::kFromFileManager,
/*window_info=*/nullptr,
base::BindLambdaForTesting(
[&result](apps::LaunchResult&& callback_result) {
result = callback_result.state;
}));
ASSERT_EQ(apps::State::kSuccess, result.value_or(apps::State::kFailed));
ASSERT_EQ(file_system_instance()->handledUrlRequests().size(), 1u);
auto& url_request = file_system_instance()->handledUrlRequests()[0];
ASSERT_EQ(url_request->action_type, arc::mojom::ActionType::SEND);
ASSERT_EQ(url_request->urls.size(), 1u);
ASSERT_EQ(url_request->urls[0]->mime_type, mime_type);
ASSERT_TRUE(
base::EndsWith(url_request->urls[0]->content_url.spec(), file_name));
}
TEST_F(ArcAppsPublisherTest, LaunchAppWithIntent_ShareFilesIntent_SendsExtras) {
SetUpFileSystemInstance();
constexpr char kTestIntentText[] = "launch text";
constexpr char kTestIntentTitle[] = "launch title";
constexpr char kTestExtraKey[] = "extra_key";
constexpr char kTestExtraValue[] = "extra_value";
GURL url = FileInDownloads(profile(), base::FilePath("test.jpeg"));
auto intent = apps_util::MakeShareIntent({url}, {"image/jpeg"},
kTestIntentText, kTestIntentTitle);
intent->extras = {std::make_pair(kTestExtraKey, kTestExtraValue)};
const auto& fake_apps = arc_test()->fake_apps();
std::string package_name = fake_apps[0]->package_name;
std::string app_id = ArcAppListPrefs::GetAppId(fake_apps[0]->package_name,
fake_apps[0]->activity);
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
app_service_proxy()->LaunchAppWithIntent(
app_id, 0, std::move(intent), apps::LaunchSource::kFromFileManager,
/*window_info=*/nullptr, base::DoNothing());
ASSERT_EQ(file_system_instance()->handledUrlRequests().size(), 1u);
auto& url_request = file_system_instance()->handledUrlRequests()[0];
ASSERT_EQ(url_request->action_type, arc::mojom::ActionType::SEND);
ASSERT_EQ(url_request->urls.size(), 1u);
ASSERT_EQ(url_request->extras.value()[kTestExtraKey], kTestExtraValue);
ASSERT_EQ(url_request->extras.value()["android.intent.extra.TEXT"],
kTestIntentText);
ASSERT_EQ(url_request->extras.value()["android.intent.extra.SUBJECT"],
kTestIntentTitle);
}
TEST_F(ArcAppsPublisherTest, SetAppLocale_SendsLocaleToArc) {
// Setup.
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(arc::kPerAppLanguage);
ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile());
ASSERT_NE(nullptr, prefs);
// fake_packages[4] is the test package with localeInfo.
const std::string& test_package_name =
arc_test()->fake_apps()[4]->package_name;
const std::string& app_id =
prefs->GetAppId(test_package_name, arc_test()->fake_apps()[4]->activity);
// Setup app.
std::vector<arc::mojom::AppInfoPtr> test_app_info_list;
test_app_info_list.push_back(arc_test()->fake_apps()[4]->Clone());
arc_test()->app_instance()->SendRefreshAppList(test_app_info_list);
// Setup package.
// Initially pref will be set with "en" as selectedLocale.
std::vector<arc::mojom::ArcPackageInfoPtr> test_packages;
test_packages.push_back(arc_test()->fake_packages()[4]->Clone());
arc_test()->app_instance()->SendRefreshPackageList(
ArcAppTest::ClonePackages(test_packages));
// Run.
app_service_proxy()->SetAppLocale(app_id, "ja");
// Assert.
ASSERT_EQ("ja",
arc_test()->app_instance()->selected_locale(test_package_name));
ASSERT_EQ("ja",
profile()->GetPrefs()->GetString(arc::prefs::kArcLastSetAppLocale));
}
class ArcAppsPublisherPromiseAppTest : public ArcAppsPublisherTest {
public:
void SetUp() override {
ArcAppsPublisherTest::SetUp();
feature_list_.InitAndEnableFeature(ash::features::kPromiseIcons);
app_service_proxy()->ReinitializeForTesting(profile());
service()->SetSkipAlmanacForTesting(true);
}
apps::PromiseAppService* service() {
return app_service_proxy()->PromiseAppService();
}
apps::PromiseAppRegistryCache* cache() {
return app_service_proxy()->PromiseAppRegistryCache();
}
private:
base::test::ScopedFeatureList feature_list_;
};
TEST_F(ArcAppsPublisherPromiseAppTest,
StartingInstallationRegistersPromiseApp) {
// Verify that the promise app is not yet registered.
EXPECT_FALSE(cache()->HasPromiseApp(kTestPackageId));
arc_test()->app_instance()->SendInstallationStarted(kTestPackageName);
// Verify that the promise app is now registered.
EXPECT_TRUE(cache()->HasPromiseApp(kTestPackageId));
}
TEST_F(ArcAppsPublisherPromiseAppTest,
InstallationProgressChangeUpdatesPromiseApp) {
float progress_initial = 0.1;
float progress_next = 0.9;
// Add a promise app for testing.
std::unique_ptr<apps::PromiseApp> promise_app =
std::make_unique<apps::PromiseApp>(kTestPackageId);
promise_app->progress = progress_initial;
cache()->OnPromiseApp(std::move(promise_app));
// Check that the initial progress value is correct.
const apps::PromiseApp* promise_app_result =
cache()->GetPromiseApp(kTestPackageId);
EXPECT_TRUE(promise_app_result);
EXPECT_TRUE(promise_app_result->progress.has_value());
EXPECT_EQ(promise_app_result->progress.value(), progress_initial);
// Send an update and check the progress value.
arc_test()->app_instance()->SendInstallationProgressChanged(kTestPackageName,
progress_next);
promise_app_result = cache()->GetPromiseApp(kTestPackageId);
EXPECT_TRUE(promise_app_result);
EXPECT_TRUE(promise_app_result->progress.has_value());
EXPECT_EQ(promise_app_result->progress.value(), progress_next);
}
TEST_F(ArcAppsPublisherPromiseAppTest, ProgressUpdateChangesPromiseStatus) {
// Add a promise app for testing.
std::unique_ptr<apps::PromiseApp> promise_app =
std::make_unique<apps::PromiseApp>(kTestPackageId);
promise_app->status = apps::PromiseStatus::kPending;
cache()->OnPromiseApp(std::move(promise_app));
// Check that the initial status is kPending.
const apps::PromiseApp* promise_app_result =
cache()->GetPromiseApp(kTestPackageId);
EXPECT_TRUE(promise_app_result);
EXPECT_EQ(promise_app_result->status, apps::PromiseStatus::kPending);
// Send a progress update and check the status.
arc_test()->app_instance()->SendInstallationProgressChanged(kTestPackageName,
0.2);
promise_app_result = cache()->GetPromiseApp(kTestPackageId);
EXPECT_TRUE(promise_app_result);
EXPECT_EQ(promise_app_result->status, apps::PromiseStatus::kInstalling);
}
TEST_F(ArcAppsPublisherPromiseAppTest, CancelledInstallationRemovesPromiseApp) {
// Add a promise app to the cache.
std::unique_ptr<apps::PromiseApp> promise_app =
std::make_unique<apps::PromiseApp>(kTestPackageId);
promise_app->status = apps::PromiseStatus::kPending;
cache()->OnPromiseApp(std::move(promise_app));
// Check that the promise app exists.
EXPECT_TRUE(cache()->HasPromiseApp(kTestPackageId));
// Confirm that the promise app gets removed after a cancelled/ failed
// installation update.
arc_test()->app_instance()->SendInstallationFinished(kTestPackageName, false);
EXPECT_FALSE(cache()->HasPromiseApp(kTestPackageId));
}
TEST_F(ArcAppsPublisherPromiseAppTest,
SuccessfulInstallationOfNonLaunchablePackageRemovesPromiseApp) {
// Add a promise app to the cache.
std::unique_ptr<apps::PromiseApp> promise_app =
std::make_unique<apps::PromiseApp>(kTestPackageId);
promise_app->status = apps::PromiseStatus::kPending;
cache()->OnPromiseApp(std::move(promise_app));
// Check that the promise app exists.
EXPECT_TRUE(cache()->HasPromiseApp(kTestPackageId));
// Confirm that the promise app gets removed after successful installation of
// a non-launchable package.
arc_test()->app_instance()->SendInstallationFinished(
kTestPackageName, /*success=*/true,
/*is_launchable_app=*/false);
EXPECT_FALSE(cache()->HasPromiseApp(kTestPackageId));
}
TEST_F(ArcAppsPublisherPromiseAppTest,
SuccessfulInstallationRemovesPromiseApp) {
// Add a promise app to the cache.
std::unique_ptr<apps::PromiseApp> promise_app =
std::make_unique<apps::PromiseApp>(kTestPackageId);
promise_app->status = apps::PromiseStatus::kPending;
cache()->OnPromiseApp(std::move(promise_app));
// Check that the promise app exists.
EXPECT_TRUE(cache()->HasPromiseApp(kTestPackageId));
// Confirm that the promise app gets removed after a successfully completed
// installation.
const auto& fake_apps = arc_test()->fake_apps();
fake_apps[0]->package_name = kTestPackageName;
std::string app_id =
ArcAppListPrefs::GetAppId(kTestPackageName, "testActivity");
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
// Confirm that the promise app gets removed after the installed app gets
// registered.
EXPECT_FALSE(cache()->HasPromiseApp(kTestPackageId));
}
TEST_F(ArcAppsPublisherPromiseAppTest, PromiseAppsAreSuppressedForPiArc) {
// Set ARC version to P, which we should not create promise apps for.
apps::ArcApps::SetArcVersionForTesting(arc::kArcVersionP);
// Verify that the promise app is not registered to begin with.
EXPECT_FALSE(cache()->HasPromiseApp(kTestPackageId));
// Trigger an installation event notification.
arc_test()->app_instance()->SendInstallationStarted(kTestPackageName);
// Verify that the promise app still isn't registered.
EXPECT_FALSE(cache()->HasPromiseApp(kTestPackageId));
}
TEST_F(ArcAppsPublisherPromiseAppTest, PromiseAppsAreCreatedForRvcArc) {
// Set ARC version to R, which should allow promise apps to be created.
apps::ArcApps::SetArcVersionForTesting(arc::kArcVersionR);
// Verify that the promise app is not registered to begin with.
EXPECT_FALSE(cache()->HasPromiseApp(kTestPackageId));
// Trigger an installation event notification.
arc_test()->app_instance()->SendInstallationStarted(kTestPackageName);
// Verify that the promise app is registered.
EXPECT_TRUE(cache()->HasPromiseApp(kTestPackageId));
}
// Verifies that only valid intent filters will be published from ARC.
TEST_F(ArcAppsPublisherTest, OnlyValidFilterIsPublished) {
const GURL kTestUrl("https://www.example.com");
const auto& fake_apps = arc_test()->fake_apps();
std::string package_name = fake_apps[0]->package_name;
std::string app_id = ArcAppListPrefs::GetAppId(fake_apps[0]->package_name,
fake_apps[0]->activity);
arc_test()->app_instance()->SendRefreshAppList(fake_apps);
std::vector<arc::IntentFilter::AuthorityEntry> filter_authorities1;
filter_authorities1.emplace_back(kTestUrl.host(), 0);
std::vector<arc::IntentFilter::PatternMatcher> patterns;
patterns.emplace_back(kTestUrl.path(), arc::PatternType::kPrefix);
auto filter = arc::IntentFilter(package_name, {arc::kIntentActionView},
std::move(filter_authorities1),
std::move(patterns), {kTestUrl.scheme()}, {});
std::vector<arc::IntentFilter> filters;
filters.push_back(std::move(filter));
std::vector<arc::IntentFilter::AuthorityEntry> filter_authorities2;
filter_authorities2.emplace_back(kTestUrl.host(), 0);
constexpr arc::PatternType kInvalidPatternType =
static_cast<arc::PatternType>(5);
ASSERT_FALSE(arc::IsKnownPatternType(kInvalidPatternType));
std::vector<arc::IntentFilter::PatternMatcher> invalid_pattern;
invalid_pattern.emplace_back(kTestUrl.path(), kInvalidPatternType);
auto invalid_filter = arc::IntentFilter(
package_name, {arc::kIntentActionView}, std::move(filter_authorities2),
std::move(invalid_pattern), {"https"}, {});
filters.push_back(std::move(invalid_filter));
// Update intent filters and supported links for the app, as if it was just
// installed.
intent_helper()->OnIntentFiltersUpdatedForPackage(package_name,
std::move(filters));
apps::IntentFilters published_filters;
apps::AppServiceProxyFactory::GetForProfile(profile())
->AppRegistryCache()
.ForOneApp(app_id, [&published_filters](const apps::AppUpdate& update) {
published_filters = update.IntentFilters();
});
// Only one valid filter should be published.
EXPECT_EQ(published_filters.size(), 1u);
apps::IntentFilterPtr expected_filter =
apps_util::MakeIntentFilterForUrlScope(kTestUrl,
/*omit_port_for_testing=*/true);
EXPECT_EQ(*published_filters[0], *expected_filter);
}
|