chromium/components/security_interstitials/content/ssl_error_navigation_throttle_unittest.cc

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

#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"

#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "components/security_interstitials/content/security_interstitial_controller_client.h"
#include "components/security_interstitials/content/security_interstitial_page.h"
#include "components/security_interstitials/content/settings_page_helper.h"
#include "components/security_interstitials/core/metrics_helper.h"
#include "components/security_interstitials/core/ssl_error_ui.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/test/mock_navigation_handle.h"
#include "content/public/test/test_renderer_host.h"
#include "net/cert/cert_status_flags.h"
#include "net/test/cert_test_util.h"
#include "net/test/test_data_directory.h"

namespace {

// Constructs a MetricsHelper instance for usage in this context.
std::unique_ptr<security_interstitials::MetricsHelper>
CreateMetricsHelperForTest(const GURL& request_url) {}

// A SecurityInterstitialPage implementation that does the minimum necessary
// to satisfy SSLErrorNavigationThrottle's expectations of the instance passed
// to its ShowInterstitial() method, in particular populates the data
// needed to instantiate the template HTML.
class FakeSSLBlockingPage
    : public security_interstitials::SecurityInterstitialPage {};

// Replacement for SSLErrorHandler::HandleSSLError that calls
// |blocking_page_ready_callback|. |async| specifies whether this call should be
// done synchronously or using PostTask().
void MockHandleSSLError(
    bool async,
    content::WebContents* web_contents,
    int cert_error,
    const net::SSLInfo& ssl_info,
    const GURL& request_url,
    base::OnceCallback<
        void(std::unique_ptr<security_interstitials::SecurityInterstitialPage>)>
        blocking_page_ready_callback) {}

bool IsInHostedApp(content::WebContents* web_contents) {}

bool ShouldIgnoreInterstitialBecauseNavigationDefaultedToHttps(
    content::NavigationHandle* handle) {}

class TestSSLErrorNavigationThrottle : public SSLErrorNavigationThrottle {};

class SSLErrorNavigationThrottleTest
    : public content::RenderViewHostTestHarness,
      public testing::WithParamInterface<bool> {};

// Tests that the throttle ignores a request with a non SSL related network
// error code.
TEST_P(SSLErrorNavigationThrottleTest, NoSSLError) {}

// Tests that the throttle defers and cancels a request with a net error that
// is a cert error.
TEST_P(SSLErrorNavigationThrottleTest, SSLInfoWithCertError) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace