Commit 525d56dd authored by Jiewei Qian's avatar Jiewei Qian Committed by Commit Bot

system-web-apps: add browsertest for SWA reinstall

This CL adds a basic browsertest to verify System Web Apps works after
a reinstall. This typically happens on a version upgrade.

This CL tests that the installation process completes without crashing,
and the installed Apps can be launched (with the exception of Terminal).

Terminal requires resources that are only available in Chrome OS images,
so we can't launch it from chromium source. Tast tests are needed for
this scenario.

Bug: 1095524
Change-Id: Ib7053ea56cf0eee8031c66b5d77edcc283236972
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2316191Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Commit-Queue: Jiewei Qian  <qjw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792221}
parent 07c39fae
...@@ -72,6 +72,10 @@ const char kFileHandlingOriginTrial[] = "FileHandling"; ...@@ -72,6 +72,10 @@ const char kFileHandlingOriginTrial[] = "FileHandling";
// bailing out. // bailing out.
const int kInstallFailureAttempts = 3; const int kInstallFailureAttempts = 3;
// When set to |true|, SystemWebAppManager will enable all registered System
// Apps, regardless of their respective feature flag.
bool g_enable_all_system_web_apps_for_testing = false;
// Use #if defined to avoid compiler error on unused function. // Use #if defined to avoid compiler error on unused function.
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -260,6 +264,9 @@ const char SystemWebAppManager::kInstallDurationHistogramName[]; ...@@ -260,6 +264,9 @@ const char SystemWebAppManager::kInstallDurationHistogramName[];
// static // static
bool SystemWebAppManager::IsAppEnabled(SystemAppType type) { bool SystemWebAppManager::IsAppEnabled(SystemAppType type) {
if (g_enable_all_system_web_apps_for_testing)
return true;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
switch (type) { switch (type) {
case SystemAppType::SETTINGS: case SystemAppType::SETTINGS:
...@@ -291,6 +298,12 @@ bool SystemWebAppManager::IsAppEnabled(SystemAppType type) { ...@@ -291,6 +298,12 @@ bool SystemWebAppManager::IsAppEnabled(SystemAppType type) {
return false; return false;
#endif // OS_CHROMEOS #endif // OS_CHROMEOS
} }
// static
void SystemWebAppManager::EnableAllSystemAppsForTesting() {
g_enable_all_system_web_apps_for_testing = true;
}
SystemWebAppManager::SystemWebAppManager(Profile* profile) SystemWebAppManager::SystemWebAppManager(Profile* profile)
: profile_(profile), : profile_(profile),
on_apps_synchronized_(new base::OneShotEvent()), on_apps_synchronized_(new base::OneShotEvent()),
...@@ -298,11 +311,11 @@ SystemWebAppManager::SystemWebAppManager(Profile* profile) ...@@ -298,11 +311,11 @@ SystemWebAppManager::SystemWebAppManager(Profile* profile)
std::string(kInstallResultHistogramName) + ".Profiles." + std::string(kInstallResultHistogramName) + ".Profiles." +
GetProfileCategoryForLogging(profile)), GetProfileCategoryForLogging(profile)),
pref_service_(profile_->GetPrefs()) { pref_service_(profile_->GetPrefs()) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch( if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
::switches::kTestType)) { // Always update in tests.
// Always update in tests, and return early to avoid populating with real
// system apps.
update_policy_ = UpdatePolicy::kAlwaysUpdate; update_policy_ = UpdatePolicy::kAlwaysUpdate;
// Return early to avoid populating with real system apps.
return; return;
} }
...@@ -313,6 +326,7 @@ SystemWebAppManager::SystemWebAppManager(Profile* profile) ...@@ -313,6 +326,7 @@ SystemWebAppManager::SystemWebAppManager(Profile* profile)
// Dev builds should update every launch. // Dev builds should update every launch.
update_policy_ = UpdatePolicy::kAlwaysUpdate; update_policy_ = UpdatePolicy::kAlwaysUpdate;
#endif #endif
system_app_infos_ = CreateSystemWebApps(); system_app_infos_ = CreateSystemWebApps();
} }
......
...@@ -148,6 +148,11 @@ class SystemWebAppManager { ...@@ -148,6 +148,11 @@ class SystemWebAppManager {
static bool IsEnabled(); static bool IsEnabled();
// This call will instruct System Web App Manager to include all registered
// System Apps for installation. Must be called before SystemWebAppManager is
// constructed.
static void EnableAllSystemAppsForTesting();
// The SystemWebAppManager is disabled in browser tests by default because it // The SystemWebAppManager is disabled in browser tests by default because it
// pollutes the startup state (several tests expect the Extensions state to be // pollutes the startup state (several tests expect the Extensions state to be
// clean). // clean).
......
...@@ -891,6 +891,16 @@ class SystemWebAppManagerFileHandlingOriginTrialsBrowserTest ...@@ -891,6 +891,16 @@ class SystemWebAppManagerFileHandlingOriginTrialsBrowserTest
url::Origin GetOrigin(const GURL& url) { return url::Origin::Create(url); } url::Origin GetOrigin(const GURL& url) { return url::Origin::Create(url); }
}; };
// Test that file handling works when the App is first installed.
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerFileHandlingOriginTrialsBrowserTest,
PRE_FileHandlingWorks) {
WaitForTestSystemAppInstall();
content::WebContents* web_contents = LaunchWithTestFiles();
EXPECT_TRUE(WaitForLaunchParam(web_contents));
}
// Test that file handling works when after a version upgrade.
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerFileHandlingOriginTrialsBrowserTest, IN_PROC_BROWSER_TEST_P(SystemWebAppManagerFileHandlingOriginTrialsBrowserTest,
FileHandlingWorks) { FileHandlingWorks) {
WaitForTestSystemAppInstall(); WaitForTestSystemAppInstall();
...@@ -1016,6 +1026,41 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerUninstallBrowserTest, Uninstall) { ...@@ -1016,6 +1026,41 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerUninstallBrowserTest, Uninstall) {
EXPECT_TRUE(GetManager().GetAppIds().empty()); EXPECT_TRUE(GetManager().GetAppIds().empty());
} }
// Test that all registered System Apps can be re-installed.
class SystemWebAppManagerUpgradeBrowserTest
: public SystemWebAppManagerBrowserTest {
public:
SystemWebAppManagerUpgradeBrowserTest()
: SystemWebAppManagerBrowserTest(/*install_mock=*/false) {
SystemWebAppManager::EnableAllSystemAppsForTesting();
}
~SystemWebAppManagerUpgradeBrowserTest() override = default;
};
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerUpgradeBrowserTest, PRE_Upgrade) {
WaitForTestSystemAppInstall();
EXPECT_GE(GetManager().GetAppIds().size(), 1U);
}
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerUpgradeBrowserTest, Upgrade) {
WaitForTestSystemAppInstall();
const auto& app_ids = GetManager().GetAppIds();
EXPECT_GE(app_ids.size(), 1U);
for (const auto& app_id : app_ids) {
const auto type = GetManager().GetSystemAppTypeForAppId(app_id).value();
// We don't launch Terminal in browsertest, because it requires resources
// that are only available in Chrome OS images.
if (type == SystemAppType::TERMINAL)
continue;
// Launch other System Apps normally, and check the app's launch_url loads.
EXPECT_TRUE(LaunchApp(type));
}
}
// Tests that SWA-specific data is correctly migrated to Web Apps without // Tests that SWA-specific data is correctly migrated to Web Apps without
// Extensions. // Extensions.
class SystemWebAppManagerMigrationTest class SystemWebAppManagerMigrationTest
...@@ -1487,4 +1532,13 @@ INSTANTIATE_TEST_SUITE_P(All, ...@@ -1487,4 +1532,13 @@ INSTANTIATE_TEST_SUITE_P(All,
ProviderType::kWebApps), ProviderType::kWebApps),
ProviderTypeParamToString); ProviderTypeParamToString);
// We only have concrete System Web Apps on Chrome OS.
#if defined(OS_CHROMEOS)
INSTANTIATE_TEST_SUITE_P(All,
SystemWebAppManagerUpgradeBrowserTest,
::testing::Values(ProviderType::kBookmarkApps,
ProviderType::kWebApps),
ProviderTypeParamToString);
#endif
} // namespace web_app } // namespace web_app
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment