ResourceLoader: Fix a bunch of double-cancellation/double-error notification cases.
There are a number of cases where ResourceLoader ends up notifying ResourceHandlers
twice of the same failure. This CL fixes them and adds some tests.
It also makes URLRequest no longer post notification on sync read errors, which was
causing double notifications in one of those cases.
Also fixes two other URLRequest consumers that depended on that behavior.
BUG=669709,670400
Review-Url: https://codereview.chromium.org/2542843006
Cr-Commit-Position: refs/heads/master@{#437057}
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 61994643..60920ef3 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -5549,7 +5549,7 @@
EXPECT_EQ("None", d.data_received());
}
-TEST_F(URLRequestTestHTTP, CancelTest) {
+TEST_F(URLRequestTestHTTP, CancelAfterStart) {
TestDelegate d;
{
std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
@@ -5570,7 +5570,7 @@
}
}
-TEST_F(URLRequestTestHTTP, CancelTest2) {
+TEST_F(URLRequestTestHTTP, CancelInResponseStarted) {
ASSERT_TRUE(http_test_server()->Start());
TestDelegate d;
@@ -5592,12 +5592,35 @@
}
}
-TEST_F(URLRequestTestHTTP, CancelTest3) {
+TEST_F(URLRequestTestHTTP, CancelOnDataReceived) {
ASSERT_TRUE(http_test_server()->Start());
TestDelegate d;
{
std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
+ http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d));
+
+ d.set_cancel_in_received_data(true);
+
+ r->Start();
+ EXPECT_TRUE(r->is_pending());
+
+ base::RunLoop().Run();
+
+ EXPECT_EQ(1, d.response_started_count());
+ EXPECT_NE(0, d.received_bytes_count());
+ EXPECT_FALSE(d.received_data_before_response());
+ EXPECT_EQ(ERR_ABORTED, d.request_status());
+ }
+}
+
+TEST_F(URLRequestTestHTTP, CancelDuringEofRead) {
+ ASSERT_TRUE(http_test_server()->Start());
+
+ TestDelegate d;
+ {
+ // This returns an empty response (With headers).
+ std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d));
d.set_cancel_in_received_data(true);
@@ -5608,16 +5631,13 @@
base::RunLoop().Run();
EXPECT_EQ(1, d.response_started_count());
- // There is no guarantee about how much data was received
- // before the cancel was issued. It could have been 0 bytes,
- // or it could have been all the bytes.
- // EXPECT_EQ(0, d.bytes_received());
+ EXPECT_EQ(0, d.received_bytes_count());
EXPECT_FALSE(d.received_data_before_response());
EXPECT_EQ(ERR_ABORTED, d.request_status());
}
}
-TEST_F(URLRequestTestHTTP, CancelTest4) {
+TEST_F(URLRequestTestHTTP, CancelByDestroyingAfterStart) {
ASSERT_TRUE(http_test_server()->Start());
TestDelegate d;
@@ -5643,7 +5663,7 @@
EXPECT_EQ(0, d.bytes_received());
}
-TEST_F(URLRequestTestHTTP, CancelTest5) {
+TEST_F(URLRequestTestHTTP, CancelWhileReadingFromCache) {
ASSERT_TRUE(http_test_server()->Start());
// populate cache