chromium/content/test/navigation_simulator_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 "content/public/test/navigation_simulator.h"

#include <memory>
#include <string>
#include <tuple>
#include <utility>

#include "base/functional/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/test/test_simple_task_runner.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/test_navigation_throttle.h"
#include "content/public/test/test_navigation_throttle_inserter.h"
#include "content/test/task_runner_deferring_throttle.h"
#include "content/test/test_render_frame_host.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace content {

class NavigationSimulatorTest : public RenderViewHostImplTestHarness {};

class CancellingNavigationSimulatorTest
    : public RenderViewHostImplTestHarness,
      public WebContentsObserver,
      public testing::WithParamInterface<
          std::tuple<std::optional<TestNavigationThrottle::ThrottleMethod>,
                     TestNavigationThrottle::ResultSynchrony>> {};

class MethodCheckingNavigationSimulatorTest : public NavigationSimulatorTest,
                                              public WebContentsObserver {};

class ResponseHeadersCheckingNavigationSimulatorTest
    : public NavigationSimulatorTest,
      public WebContentsObserver {};

// Test that NavigationSimulator accurately commits about:blank if the browser
// requests a navigation to an empty URL.
TEST_F(NavigationSimulatorTest, EmptyURL) {}

TEST_F(NavigationSimulatorTest, AutoAdvanceOff) {}

TEST_F(MethodCheckingNavigationSimulatorTest, SetMethodPostWithRedirect) {}

TEST_F(MethodCheckingNavigationSimulatorTest, SetMethodPost) {}

TEST_F(ResponseHeadersCheckingNavigationSimulatorTest, CheckResponseHeaders) {}

// Stress test the navigation simulator by having a navigation throttle cancel
// the navigation at various points in the flow, both synchronously and
// asynchronously.
TEST_P(CancellingNavigationSimulatorTest, Cancel) {}

INSTANTIATE_TEST_SUITE_P();

// Create a version of the test class for parameterized testing.
NavigationSimulatorTestCancelFail;

// Test canceling the simulated navigation.
TEST_P(NavigationSimulatorTestCancelFail, Fail) {}

INSTANTIATE_TEST_SUITE_P();

// Create a version of the test class for parameterized testing.
NavigationSimulatorTestCancelFailErrAborted;

// Test canceling the simulated navigation with net::ERR_ABORTED, which should
// not call WillFailRequest on the throttle.
TEST_P(NavigationSimulatorTestCancelFailErrAborted, Fail) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace content