#include <string>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/history_test_utils.h"
#include "chrome/browser/lookalikes/lookalike_test_helper.h"
#include "chrome/browser/lookalikes/lookalike_url_service.h"
#include "chrome/browser/lookalikes/safety_tip_ui.h"
#include "chrome/browser/lookalikes/safety_tip_ui_helper.h"
#include "chrome/browser/lookalikes/safety_tip_web_contents_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/location_icon_view.h"
#include "chrome/browser/ui/views/page_info/page_info_bubble_view.h"
#include "chrome/browser/ui/views/page_info/page_info_bubble_view_base.h"
#include "chrome/browser/ui/views/page_info/page_info_view_factory.h"
#include "chrome/browser/ui/views/page_info/safety_tip_page_info_bubble_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/lookalikes/core/lookalike_url_util.h"
#include "components/lookalikes/core/safety_tip_test_utils.h"
#include "components/lookalikes/core/safety_tips.pb.h"
#include "components/lookalikes/core/safety_tips_config.h"
#include "components/page_info/core/features.h"
#include "components/safe_browsing/core/browser/db/v4_protocol_manager_util.h"
#include "components/security_interstitials/core/common_string_util.h"
#include "components/security_state/core/security_state.h"
#include "components/site_engagement/content/site_engagement_score.h"
#include "components/site_engagement/content/site_engagement_service.h"
#include "components/strings/grit/components_branded_strings.h"
#include "components/strings/grit/components_strings.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/referrer.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/url_loader_interceptor.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "third_party/blink/public/common/features.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/window_open_disposition.h"
#include "ui/events/test/test_event.h"
#include "ui/gfx/range/range.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
kInterstitialHistogramName;
NavigationSuggestionEvent;
namespace {
enum class UIStatus { … };
const int kHighEngagement = …;
const int kLowEngagement = …;
const char kSafetyTipShownHistogram[] = …;
struct HeuristicsTestCase { … };
std::string GetInteractionHistogram(const char* name) { … }
void NavigateToURL(Browser* browser,
const GURL& url,
WindowOpenDisposition disposition) { … }
void PerformMouseClickOnView(views::View* view) { … }
bool IsUIShowing() { … }
void CloseWarningIgnore(views::Widget::ClosedReason reason) { … }
void SetEngagementScore(Browser* browser, const GURL& url, double score) { … }
void OpenPageInfoBubble(Browser* browser) { … }
void SwitchToTabAndWait(const Browser* browser, int tab_index) { … }
void ConfigureAllowlistWithScopes() { … }
}
class SafetyTipPageInfoBubbleViewBrowserTest : public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
NoShowOnLowEngagement) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
NoShowOnLowEngagementIncognito) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
NoShowOnHighEngagement) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
NoShowOnHighEngagementIncognito) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest, ShowOnBlock) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest, NoShowOnError) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
DISABLED_ShowOnBlockIncognito) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
StillShowAfterSameDocNav) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
NoShowOnEnterpriseAllowlist) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
LeaveSiteLeavesSite) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
LearnMoreOpensHelpCenter) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
DISABLED_LeaveSiteStillWarnsAfter) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
IgnoreWarningStaysOnPage) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
IgnoreWarningStopsWarning) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
IgnoreIFrameNavigations) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_BubbleWaitsForVisible …
#else
#define MAYBE_BubbleWaitsForVisible …
#endif
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
MAYBE_BubbleWaitsForVisible) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
NoBubbleOnErrorEvenAfterVisible) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
SkipLookalikeInterstitialed) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
TriggersOnLookalike) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
NoTriggersOnLookalikeAllowlist) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
NoTriggersOnEmbeddedAllowlist) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
TriggersOnEditDistance) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
DoesntTriggerOnScopedAllowlist) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
TriggersOnWrongScopedAllowlist) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
TriggersOnCharacterSwap_SiteEngagement) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
TriggersOnCharacterSwap_SiteEngagement_HostnameMatch) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
TriggersOnCharacterSwap_TopSite) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
TriggersOnCharacterSwapSafeTLD_CanSpoof) { … }
IN_PROC_BROWSER_TEST_F(
SafetyTipPageInfoBubbleViewBrowserTest,
DoesntTriggerOnCharacterSwap_TopSiteWithDifferentRegistry) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
TriggersOnTailEmbedding) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
DoesntTriggersOnGenericTargetEmbedding) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
DISABLED_SafetyTipShownHistogram) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
SafetyTipIgnoredPageLoadHistogram) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
InteractionsHistogram_LeaveSite) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
InteractionsHistogram_DismissWithClose) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
InteractionsHistogram_DismissWithEsc) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
DISABLED_InteractionsHistogram_CloseTab) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
InteractionsHistogram_SwitchTab) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
InteractionsHistogram_NavigateAway) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
MetricsOnlyHeuristicDoesntShowInPageInfo) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
HeuristicsUkmRecorded) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
WarningDismissalCausesUkmRecordingForLookalike) { … }
IN_PROC_BROWSER_TEST_F(
SafetyTipPageInfoBubbleViewBrowserTest,
DISABLED_WarningDismissalCausesUkmRecordingForBlocklist) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
TriggerOnComboSquatting) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
DontTriggerOnAllowlistedComboSquatting) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
TriggerOnlyOnComboSquatting) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
ComboSquattingSiteEngagement_UIEnabled) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewBrowserTest,
ComboSquatting_UIDisabled_ShouldRecordMetrics) { … }
IN_PROC_BROWSER_TEST_F(
SafetyTipPageInfoBubbleViewBrowserTest,
ComboSquattingSiteEngagement_UIDisabled_ShouldRecordMetrics) { … }
class SafetyTipPageInfoBubbleViewPrerenderBrowserTest
: public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewPrerenderBrowserTest,
SafetyTipOnPrerender) { … }
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewPrerenderBrowserTest,
StillShowAfterPrerenderNavigation) { … }
class SafetyTipPageInfoBubbleViewDialogTest : public DialogBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SafetyTipPageInfoBubbleViewDialogTest,
InvokeUi_Lookalike) { … }