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

Unified Diff: net/url_request/url_request_http_job_unittest.cc

Issue 2519473002: Fixes the cache lock issue. (Closed)
Patch Set: Feedback addressed Created 3 years, 10 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
« no previous file with comments | « net/log/net_log_event_type_list.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_http_job_unittest.cc
diff --git a/net/url_request/url_request_http_job_unittest.cc b/net/url_request/url_request_http_job_unittest.cc
index dbaea28f76e0115df4041995cea3b3a60e93bfeb..ff622dac30950d3148c289b620c8562329073749 100644
--- a/net/url_request/url_request_http_job_unittest.cc
+++ b/net/url_request/url_request_http_job_unittest.cc
@@ -359,6 +359,59 @@ TEST_F(URLRequestHttpJobWithMockSocketsTest, TestContentLengthFailedRequest) {
network_delegate_.total_network_bytes_received());
}
+// Similar to the test above except it creates multiple URL Requests so that
+// when one fails, the other is in the validation stage due to Shared Writing.
+TEST_F(URLRequestHttpJobWithMockSocketsTest, TestContentLengthFailedRequest2) {
+ MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
+ MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
+ "Content-Length: 20\r\n\r\n"),
+ MockRead("Test Content"),
+ MockRead(net::SYNCHRONOUS, net::ERR_FAILED)};
+
+ int kNumRequests = 3;
+
+ StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
+ arraysize(writes));
+ StaticSocketDataProvider socket_data1(reads, arraysize(reads), writes,
+ arraysize(writes));
+
+ StaticSocketDataProvider socket_data2(reads, arraysize(reads), writes,
+ arraysize(writes));
+
+ socket_factory_.AddSocketDataProvider(&socket_data);
+ socket_factory_.AddSocketDataProvider(&socket_data1);
+ socket_factory_.AddSocketDataProvider(&socket_data2);
+
+ std::vector<TestDelegate> delegates(kNumRequests);
+ std::vector<std::unique_ptr<URLRequest>> requests(kNumRequests);
+
+ for (int i = 0; i < kNumRequests; i++) {
+ requests[i] = context_->CreateRequest(GURL("http://www.example.com"),
+ DEFAULT_PRIORITY, &delegates[i]);
+ requests[i]->Start();
+ ASSERT_TRUE(requests[i]->is_pending());
+ }
+
+ base::RunLoop().Run();
+
+ EXPECT_THAT(delegates[0].request_status(), IsError(ERR_FAILED));
+ EXPECT_EQ(12, requests[0]->received_response_content_length());
+ EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
+ requests[0]->GetTotalSentBytes());
+ EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
+ requests[0]->GetTotalReceivedBytes());
+ // [1] request does not read the response body since its failed when current
+ // writer transaction receives a network failure. [2] has not yet started so
+ // it goes ahead and reads the response body.
+ EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
+ requests[2]->GetTotalReceivedBytes());
+ EXPECT_EQ(3 * CountWriteBytes(writes, arraysize(writes)),
+ network_delegate_.total_network_bytes_sent());
+ // Hardcoding this number since [1] only receives the headers.
+ EXPECT_EQ(2 * CountReadBytes(reads, arraysize(reads)) + 39,
+ network_delegate_.total_network_bytes_received());
+}
+
TEST_F(URLRequestHttpJobWithMockSocketsTest,
TestContentLengthCancelledRequest) {
MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
« no previous file with comments | « net/log/net_log_event_type_list.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698