Commit 79e1a976 authored by Lucas Garron's avatar Lucas Garron Committed by Commit Bot

Generalize CancellingNavigationThrottle to a new TestNavigationThrottle class.

Bug: 770292
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_site_isolation
Change-Id: I1f3cb8d0d38503326b37adcebf3dee17856c82d4
Reviewed-on: https://chromium-review.googlesource.com/693376
Commit-Queue: Lucas Garron <lgarron@chromium.org>
Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506542}
parent 52b7477e
......@@ -32,14 +32,14 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/resource_type.h"
#include "content/public/test/cancelling_navigation_throttle.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_navigation_throttle.h"
#include "content/public/test/test_navigation_throttle_inserter.h"
#include "content/public/test/test_renderer_host.h"
#include "net/base/host_port_pair.h"
#include "url/gurl.h"
using content::CancellingNavigationThrottle;
using content::TestNavigationThrottle;
using content::RenderFrameHost;
using content::RenderFrameHostTester;
using content::NavigationSimulator;
......@@ -67,7 +67,7 @@ const char kNonAdName[] = "foo";
// Asynchronously cancels the navigation at WillProcessResponse. Before
// cancelling, simulates loading a main frame resource.
class ResourceLoadingCancellingThrottle
: public content::CancellingNavigationThrottle {
: public content::TestNavigationThrottle {
public:
static std::unique_ptr<content::NavigationThrottle> Create(
content::NavigationHandle* handle) {
......@@ -76,14 +76,18 @@ class ResourceLoadingCancellingThrottle
explicit ResourceLoadingCancellingThrottle(
content::NavigationHandle* navigation_handle)
: content::CancellingNavigationThrottle(
navigation_handle,
CancellingNavigationThrottle::WILL_PROCESS_RESPONSE,
CancellingNavigationThrottle::ASYNCHRONOUS) {}
: content::TestNavigationThrottle(navigation_handle) {
SetResponse(TestNavigationThrottle::WILL_PROCESS_RESPONSE,
TestNavigationThrottle::ASYNCHRONOUS, CANCEL);
}
private:
// content::CancellingNavigationThrottle:
void OnWillCancel() override {
// content::TestNavigationThrottle:
void OnWillRespond(NavigationThrottle::ThrottleCheckResult result) {
if (result.action() != CANCEL) {
return;
}
auto* observer =
page_load_metrics::MetricsWebContentsObserver::FromWebContents(
navigation_handle()->GetWebContents());
......
......@@ -38,8 +38,8 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/cancelling_navigation_throttle.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_navigation_throttle.h"
#include "content/public/test/test_renderer_host.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -408,34 +408,35 @@ class SubresourceFilterSafeBrowsingActivationThrottleParamTest
class SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling
: public SubresourceFilterSafeBrowsingActivationThrottleTest,
public ::testing::WithParamInterface<
std::tuple<content::CancellingNavigationThrottle::CancelTime,
content::CancellingNavigationThrottle::ResultSynchrony>> {
std::tuple<content::TestNavigationThrottle::ThrottleMethod,
content::TestNavigationThrottle::ResultSynchrony>> {
public:
SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling() {
std::tie(cancel_time_, result_sync_) = GetParam();
std::tie(throttle_method_, result_sync_) = GetParam();
}
~SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling()
override {}
void DidStartNavigation(content::NavigationHandle* handle) override {
handle->RegisterThrottleForTesting(
base::MakeUnique<content::CancellingNavigationThrottle>(
handle, cancel_time_, result_sync_));
auto throttle = base::MakeUnique<content::TestNavigationThrottle>(handle);
throttle->SetResponse(throttle_method_, result_sync_,
content::NavigationThrottle::CANCEL);
handle->RegisterThrottleForTesting(std::move(throttle));
SubresourceFilterSafeBrowsingActivationThrottleTest::DidStartNavigation(
handle);
}
content::CancellingNavigationThrottle::CancelTime cancel_time() {
return cancel_time_;
content::TestNavigationThrottle::ThrottleMethod throttle_method() {
return throttle_method_;
}
content::CancellingNavigationThrottle::ResultSynchrony result_sync() {
content::TestNavigationThrottle::ResultSynchrony result_sync() {
return result_sync_;
}
private:
content::CancellingNavigationThrottle::CancelTime cancel_time_;
content::CancellingNavigationThrottle::ResultSynchrony result_sync_;
content::TestNavigationThrottle::ThrottleMethod throttle_method_;
content::TestNavigationThrottle::ResultSynchrony result_sync_;
DISALLOW_COPY_AND_ASSIGN(
SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling);
......@@ -1109,13 +1110,13 @@ TEST_P(SubresourceFilterSafeBrowsingActivationThrottleParamTest,
TEST_P(SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling,
Cancel) {
const GURL url(kURL);
SCOPED_TRACE(::testing::Message() << "CancelTime: " << cancel_time()
SCOPED_TRACE(::testing::Message() << "ThrottleMethod: " << throttle_method()
<< " ResultSynchrony: " << result_sync());
ConfigureForMatch(url);
content::NavigationThrottle::ThrottleCheckResult result =
SimulateStart(url, main_rfh());
if (cancel_time() ==
content::CancellingNavigationThrottle::WILL_START_REQUEST) {
if (throttle_method() ==
content::TestNavigationThrottle::WILL_START_REQUEST) {
EXPECT_EQ(content::NavigationThrottle::CANCEL, result);
tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 0);
return;
......@@ -1123,8 +1124,8 @@ TEST_P(SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling,
EXPECT_EQ(content::NavigationThrottle::PROCEED, result);
result = SimulateRedirect(GURL(kRedirectURL));
if (cancel_time() ==
content::CancellingNavigationThrottle::WILL_REDIRECT_REQUEST) {
if (throttle_method() ==
content::TestNavigationThrottle::WILL_REDIRECT_REQUEST) {
EXPECT_EQ(content::NavigationThrottle::CANCEL, result);
tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 0);
return;
......@@ -1143,12 +1144,11 @@ INSTANTIATE_TEST_CASE_P(
SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling,
::testing::Combine(
::testing::Values(
content::CancellingNavigationThrottle::WILL_START_REQUEST,
content::CancellingNavigationThrottle::WILL_REDIRECT_REQUEST,
content::CancellingNavigationThrottle::WILL_PROCESS_RESPONSE),
::testing::Values(
content::CancellingNavigationThrottle::SYNCHRONOUS,
content::CancellingNavigationThrottle::ASYNCHRONOUS)));
content::TestNavigationThrottle::WILL_START_REQUEST,
content::TestNavigationThrottle::WILL_REDIRECT_REQUEST,
content::TestNavigationThrottle::WILL_PROCESS_RESPONSE),
::testing::Values(content::TestNavigationThrottle::SYNCHRONOUS,
content::TestNavigationThrottle::ASYNCHRONOUS)));
INSTANTIATE_TEST_CASE_P(
ActivationLevelTest,
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/public/test/cancelling_navigation_throttle.h"
#include "base/bind.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h"
namespace content {
CancellingNavigationThrottle::CancellingNavigationThrottle(
NavigationHandle* handle,
CancelTime cancel_time,
ResultSynchrony sync)
: NavigationThrottle(handle),
cancel_time_(cancel_time),
sync_(sync),
weak_ptr_factory_(this) {}
CancellingNavigationThrottle::~CancellingNavigationThrottle() {}
NavigationThrottle::ThrottleCheckResult
CancellingNavigationThrottle::WillStartRequest() {
return ProcessState(cancel_time_ == WILL_START_REQUEST);
}
NavigationThrottle::ThrottleCheckResult
CancellingNavigationThrottle::WillRedirectRequest() {
return ProcessState(cancel_time_ == WILL_REDIRECT_REQUEST);
}
NavigationThrottle::ThrottleCheckResult
CancellingNavigationThrottle::WillProcessResponse() {
return ProcessState(cancel_time_ == WILL_PROCESS_RESPONSE);
}
void CancellingNavigationThrottle::OnWillCancel() {}
NavigationThrottle::ThrottleCheckResult
CancellingNavigationThrottle::ProcessState(bool should_cancel) {
if (sync_ == ASYNCHRONOUS) {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::BindOnce(&CancellingNavigationThrottle::MaybeCancel,
weak_ptr_factory_.GetWeakPtr(), should_cancel));
return NavigationThrottle::DEFER;
}
if (should_cancel) {
OnWillCancel();
return NavigationThrottle::CANCEL;
}
return NavigationThrottle::PROCEED;
}
const char* CancellingNavigationThrottle::GetNameForLogging() {
return "CancellingNavigationThrottle";
}
void CancellingNavigationThrottle::MaybeCancel(bool cancel) {
if (cancel) {
OnWillCancel();
CancelDeferredNavigation(NavigationThrottle::CANCEL);
} else {
Resume();
}
}
} // namespace content
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_
#define CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/navigation_throttle.h"
namespace content {
class NavigationHandle;
// This class can be used to cancel navigations synchronously or asynchronously
// at a specific time in the NavigationThrottle lifecycle.
//
// Consider using it in conjunction with NavigationSimulator.
// TODO(clamy): Check if this could be used in unit tests exercising
// NavigationThrottle code.
class CancellingNavigationThrottle : public NavigationThrottle {
public:
enum CancelTime {
WILL_START_REQUEST,
WILL_REDIRECT_REQUEST,
WILL_PROCESS_RESPONSE,
NEVER,
};
enum ResultSynchrony {
SYNCHRONOUS,
ASYNCHRONOUS,
};
CancellingNavigationThrottle(NavigationHandle* handle,
CancelTime cancel_time,
ResultSynchrony sync);
~CancellingNavigationThrottle() override;
// NavigationThrottle:
NavigationThrottle::ThrottleCheckResult WillStartRequest() override;
NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override;
NavigationThrottle::ThrottleCheckResult WillProcessResponse() override;
const char* GetNameForLogging() override;
protected:
// Will be called before the navigation is cancelled.
virtual void OnWillCancel();
private:
NavigationThrottle::ThrottleCheckResult ProcessState(bool should_cancel);
void MaybeCancel(bool cancel);
private:
const CancelTime cancel_time_;
const ResultSynchrony sync_;
base::WeakPtrFactory<CancellingNavigationThrottle> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(CancellingNavigationThrottle);
};
} // namespace content
#endif // CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/public/test/test_navigation_throttle.h"
#include "base/bind.h"
#include "base/optional.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h"
namespace content {
TestNavigationThrottle::TestNavigationThrottle(NavigationHandle* handle)
: NavigationThrottle(handle), weak_ptr_factory_(this) {}
TestNavigationThrottle::~TestNavigationThrottle() {}
NavigationThrottle::ThrottleCheckResult
TestNavigationThrottle::WillStartRequest() {
return ProcessMethod(WILL_START_REQUEST);
}
NavigationThrottle::ThrottleCheckResult
TestNavigationThrottle::WillRedirectRequest() {
return ProcessMethod(WILL_REDIRECT_REQUEST);
}
NavigationThrottle::ThrottleCheckResult
TestNavigationThrottle::WillProcessResponse() {
return ProcessMethod(WILL_PROCESS_RESPONSE);
}
const char* TestNavigationThrottle::GetNameForLogging() {
return "TestNavigationThrottle";
}
int TestNavigationThrottle::GetCallCount(ThrottleMethod method) {
return method_properties_[method].call_count;
}
void TestNavigationThrottle::SetResponse(
ThrottleMethod method,
ResultSynchrony synchrony,
NavigationThrottle::ThrottleCheckResult result) {
CHECK_LT(method, NUM_THROTTLE_METHODS) << "Invalid throttle method";
if (synchrony == ASYNCHRONOUS) {
DCHECK(result.action() == NavigationThrottle::CANCEL_AND_IGNORE ||
result.action() == NavigationThrottle::CANCEL ||
result.action() == NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE)
<< "Invalid result for asynchronous response. Must have a valid action "
"for CancelDeferredNavigation().";
}
method_properties_[method].synchrony = synchrony;
method_properties_[method].result = result;
}
void TestNavigationThrottle::SetResponseForAllMethods(
ResultSynchrony synchrony,
NavigationThrottle::ThrottleCheckResult result) {
for (size_t method = 0; method < NUM_THROTTLE_METHODS; method++) {
SetResponse(static_cast<ThrottleMethod>(method), synchrony, result);
}
}
void TestNavigationThrottle::SetCallback(ThrottleMethod method,
base::Closure callback) {
method_properties_[method].callback = callback;
}
void TestNavigationThrottle::OnWillRespond() {}
NavigationThrottle::ThrottleCheckResult TestNavigationThrottle::ProcessMethod(
ThrottleMethod method) {
method_properties_[method].call_count++;
if (!method_properties_[method].callback.is_null())
method_properties_[method].callback.Run();
NavigationThrottle::ThrottleCheckResult result =
method_properties_[method].result;
if (method_properties_[method].synchrony == ASYNCHRONOUS) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::BindOnce(&TestNavigationThrottle::TestNavigationThrottle::
CancelAsynchronously,
weak_ptr_factory_.GetWeakPtr(), result));
return NavigationThrottle::DEFER;
}
OnWillRespond();
return result;
}
void TestNavigationThrottle::CancelAsynchronously(
NavigationThrottle::ThrottleCheckResult result) {
OnWillRespond();
CancelDeferredNavigation(result);
}
TestNavigationThrottle::MethodProperties::MethodProperties() {}
TestNavigationThrottle::MethodProperties::~MethodProperties() {}
} // namespace content
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_
#define CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "content/public/browser/navigation_throttle.h"
namespace content {
class NavigationHandle;
// This class can be used to cancel navigations synchronously or asynchronously
// at specific times in the NavigationThrottle lifecycle.
//
// By default TestNavigationThrottle responds to every method synchronously with
// NavigationThrottle::PROCEED.
class TestNavigationThrottle : public NavigationThrottle {
public:
enum ThrottleMethod {
WILL_START_REQUEST,
WILL_REDIRECT_REQUEST,
WILL_PROCESS_RESPONSE,
NUM_THROTTLE_METHODS
};
enum ResultSynchrony {
SYNCHRONOUS,
ASYNCHRONOUS,
};
struct Status {
Status(ThrottleMethod method,
ResultSynchrony synchrony,
NavigationThrottle::ThrottleCheckResult result)
: method(method), synchrony(synchrony), result(result) {}
ThrottleMethod method;
ResultSynchrony synchrony;
NavigationThrottle::ThrottleCheckResult result;
};
TestNavigationThrottle(NavigationHandle* handle);
~TestNavigationThrottle() override;
// NavigationThrottle:
NavigationThrottle::ThrottleCheckResult WillStartRequest() override;
NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override;
NavigationThrottle::ThrottleCheckResult WillProcessResponse() override;
const char* GetNameForLogging() override;
// Return how often the indicated |method| was called.
int GetCallCount(ThrottleMethod method);
// Sets the throttle to respond to the method indicated by |method| using
// |result|, with the given |synchrony|. This overrides any behaviour
// previously set for the same |method| using SetResult().
//
// If |synchrony| is ASYNCHRONOUS, |result|'s action must be one that that is
// allowed for NavigationThrottle::CancelDeferredNavigation():
// - NavigationThrottle::CANCEL,
// - NavigationThrottle::CANCEL_AND_IGNORE, or
// - NavigationThrottle::BLOCK_REQUEST_AND_COLLAPSE.
//
// At the moment, it is not possible to specify that the throttle should defer
// and then asynchronously call Resume().
void SetResponse(ThrottleMethod method,
ResultSynchrony synchrony,
NavigationThrottle::ThrottleCheckResult result);
// Calls SetResponse with the given values for every method.
void SetResponseForAllMethods(ResultSynchrony synchrony,
NavigationThrottle::ThrottleCheckResult result);
// Callback to be called when the given method is called.
void SetCallback(ThrottleMethod method, base::RepeatingClosure callback);
protected:
// A method that subclasses can override to be called immediately before a
// throttle responds, either by returning synchronously, or by calling
// CancelDeferredNavigation() asynchronously.
//
// TODO(crbug.com/770292): Support setting a callback instead, and use that to
// get rid of the following classes:
// - ResourceLoadingCancellingThrottle in
// ads_page_load_metrics_observer_unittest.cc
// - DeletingNavigationThrottle in navigation_handle_impl_unittest.cc
void OnWillRespond();
private:
NavigationThrottle::ThrottleCheckResult ProcessMethod(ThrottleMethod method);
void CancelAsynchronously(NavigationThrottle::ThrottleCheckResult result);
struct MethodProperties {
public:
MethodProperties();
~MethodProperties();
ResultSynchrony synchrony = SYNCHRONOUS;
NavigationThrottle::ThrottleCheckResult result = {
NavigationThrottle::PROCEED};
base::RepeatingClosure callback;
int call_count = 0;
};
MethodProperties method_properties_[NUM_THROTTLE_METHODS];
base::WeakPtrFactory<TestNavigationThrottle> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(TestNavigationThrottle);
};
} // namespace content
#endif // CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_
......@@ -67,8 +67,6 @@ static_library("test_support") {
"../public/test/browsing_data_remover_test_util.h",
"../public/test/cache_test_util.cc",
"../public/test/cache_test_util.h",
"../public/test/cancelling_navigation_throttle.cc",
"../public/test/cancelling_navigation_throttle.h",
"../public/test/content_test_suite_base.cc",
"../public/test/content_test_suite_base.h",
"../public/test/controllable_http_response.cc",
......@@ -139,6 +137,8 @@ static_library("test_support") {
"../public/test/test_launcher.h",
"../public/test/test_navigation_observer.cc",
"../public/test/test_navigation_observer.h",
"../public/test/test_navigation_throttle.cc",
"../public/test/test_navigation_throttle.h",
"../public/test/test_navigation_throttle_inserter.cc",
"../public/test/test_navigation_throttle_inserter.h",
"../public/test/test_notification_tracker.cc",
......
......@@ -15,7 +15,7 @@
#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/cancelling_navigation_throttle.h"
#include "content/public/test/test_navigation_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"
......@@ -28,8 +28,8 @@ class NavigationSimulatorTest
: public RenderViewHostImplTestHarness,
public WebContentsObserver,
public testing::WithParamInterface<
std::tuple<CancellingNavigationThrottle::CancelTime,
CancellingNavigationThrottle::ResultSynchrony>> {
std::tuple<base::Optional<TestNavigationThrottle::ThrottleMethod>,
TestNavigationThrottle::ResultSynchrony>> {
public:
NavigationSimulatorTest() {}
~NavigationSimulatorTest() override {}
......@@ -49,17 +49,20 @@ class NavigationSimulatorTest
}
void DidStartNavigation(content::NavigationHandle* handle) override {
handle->RegisterThrottleForTesting(
base::MakeUnique<CancellingNavigationThrottle>(handle, cancel_time_,
sync_));
auto throttle = base::MakeUnique<TestNavigationThrottle>(handle);
if (cancel_time_.has_value()) {
throttle->SetResponse(cancel_time_.value(), sync_,
NavigationThrottle::CANCEL);
}
handle->RegisterThrottleForTesting(std::move(throttle));
}
void DidFinishNavigation(content::NavigationHandle* handle) override {
did_finish_navigation_ = true;
}
CancellingNavigationThrottle::CancelTime cancel_time_;
CancellingNavigationThrottle::ResultSynchrony sync_;
base::Optional<TestNavigationThrottle::ThrottleMethod> cancel_time_;
TestNavigationThrottle::ResultSynchrony sync_;
std::unique_ptr<NavigationSimulator> simulator_;
bool did_finish_navigation_ = false;
......@@ -71,10 +74,13 @@ class NavigationSimulatorTest
// the navigation at various points in the flow, both synchronously and
// asynchronously.
TEST_P(NavigationSimulatorTest, Cancel) {
SCOPED_TRACE(::testing::Message() << "CancelTime: " << cancel_time_
<< " ResultSynchrony: " << sync_);
SCOPED_TRACE(::testing::Message()
<< "CancelTime: "
<< (cancel_time_.has_value() ? cancel_time_.value() : -1)
<< " ResultSynchrony: " << sync_);
simulator_->Start();
if (cancel_time_ == CancellingNavigationThrottle::WILL_START_REQUEST) {
if (cancel_time_.has_value() &&
cancel_time_.value() == TestNavigationThrottle::WILL_START_REQUEST) {
EXPECT_EQ(NavigationThrottle::CANCEL,
simulator_->GetLastThrottleCheckResult());
return;
......@@ -82,7 +88,8 @@ TEST_P(NavigationSimulatorTest, Cancel) {
EXPECT_EQ(NavigationThrottle::PROCEED,
simulator_->GetLastThrottleCheckResult());
simulator_->Redirect(GURL("https://example.redirect"));
if (cancel_time_ == CancellingNavigationThrottle::WILL_REDIRECT_REQUEST) {
if (cancel_time_.has_value() &&
cancel_time_.value() == TestNavigationThrottle::WILL_REDIRECT_REQUEST) {
EXPECT_EQ(NavigationThrottle::CANCEL,
simulator_->GetLastThrottleCheckResult());
return;
......@@ -90,7 +97,8 @@ TEST_P(NavigationSimulatorTest, Cancel) {
EXPECT_EQ(NavigationThrottle::PROCEED,
simulator_->GetLastThrottleCheckResult());
simulator_->Commit();
if (cancel_time_ == CancellingNavigationThrottle::WILL_PROCESS_RESPONSE) {
if (cancel_time_.has_value() &&
cancel_time_.value() == TestNavigationThrottle::WILL_PROCESS_RESPONSE) {
EXPECT_EQ(NavigationThrottle::CANCEL,
simulator_->GetLastThrottleCheckResult());
return;
......@@ -103,11 +111,11 @@ INSTANTIATE_TEST_CASE_P(
CancelMethod,
NavigationSimulatorTest,
::testing::Combine(
::testing::Values(CancellingNavigationThrottle::WILL_START_REQUEST,
CancellingNavigationThrottle::WILL_REDIRECT_REQUEST,
CancellingNavigationThrottle::WILL_PROCESS_RESPONSE,
CancellingNavigationThrottle::NEVER),
::testing::Values(CancellingNavigationThrottle::SYNCHRONOUS,
CancellingNavigationThrottle::ASYNCHRONOUS)));
::testing::Values(TestNavigationThrottle::WILL_START_REQUEST,
TestNavigationThrottle::WILL_REDIRECT_REQUEST,
TestNavigationThrottle::WILL_PROCESS_RESPONSE,
base::nullopt),
::testing::Values(TestNavigationThrottle::SYNCHRONOUS,
TestNavigationThrottle::ASYNCHRONOUS)));
} // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment