#include <climits>
#include <initializer_list>
#include <memory>
#include <string>
#include <string_view>
#include <tuple>
#include <vector>
#include "base/base_paths.h"
#include "base/check.h"
#include "base/functional/function_ref.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/badging/badge_manager.h"
#include "chrome/browser/badging/badge_manager_factory.h"
#include "chrome/browser/devtools/protocol/devtools_protocol_test_support.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/web_applications/proto/web_app_os_integration_state.pb.h"
#include "chrome/browser/web_applications/proto/web_app_proto_package.pb.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/web_app.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_tab_helper.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/services/app_service/public/cpp/file_handler.h"
#include "components/ukm/test_ukm_recorder.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h"
namespace {
WebAppInstallInfo;
WebAppProvider;
ManifestId;
class PWAProtocolTestWithoutApp : public DevToolsProtocolTestBase { … };
class PWAProtocolTest : public PWAProtocolTestWithoutApp { … };
IN_PROC_BROWSER_TEST_F(PWAProtocolTestWithoutApp, GetOsAppState_CannotFindApp) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, GetOsAppState) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, GetOsAppState_WithBadge) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, GetOsAppState_WithZeroBadge) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, GetOsAppState_WithBadgeOverInt) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, GetOsAppState_WithFileHandler) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, GetProcessedManifest_CannotFindApp) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
GetProcessedManifest_CannotFindApp_WithoutManfiestId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
GetProcessedManifest_WithoutManifestId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, GetProcessedManifest_WithManifestId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, GetProcessedManifest_IconWithNoSizes) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, GetProcessedManifest_MismatchId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
GetProcessedManifest_NotOnPage_WithManifestId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, GetProcessedManifest_NotInstallable) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Uninstall) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Uninstall_CannotFindApp) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Uninstall_MissingManifestId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromManifest) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromManifest_Twice) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromManifest_NoWebContents) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromManifest_InvalidStartUrl) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
Install_FromManifest_InconsistentAppId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromManifest_HasManifestId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
Install_FromManifest_HasManifestId_UrlAsManifestId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromUrl) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromUrl_Twice) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromManifest_FromUrl) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromUrl_FromManifest) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromUrl_UpperCase) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromUrl_Unreachable) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromUrl_UnmatchManifestId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
Install_FromUrl_ValidManifestId_DifferentInstallUrl) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromUrl_InconsistentAppId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromUrl_NoScheme) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromUrl_UnsupportedScheme) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_FromUrl_HasManifestId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Install_Uninstall) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Launch) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Launch_ReturnsAttachableTargetId) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Launch_AutoAttach) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Launch_NoApp) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Launch_InFullScreenMode) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Launch_FromUrl) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Launch_FromUrl_InScope) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Launch_FromUrl_NoApp) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Launch_FromUrl_InvalidUrl) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, Launch_FromUrl_OutOfScopeUrl) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, LaunchFilesInApp) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, LaunchFilesInApp_MultipleFiles) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, LaunchFilesInApp_RepeatedFiles) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, LaunchFilesInApp_MultipleTypes) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
LaunchFilesInApp_OneTypeMultipleFilesPerRequest) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
LaunchFilesInApp_MultipleTypesMultipleFiles) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, LaunchFilesInApp_PartiallyUnsupported) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, LaunchFilesInApp_PartiallyFailed) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, LaunchFilesInApp_NonexistentFiles) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, LaunchFilesInApp_NoFileHandlers) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, LaunchFilesInApp_NoFilesField) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, LaunchFilesInApp_NoFile) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, LaunchFilesInApp_UnsupportedFile) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, OpenCurrentPageInApp) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, OpenCurrentPageInApp_NoWebContents) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, OpenCurrentPageInApp_NotInstalled) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
OpenCurrentPageInApp_DifferentManifestIdUrl) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
DISABLED_OpenCurrentPageInApp_NotReparentable) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
OpenCurrentPageInApp_StillAttachedInNewAppWindow) { … }
#if BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, OpenCurrentPageInApp_NoShortcut) {
InstallWebApp();
ASSERT_FALSE(
SendCommandSync("PWA.openCurrentPageInApp",
base::Value::Dict{}.Set(
"manifestId", InstallableWebAppManifestId().spec())));
ASSERT_TRUE(ErrorMessageContains({InstallableWebAppManifestId().spec()}));
}
#endif
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, ChangeAppUserSettings_ChangeNothing) { … }
#if BUILDFLAG(IS_CHROMEOS)
#define DISABLE_ON_CHROMEOS …
#else
#define DISABLE_ON_CHROMEOS(x) …
#endif
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
DISABLE_ON_CHROMEOS(ChangeAppUserSettings_NoApp)) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, ChangeAppUserSettings_NoAppNoChange) { … }
IN_PROC_BROWSER_TEST_F(
PWAProtocolTest,
DISABLE_ON_CHROMEOS(
ChangeAppUserSettings_ChangeLinkCapturingAndDisplayMode)) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
ChangeAppUserSettings_ChangeToStandaloneDisplayMode) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, ChangeAppUserSettings_NotCrash) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest,
ChangeAppUserSettings_UnknownDisplayMode) { … }
IN_PROC_BROWSER_TEST_F(
PWAProtocolTest,
DISABLE_ON_CHROMEOS(ChangeAppUserSettings_DoNotCapture)) { … }
IN_PROC_BROWSER_TEST_F(PWAProtocolTest, ChangeAppUserSettings_NoManifestId) { … }
}