chromium/chrome/browser/ui/passwords/well_known_change_password_navigation_throttle_browsertest.cc

// Copyright 2018 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/passwords/well_known_change_password_navigation_throttle.h"

#include <map>
#include <optional>
#include <utility>

#include "base/callback_list.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/time/time.h"
#include "chrome/browser/affiliations/affiliation_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ssl/cert_verifier_browser_test.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/common/url_constants.h"
#include "components/affiliations/core/browser/affiliation_service_impl.h"
#include "components/affiliations/core/browser/hash_affiliation_fetcher.h"
#include "components/affiliations/core/browser/mock_affiliation_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/password_manager/core/browser/well_known_change_password/well_known_change_password_util.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/sync/test/test_sync_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/mock_navigation_handle.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/url_loader_interceptor.h"
#include "net/cert/x509_certificate.h"
#include "net/dns/mock_host_resolver.h"
#include "net/http/http_status_code.h"
#include "net/test/embedded_test_server/embedded_test_server.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 "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/page_transition_types.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace {
FacetURI;
MockAffiliationService;
NavigationThrottle;
RenderFrameHost;
TestNavigationObserver;
URLLoaderInterceptor;
BasicHttpResponse;
DelayedHttpResponse;
EmbeddedTestServer;
EmbeddedTestServerHandle;
HttpRequest;
HttpResponse;
kWellKnownChangePasswordPath;
kWellKnownNotExistingResourcePath;
WellKnownChangePasswordResult;
_;
Return;

constexpr char kMockChangePasswordPath[] =;

// ServerResponse describes how a server should respond to a given path.
struct ServerResponse {};

// The NavigationThrottle is making 2 requests in parallel. With this config we
// simulate the different orders for the arrival of the responses. The value
// represents the delay in milliseconds.
struct ResponseDelayParams {};

}  // namespace

// Browser Test that checks navigation to /.well-known/change-password path and
// redirection to change password URL returned by Change Password Service.
class WellKnownChangePasswordNavigationThrottleBrowserTest
    : public CertVerifierBrowserTest,
      public testing::WithParamInterface<
          std::tuple<ui::PageTransition, ResponseDelayParams>> {};

IN_PROC_BROWSER_TEST_P(WellKnownChangePasswordNavigationThrottleBrowserTest,
                       SupportForChangePassword) {}

IN_PROC_BROWSER_TEST_P(WellKnownChangePasswordNavigationThrottleBrowserTest,
                       SupportForChangePassword_WithRedirect) {}

// Tests that the throttle behaves correctly for all types of page transitions
// when initiated from within Chrome settings.
IN_PROC_BROWSER_TEST_P(
    WellKnownChangePasswordNavigationThrottleBrowserTest,
    SupportForChangePassword_WithRedirect_FromChromeSettings) {}

// Tests that the throttle behaves correctly for all types of page transitions
// when initiated from p.g.c.'s checkup.
IN_PROC_BROWSER_TEST_P(
    WellKnownChangePasswordNavigationThrottleBrowserTest,
    SupportForChangePassword_WithRedirect_FromPasswordCheckup) {}

IN_PROC_BROWSER_TEST_P(WellKnownChangePasswordNavigationThrottleBrowserTest,
                       SupportForChangePassword_PartialContent) {}

IN_PROC_BROWSER_TEST_P(
    WellKnownChangePasswordNavigationThrottleBrowserTest,
    SupportForChangePassword_WithXOriginRedirectToNotFoundPage) {}

IN_PROC_BROWSER_TEST_P(WellKnownChangePasswordNavigationThrottleBrowserTest,
                       NoSupportForChangePassword_NotFound) {}

IN_PROC_BROWSER_TEST_P(WellKnownChangePasswordNavigationThrottleBrowserTest,
                       NoSupportForChangePassword_WithUrlOverride) {}

// Single page applications often return 200 for all paths
IN_PROC_BROWSER_TEST_P(WellKnownChangePasswordNavigationThrottleBrowserTest,
                       NoSupportForChangePassword_Ok) {}

IN_PROC_BROWSER_TEST_P(
    WellKnownChangePasswordNavigationThrottleBrowserTest,
    NoSupportForChangePassword_WithXOriginRedirectToNotFoundPage) {}

IN_PROC_BROWSER_TEST_P(WellKnownChangePasswordNavigationThrottleBrowserTest,
                       NoSupportForChangePassword_WillFailRequest) {}

IN_PROC_BROWSER_TEST_P(WellKnownChangePasswordNavigationThrottleBrowserTest,
                       AffiliationServiceReturnsWellKnownChangePasswordPath) {}

// Harness for testing the throttle with prerendering involved.
class PrerenderingChangePasswordNavigationThrottleBrowserTest
    : public WellKnownChangePasswordNavigationThrottleBrowserTest {};

// Test the behavior of the throttle when navigated from a prerendering
// context. This is a fairly narrow use case since, of prerendering-capable
// navigations, the throttle only runs when initiated by passwords.google.com.
// However, if that origin did prerendering the well known password change URL,
// make sure we don't run the throttle as it doesn't currently support
// Prerender2. This test just ensures we don't run the throttle in this case so
// we don't get side-effects in the primary frame while prerendering the
// .well-known URL.
IN_PROC_BROWSER_TEST_P(PrerenderingChangePasswordNavigationThrottleBrowserTest,
                       EnsurePrerenderCanceled) {}

constexpr ResponseDelayParams kDelayParams[] =;

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();