#include "chrome/browser/web_applications/policy/web_app_policy_manager.h"
#include <memory>
#include <string_view>
#include "base/command_line.h"
#include "base/json/json_reader.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_future.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/web_applications/web_app_browsertest_base.h"
#include "chrome/browser/web_applications/policy/web_app_policy_constants.h"
#include "chrome/browser/web_applications/test/os_integration_test_override_impl.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/browser/web_applications/test/web_app_test_observers.h"
#include "chrome/browser/web_applications/test/web_app_test_utils.h"
#include "chrome/browser/web_applications/web_app_command_scheduler.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_install_utils.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/prefs/pref_service.h"
#include "components/webapps/browser/installable/installable_metrics.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/test/browser_test.h"
#include "third_party/blink/public/common/manifest/manifest.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_switches.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_profile.h"
#include "components/user_manager/user_names.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/base_paths_win.h"
#include "base/test/scoped_path_override.h"
#endif
namespace web_app {
namespace {
const char kDefaultAppName[] = …;
const char kDefaultAppIconUrl1[] = …;
const char kDefaultAppIconUrl2[] = …;
const char kDefaultCustomName[] = …;
const char kDefaultCustomIconUrl[] = …;
const char kDefaultCustomIconHash[] = …;
constexpr char kInstallUrl[] = …;
constexpr char kStartUrl[] = …;
constexpr char kManifestUrl[] = …;
base::Value::Dict GetForceInstalledAppItem() { … }
base::Value::Dict GetCustomAppNameItem() { … }
base::Value::Dict GetCustomAppIconItem() { … }
base::Value::Dict GetCustomAppIconAndNameItem() { … }
}
class WebAppPolicyManagerBrowserTest : public WebAppBrowserTestBase { … };
IN_PROC_BROWSER_TEST_F(WebAppPolicyManagerBrowserTest,
OverrideManifestWithCustomName) { … }
IN_PROC_BROWSER_TEST_F(WebAppPolicyManagerBrowserTest,
OverrideManifestWithCustomIcon) { … }
IN_PROC_BROWSER_TEST_F(WebAppPolicyManagerBrowserTest, DontOverrideManifest) { … }
IN_PROC_BROWSER_TEST_F(WebAppPolicyManagerBrowserTest, AppIdWhenNoManifestId) { … }
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_MismatchedInstallAndStartUrl …
#else
#define MAYBE_MismatchedInstallAndStartUrl …
#endif
IN_PROC_BROWSER_TEST_F(WebAppPolicyManagerBrowserTest,
MAYBE_MismatchedInstallAndStartUrl) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(WebAppPolicyManagerBrowserTest, MigratingPolicyApp) {
auto install_info = WebAppInstallInfo::CreateWithStartUrlForTesting(
GURL("https://some.app.com"));
install_info->title = u"some app";
webapps::AppId old_app_id =
test::InstallWebApp(profile(), std::move(install_info));
WebAppTestUninstallObserver uninstall_observer(profile());
uninstall_observer.BeginListening({old_app_id});
SetPolicyPrefs(R"([{
"url": "https://example.com/install",
"uninstall_and_replace": ["$1"]
}])",
{old_app_id});
uninstall_observer.Wait();
}
#endif
class WebAppPolicyManagerGuestModeTest : public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(WebAppPolicyManagerGuestModeTest,
DoNotCreateAppsOnGuestMode) { … }
}