#include <cmath>
#include <optional>
#include <string_view>
#include <tuple>
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/icu_test_util.h"
#include "base/test/run_until.h"
#include "base/test/test_future.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/download/bubble/download_bubble_ui_controller.h"
#include "chrome/browser/download/bubble/download_display_controller.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/custom_theme_supplier.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/download/download_display.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_view.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_button.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_container.h"
#include "chrome/browser/ui/views/frame/app_menu_button.h"
#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.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/frame/top_container_view.h"
#include "chrome/browser/ui/views/infobars/infobar_container_view.h"
#include "chrome/browser/ui/views/infobars/infobar_view.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_controller.h"
#include "chrome/browser/ui/views/web_apps/frame_toolbar/web_app_frame_toolbar_test_helper.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_navigation_button_container.h"
#include "chrome/browser/ui/views/web_apps/frame_toolbar/web_app_origin_text.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/web_applications/app_browser_controller.h"
#include "chrome/browser/ui/web_applications/test/isolated_web_app_test_utils.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/ui/web_applications/web_app_browsertest_base.h"
#include "chrome/browser/ui/web_applications/web_app_menu_model.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_url_info.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/scope_extension_info.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/browser/web_applications/web_app_origin_association_manager.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registry_update.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/ui/frame/caption_buttons/frame_caption_button_container_view.h"
#include "components/infobars/content/content_infobar_manager.h"
#include "components/permissions/permission_request_manager.h"
#include "components/webapps/services/web_app_origin_association/test/test_web_app_origin_association_fetcher.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/page_zoom.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/theme_change_waiter.h"
#include "extensions/test/test_extension_dir.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/widget/constants.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkRect.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/controls/label.h"
#include "ui/views/test/views_test_utils.h"
#include "ui/views/view.h"
#include "ui/views/view_observer.h"
#include "ui/views/widget/any_widget_observer.h"
#include "url/gurl.h"
#include "url/origin.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ui/views/frame/browser_non_client_frame_view_chromeos.h"
#endif
#if BUILDFLAG(IS_LINUX)
#include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h"
#endif
#if defined(USE_AURA)
#include "ui/aura/client/aura_constants.h"
#endif
namespace {
#if BUILDFLAG(IS_MAC)
constexpr double kTitlePaddingWidthFraction = 0.1;
#endif
template <typename T>
T* GetLastVisible(const std::vector<T*>& views) { … }
void LoadTestPopUpExtension(Profile* profile) { … }
SkColor GetFrameColor(Browser* browser) { … }
}
class WebAppFrameToolbarBrowserTest : public web_app::WebAppBrowserTestBase { … };
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest, SpaceConstrained) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_ThemeChange …
#else
#define MAYBE_ThemeChange …
#endif
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest, MAYBE_ThemeChange) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest, TitleHover) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest,
MenuButtonAccessibleName) { … }
class WebAppFrameToolbarBrowserTest_ElidedExtensionsMenu
: public WebAppFrameToolbarBrowserTest { … };
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_ElidedExtensionsMenu,
Test) { … }
class WebAppFrameToolbarBrowserTest_NoElidedExtensionsMenu
: public WebAppFrameToolbarBrowserTest { … };
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_NoElidedExtensionsMenu,
Test) { … }
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS))
class BorderlessIsolatedWebAppBrowserTest
: public web_app::IsolatedWebAppBrowserTestHarness { … };
IN_PROC_BROWSER_TEST_F(BorderlessIsolatedWebAppBrowserTest,
AppUsesBorderlessModeAndHasWindowManagementPermission) { … }
IN_PROC_BROWSER_TEST_F(BorderlessIsolatedWebAppBrowserTest,
BorderlessModeHidesTitlebarAndWindowingControls) { … }
IN_PROC_BROWSER_TEST_F(BorderlessIsolatedWebAppBrowserTest,
DisplayModeMediaCSS) { … }
IN_PROC_BROWSER_TEST_F(
BorderlessIsolatedWebAppBrowserTest,
AppUsesBorderlessModeAndDoesNotHaveWindowManagementPermission) { … }
IN_PROC_BROWSER_TEST_F(BorderlessIsolatedWebAppBrowserTest,
AppDoesntUseBorderlessMode) { … }
IN_PROC_BROWSER_TEST_F(BorderlessIsolatedWebAppBrowserTest,
PopupToItselfIsBorderless) { … }
IN_PROC_BROWSER_TEST_F(BorderlessIsolatedWebAppBrowserTest,
PopupToAnyOtherOriginIsNotBorderless) { … }
IN_PROC_BROWSER_TEST_F(
BorderlessIsolatedWebAppBrowserTest,
PopupSize_CanSubceedMinimumWindowSize_And_InnerAndOuterSizesAreCorrect) { … }
IN_PROC_BROWSER_TEST_F(
BorderlessIsolatedWebAppBrowserTest,
PopupResize_CanSubceedMinimumWindowSize_And_InnerAndOuterSizesAreCorrect) { … }
IN_PROC_BROWSER_TEST_F(BorderlessIsolatedWebAppBrowserTest, FrameMinimumSize) { … }
class BorderlessIsolatedWebAppBrowserTestDisabledFlag
: public BorderlessIsolatedWebAppBrowserTest { … };
IN_PROC_BROWSER_TEST_F(BorderlessIsolatedWebAppBrowserTestDisabledFlag,
AppCannotUseFeatureWhenBorderlessFlagIsDisabled) { … }
#endif
class WebAppFrameToolbarBrowserTest_WindowControlsOverlay
: public WebAppFrameToolbarBrowserTest { … };
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
WindowControlsOverlay) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
GeometryChangeEvent) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
NoGeometryChangeEventIfOverlayIsOff) { … }
#if !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
PopupFromWcoAppToItself) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
PopupFromWcoAppToAnyOtherWebsite) { … }
#endif
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
WindowControlsOverlayRTL) { … }
#if BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
WindowControlsOverlayFrameViewHeight) {
InstallAndLaunchWebApp();
ToggleWindowControlsOverlayAndWait();
EXPECT_TRUE(GetWindowControlOverlayVisibility());
BrowserNonClientFrameViewChromeOS* frame_view_cros =
static_cast<BrowserNonClientFrameViewChromeOS*>(helper()->frame_view());
int frame_view_height = frame_view_cros->GetMinimumSize().height();
int caption_container_height =
frame_view_cros->caption_button_container()->size().height();
int client_view_height =
frame_view_cros->frame()->client_view()->GetMinimumSize().height();
int window_radius = chromeos::features::RoundedWindowsRadius();
EXPECT_EQ(frame_view_height,
caption_container_height + client_view_height + window_radius);
}
#endif
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
CSSRectTestLTR) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
CSSRectTestRTL) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
DISABLED_WindowControlsOverlayDraggableRegions) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
DraggableRegionsIgnoredForOwnedWidgets) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
ToggleWindowControlsOverlay) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
OpenInChrome) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
HideToggleButtonWhenCCTIsVisible) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
HideToggleButtonWhenInfoBarIsVisible) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
OpenWithOverlayEnabled) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
DraggableRegionNotResetByFencedFrameNavigation) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
FencedFrame) { … }
#if !BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
ExtensionsIconVisibility) { … }
#endif
#if !BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
DownloadIconVisibilityForAppDownload) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
DownloadIconVisibilityForRegularDownload) { … }
#endif
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
DisplayModeMediaCSS) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
DraggableRegionsEnabled) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_WindowControlsOverlay,
DragAfterNavigation) { … }
#if !BUILDFLAG(IS_ANDROID)
class WebAppFrameToolbarBrowserTest_AdditionalWindowingControls
: public WebAppFrameToolbarBrowserTest { … };
IN_PROC_BROWSER_TEST_F(
WebAppFrameToolbarBrowserTest_AdditionalWindowingControls,
WindowSetResizableMatches) { … }
IN_PROC_BROWSER_TEST_F(
WebAppFrameToolbarBrowserTest_AdditionalWindowingControls,
NavigatingBetweenTwoPagesWithUnsetResizability) { … }
IN_PROC_BROWSER_TEST_F(
WebAppFrameToolbarBrowserTest_AdditionalWindowingControls,
NavigatingBetweenTwoPagesWithNonNullResizability) { … }
IN_PROC_BROWSER_TEST_F(
WebAppFrameToolbarBrowserTest_AdditionalWindowingControls,
NavigatingOutsideTheAppScopeAndBackResetsAndThenRestoresResizability) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_WindowSetResizableBlocksResizeToAndResizeByApis …
#else
#define MAYBE_WindowSetResizableBlocksResizeToAndResizeByApis …
#endif
IN_PROC_BROWSER_TEST_F(
WebAppFrameToolbarBrowserTest_AdditionalWindowingControls,
MAYBE_WindowSetResizableBlocksResizeToAndResizeByApis) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_WindowSetResizableDoesntBlockMoveToAndMoveByApis …
#else
#define MAYBE_WindowSetResizableDoesntBlockMoveToAndMoveByApis …
#endif
IN_PROC_BROWSER_TEST_F(
WebAppFrameToolbarBrowserTest_AdditionalWindowingControls,
MAYBE_WindowSetResizableDoesntBlockMoveToAndMoveByApis) { … }
IN_PROC_BROWSER_TEST_F(
WebAppFrameToolbarBrowserTest_AdditionalWindowingControls,
MinimizeWindowWithApi) { … }
IN_PROC_BROWSER_TEST_F(
WebAppFrameToolbarBrowserTest_AdditionalWindowingControls,
MaximizeAndRestoreWindowWithApi) { … }
#if !BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(
WebAppFrameToolbarBrowserTest_AdditionalWindowingControls,
WindowSetResizableBlocksMaximizingNormalWindow) { … }
IN_PROC_BROWSER_TEST_F(
WebAppFrameToolbarBrowserTest_AdditionalWindowingControls,
WindowSetResizableBlocksRestoringMaximizedWindow) { … }
#endif
IN_PROC_BROWSER_TEST_F(
WebAppFrameToolbarBrowserTest_AdditionalWindowingControls,
MoveCallFiresMoveEvent) { … }
#endif
class OriginTextVisibilityWaiter : public views::ViewObserver { … };
class WebAppFrameToolbarBrowserTest_OriginText
: public WebAppFrameToolbarBrowserTest,
public testing::WithParamInterface<bool> { … };
IN_PROC_BROWSER_TEST_P(WebAppFrameToolbarBrowserTest_OriginText,
InScopeNavigation) { … }
IN_PROC_BROWSER_TEST_P(WebAppFrameToolbarBrowserTest_OriginText,
OutOfScopeBarShown) { … }
IN_PROC_BROWSER_TEST_P(WebAppFrameToolbarBrowserTest_OriginText,
ThemeColorChange) { … }
IN_PROC_BROWSER_TEST_P(WebAppFrameToolbarBrowserTest_OriginText,
OutOfScopeBarWithThemeColorChange) { … }
IN_PROC_BROWSER_TEST_P(WebAppFrameToolbarBrowserTest_OriginText,
WebAppOriginTextAccessibleProperties) { … }
INSTANTIATE_TEST_SUITE_P(…);
class WebAppFrameToolbarBrowserTest_ScopeExtensionsOriginText
: public WebAppFrameToolbarBrowserTest { … };
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_ScopeExtensionsOriginText,
ExtendedScope) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_ScopeExtensionsOriginText,
ExtendedScopeToOutOfScope) { … }
IN_PROC_BROWSER_TEST_F(WebAppFrameToolbarBrowserTest_ScopeExtensionsOriginText,
ExtendedScopeThemeColorChange) { … }