chromium/chrome/browser/ui/views/page_info/page_info_bubble_view_browsertest.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/page_info/page_info_bubble_view.h"

#include "base/files/file_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/strings/escape.h"
#include "base/strings/strcat.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/with_feature_override.h"
#include "build/build_config.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/file_system_access/chrome_file_system_access_permission_context.h"
#include "chrome/browser/file_system_access/file_system_access_features.h"
#include "chrome/browser/file_system_access/file_system_access_permission_context_factory.h"
#include "chrome/browser/file_system_access/file_system_access_permission_request_manager.h"
#include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/page_info/page_info_features.h"
#include "chrome/browser/privacy_sandbox/mock_privacy_sandbox_service.h"
#include "chrome/browser/privacy_sandbox/privacy_sandbox_service.h"
#include "chrome/browser/privacy_sandbox/privacy_sandbox_service_factory.h"
#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
#include "chrome/browser/ssl/https_upgrades_interceptor.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/file_system_access/file_system_access_ui_helpers.h"
#include "chrome/browser/ui/hats/mock_trust_safety_sentiment_service.h"
#include "chrome/browser/ui/hats/trust_safety_sentiment_service_factory.h"
#include "chrome/browser/ui/page_info/chrome_page_info_delegate.h"
#include "chrome/browser/ui/page_info/page_info_dialog.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/controls/rich_hover_button.h"
#include "chrome/browser/ui/views/file_system_access/file_system_access_test_utils.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/location_bar/location_icon_view.h"
#include "chrome/browser/ui/views/page_info/page_info_cookies_content_view.h"
#include "chrome/browser/ui/views/page_info/page_info_permission_content_view.h"
#include "chrome/browser/ui/views/page_info/page_info_view_factory.h"
#include "chrome/browser/ui/views/page_info/security_information_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/core/common/features.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/optimization_guide/core/optimization_guide_switches.h"
#include "components/page_info/core/about_this_site_service.h"
#include "components/page_info/core/about_this_site_validation.h"
#include "components/page_info/core/features.h"
#include "components/page_info/core/proto/about_this_site_metadata.pb.h"
#include "components/page_info/page_info.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/permissions/features.h"
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#include "components/safe_browsing/content/browser/password_protection/password_protection_test_util.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/security_state/content/security_state_tab_helper.h"
#include "components/strings/grit/components_strings.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/isolated_world_ids.h"
#include "content/public/common/referrer.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/cert_test_util.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/test_certificate_data.h"
#include "net/test/test_data_directory.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.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/events/test/test_event.h"
#include "ui/views/controls/button/toggle_button.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/test/widget_test.h"

AboutThisSiteStatus;
AboutThisSiteInteraction;

namespace {
IsFalse;
IsTrue;

constexpr char kExpiredCertificateFile[] =;

void PerformMouseClickOnView(views::View* view) {}

// Clicks the location icon to open the page info bubble.
void OpenPageInfoBubble(Browser* browser) {}

// Opens the Page Info bubble and retrieves the UI view identified by
// |view_id|.
views::View* GetView(int view_id) {}

// Clicks the "Site settings" button from Page Info and waits for a "Settings"
// tab to open.
void ClickAndWaitForSettingsPageToOpen(views::View* site_settings_button) {}

// Returns the URL of the new tab that's opened on clicking the "Site settings"
// button from Page Info.
const GURL OpenSiteSettingsForUrl(Browser* browser, const GURL& url) {}

void AddHintForTesting(Browser* browser,
                       const GURL& url,
                       page_info::proto::SiteInfo site_info) {}

}  // namespace

class PageInfoBubbleViewBrowserTest : public InProcessBrowserTest {};

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest, ShowBubble) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest,
                       StopShowingBubbleWhenWebContentsDestroyed) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest, ChromeURL) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest, ChromeExtensionURL) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest, ChromeDevtoolsURL) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest, ViewSourceURL) {}

// Test opening "Site Details" via Page Info from an ASCII origin does the
// correct URL canonicalization.
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest, SiteSettingsLink) {}

// Test opening "Site Details" via Page Info from a non-ASCII URL converts it to
// an origin and does punycode conversion as well as URL canonicalization.
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest,
                       SiteSettingsLinkWithNonAsciiUrl) {}

// Test opening "Site Details" via Page Info from an origin with a non-default
// (scheme, port) pair will specify port # in the origin passed to query params.
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest,
                       SiteSettingsLinkWithNonDefaultPort) {}

// Test opening "Site Details" via Page Info from about:blank goes to "Content
// Settings" (the alternative is a blank origin being sent to "Site Details").
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest,
                       SiteSettingsLinkWithAboutBlankURL) {}

// Test opening page info bubble that matches
// SB_THREAT_TYPE_ENTERPRISE_PASSWORD_REUSE threat type.
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest,
                       VerifyEnterprisePasswordReusePageInfoBubble) {}

// Test opening page info bubble that matches
// SB_THREAT_TYPE_SAVED_PASSWORD_REUSE threat type.
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest,
                       VerifySavedPasswordReusePageInfoBubble) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest,
                       ClosesOnUserNavigateToSamePage) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest,
                       ClosesOnUserNavigateToDifferentPage) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest,
                       DoesntCloseOnSubframeNavigate) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest,
                       InteractedWithCookiesButton) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest,
                       InteractedWithFileSystemSubpage) {}

class PageInfoBubbleViewBrowserTestWithAutoupgradesDisabled
    : public PageInfoBubbleViewBrowserTest {};

// Ensure changes to security state are reflected in an open PageInfo bubble.
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTestWithAutoupgradesDisabled,
                       UpdatesOnSecurityStateChange) {}

// Ensure a page can both have an invalid certificate *and* be blocked by Safe
// Browsing.  Regression test for bug 869925.
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest, BlockedAndInvalidCert) {}

// Ensure a page that has an EV certificate *and* is blocked by Safe Browsing
// shows the correct PageInfo UI. Regression test for crbug.com/1014240.
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest, MalwareAndEvCert) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest,
                       SocialEngineeringStrings) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewBrowserTest, UnwantedSoftwareStrings) {}

// Tests that the "reset warning decisions" button is shown if the user has
// clicked through an SSL warning or the HTTP interstitial, but not for silent
// fallback to HTTP under HTTPS-Upgrades.
// TODO(crbug.com/40248833): Convert these tests to be normal
// PageInfoBubbleViewBrowserTest when HTTPS-Upgrades is enabled-by-default.
class PageInfoBubbleViewHttpsUpgradesBrowserTest
    : public PageInfoBubbleViewBrowserTest {};

// Navigate to a page with an SSL warning (but no malware status) and click
// through the SSL warning. The "reset decisions" button should be shown.
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewHttpsUpgradesBrowserTest,
                       ResetWarningDecisionsButtonCertWarningOnly) {}

// Navigate to a malware page with an SSL warning and click through the warning.
// The "reset decisions" button should not be displayed (otherwise it's
// confusing which warning the user is re-enabling).
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewHttpsUpgradesBrowserTest,
                       ResetWarningDecisionsButtonCertAndMalwareWarnings) {}

// Navigate to an HTTP page with HTTPS-First Mode enabled and click through the
// warning. The reset decisions button should be shown.
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewHttpsUpgradesBrowserTest,
                       ResetWarningDecisionsButtonHttpsFirstMode) {}

// Navigate to an HTTP page with HTTPS-Upgrades enabled but not HTTPS-First
// Mode (so no warning is shown). The reset decisions button should not be
// shown.
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewHttpsUpgradesBrowserTest,
                       ResetWarningDecisionsButtonHttpsUpgrades) {}

class PageInfoBubbleViewPrerenderBrowserTest
    : public PageInfoBubbleViewBrowserTest {};

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewPrerenderBrowserTest,
                       DoesntCloseOnPrerenderNavigate) {}

class PageInfoBubbleViewAboutThisSiteBrowserTest : public InProcessBrowserTest {};

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewAboutThisSiteBrowserTest,
                       AboutThisSite) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewAboutThisSiteBrowserTest,
                       AboutThisSiteInteraction) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewAboutThisSiteBrowserTest,
                       AboutThisSiteInteractionWithoutDescription) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewAboutThisSiteBrowserTest,
                       AboutThisSiteNotValid) {}

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewAboutThisSiteBrowserTest,
                       AboutThisSiteNotSecure) {}

// Test that no info is shown and "kNotShownOptimizationGuideNotAllowed" is
// logged when hints fetching is disabled.
class PageInfoBubbleViewAboutThisSiteDisabledBrowserTest
    : public PageInfoBubbleViewAboutThisSiteBrowserTest {};

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewAboutThisSiteDisabledBrowserTest,
                       AboutThisSiteWithoutOptin) {}

class PageInfoBubbleViewSiteSettingsBrowserTest : public InProcessBrowserTest {};

IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewSiteSettingsBrowserTest,
                       SiteSettingsNotValid) {}

class PageInfoBubbleViewBrowserTestCookiesSubpage
    : public PageInfoBubbleViewBrowserTest,
      public testing::WithParamInterface</*is_3pcd_enabled*/ bool> {};

INSTANTIATE_TEST_SUITE_P();

// Checks if there is correct number of buttons in cookies subpage when rws are
// blocked and based on the third party cookies state (dependent on 3PCD) and
// checks if the metrics for opening cookies dialog work properly.
IN_PROC_BROWSER_TEST_P(PageInfoBubbleViewBrowserTestCookiesSubpage,
                       ClickingCookieDialogButton) {}

// Checks if there is a correct number of buttons in cookies subpage when rws
// are allowed and third party cookies are blocked and tests the
// click on the rws button (result and user action).
IN_PROC_BROWSER_TEST_P(PageInfoBubbleViewBrowserTestCookiesSubpage,
                       ClickingRwsButton) {}

// Checks if there is a correct number of buttons in cookies subpage when rws
// are blocked and third party cookies are blocked(in settings) and testing the
// toggle on blocking third party button.
IN_PROC_BROWSER_TEST_P(PageInfoBubbleViewBrowserTestCookiesSubpage,
                       ToggleForBlockingThirdPartyCookies) {}

// Checks if there is a correct number of buttons in cookies subpage when rws
// are allowed and based on third party cookies state (dependent on 3PCD) and
// click on link in description of cookies subapge.
IN_PROC_BROWSER_TEST_P(PageInfoBubbleViewBrowserTestCookiesSubpage,
                       LinkInDescriptionForCookiesSettings) {}

class PageInfoBubbleViewBrowserTestTrackingProtectionSubpage
    : public PageInfoBubbleViewBrowserTestCookiesSubpage {};

IN_PROC_BROWSER_TEST_P(
    PageInfoBubbleViewBrowserTestTrackingProtectionSubpage,
    ToggleForBlockingThirdPartyCookiesUpdatesTrackingProtectionException) {}

INSTANTIATE_TEST_SUITE_P();