Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(725)

Unified Diff: content/browser/frame_host/navigation_handle_impl_unittest.cc

Issue 1645363002: Revert of Teach navigation throttles how to cancel requests in WillProcessResponse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/frame_host/navigation_handle_impl_unittest.cc
diff --git a/content/browser/frame_host/navigation_handle_impl_unittest.cc b/content/browser/frame_host/navigation_handle_impl_unittest.cc
index 950ee993b6e3bafc9ab8dc7735deef29bf01dabd..ee999cb31b06a0f9fcfb7c50ab0f75e92fe0ef67 100644
--- a/content/browser/frame_host/navigation_handle_impl_unittest.cc
+++ b/content/browser/frame_host/navigation_handle_impl_unittest.cc
@@ -9,10 +9,9 @@
namespace content {
-// Test version of a NavigationThrottle. It will always return the current
+// Test version of a NavigationThrottle. It will always return the same
// NavigationThrottle::ThrottleCheckResult |result_|, It also monitors the
-// number of times WillStartRequest, WillRedirectRequest, and
-// WillProcessResponse were called.
+// number of times WillStartRequest and WillRedirectRequest were called.
class TestNavigationThrottle : public NavigationThrottle {
public:
TestNavigationThrottle(NavigationHandle* handle,
@@ -20,8 +19,7 @@
: NavigationThrottle(handle),
result_(result),
will_start_calls_(0),
- will_redirect_calls_(0),
- will_process_response_calls_(0) {}
+ will_redirect_calls_(0) {}
~TestNavigationThrottle() override {}
@@ -35,25 +33,16 @@
return result_;
}
- NavigationThrottle::ThrottleCheckResult WillProcessResponse() override {
- ++will_process_response_calls_;
- return result_;
- }
-
int will_start_calls() const { return will_start_calls_; }
int will_redirect_calls() const { return will_redirect_calls_; }
- int will_process_response_calls() const {
- return will_process_response_calls_;
- }
private:
// The result returned by the TestNavigationThrottle.
NavigationThrottle::ThrottleCheckResult result_;
- // The number of times each handler was called.
+ // The number of times WillStartRequest and WillRedirectRequest were called.
int will_start_calls_;
int will_redirect_calls_;
- int will_process_response_calls_;
};
class NavigationHandleImplTest : public RenderViewHostImplTestHarness {
@@ -81,10 +70,6 @@
bool IsDeferringRedirect() {
return test_handle_->state() == NavigationHandleImpl::DEFERRING_REDIRECT;
- }
-
- bool IsDeferringResponse() {
- return test_handle_->state() == NavigationHandleImpl::DEFERRING_RESPONSE;
}
bool IsCanceling() {
@@ -119,24 +104,6 @@
// the NavigationHandleImplTest.
test_handle_->WillRedirectRequest(
GURL(), false, GURL(), false, scoped_refptr<net::HttpResponseHeaders>(),
- base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult,
- base::Unretained(this)));
- }
-
- // Helper function to call WillProcessResponse on |handle|. If this function
- // returns DEFER, |callback_result_| will be set to the actual result of the
- // throttle checks when they are finished.
- // TODO(clamy): this should also simulate that WillStartRequest was called if
- // it has not been called before.
- void SimulateWillProcessResponse() {
- was_callback_called_ = false;
- callback_result_ = NavigationThrottle::DEFER;
-
- // It's safe to use base::Unretained since the NavigationHandle is owned by
- // the NavigationHandleImplTest.
- test_handle_->WillProcessResponse(
- main_test_rfh(),
- scoped_refptr<net::HttpResponseHeaders>(),
base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult,
base::Unretained(this)));
}
@@ -183,80 +150,46 @@
CreateTestNavigationThrottle(NavigationThrottle::DEFER);
EXPECT_FALSE(IsDeferringStart());
EXPECT_FALSE(IsDeferringRedirect());
- EXPECT_FALSE(IsDeferringResponse());
- EXPECT_EQ(0, test_throttle->will_start_calls());
- EXPECT_EQ(0, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
+ EXPECT_EQ(0, test_throttle->will_start_calls());
+ EXPECT_EQ(0, test_throttle->will_redirect_calls());
// Simulate WillStartRequest. The request should be deferred. The callback
// should not have been called.
SimulateWillStartRequest();
EXPECT_TRUE(IsDeferringStart());
EXPECT_FALSE(IsDeferringRedirect());
- EXPECT_FALSE(IsDeferringResponse());
- EXPECT_FALSE(was_callback_called());
- EXPECT_EQ(1, test_throttle->will_start_calls());
- EXPECT_EQ(0, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
+ EXPECT_FALSE(was_callback_called());
+ EXPECT_EQ(1, test_throttle->will_start_calls());
+ EXPECT_EQ(0, test_throttle->will_redirect_calls());
// Resume the request. It should no longer be deferred and the callback
// should have been called.
test_handle()->Resume();
EXPECT_FALSE(IsDeferringStart());
EXPECT_FALSE(IsDeferringRedirect());
- EXPECT_FALSE(IsDeferringResponse());
EXPECT_TRUE(was_callback_called());
EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
EXPECT_EQ(1, test_throttle->will_start_calls());
EXPECT_EQ(0, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
// Simulate WillRedirectRequest. The request should be deferred. The callback
// should not have been called.
SimulateWillRedirectRequest();
EXPECT_FALSE(IsDeferringStart());
EXPECT_TRUE(IsDeferringRedirect());
- EXPECT_FALSE(IsDeferringResponse());
EXPECT_FALSE(was_callback_called());
EXPECT_EQ(1, test_throttle->will_start_calls());
EXPECT_EQ(1, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
// Resume the request. It should no longer be deferred and the callback
// should have been called.
test_handle()->Resume();
EXPECT_FALSE(IsDeferringStart());
EXPECT_FALSE(IsDeferringRedirect());
- EXPECT_FALSE(IsDeferringResponse());
EXPECT_TRUE(was_callback_called());
EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
EXPECT_EQ(1, test_throttle->will_start_calls());
EXPECT_EQ(1, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
-
- // Simulate WillProcessResponse. It will be deferred. The callback should not
- // have been called.
- SimulateWillProcessResponse();
- EXPECT_FALSE(IsDeferringStart());
- EXPECT_FALSE(IsDeferringRedirect());
- EXPECT_TRUE(IsDeferringResponse());
- EXPECT_FALSE(was_callback_called());
- EXPECT_EQ(1, test_throttle->will_start_calls());
- EXPECT_EQ(1, test_throttle->will_redirect_calls());
- EXPECT_EQ(1, test_throttle->will_process_response_calls());
-
- // Resume the request. It should no longer be deferred and the callback should
- // have been called.
- test_handle()->Resume();
- EXPECT_FALSE(IsDeferringStart());
- EXPECT_FALSE(IsDeferringRedirect());
- EXPECT_FALSE(IsDeferringResponse());
- EXPECT_TRUE(was_callback_called());
- EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
- EXPECT_EQ(1, test_throttle->will_start_calls());
- EXPECT_EQ(1, test_throttle->will_redirect_calls());
- EXPECT_EQ(1, test_throttle->will_process_response_calls());
- EXPECT_TRUE(test_handle()->GetRenderFrameHost());
}
// Checks that a navigation deferred during WillStartRequest can be properly
@@ -268,7 +201,6 @@
EXPECT_FALSE(IsDeferringRedirect());
EXPECT_EQ(0, test_throttle->will_start_calls());
EXPECT_EQ(0, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
// Simulate WillStartRequest. The request should be deferred. The callback
// should not have been called.
@@ -278,7 +210,6 @@
EXPECT_FALSE(was_callback_called());
EXPECT_EQ(1, test_throttle->will_start_calls());
EXPECT_EQ(0, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
// Cancel the request. The callback should have been called.
test_handle()->CancelDeferredNavigation(
@@ -290,7 +221,6 @@
EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
EXPECT_EQ(1, test_throttle->will_start_calls());
EXPECT_EQ(0, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
}
// Checks that a navigation deferred during WillRedirectRequest can be properly
@@ -302,7 +232,6 @@
EXPECT_FALSE(IsDeferringRedirect());
EXPECT_EQ(0, test_throttle->will_start_calls());
EXPECT_EQ(0, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
// Simulate WillRedirectRequest. The request should be deferred. The callback
// should not have been called.
@@ -312,7 +241,6 @@
EXPECT_FALSE(was_callback_called());
EXPECT_EQ(0, test_throttle->will_start_calls());
EXPECT_EQ(1, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
// Cancel the request. The callback should have been called.
test_handle()->CancelDeferredNavigation(
@@ -324,7 +252,6 @@
EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
EXPECT_EQ(0, test_throttle->will_start_calls());
EXPECT_EQ(1, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
}
// Checks that a navigation deferred can be canceled and not ignored.
@@ -335,7 +262,6 @@
EXPECT_FALSE(IsDeferringRedirect());
EXPECT_EQ(0, test_throttle->will_start_calls());
EXPECT_EQ(0, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
// Simulate WillRedirectRequest. The request should be deferred. The callback
// should not have been called.
@@ -345,7 +271,6 @@
EXPECT_FALSE(was_callback_called());
EXPECT_EQ(1, test_throttle->will_start_calls());
EXPECT_EQ(0, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
// Cancel the request. The callback should have been called with CANCEL, and
// not CANCEL_AND_IGNORE.
@@ -357,7 +282,6 @@
EXPECT_EQ(NavigationThrottle::CANCEL, callback_result());
EXPECT_EQ(1, test_throttle->will_start_calls());
EXPECT_EQ(0, test_throttle->will_redirect_calls());
- EXPECT_EQ(0, test_throttle->will_process_response_calls());
}
// Checks that a NavigationThrottle asking to defer followed by a
@@ -371,10 +295,8 @@
EXPECT_FALSE(IsDeferringRedirect());
EXPECT_EQ(0, defer_throttle->will_start_calls());
EXPECT_EQ(0, defer_throttle->will_redirect_calls());
- EXPECT_EQ(0, defer_throttle->will_process_response_calls());
- EXPECT_EQ(0, proceed_throttle->will_start_calls());
- EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
- EXPECT_EQ(0, proceed_throttle->will_process_response_calls());
+ EXPECT_EQ(0, proceed_throttle->will_start_calls());
+ EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
// Simulate WillStartRequest. The request should be deferred. The callback
// should not have been called. The second throttle should not have been
@@ -385,7 +307,6 @@
EXPECT_FALSE(was_callback_called());
EXPECT_EQ(1, defer_throttle->will_start_calls());
EXPECT_EQ(0, defer_throttle->will_redirect_calls());
- EXPECT_EQ(0, defer_throttle->will_process_response_calls());
EXPECT_EQ(0, proceed_throttle->will_start_calls());
EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
@@ -398,7 +319,6 @@
EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
EXPECT_EQ(1, defer_throttle->will_start_calls());
EXPECT_EQ(0, defer_throttle->will_redirect_calls());
- EXPECT_EQ(0, defer_throttle->will_process_response_calls());
EXPECT_EQ(1, proceed_throttle->will_start_calls());
EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
@@ -411,7 +331,6 @@
EXPECT_FALSE(was_callback_called());
EXPECT_EQ(1, defer_throttle->will_start_calls());
EXPECT_EQ(1, defer_throttle->will_redirect_calls());
- EXPECT_EQ(0, defer_throttle->will_process_response_calls());
EXPECT_EQ(1, proceed_throttle->will_start_calls());
EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
@@ -424,7 +343,6 @@
EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
EXPECT_EQ(1, defer_throttle->will_start_calls());
EXPECT_EQ(1, defer_throttle->will_redirect_calls());
- EXPECT_EQ(0, defer_throttle->will_process_response_calls());
EXPECT_EQ(1, proceed_throttle->will_start_calls());
EXPECT_EQ(1, proceed_throttle->will_redirect_calls());
}
@@ -440,7 +358,6 @@
EXPECT_FALSE(IsDeferringRedirect());
EXPECT_EQ(0, defer_throttle->will_start_calls());
EXPECT_EQ(0, defer_throttle->will_redirect_calls());
- EXPECT_EQ(0, defer_throttle->will_process_response_calls());
EXPECT_EQ(0, cancel_throttle->will_start_calls());
EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
@@ -453,7 +370,6 @@
EXPECT_FALSE(was_callback_called());
EXPECT_EQ(1, defer_throttle->will_start_calls());
EXPECT_EQ(0, defer_throttle->will_redirect_calls());
- EXPECT_EQ(0, defer_throttle->will_process_response_calls());
EXPECT_EQ(0, cancel_throttle->will_start_calls());
EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
@@ -467,7 +383,6 @@
EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
EXPECT_EQ(1, defer_throttle->will_start_calls());
EXPECT_EQ(0, defer_throttle->will_redirect_calls());
- EXPECT_EQ(0, defer_throttle->will_process_response_calls());
EXPECT_EQ(1, cancel_throttle->will_start_calls());
EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
}
@@ -483,7 +398,6 @@
EXPECT_FALSE(IsDeferringRedirect());
EXPECT_EQ(0, defer_throttle->will_start_calls());
EXPECT_EQ(0, defer_throttle->will_redirect_calls());
- EXPECT_EQ(0, defer_throttle->will_process_response_calls());
EXPECT_EQ(0, cancel_throttle->will_start_calls());
EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
@@ -496,7 +410,6 @@
EXPECT_FALSE(was_callback_called());
EXPECT_EQ(0, defer_throttle->will_start_calls());
EXPECT_EQ(1, defer_throttle->will_redirect_calls());
- EXPECT_EQ(0, defer_throttle->will_process_response_calls());
EXPECT_EQ(0, cancel_throttle->will_start_calls());
EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
@@ -510,7 +423,6 @@
EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
EXPECT_EQ(0, defer_throttle->will_start_calls());
EXPECT_EQ(1, defer_throttle->will_redirect_calls());
- EXPECT_EQ(0, defer_throttle->will_process_response_calls());
EXPECT_EQ(0, cancel_throttle->will_start_calls());
EXPECT_EQ(1, cancel_throttle->will_redirect_calls());
}
@@ -528,7 +440,6 @@
EXPECT_FALSE(IsDeferringRedirect());
EXPECT_EQ(0, cancel_throttle->will_start_calls());
EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
- EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
EXPECT_EQ(0, proceed_throttle->will_start_calls());
EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
@@ -542,7 +453,6 @@
EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
EXPECT_EQ(1, cancel_throttle->will_start_calls());
EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
- EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
EXPECT_EQ(0, proceed_throttle->will_start_calls());
EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
}
@@ -560,7 +470,6 @@
EXPECT_FALSE(IsDeferringRedirect());
EXPECT_EQ(0, cancel_throttle->will_start_calls());
EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
- EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
EXPECT_EQ(0, proceed_throttle->will_start_calls());
EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
@@ -574,74 +483,8 @@
EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
EXPECT_EQ(0, cancel_throttle->will_start_calls());
EXPECT_EQ(1, cancel_throttle->will_redirect_calls());
- EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
- EXPECT_EQ(0, proceed_throttle->will_start_calls());
- EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
-}
-
-// Checks that a NavigationThrottle asking to proceed followed by a
-// NavigationThrottle asking to cancel behave correctly in WillProcessResponse.
-// Both throttles will be called, and the request will be cancelled.
-TEST_F(NavigationHandleImplTest, ProceedThenCancelWillProcessResponse) {
- TestNavigationThrottle* proceed_throttle =
- CreateTestNavigationThrottle(NavigationThrottle::PROCEED);
- TestNavigationThrottle* cancel_throttle =
- CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
- EXPECT_FALSE(IsDeferringStart());
- EXPECT_FALSE(IsDeferringRedirect());
- EXPECT_EQ(0, cancel_throttle->will_start_calls());
- EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
- EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
- EXPECT_EQ(0, proceed_throttle->will_start_calls());
- EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
- EXPECT_EQ(0, proceed_throttle->will_process_response_calls());
-
- // Simulate WillRedirectRequest. The request should not be deferred. The
- // callback should have been called.
- SimulateWillProcessResponse();
- EXPECT_FALSE(IsDeferringStart());
- EXPECT_FALSE(IsDeferringRedirect());
- EXPECT_TRUE(was_callback_called());
- EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
- EXPECT_EQ(0, cancel_throttle->will_start_calls());
- EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
- EXPECT_EQ(1, cancel_throttle->will_process_response_calls());
- EXPECT_EQ(0, proceed_throttle->will_start_calls());
- EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
- EXPECT_EQ(1, proceed_throttle->will_process_response_calls());
-}
-
-// Checks that a NavigationThrottle asking to cancel followed by a
-// NavigationThrottle asking to proceed behave correctly in WillProcessResponse.
-// The navigation will be canceled directly, and the second throttle will not
-// be called.
-TEST_F(NavigationHandleImplTest, CancelThenProceedWillProcessResponse) {
- TestNavigationThrottle* cancel_throttle =
- CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
- TestNavigationThrottle* proceed_throttle =
- CreateTestNavigationThrottle(NavigationThrottle::PROCEED);
- EXPECT_FALSE(IsDeferringStart());
- EXPECT_FALSE(IsDeferringRedirect());
- EXPECT_EQ(0, cancel_throttle->will_start_calls());
- EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
- EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
- EXPECT_EQ(0, proceed_throttle->will_start_calls());
- EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
-
- // Simulate WillRedirectRequest. The request should not be deferred. The
- // callback should have been called. The second throttle should not have
- // been notified.
- SimulateWillProcessResponse();
- EXPECT_FALSE(IsDeferringStart());
- EXPECT_FALSE(IsDeferringRedirect());
- EXPECT_TRUE(was_callback_called());
- EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
- EXPECT_EQ(0, cancel_throttle->will_start_calls());
- EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
- EXPECT_EQ(1, cancel_throttle->will_process_response_calls());
- EXPECT_EQ(0, proceed_throttle->will_start_calls());
- EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
- EXPECT_EQ(0, proceed_throttle->will_process_response_calls());
+ EXPECT_EQ(0, proceed_throttle->will_start_calls());
+ EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
}
} // namespace content
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.cc ('k') | content/browser/loader/navigation_resource_throttle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698