#include "chrome/browser/ui/views/web_apps/web_app_integration_test_driver.h"
#include <cstddef>
#include <cstring>
#include <ios>
#include <map>
#include <optional>
#include <ostream>
#include <string>
#include <string_view>
#include <utility>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/containers/extend.h"
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "base/strings/pattern.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/test_future.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/apps/app_service/app_icon_source.h"
#include "chrome/browser/apps/app_service/app_registry_cache_waiter.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/link_capturing/link_capturing_features.h"
#include "chrome/browser/banners/test_app_banner_manager_desktop.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
#include "chrome/browser/ui/intent_picker_tab_helper.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/startup/web_app_startup_utils.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/create_application_shortcut_view_test_support.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/browser_view_layout.h"
#include "chrome/browser/ui/views/frame/toolbar_button_provider.h"
#include "chrome/browser/ui/views/intent_picker_bubble_view.h"
#include "chrome/browser/ui/views/location_bar/custom_tab_bar_view.h"
#include "chrome/browser/ui/views/location_bar/intent_chip_button.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "chrome/browser/ui/views/page_info/page_info_bubble_view.h"
#include "chrome/browser/ui/views/page_info/page_info_view_factory.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/ui/views/web_apps/file_handler_launch_dialog_view.h"
#include "chrome/browser/ui/views/web_apps/frame_toolbar/web_app_frame_toolbar_view.h"
#include "chrome/browser/ui/views/web_apps/frame_toolbar/web_app_toolbar_button_container.h"
#include "chrome/browser/ui/views/web_apps/frame_toolbar/window_controls_overlay_toggle_button.h"
#include "chrome/browser/ui/views/web_apps/web_app_link_capturing_test_utils.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/ui/web_applications/sub_apps_install_dialog_controller.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/ui/web_applications/web_app_dialog_utils.h"
#include "chrome/browser/ui/web_applications/web_app_dialogs.h"
#include "chrome/browser/ui/web_applications/web_app_launch_utils.h"
#include "chrome/browser/ui/web_applications/web_app_menu_model.h"
#include "chrome/browser/ui/webui/app_settings/web_app_settings_ui.h"
#include "chrome/browser/ui/webui/web_app_internals/web_app_internals_handler.h"
#include "chrome/browser/web_applications/app_service/web_app_publisher_helper.h"
#include "chrome/browser/web_applications/commands/run_on_os_login_command.h"
#include "chrome/browser/web_applications/externally_managed_app_manager.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_install_source.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_trust_checker.h"
#include "chrome/browser/web_applications/isolated_web_apps/test/test_signed_web_bundle_builder.h"
#include "chrome/browser/web_applications/manifest_update_manager.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/os_integration/web_app_file_handler_registration.h"
#include "chrome/browser/web_applications/os_integration/web_app_shortcut.h"
#include "chrome/browser/web_applications/policy/web_app_policy_constants.h"
#include "chrome/browser/web_applications/policy/web_app_policy_manager.h"
#include "chrome/browser/web_applications/preinstalled_web_app_config_utils.h"
#include "chrome/browser/web_applications/preinstalled_web_app_manager.h"
#include "chrome/browser/web_applications/proto/web_app_install_state.pb.h"
#include "chrome/browser/web_applications/test/debug_info_printer.h"
#include "chrome/browser/web_applications/test/os_integration_test_override_impl.h"
#include "chrome/browser/web_applications/test/web_app_icon_test_utils.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/web_app_callback_app_identity.h"
#include "chrome/browser/web_applications/web_app_command_manager.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_icon_generator.h"
#include "chrome/browser/web_applications/web_app_install_finalizer.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_sync_bridge.h"
#include "chrome/browser/web_applications/web_app_tab_helper.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/webapps/browser/features.h"
#include "components/webapps/browser/install_result_code.h"
#include "components/webapps/browser/installable/installable_metrics.h"
#include "components/webapps/browser/uninstall_result_code.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/test_web_ui.h"
#include "extensions/browser/extension_dialog_auto_confirm.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/network/public/cpp/network_switches.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/frame/fullscreen.mojom.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom-shared.h"
#include "third_party/boringssl/src/include/openssl/curve25519.h"
#include "third_party/re2/src/re2/re2.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/test/dialog_test.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/widget.h"
#include "ui/webui/resources/cr_components/app_management/app_management.mojom-forward.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/ui/views/apps/app_dialog/app_uninstall_dialog_view.h"
#else
#include "chrome/browser/ui/webui/app_home/app_home.mojom.h"
#include "chrome/browser/ui/webui/app_home/app_home_page_handler.h"
#include "chrome/browser/ui/webui/app_management/web_app_settings_page_handler.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_features.h"
#include "chromeos/ash/components/standalone_browser/feature_refs.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "base/version.h"
#include "chrome/browser/apps/app_service/app_service_proxy_lacros.h"
#include "chromeos/crosapi/mojom/test_controller.mojom.h"
#include "chromeos/lacros/lacros_service.h"
#include "chromeos/lacros/lacros_test_helper.h"
#include "mojo/public/cpp/bindings/remote.h"
#endif
#if BUILDFLAG(IS_MAC)
#include <ImageIO/ImageIO.h>
#include "base/mac/mac_util.h"
#include "chrome/browser/apps/app_shim/app_shim_manager_mac.h"
#include "chrome/browser/apps/app_shim/web_app_shim_manager_delegate_mac.h"
#include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/web_applications/os_integration/mac/app_shim_launch.h"
#include "chrome/browser/web_applications/os_integration/mac/app_shim_registry.h"
#include "chrome/browser/web_applications/web_app_ui_manager.h"
#include "chrome/common/mac/app_mode_common.h"
#include "chrome/test/base/launchservices_utils_mac.h"
#include "net/base/filename_util.h"
#include "skia/ext/skia_utils_mac.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/test/test_reg_util_win.h"
#include "base/win/shortcut.h"
#include "chrome/browser/web_applications/os_integration/web_app_handler_registration_utils_win.h"
#include "chrome/installer/util/shell_util.h"
#endif
namespace web_app::integration_tests {
namespace {
base::FilePath GetTestDataDir() { … }
Site InstallableSiteToSite(InstallableSite site) { … }
int NumberToInt(Number number) { … }
void FlushShortcutTasks() { … }
struct SiteConfig { … };
base::flat_map<Site, SiteConfig> g_site_configs = …;
struct DisplayConfig { … };
base::flat_map<Display, DisplayConfig> g_display_configs = …;
struct ScopeConfig { … };
base::flat_map<Site, ScopeConfig> g_scope_configs = …;
ScopeConfig GetScopeUpdateConfiguration(Site scope) { … }
DisplayConfig GetDisplayUpdateConfiguration(Display display) { … }
SiteConfig GetSiteConfiguration(Site site) { … }
std::string GetRelativeSubAppPath(Site sub_app) { … }
std::string GetSiteId(Site site) { … }
web_package::test::Ed25519KeyPair GetKeyPairForSite(Site site) { … }
std::string GetFileExtension(FileExtension file_extension) { … }
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS)
SiteConfig GetSiteConfigurationFromAppName(const std::string& app_name) { … }
#endif
class BrowserAddedWaiter final : public BrowserListObserver { … };
class PageLoadWaiter final : public content::WebContentsObserver { … };
Browser* GetAppBrowserForAppId(const Profile* profile,
const webapps::AppId& app_id) { … }
bool AreAppBrowsersOpen(const Profile* profile, const webapps::AppId& app_id) { … }
content::WebContents* GetAnyWebContentsForAppId(const webapps::AppId& app_id) { … }
class UninstallCompleteWaiter final : public BrowserListObserver,
public WebAppInstallManagerObserver { … };
std::optional<ProfileState> GetStateForProfile(StateSnapshot* state_snapshot,
Profile* profile) { … }
std::optional<BrowserState> GetStateForBrowser(StateSnapshot* state_snapshot,
Profile* profile,
Browser* browser) { … }
std::optional<TabState> GetStateForActiveTab(BrowserState browser_state) { … }
std::optional<AppState> GetStateForAppId(StateSnapshot* state_snapshot,
Profile* profile,
const webapps::AppId& id) { … }
#if !BUILDFLAG(IS_CHROMEOS)
WebAppSettingsPageHandler CreateAppManagementPageHandler(Profile* profile) { … }
#endif
void ActivateBrowserAndWait(Browser* browser) { … }
void WaitForAndAcceptInstallDialogForSite(InstallableSite site) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
void ReinitializeAppService(Profile* profile) {
if (chromeos::IsAshVersionAtLeastForTesting(base::Version({108, 0, 5354}))) {
base::test::TestFuture<void> future;
chromeos::LacrosService::Get()
->GetRemote<crosapi::mojom::TestController>()
->ReinitializeAppService(future.GetCallback());
ASSERT_TRUE(future.Wait());
apps::AppServiceProxyFactory::GetForProfile(profile)
->ReinitializeForTesting(profile);
apps::AppTypeInitializationWaiter(profile, apps::AppType::kWeb).Await();
} else {
LOG(ERROR) << "Cannot ReinitializeAppService - Unsupported ash version.";
}
}
#endif
bool ShouldLoadResponseFromDisk(const base::FilePath& root,
const std::string& path) { … }
void LoadFileFromDisk(const base::FilePath& path,
content::WebUIDataSource::GotDataCallback callback) { … }
void LoadResponseFromDisk(const base::FilePath& root,
const std::string& path,
content::WebUIDataSource::GotDataCallback callback) { … }
}
BrowserState::BrowserState(
Browser* browser_ptr,
base::flat_map<content::WebContents*, TabState> tab_state,
content::WebContents* active_web_contents,
const webapps::AppId& app_id,
bool launch_icon_visible)
: … { … }
BrowserState::~BrowserState() = default;
BrowserState::BrowserState(const BrowserState&) = default;
bool BrowserState::operator==(const BrowserState& other) const { … }
AppState::AppState(webapps::AppId app_id,
std::string app_name,
GURL app_scope,
apps::RunOnOsLoginMode run_on_os_login_mode,
blink::mojom::DisplayMode effective_display_mode,
std::optional<mojom::UserDisplayMode> user_display_mode,
std::string manifest_launcher_icon_filename,
bool installed_locally,
bool shortcut_created)
: … { … }
AppState::~AppState() = default;
AppState::AppState(const AppState&) = default;
bool AppState::operator==(const AppState& other) const { … }
ProfileState::ProfileState(base::flat_map<Browser*, BrowserState> browser_state,
base::flat_map<webapps::AppId, AppState> app_state)
: … { … }
ProfileState::~ProfileState() = default;
ProfileState::ProfileState(const ProfileState&) = default;
bool ProfileState::operator==(const ProfileState& other) const { … }
StateSnapshot::StateSnapshot(
base::flat_map<Profile*, ProfileState> profile_state)
: … { … }
StateSnapshot::~StateSnapshot() = default;
StateSnapshot::StateSnapshot(const StateSnapshot&) = default;
bool StateSnapshot::operator==(const StateSnapshot& other) const { … }
std::ostream& operator<<(std::ostream& os, const StateSnapshot& snapshot) { … }
WebAppIntegrationTestDriver::WebAppIntegrationTestDriver(TestDelegate* delegate)
: … { … }
WebAppIntegrationTestDriver::~WebAppIntegrationTestDriver() = default;
void WebAppIntegrationTestDriver::SetUp() { … }
void WebAppIntegrationTestDriver::SetUpOnMainThread() { … }
void WebAppIntegrationTestDriver::TearDownOnMainThread() { … }
void WebAppIntegrationTestDriver::HandleAppIdentityUpdateDialogResponse(
UpdateDialogResponse response) { … }
void WebAppIntegrationTestDriver::AwaitManifestUpdate(Site site) { … }
void WebAppIntegrationTestDriver::CloseCustomToolbar() { … }
void WebAppIntegrationTestDriver::ClosePwa() { … }
void WebAppIntegrationTestDriver::MaybeClosePwa() { … }
void WebAppIntegrationTestDriver::DisableRunOnOsLoginFromAppSettings(
Site site) { … }
void WebAppIntegrationTestDriver::DisableRunOnOsLoginFromAppHome(Site site) { … }
void WebAppIntegrationTestDriver::EnableRunOnOsLoginFromAppSettings(Site site) { … }
void WebAppIntegrationTestDriver::EnableRunOnOsLoginFromAppHome(Site site) { … }
void WebAppIntegrationTestDriver::EnterFullScreenApp() { … }
void WebAppIntegrationTestDriver::ExitFullScreenApp() { … }
void WebAppIntegrationTestDriver::DisableFileHandling(Site site) { … }
void WebAppIntegrationTestDriver::EnableFileHandling(Site site) { … }
void WebAppIntegrationTestDriver::CreateShortcut(Site site,
WindowOptions options) { … }
void WebAppIntegrationTestDriver::InstallMenuOption(InstallableSite site) { … }
#if !BUILDFLAG(IS_CHROMEOS)
void WebAppIntegrationTestDriver::InstallLocally(Site site) { … }
#endif
void WebAppIntegrationTestDriver::InstallOmniboxIcon(InstallableSite site) { … }
void WebAppIntegrationTestDriver::InstallPolicyApp(Site site,
ShortcutOptions shortcut,
WindowOptions window,
InstallMode mode) { … }
void WebAppIntegrationTestDriver::InstallPreinstalledApp(Site site) { … }
void WebAppIntegrationTestDriver::InstallIsolatedApp(Site site) { … }
void WebAppIntegrationTestDriver::InstallSubApp(
Site parent_app,
Site sub_app,
SubAppInstallDialogOptions option) { … }
void WebAppIntegrationTestDriver::RemoveSubApp(Site parent_app, Site sub_app) { … }
void WebAppIntegrationTestDriver::EnableWindowControlsOverlay(Site site) { … }
void WebAppIntegrationTestDriver::DisableWindowControlsOverlay(Site site) { … }
void WebAppIntegrationTestDriver::ApplyRunOnOsLoginPolicyAllowed(Site site) { … }
void WebAppIntegrationTestDriver::ApplyRunOnOsLoginPolicyBlocked(Site site) { … }
void WebAppIntegrationTestDriver::ApplyRunOnOsLoginPolicyRunWindowed(
Site site) { … }
void WebAppIntegrationTestDriver::RemoveRunOnOsLoginPolicy(Site site) { … }
void WebAppIntegrationTestDriver::LaunchFileExpectDialog(
Site site,
FilesOptions files_options,
AllowDenyOptions allow_deny,
AskAgainOptions ask_again) { … }
void WebAppIntegrationTestDriver::LaunchFileExpectNoDialog(
Site site,
FilesOptions files_options) { … }
void WebAppIntegrationTestDriver::LaunchFromChromeApps(Site site) { … }
void WebAppIntegrationTestDriver::LaunchFromLaunchIcon(Site site) { … }
void WebAppIntegrationTestDriver::LaunchFromMenuOption(Site site) { … }
void WebAppIntegrationTestDriver::LaunchFromPlatformShortcut(Site site) { … }
#if BUILDFLAG(IS_MAC)
void WebAppIntegrationTestDriver::LaunchFromAppShimFallback(Site site) {
if (!BeforeStateChangeAction(__FUNCTION__)) {
return;
}
webapps::AppId app_id = GetAppIdBySiteMode(site);
ASSERT_TRUE(provider()->registrar_unsafe().GetAppById(app_id))
<< "No app installed for site: " << static_cast<int>(site);
WebAppRegistrar& app_registrar = provider()->registrar_unsafe();
DisplayMode display_mode = app_registrar.GetAppEffectiveDisplayMode(app_id);
bool is_open_in_app_browser =
(display_mode != blink::mojom::DisplayMode::kBrowser);
base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
command_line.AppendSwitchASCII(switches::kAppId, app_id);
command_line.AppendSwitchASCII(switches::kTestType, "browser");
command_line.AppendSwitchASCII(switches::kProfileDirectory, "");
if (is_open_in_app_browser) {
BrowserAddedWaiter browser_added_waiter;
ASSERT_TRUE(ChromeBrowserMainParts::ProcessSingletonNotificationCallback(
command_line, {}));
content::RunAllTasksUntilIdle();
browser_added_waiter.Wait();
app_browser_ = browser_added_waiter.browser_added();
active_app_id_ = app_id;
EXPECT_TRUE(AppBrowserController::IsForWebApp(app_browser(), app_id));
} else {
ASSERT_TRUE(ChromeBrowserMainParts::ProcessSingletonNotificationCallback(
command_line, {}));
content::RunAllTasksUntilIdle();
}
AfterStateChangeAction();
}
#endif
void WebAppIntegrationTestDriver::OpenAppSettingsFromAppMenu(Site site) { … }
void WebAppIntegrationTestDriver::OpenAppSettingsFromChromeApps(Site site) { … }
void WebAppIntegrationTestDriver::OpenAppSettingsFromCommand(Site site) { … }
void WebAppIntegrationTestDriver::CreateShortcutsFromList(Site site) { … }
void WebAppIntegrationTestDriver::DeletePlatformShortcut(Site site) { … }
void WebAppIntegrationTestDriver::CheckAppSettingsAppState(
Profile* profile,
const AppState& app_state) { … }
base::FilePath WebAppIntegrationTestDriver::GetResourceFile(
base::FilePath::StringPieceType relative_path) { … }
std::vector<base::FilePath> WebAppIntegrationTestDriver::GetTestFilePaths(
FilesOptions files_options) { … }
void WebAppIntegrationTestDriver::SyncAndInstallPreinstalledAppConfig(
const GURL& install_url,
std::string_view app_config_string) { … }
void WebAppIntegrationTestDriver::NavigateAppHome() { … }
void WebAppIntegrationTestDriver::NavigateBrowser(Site site) { … }
void WebAppIntegrationTestDriver::NavigatePwa(Site pwa, Site to) { … }
void WebAppIntegrationTestDriver::NavigateNotfoundUrl() { … }
void WebAppIntegrationTestDriver::NewAppTab(Site site) { … }
void WebAppIntegrationTestDriver::ManifestUpdateIcon(
Site site,
UpdateDialogResponse response) { … }
void WebAppIntegrationTestDriver::ManifestUpdateTitle(
Site site,
Title title,
UpdateDialogResponse response) { … }
void WebAppIntegrationTestDriver::ManifestUpdateDisplay(Site site,
Display display) { … }
void WebAppIntegrationTestDriver::ManifestUpdateScopeTo(Site app, Site scope) { … }
void WebAppIntegrationTestDriver::OpenInChrome() { … }
void WebAppIntegrationTestDriver::SetOpenInTabFromAppHome(Site site) { … }
void WebAppIntegrationTestDriver::SetOpenInTabFromAppSettings(Site site) { … }
void WebAppIntegrationTestDriver::SetOpenInWindowFromAppHome(Site site) { … }
void WebAppIntegrationTestDriver::SetOpenInWindowFromAppSettings(Site site) { … }
void WebAppIntegrationTestDriver::SwitchIncognitoProfile() { … }
void WebAppIntegrationTestDriver::SwitchProfileClients(ProfileClient client) { … }
void WebAppIntegrationTestDriver::SwitchActiveProfile(
ProfileName profile_name) { … }
void WebAppIntegrationTestDriver::SyncTurnOff() { … }
void WebAppIntegrationTestDriver::SyncTurnOn() { … }
void WebAppIntegrationTestDriver::UninstallFromList(Site site) { … }
void WebAppIntegrationTestDriver::UninstallFromAppSettings(Site site) { … }
void WebAppIntegrationTestDriver::UninstallFromMenu(Site site) { … }
void WebAppIntegrationTestDriver::UninstallPolicyApp(Site site) { … }
void WebAppIntegrationTestDriver::UninstallFromOs(Site site) { … }
#if BUILDFLAG(IS_MAC)
void WebAppIntegrationTestDriver::CorruptAppShim(Site site,
AppShimCorruption corruption) {
if (!BeforeStateChangeAction(__FUNCTION__)) {
return;
}
base::ScopedAllowBlockingForTesting allow_blocking;
webapps::AppId app_id = GetAppIdBySiteMode(site);
std::string app_name = GetSiteConfiguration(site).app_name;
base::FilePath app_path = GetShortcutPath(
override_registration_->test_override().chrome_apps_folder(), app_name,
app_id);
base::FilePath bin_path = app_path.AppendASCII("Contents")
.AppendASCII("MacOS")
.AppendASCII("app_mode_loader");
switch (corruption) {
case AppShimCorruption::kNoExecutable:
EXPECT_TRUE(base::DeleteFile(bin_path));
break;
case AppShimCorruption::kIncompatibleVersion: {
std::string bin_contents;
EXPECT_TRUE(base::ReadFileToString(bin_path, &bin_contents));
auto pos = bin_contents.find(APP_SHIM_ENTRY_POINT_NAME_STRING);
ASSERT_NE(pos, std::string::npos);
bin_contents[pos] = 'D';
EXPECT_TRUE(base::WriteFile(bin_path, bin_contents));
if (base::mac::MacOSMajorVersion() >= 12) {
std::string codesign_output;
std::vector<std::string> codesign_argv = {
"codesign", "--force", "--sign", "-", bin_path.value()};
EXPECT_TRUE(base::GetAppOutputAndError(base::CommandLine(codesign_argv),
&codesign_output))
<< "Failed to sign executable at " << bin_path << ": "
<< codesign_output;
}
break;
}
}
AfterStateChangeAction();
}
void WebAppIntegrationTestDriver::QuitAppShim(Site site) {
if (!BeforeStateChangeAction(__FUNCTION__)) {
return;
}
webapps::AppId app_id = GetAppIdBySiteMode(site);
std::string app_name = GetSiteConfiguration(site).app_name;
base::FilePath app_path = GetShortcutPath(
override_registration_->test_override().chrome_apps_folder(), app_name,
app_id);
if (AppBrowserController::IsForWebApp(app_browser_, app_id)) {
app_browser_ = nullptr;
}
WaitForShimToQuitForTesting(app_path, app_id, true);
AfterStateChangeAction();
}
#endif
void WebAppIntegrationTestDriver::CheckAppListEmpty() { … }
void WebAppIntegrationTestDriver::CheckAppInListIconCorrect(Site site) { … }
void WebAppIntegrationTestDriver::CheckAppInListNotLocallyInstalled(Site site) { … }
void WebAppIntegrationTestDriver::CheckAppInListWindowed(Site site) { … }
void WebAppIntegrationTestDriver::CheckAppInListTabbed(Site site) { … }
void WebAppIntegrationTestDriver::CheckAppNavigation(Site site) { … }
void WebAppIntegrationTestDriver::CheckAppNavigationIsStartUrl() { … }
void WebAppIntegrationTestDriver::CheckAppTabIsSite(Site site, Number number) { … }
void WebAppIntegrationTestDriver::CheckAppTabCreated() { … }
void WebAppIntegrationTestDriver::CheckBrowserNavigation(Site site) { … }
void WebAppIntegrationTestDriver::CheckBrowserNavigationIsAppSettings(
Site site) { … }
void WebAppIntegrationTestDriver::CheckBrowserNotAtAppHome() { … }
void WebAppIntegrationTestDriver::CheckAppNotInList(Site site) { … }
void WebAppIntegrationTestDriver::CheckPlatformShortcutAndIcon(Site site) { … }
void WebAppIntegrationTestDriver::CheckPlatformShortcutNotExists(Site site) { … }
void WebAppIntegrationTestDriver::CheckAppIcon(Site site, Color color) { … }
void WebAppIntegrationTestDriver::CheckAppTitle(Site site, Title title) { … }
void WebAppIntegrationTestDriver::CheckCreateShortcutNotShown() { … }
void WebAppIntegrationTestDriver::CheckCreateShortcutShown() { … }
void WebAppIntegrationTestDriver::CheckFilesLoadedInSite(
Site site,
FilesOptions files_options) { … }
void WebAppIntegrationTestDriver::CheckInstallIconShown() { … }
void WebAppIntegrationTestDriver::CheckInstallIconNotShown() { … }
void WebAppIntegrationTestDriver::CheckLaunchIconShown() { … }
void WebAppIntegrationTestDriver::CheckLaunchIconNotShown() { … }
void WebAppIntegrationTestDriver::CheckTabCreated(Number number) { … }
void WebAppIntegrationTestDriver::CheckTabNotCreated() { … }
void WebAppIntegrationTestDriver::CheckCustomToolbar() { … }
void WebAppIntegrationTestDriver::CheckNoToolbar() { … }
void WebAppIntegrationTestDriver::CheckRunOnOsLoginEnabled(Site site) { … }
void WebAppIntegrationTestDriver::CheckRunOnOsLoginDisabled(Site site) { … }
void WebAppIntegrationTestDriver::CheckSiteHandlesFile(
Site site,
FileExtension file_extension) { … }
void WebAppIntegrationTestDriver::CheckSiteNotHandlesFile(
Site site,
FileExtension file_extension) { … }
void WebAppIntegrationTestDriver::CheckUserCannotSetRunOnOsLoginAppSettings(
Site site) { … }
void WebAppIntegrationTestDriver::CheckUserCannotSetRunOnOsLoginAppHome(
Site site) { … }
void WebAppIntegrationTestDriver::CheckUserDisplayModeInternal(
mojom::UserDisplayMode user_display_mode) { … }
void WebAppIntegrationTestDriver::CheckWindowClosed() { … }
void WebAppIntegrationTestDriver::CheckWindowCreated() { … }
void WebAppIntegrationTestDriver::CheckPwaWindowCreated(Site site,
Number number) { … }
void WebAppIntegrationTestDriver::CheckPwaWindowCreatedImpl(Profile* profile,
Site site,
Number number) { … }
void WebAppIntegrationTestDriver::CheckPwaWindowCreatedInProfile(
Site site,
Number number,
ProfileName profile_name) { … }
void WebAppIntegrationTestDriver::CheckWindowNotCreated() { … }
void WebAppIntegrationTestDriver::CheckWindowControlsOverlayToggle(
Site site,
IsShown is_shown) { … }
void WebAppIntegrationTestDriver::CheckWindowControlsOverlayToggleIcon(
IsShown is_shown) { … }
void WebAppIntegrationTestDriver::CheckWindowControlsOverlay(Site site,
IsOn is_on) { … }
void WebAppIntegrationTestDriver::CheckWindowDisplayMinimal() { … }
void WebAppIntegrationTestDriver::CheckWindowDisplayTabbed() { … }
void WebAppIntegrationTestDriver::CheckWindowDisplayStandalone() { … }
void WebAppIntegrationTestDriver::CheckHasSubApp(Site parent_app,
Site sub_app) { … }
void WebAppIntegrationTestDriver::CheckNotHasSubApp(Site parent_app,
Site sub_app) { … }
void WebAppIntegrationTestDriver::CheckNoSubApps(Site parent_app) { … }
void WebAppIntegrationTestDriver::CheckAppLoadedInTab(Site site) { … }
void WebAppIntegrationTestDriver::OnWebAppManifestUpdated(
const webapps::AppId& app_id) { … }
void WebAppIntegrationTestDriver::OnWebAppUninstalled(
const webapps::AppId& app_id,
webapps::WebappUninstallSource uninstall_source) { … }
bool WebAppIntegrationTestDriver::BeforeStateChangeAction(
const char* function) { … }
void WebAppIntegrationTestDriver::AfterStateChangeAction() { … }
bool WebAppIntegrationTestDriver::BeforeStateCheckAction(const char* function) { … }
void WebAppIntegrationTestDriver::AfterStateCheckAction() { … }
void WebAppIntegrationTestDriver::AwaitManifestSystemIdle() { … }
webapps::AppId GetAppIdForIsolatedSite(Site site) { … }
webapps::AppId WebAppIntegrationTestDriver::GetAppIdBySiteMode(Site site) { … }
GURL WebAppIntegrationTestDriver::GetUrlForSite(Site site,
const std::string& suffix) { … }
std::optional<AppState> WebAppIntegrationTestDriver::GetAppBySiteMode(
StateSnapshot* state_snapshot,
Profile* profile,
Site site) { … }
WebAppProvider* WebAppIntegrationTestDriver::GetProviderForProfile(
Profile* profile) { … }
std::unique_ptr<StateSnapshot>
WebAppIntegrationTestDriver::ConstructStateSnapshot() { … }
Profile* WebAppIntegrationTestDriver::GetOrCreateProfile(
ProfileName profile_name) { … }
content::WebContents* WebAppIntegrationTestDriver::GetCurrentTab(
Browser* browser) { … }
GURL WebAppIntegrationTestDriver::GetInScopeURL(Site site) { … }
base::FilePath WebAppIntegrationTestDriver::GetShortcutPath(
base::FilePath shortcut_dir,
const std::string& app_name,
const webapps::AppId& app_id) { … }
void WebAppIntegrationTestDriver::InstallPolicyAppInternal(
Site site,
base::Value default_launch_container,
const bool create_shortcut,
const bool install_as_shortcut) { … }
void WebAppIntegrationTestDriver::ApplyRunOnOsLoginPolicy(Site site,
const char* policy) { … }
void WebAppIntegrationTestDriver::UninstallPolicyAppById(
Profile* profile,
const webapps::AppId& id) { … }
void WebAppIntegrationTestDriver::ForceUpdateManifestContents(
Site site,
const GURL& app_url_with_manifest_param) { … }
void WebAppIntegrationTestDriver::MaybeNavigateTabbedBrowserInScope(Site site) { … }
void WebAppIntegrationTestDriver::NavigateTabbedBrowserToSite(
const GURL& url,
NavigationMode mode) { … }
Browser* WebAppIntegrationTestDriver::GetAppBrowserForSite(
Site site,
bool launch_if_not_open) { … }
bool WebAppIntegrationTestDriver::IsShortcutAndIconCreated(
Profile* profile,
const std::string& name,
const webapps::AppId& id) { … }
bool WebAppIntegrationTestDriver::DoIconColorsMatch(Profile* profile,
const std::string& name,
const webapps::AppId& id) { … }
void WebAppIntegrationTestDriver::SetFileHandlingEnabled(Site site,
bool enabled) { … }
void WebAppIntegrationTestDriver::LaunchFile(Site site,
FilesOptions files_options) { … }
void WebAppIntegrationTestDriver::LaunchAppStartupBrowserCreator(
const webapps::AppId& app_id) { … }
#if BUILDFLAG(IS_MAC)
class AppShimLaunchWaiter : public apps::AppShimManager::AppShimObserver {
public:
explicit AppShimLaunchWaiter(bool wait_for_complete_launch)
: wait_for_complete_launch_(wait_for_complete_launch) {}
base::WeakPtr<AppShimLaunchWaiter> AsWeakPtr() {
return weak_factory_.GetWeakPtr();
}
bool did_launch() const { return did_launch_; }
void OnLaunchStarted(base::Process process) {
if (!process.IsValid()) {
LOG(INFO) << "App Shim quit before finishing launch";
loop_.Quit();
return;
}
expected_pid_ = process.Pid();
LOG(INFO) << "Waiting for App Shim with PID " << *expected_pid_;
MaybeQuitLoop();
}
void Wait() { loop_.Run(); }
void OnShimTerminated() {
LOG(INFO) << "App Shim terminated while launching";
loop_.Quit();
}
void OnShimProcessConnected(base::ProcessId pid) override {
LOG(INFO) << "Got App Shim connection from " << pid;
if (!wait_for_complete_launch_) {
launched_shims_.insert(pid);
did_launch_ = true;
MaybeQuitLoop();
}
}
void OnShimProcessConnectedAndAllLaunchesDone(
base::ProcessId pid,
chrome::mojom::AppShimLaunchResult result) override {
LOG(INFO) << "Finished launching App Shim " << pid << " with result "
<< result;
did_launch_ = true;
launched_shims_.insert(pid);
MaybeQuitLoop();
}
void OnShimReopen(base::ProcessId pid) override {
LOG(INFO) << "Reopened App Shim " << pid;
did_launch_ = true;
launched_shims_.insert(pid);
MaybeQuitLoop();
}
void OnShimOpenedURLs(base::ProcessId pid) override {
LOG(INFO) << "App Shim opened URLs " << pid;
did_launch_ = true;
launched_shims_.insert(pid);
MaybeQuitLoop();
}
private:
void MaybeQuitLoop() {
if (expected_pid_.has_value() &&
launched_shims_.find(*expected_pid_) != launched_shims_.end()) {
loop_.Quit();
}
}
bool wait_for_complete_launch_ = true;
base::RunLoop loop_;
std::set<base::ProcessId> launched_shims_;
std::optional<base::ProcessId> expected_pid_;
bool did_launch_ = false;
base::WeakPtrFactory<AppShimLaunchWaiter> weak_factory_{this};
};
bool WebAppIntegrationTestDriver::LaunchFromAppShim(
Site site,
const std::vector<GURL>& urls,
bool wait_for_complete_launch) {
webapps::AppId app_id = GetAppIdBySiteMode(site);
std::string app_name = GetSiteConfiguration(site).app_name;
base::FilePath app_path = GetShortcutPath(
override_registration_->test_override().chrome_apps_folder(), app_name,
app_id);
base::FilePath chrome_path = ::test::GuessAppBundlePath();
chrome_path =
chrome_path.Append("Contents")
.Append("MacOS")
.Append(chrome_path.BaseName().RemoveFinalExtension().value());
AppShimLaunchWaiter launch_waiter(wait_for_complete_launch);
apps::AppShimManager::Get()->SetAppShimObserverForTesting(&launch_waiter);
LaunchShimForTesting(app_path, urls,
base::BindOnce(&AppShimLaunchWaiter::OnLaunchStarted,
launch_waiter.AsWeakPtr()),
base::BindOnce(&AppShimLaunchWaiter::OnShimTerminated,
launch_waiter.AsWeakPtr()),
chrome_path);
launch_waiter.Wait();
apps::AppShimManager::Get()->SetAppShimObserverForTesting(nullptr);
return launch_waiter.did_launch();
}
#endif
Browser* WebAppIntegrationTestDriver::browser() { … }
Profile* WebAppIntegrationTestDriver::profile() { … }
std::vector<Profile*> WebAppIntegrationTestDriver::GetAllProfiles() { … }
PageActionIconView* WebAppIntegrationTestDriver::pwa_install_view() { … }
IntentChipButton* WebAppIntegrationTestDriver::intent_chip_view() { … }
const net::EmbeddedTestServer&
WebAppIntegrationTestDriver::GetTestServerForSiteMode(Site site) const { … }
#if !BUILDFLAG(IS_CHROMEOS)
webapps::AppHomePageHandler
WebAppIntegrationTestDriver::GetTestAppHomePageHandler(
content::TestWebUI* web_ui) { … }
#endif
WebAppIntegrationTest::WebAppIntegrationTest() : … { … }
WebAppIntegrationTest::~WebAppIntegrationTest() = default;
void WebAppIntegrationTest::SetUp() { … }
void WebAppIntegrationTest::SetUpOnMainThread() { … }
void WebAppIntegrationTest::TearDownOnMainThread() { … }
void WebAppIntegrationTest::SetUpCommandLine(base::CommandLine* command_line) { … }
Browser* WebAppIntegrationTest::CreateBrowser(Profile* profile) { … }
void WebAppIntegrationTest::CloseBrowserSynchronously(Browser* browser) { … }
void WebAppIntegrationTest::AddBlankTabAndShow(Browser* browser) { … }
const net::EmbeddedTestServer* WebAppIntegrationTest::EmbeddedTestServer()
const { … }
Profile* WebAppIntegrationTest::GetDefaultProfile() { … }
bool WebAppIntegrationTest::IsSyncTest() { … }
void WebAppIntegrationTest::SyncTurnOff() { … }
void WebAppIntegrationTest::SyncTurnOn() { … }
void WebAppIntegrationTest::AwaitWebAppQuiescence() { … }
Profile* WebAppIntegrationTest::GetProfileClient(ProfileClient client) { … }
}