#include <memory>
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/performance_controls/memory_saver_utils.h"
#include "chrome/browser/ui/performance_controls/tab_resource_usage_tab_helper.h"
#include "chrome/browser/ui/performance_controls/test_support/memory_metrics_refresh_waiter.h"
#include "chrome/browser/ui/performance_controls/test_support/memory_saver_interactive_test_mixin.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/tabs/fade_footer_view.h"
#include "chrome/browser/ui/views/tabs/fade_label_view.h"
#include "chrome/browser/ui/views/tabs/tab.h"
#include "chrome/browser/ui/views/tabs/tab_close_button.h"
#include "chrome/browser/ui/views/tabs/tab_hover_card_bubble_view.h"
#include "chrome/browser/ui/views/tabs/tab_hover_card_controller.h"
#include "chrome/browser/ui/views/tabs/tab_hover_card_test_util.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "components/lookalikes/core/safety_tip_test_utils.h"
#include "components/performance_manager/public/decorators/process_metrics_decorator.h"
#include "components/performance_manager/public/performance_manager.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "net/base/url_util.h"
#include "net/dns/mock_host_resolver.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/image_model.h"
#include "ui/base/models/list_selection_model.h"
#include "ui/base/test/ui_controls.h"
#include "ui/base/text/bytes_formatting.h"
#include "ui/display/display.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/geometry/point.h"
#include "ui/views/controls/label.h"
#include "ui/views/test/widget_activation_waiter.h"
#include "ui/views/test/widget_test.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/system_web_apps/test_support/test_system_web_app_installation.h"
#endif
namespace {
constexpr char16_t kTabTitle[] = …;
constexpr char16_t kTabDomain[] = …;
constexpr char kTabUrl[] = …;
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(…);
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(…);
TabRendererData MakeTabRendererData() { … }
}
class TabHoverCardInteractiveUiTest
: public MemorySaverInteractiveTestMixin<InteractiveBrowserTest>,
public test::TabHoverCardTestUtil { … };
#if defined(USE_AURA)
IN_PROC_BROWSER_TEST_F(TabHoverCardInteractiveUiTest,
HoverCardHidesOnAnyKeyPressInSameWindow) { … }
#endif
IN_PROC_BROWSER_TEST_F(TabHoverCardInteractiveUiTest,
HoverCardHidesOnMouseExit) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_HoverCardShownOnTabFocus …
#else
#define MAYBE_HoverCardShownOnTabFocus …
#endif
IN_PROC_BROWSER_TEST_F(TabHoverCardInteractiveUiTest,
MAYBE_HoverCardShownOnTabFocus) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardInteractiveUiTest,
HoverCardVisibleOnTabCloseButtonFocusAfterTabFocus) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardInteractiveUiTest,
WidgetVisibleOnKeyPressAfterTabFocus) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardInteractiveUiTest,
ThumbnailNotVisibileOnActiveTabs) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardInteractiveUiTest,
WidgetNotVisibleOnMousePressAfterTabFocus) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardInteractiveUiTest,
WidgetNotVisibleOnMousePressAfterHover) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardInteractiveUiTest,
HoverCardVisibleOnTabFocusFromKeyboardAccelerator) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardInteractiveUiTest,
InactiveWindowStaysInactiveOnHover) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardInteractiveUiTest,
UpdatesHoverCardOnHoverDifferentTab) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardInteractiveUiTest,
HoverCardDoesNotHaveFooterView) { … }
TabHoverCardBubbleViewMetricsTest;
IN_PROC_BROWSER_TEST_F(TabHoverCardBubbleViewMetricsTest,
HoverCardsSeenRatioMetric) { … }
class TabHoverCardBubbleViewInterstitialBrowserTest
: public TabHoverCardInteractiveUiTest { … };
IN_PROC_BROWSER_TEST_F(TabHoverCardBubbleViewInterstitialBrowserTest,
LookalikeInterstitial_ShouldHideHoverCardUrl) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardBubbleViewInterstitialBrowserTest,
SSLInterstitial_ShouldShowHoverCardUrl) { … }
class TabHoverCardFadeFooterInteractiveUiTest
: public TabHoverCardInteractiveUiTest { … };
IN_PROC_BROWSER_TEST_F(TabHoverCardFadeFooterInteractiveUiTest,
HoverCardFooterUpdatesTabAlertStatus) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardFadeFooterInteractiveUiTest,
HoverCardFooterShowsDiscardStatus) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardFadeFooterInteractiveUiTest,
HoverCardFooterMemoryUsagePrefEnabled) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardFadeFooterInteractiveUiTest,
HoverCardFooterMemoryUsagePrefDisabled) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardFadeFooterInteractiveUiTest,
ActiveMemoryUsageHidesOnDiscard) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardFadeFooterInteractiveUiTest,
DiscardStatusHidesOnReload) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardFadeFooterInteractiveUiTest,
MemoryUpdatesOnNavigation) { … }
IN_PROC_BROWSER_TEST_F(TabHoverCardFadeFooterInteractiveUiTest,
FooterHidesOnTabWithoutMemoryUsage) { … }
IN_PROC_BROWSER_TEST_F(
TabHoverCardFadeFooterInteractiveUiTest,
BackgroundTabHoverCardContentsHaveCorrectDimensions) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
class TabHoverCardSystemWebAppTest : public InteractiveBrowserTest {
public:
TabHoverCardSystemWebAppTest()
: test_system_web_app_installation_(
ash::TestSystemWebAppInstallation::SetUpTabbedMultiWindowApp()) {}
void SetUpOnMainThread() override {
InteractiveBrowserTest::SetUpOnMainThread();
Tab::SetShowHoverCardOnMouseHoverForTesting(true);
}
protected:
std::unique_ptr<ash::TestSystemWebAppInstallation>
test_system_web_app_installation_;
};
IN_PROC_BROWSER_TEST_F(TabHoverCardSystemWebAppTest,
HideDomainNameFromHoverCard) {
test_system_web_app_installation_->WaitForAppInstall();
const auto* const app_browser = web_app::LaunchWebAppBrowser(
browser()->profile(), test_system_web_app_installation_->GetAppId());
const char kTabToHover[] = "Tab to hover";
RunTestSequenceInContext(
app_browser->window()->GetElementContext(),
WithView(kTabStripElementId,
[](TabStrip* tab_strip) { tab_strip->StopAnimating(true); }),
NameDescendantViewByType<Tab>(kBrowserViewElementId, kTabToHover, 0),
MoveMouseTo(kTabToHover),
WaitForShow(TabHoverCardBubbleView::kHoverCardBubbleElementId),
EnsureNotPresent(TabHoverCardBubbleView::kHoverCardDomainLabelElementId),
MoveMouseTo(kNewTabButtonElementId),
WaitForHide(TabHoverCardBubbleView::kHoverCardBubbleElementId));
}
#endif