Commit c5f21dfd authored by Jiewei Qian's avatar Jiewei Qian Committed by Commit Bot

system-web-apps: add EnableAllSystemWebApps chrome feature

This CL adds a EnableAllSystemWebApps chrome feature, when enabled
SystemWebAppManager will enable and install all registered system apps,
and ignoring each system app's respective feature flag.

This is useful for testing.

This CL migrates the existing g_enable_all_system_web_apps_for_testing
to this new feature, and adds a kNumberOfRegisteredSystemApps to verify
all the apps can be installed successfully.

Bug: 1095524
Change-Id: Iba595e7d94ff20076a6bfb36e0a91cee09c897bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2366952Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Commit-Queue: Jiewei Qian  <qjw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800906}
parent 7213338a
...@@ -73,10 +73,6 @@ const char kFileHandlingOriginTrial[] = "FileHandling"; ...@@ -73,10 +73,6 @@ 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)
...@@ -284,7 +280,7 @@ const char SystemWebAppManager::kInstallDurationHistogramName[]; ...@@ -284,7 +280,7 @@ 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) if (base::FeatureList::IsEnabled(features::kEnableAllSystemWebApps))
return true; return true;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -321,11 +317,6 @@ bool SystemWebAppManager::IsAppEnabled(SystemAppType type) { ...@@ -321,11 +317,6 @@ bool SystemWebAppManager::IsAppEnabled(SystemAppType type) {
#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()),
......
...@@ -59,6 +59,9 @@ enum class SystemAppType { ...@@ -59,6 +59,9 @@ enum class SystemAppType {
TELEMETRY, TELEMETRY,
SAMPLE, SAMPLE,
#endif // !defined(OFFICIAL_BUILD) #endif // !defined(OFFICIAL_BUILD)
// When adding a new system app, update system_web_app_manager_browsertest.cc
// |GetExpectedNumberOfInstalledSystemApps| method accordingly.
}; };
using OriginTrialsMap = std::map<url::Origin, std::vector<std::string>>; using OriginTrialsMap = std::map<url::Origin, std::vector<std::string>>;
...@@ -156,11 +159,6 @@ class SystemWebAppManager { ...@@ -156,11 +159,6 @@ 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).
......
...@@ -1119,21 +1119,36 @@ class SystemWebAppManagerUpgradeBrowserTest ...@@ -1119,21 +1119,36 @@ class SystemWebAppManagerUpgradeBrowserTest
public: public:
SystemWebAppManagerUpgradeBrowserTest() SystemWebAppManagerUpgradeBrowserTest()
: SystemWebAppManagerBrowserTest(/*install_mock=*/false) { : SystemWebAppManagerBrowserTest(/*install_mock=*/false) {
SystemWebAppManager::EnableAllSystemAppsForTesting(); features_.InitAndEnableFeature(features::kEnableAllSystemWebApps);
} }
~SystemWebAppManagerUpgradeBrowserTest() override = default; ~SystemWebAppManagerUpgradeBrowserTest() override = default;
unsigned int GetExpectedNumberOfInstalledSystemApps() {
#if defined(OFFICIAL_BUILD)
return 8;
#else
// TODO(http://crbug.com/1120208): Telemetry isn't available for install
// unless its flag is enabled. So it's not included here. Update this after
// Telemetry is available for install without a flag.
return 9;
#endif // defined(OFFICIAL_BUILD)
}
private:
base::test::ScopedFeatureList features_;
}; };
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerUpgradeBrowserTest, PRE_Upgrade) { IN_PROC_BROWSER_TEST_P(SystemWebAppManagerUpgradeBrowserTest, PRE_Upgrade) {
WaitForTestSystemAppInstall(); WaitForTestSystemAppInstall();
EXPECT_GE(GetManager().GetAppIds().size(), 1U); EXPECT_GE(GetExpectedNumberOfInstalledSystemApps(),
GetManager().GetAppIds().size());
} }
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerUpgradeBrowserTest, Upgrade) { IN_PROC_BROWSER_TEST_P(SystemWebAppManagerUpgradeBrowserTest, Upgrade) {
WaitForTestSystemAppInstall(); WaitForTestSystemAppInstall();
const auto& app_ids = GetManager().GetAppIds(); const auto& app_ids = GetManager().GetAppIds();
EXPECT_GE(app_ids.size(), 1U); EXPECT_EQ(GetExpectedNumberOfInstalledSystemApps(), app_ids.size());
for (const auto& app_id : app_ids) { for (const auto& app_id : app_ids) {
const auto type = GetManager().GetSystemAppTypeForAppId(app_id).value(); const auto type = GetManager().GetSystemAppTypeForAppId(app_id).value();
......
...@@ -292,6 +292,11 @@ const base::Feature kDownloadsLocationChange{"DownloadsLocationChange", ...@@ -292,6 +292,11 @@ const base::Feature kDownloadsLocationChange{"DownloadsLocationChange",
base::FEATURE_ENABLED_BY_DEFAULT}; base::FEATURE_ENABLED_BY_DEFAULT};
#endif #endif
// Enables all registered system web apps, regardless of their respective
// feature flags.
const base::Feature kEnableAllSystemWebApps{"EnableAllSystemWebApps",
base::FEATURE_DISABLED_BY_DEFAULT};
// Disables ambient authentication in guest sessions. // Disables ambient authentication in guest sessions.
const base::Feature kEnableAmbientAuthenticationInGuestSession{ const base::Feature kEnableAmbientAuthenticationInGuestSession{
"EnableAmbientAuthenticationInGuestSession", "EnableAmbientAuthenticationInGuestSession",
......
...@@ -196,6 +196,9 @@ COMPONENT_EXPORT(CHROME_FEATURES) ...@@ -196,6 +196,9 @@ COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kDownloadsLocationChange; extern const base::Feature kDownloadsLocationChange;
#endif #endif
COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kEnableAllSystemWebApps;
COMPONENT_EXPORT(CHROME_FEATURES) COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kEnableAmbientAuthenticationInGuestSession; extern const base::Feature kEnableAmbientAuthenticationInGuestSession;
......
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