chromium/content/browser/renderer_host/navigation_throttle_runner_unittest.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 "content/browser/renderer_host/navigation_throttle_runner.h"

#include <optional>

#include "base/functional/bind.h"
#include "base/metrics/metrics_hashes.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/mock_navigation_handle.h"
#include "content/public/test/test_navigation_throttle.h"
#include "content/public/test/test_renderer_host.h"
#include "services/metrics/public/cpp/ukm_builders.h"

namespace content {

// Test version of a NavigationThrottle that will execute a callback when
// called.
class DeletingNavigationThrottle : public NavigationThrottle {};

class NavigationThrottleRunnerTest : public RenderViewHostTestHarness,
                                     public NavigationThrottleRunner::Delegate {};

class NavigationThrottleRunnerTestWithEvent
    : public NavigationThrottleRunnerTest,
      public testing::WithParamInterface<NavigationThrottleRunner::Event> {};

// Checks that a navigation deferred by a NavigationThrottle can be properly
// resumed.
TEST_P(NavigationThrottleRunnerTestWithEvent, ResumeDeferred) {}

// Checks that a NavigationThrottleRunner can be safely deleted by the execution
// of one of its NavigationThrottle.
TEST_P(NavigationThrottleRunnerTestWithEvent, DeletionByNavigationThrottle) {}

// Checks that a NavigationThrottleRunner can be safely deleted by the execution
// of one of its NavigationThrottle following a call to
// ResumeProcessingNavigationEvent.
TEST_P(NavigationThrottleRunnerTestWithEvent,
       DeletionByNavigationThrottleAfterResume) {}

INSTANTIATE_TEST_SUITE_P();

class NavigationThrottleRunnerTestWithEventAndAction
    : public NavigationThrottleRunnerTest,
      public testing::WithParamInterface<
          std::tuple<NavigationThrottleRunner::Event,
                     NavigationThrottle::ThrottleAction>> {};

// Checks that a NavigationThrottle asking during to defer
// followed by another NavigationThrottle behave correctly.
TEST_P(NavigationThrottleRunnerTestWithEventAndAction, DeferThenAction) {}

// Checks that a NavigationThrottle asking to cancel followed by a
// NavigationThrottle asking to proceed behave correctly. The navigation will
// be stopped directly, and the second throttle will not be called.
TEST_P(NavigationThrottleRunnerTestWithEventAndAction, CancelThenProceed) {}

// Checks that a NavigationThrottle asking to proceed followed by a
// NavigationThrottle asking to cancel behave correctly.
// Both throttles will be called, and the request will be cancelled.
TEST_P(NavigationThrottleRunnerTestWithEventAndAction, ProceedThenCancel) {}

// Checks that a NavigationThrottle being deferred and resumed records UKM about
// the deferral.
TEST_P(NavigationThrottleRunnerTestWithEventAndAction, DeferRecordsUKM) {}

INSTANTIATE_TEST_SUITE_P();

class NavigationThrottleRunnerTestWithEventAndError
    : public NavigationThrottleRunnerTest,
      public testing::WithParamInterface<
          std::tuple<NavigationThrottleRunner::Event,
                     net::Error,
                     std::optional<std::string>>> {};

// Checks that the NavigationThrottleRunner correctly propagates a
// ThrottleCheckResult with a custom error page and/or error code to its
// delegate.
TEST_P(NavigationThrottleRunnerTestWithEventAndError, CustomNetError) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace content