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

Unified Diff: net/url_request/url_request_unittest.cc

Issue 10911151: URLRequestHttpJob::StartTransaction should honour network delegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove code duplication + disable *CancelRequest* tests in Chrome Frame Created 8 years, 3 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/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_unittest.cc
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 42e8e6ef7296db3241f2ebb2f7bfd6614d8d618f..5ff08977ef701004562f69e36165a7acf3cd0ba1 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -2063,32 +2063,57 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) {
EXPECT_EQ(1, network_delegate.destroyed_requests());
}
-// Tests that the network delegate can cancel a request synchronously.
-TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) {
- ASSERT_TRUE(test_server_.Start());
+// Helper function for NetworkDelegateCancelRequestAsynchronously and
+// NetworkDelegateCancelRequestSynchronously. Sets up a blocking network
+// delegate operating in |block_mode| and a request for |url|. It blocks the
+// request in various tages and cancels it with ERR_BLOCKED_BY_CLIENT.
+void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode,
+ const GURL& url) {
+ static const BlockingNetworkDelegate::Stage blocking_stages[] = {
+ BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST,
erikwright (departed) 2012/09/26 15:41:42 Could you just make the blocking stage a parameter
vabr (Chromium) 2012/09/26 16:04:08 Done. I disabled all of them in Chrome Frame, exce
+ BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS,
+ BlockingNetworkDelegate::ON_HEADERS_RECEIVED
+ };
- TestDelegate d;
- BlockingNetworkDelegate network_delegate(
- BlockingNetworkDelegate::SYNCHRONOUS);
- network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
- network_delegate.set_retval(ERR_EMPTY_RESPONSE);
+ for (size_t i = 0; i < arraysize(blocking_stages); ++i) {
+ TestDelegate d;
+ BlockingNetworkDelegate network_delegate(block_mode);
+ network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT);
+ network_delegate.set_block_on(blocking_stages[i]);
- TestURLRequestContextWithProxy context(
- test_server_.host_port_pair().ToString(),
- &network_delegate);
+ TestURLRequestContext context(true);
+ context.set_network_delegate(&network_delegate);
+ context.Init();
- {
- URLRequest r(test_server_.GetURL(""), &d, &context);
+ {
+ URLRequest r(url, &d, &context);
- r.Start();
- MessageLoop::current()->Run();
+ r.Start();
+ MessageLoop::current()->Run();
- EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
- EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error());
- EXPECT_EQ(1, network_delegate.created_requests());
- EXPECT_EQ(0, network_delegate.destroyed_requests());
+ EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
+ EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r.status().error());
+ EXPECT_EQ(1, network_delegate.created_requests());
+ EXPECT_EQ(0, network_delegate.destroyed_requests());
+ }
+ EXPECT_EQ(1, network_delegate.destroyed_requests());
}
- EXPECT_EQ(1, network_delegate.destroyed_requests());
+}
+
+// Tests that the network delegate can cancel a request synchronously in
+// various stages of the request.
+TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) {
+ ASSERT_TRUE(test_server_.Start());
+ NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS,
+ test_server_.GetURL(""));
+}
+
+// Tests that the network delegate can cancel a request asynchronously in
+// various stages of the request.
+TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously) {
+ ASSERT_TRUE(test_server_.Start());
+ NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK,
+ test_server_.GetURL(""));
}
// Tests that the network delegate can block and redirect a request to a new
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698