Commit 15e8dc00 authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

Migrate WebAppPolicy shelf tests to support BMO

This CL updates ChromeLauncherControllerTest.WebAppPolicy* to be
ShelfWebAppBrowserTest.WebAppPolicy* tests and removes the dependency
on web apps being Extensions.

Bug: 1068919, 1054116
Change-Id: I0a89b926d1ff2184896c03f608879a3265922a4a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2141397Reviewed-by: default avatarNancy Wang <nancylingwang@chromium.org>
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757745}
parent 7bcf733d
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "chrome/browser/extensions/launch_util.h" #include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
#include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h" #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_test_util.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_test_util.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
...@@ -71,6 +72,7 @@ ...@@ -71,6 +72,7 @@
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h" #include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/web_applications/components/app_registry_controller.h" #include "chrome/browser/web_applications/components/app_registry_controller.h"
#include "chrome/browser/web_applications/components/app_shortcut_manager.h" #include "chrome/browser/web_applications/components/app_shortcut_manager.h"
#include "chrome/browser/web_applications/components/externally_installed_web_app_prefs.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h" #include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/components/web_app_id.h" #include "chrome/browser/web_applications/components/web_app_id.h"
...@@ -82,6 +84,7 @@ ...@@ -82,6 +84,7 @@
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
...@@ -2276,6 +2279,52 @@ IN_PROC_BROWSER_TEST_P(ShelfWebAppBrowserTest, ...@@ -2276,6 +2279,52 @@ IN_PROC_BROWSER_TEST_P(ShelfWebAppBrowserTest,
ChromeLauncherController::instance()->shelf_model()->active_shelf_id()); ChromeLauncherController::instance()->shelf_model()->active_shelf_id());
} }
IN_PROC_BROWSER_TEST_P(ShelfWebAppBrowserTest, WebAppPolicy) {
// Install web app.
GURL app_url = GURL("https://example.org/");
web_app::AppId app_id = InstallWebApp(app_url);
web_app::ExternallyInstalledWebAppPrefs web_app_prefs(
browser()->profile()->GetPrefs());
web_app_prefs.Insert(app_url, app_id,
web_app::ExternalInstallSource::kExternalPolicy);
apps::AppServiceProxyFactory::GetForProfile(profile())
->FlushMojoCallsForTesting();
// Set policy to pin the web app.
base::DictionaryValue entry;
entry.SetKey(kPinnedAppsPrefAppIDKey, base::Value(app_url.spec()));
base::ListValue policy_value;
policy_value.Append(std::move(entry));
profile()->GetPrefs()->Set(prefs::kPolicyPinnedLauncherApps, policy_value);
// Check web app is pinned and fixed.
EXPECT_EQ(shelf_model()->item_count(), 2);
EXPECT_EQ(shelf_model()->items()[0].type, ash::TYPE_BROWSER_SHORTCUT);
EXPECT_EQ(shelf_model()->items()[1].type, ash::TYPE_PINNED_APP);
EXPECT_EQ(shelf_model()->items()[1].id.app_id, app_id);
EXPECT_EQ(AppListControllerDelegate::PIN_FIXED,
GetPinnableForAppID(app_id, profile()));
}
IN_PROC_BROWSER_TEST_P(ShelfWebAppBrowserTest, WebAppPolicyNonExistentApp) {
// Don't install the web app.
GURL app_url = GURL("https://example.org/");
web_app::AppId app_id = web_app::GenerateAppIdFromURL(app_url);
// Set policy to pin the non existent web app.
base::DictionaryValue entry;
entry.SetKey(kPinnedAppsPrefAppIDKey, base::Value(app_url.spec()));
base::ListValue policy_value;
policy_value.Append(std::move(entry));
profile()->GetPrefs()->Set(prefs::kPolicyPinnedLauncherApps, policy_value);
// Check web app policy is ignored.
EXPECT_EQ(shelf_model()->item_count(), 1);
EXPECT_EQ(shelf_model()->items()[0].type, ash::TYPE_BROWSER_SHORTCUT);
EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE,
GetPinnableForAppID(app_id, profile()));
}
// Test that "Close" is shown in the context menu when there are opened browsers // Test that "Close" is shown in the context menu when there are opened browsers
// windows. // windows.
IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest,
......
...@@ -151,6 +151,7 @@ namespace { ...@@ -151,6 +151,7 @@ namespace {
constexpr char kOfflineGmailUrl[] = "https://mail.google.com/mail/mu/u"; constexpr char kOfflineGmailUrl[] = "https://mail.google.com/mail/mu/u";
constexpr char kGmailUrl[] = "https://mail.google.com/mail/u"; constexpr char kGmailUrl[] = "https://mail.google.com/mail/u";
constexpr char kGmailLaunchURL[] = "https://mail.google.com/mail/ca"; constexpr char kGmailLaunchURL[] = "https://mail.google.com/mail/ca";
constexpr char kLaunchURL[] = "https://foo.example/";
// An extension prefix. // An extension prefix.
constexpr char kCrxAppPrefix[] = "_crx_"; constexpr char kCrxAppPrefix[] = "_crx_";
...@@ -159,10 +160,6 @@ constexpr char kCrxAppPrefix[] = "_crx_"; ...@@ -159,10 +160,6 @@ constexpr char kCrxAppPrefix[] = "_crx_";
// pin model with default apps that can affect some tests. // pin model with default apps that can affect some tests.
constexpr char kDummyAppId[] = "dummyappid_dummyappid_dummyappid"; constexpr char kDummyAppId[] = "dummyappid_dummyappid_dummyappid";
// Web App id.
constexpr char kWebAppId[] = "lpikggcgamknpihimepdkohalcnpofed";
constexpr char kWebAppUrl[] = "https://foo.example/";
// Test implementation of AppIconLoader. // Test implementation of AppIconLoader.
class TestAppIconLoaderImpl : public AppIconLoader { class TestAppIconLoaderImpl : public AppIconLoader {
public: public:
...@@ -299,7 +296,7 @@ class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { ...@@ -299,7 +296,7 @@ class ChromeLauncherControllerTest : public BrowserWithTestWindowTest {
// AppService checks the app's type. So set the // AppService checks the app's type. So set the
// manifest_keys::kLaunchWebURL, so that the extension can get the type // manifest_keys::kLaunchWebURL, so that the extension can get the type
// from manifest value, and then AppService can get the extension's type. // from manifest value, and then AppService can get the extension's type.
manifest.SetString(extensions::manifest_keys::kLaunchWebURL, kWebAppUrl); manifest.SetString(extensions::manifest_keys::kLaunchWebURL, kLaunchURL);
base::DictionaryValue manifest_platform_app; base::DictionaryValue manifest_platform_app;
manifest_platform_app.SetString(extensions::manifest_keys::kName, manifest_platform_app.SetString(extensions::manifest_keys::kName,
...@@ -408,10 +405,7 @@ class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { ...@@ -408,10 +405,7 @@ class ChromeLauncherControllerTest : public BrowserWithTestWindowTest {
// manifest_keys::kLaunchWebURL, so that the extension can get the type // manifest_keys::kLaunchWebURL, so that the extension can get the type
// from manifest value, and then AppService can get the extension's type. // from manifest value, and then AppService can get the extension's type.
manifest_web_app.SetString(extensions::manifest_keys::kLaunchWebURL, manifest_web_app.SetString(extensions::manifest_keys::kLaunchWebURL,
kWebAppUrl); kLaunchURL);
web_app_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
manifest_web_app, Extension::FROM_BOOKMARK,
kWebAppId, &error);
} }
ui::BaseWindow* GetLastActiveWindowForItemController( ui::BaseWindow* GetLastActiveWindowForItemController(
...@@ -775,8 +769,6 @@ class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { ...@@ -775,8 +769,6 @@ class ChromeLauncherControllerTest : public BrowserWithTestWindowTest {
result += "Play Store"; result += "Play Store";
} else if (app == crostini::GetTerminalId()) { } else if (app == crostini::GetTerminalId()) {
result += "Terminal"; result += "Terminal";
} else if (app == web_app_->id()) {
result += "WebApp";
} else { } else {
bool arc_app_found = false; bool arc_app_found = false;
for (const auto& arc_app : arc_test_.fake_apps()) { for (const auto& arc_app : arc_test_.fake_apps()) {
...@@ -946,7 +938,6 @@ class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { ...@@ -946,7 +938,6 @@ class ChromeLauncherControllerTest : public BrowserWithTestWindowTest {
scoped_refptr<Extension> extensionYoutubeApp_; scoped_refptr<Extension> extensionYoutubeApp_;
scoped_refptr<Extension> extension_platform_app_; scoped_refptr<Extension> extension_platform_app_;
scoped_refptr<Extension> arc_support_host_; scoped_refptr<Extension> arc_support_host_;
scoped_refptr<Extension> web_app_;
ArcAppTest arc_test_; ArcAppTest arc_test_;
bool auto_start_arc_test_ = false; bool auto_start_arc_test_ = false;
...@@ -1024,7 +1015,7 @@ class ChromeLauncherControllerExtendedShelfTest ...@@ -1024,7 +1015,7 @@ class ChromeLauncherControllerExtendedShelfTest
// AppService checks the app's type. So set the // AppService checks the app's type. So set the
// manifest_keys::kLaunchWebURL, so that the extension can get the type // manifest_keys::kLaunchWebURL, so that the extension can get the type
// from manifest value, and then AppService can get the extension's type. // from manifest value, and then AppService can get the extension's type.
manifest.SetString(extensions::manifest_keys::kLaunchWebURL, kWebAppUrl); manifest.SetString(extensions::manifest_keys::kLaunchWebURL, kLaunchURL);
const std::vector<std::pair<std::string, std::string>> extra_extensions = { const std::vector<std::pair<std::string, std::string>> extra_extensions = {
{extension_misc::kCalendarAppId, "Calendar"}, {extension_misc::kCalendarAppId, "Calendar"},
...@@ -2998,42 +2989,6 @@ TEST_F(ChromeLauncherControllerTest, Policy) { ...@@ -2998,42 +2989,6 @@ TEST_F(ChromeLauncherControllerTest, Policy) {
EXPECT_EQ("Chrome, App1, App2", GetPinnedAppStatus()); EXPECT_EQ("Chrome, App1, App2", GetPinnedAppStatus());
} }
TEST_F(ChromeLauncherControllerTest, WebAppPolicy) {
// Simulate one Web App being installed.
web_app::ExternallyInstalledWebAppPrefs web_app_prefs(profile()->GetPrefs());
web_app_prefs.Insert(GURL(kWebAppUrl), kWebAppId,
web_app::ExternalInstallSource::kExternalPolicy);
extension_service_->AddExtension(web_app_.get());
// Set the policy value.
base::ListValue policy_value;
AppendPrefValue(&policy_value, kWebAppUrl);
profile()->GetTestingPrefService()->SetManagedPref(
prefs::kPolicyPinnedLauncherApps,
base::Value::ToUniquePtrValue(std::move(policy_value)));
InitLauncherController();
EXPECT_EQ("Chrome, WebApp", GetPinnedAppStatus());
EXPECT_EQ(AppListControllerDelegate::PIN_FIXED,
GetPinnableForAppID(kWebAppId, profile()));
}
TEST_F(ChromeLauncherControllerTest, WebAppPolicyNonExistentApp) {
// Set the policy value but don't install an app for it.
base::ListValue policy_value;
AppendPrefValue(&policy_value, kWebAppUrl);
profile()->GetTestingPrefService()->SetManagedPref(
prefs::kPolicyPinnedLauncherApps,
base::Value::ToUniquePtrValue(std::move(policy_value)));
InitLauncherController();
EXPECT_EQ("Chrome", GetPinnedAppStatus());
EXPECT_EQ(AppListControllerDelegate::PIN_EDITABLE,
GetPinnableForAppID(kWebAppId, profile()));
}
TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) { TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) {
extension_service_->AddExtension(extensionGmailApp_.get()); extension_service_->AddExtension(extensionGmailApp_.get());
extension_service_->AddExtension(extensionDocApp_.get()); extension_service_->AddExtension(extensionDocApp_.get());
......
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