Index: net/proxy/proxy_resolver_v8_tracing_wrapper_unittest.cc |
diff --git a/net/proxy/proxy_resolver_v8_tracing_wrapper_unittest.cc b/net/proxy/proxy_resolver_v8_tracing_wrapper_unittest.cc |
index 19ab3cd65a8dc4756c33a1e709c6172993d8a256..53cb1cbb7a8b259793af92f72df3866c1510097c 100644 |
--- a/net/proxy/proxy_resolver_v8_tracing_wrapper_unittest.cc |
+++ b/net/proxy/proxy_resolver_v8_tracing_wrapper_unittest.cc |
@@ -136,9 +136,10 @@ TEST_F(ProxyResolverV8TracingWrapperTest, Simple) { |
TestCompletionCallback callback; |
ProxyInfo proxy_info; |
+ std::unique_ptr<ProxyResolver::Request> req; |
int rv = |
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
- callback.callback(), NULL, request_log.bound()); |
+ callback.callback(), &req, request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback.WaitForResult(), IsOk()); |
@@ -167,9 +168,10 @@ TEST_F(ProxyResolverV8TracingWrapperTest, JavascriptError) { |
TestCompletionCallback callback; |
ProxyInfo proxy_info; |
+ std::unique_ptr<ProxyResolver::Request> req; |
int rv = |
resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info, |
- callback.callback(), NULL, request_log.bound()); |
+ callback.callback(), &req, request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback.WaitForResult(), IsError(ERR_PAC_SCRIPT_FAILED)); |
@@ -218,9 +220,10 @@ TEST_F(ProxyResolverV8TracingWrapperTest, TooManyAlerts) { |
TestCompletionCallback callback; |
ProxyInfo proxy_info; |
+ std::unique_ptr<ProxyResolver::Request> req; |
int rv = |
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
- callback.callback(), NULL, request_log.bound()); |
+ callback.callback(), &req, request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback.WaitForResult(), IsOk()); |
@@ -267,9 +270,10 @@ TEST_F(ProxyResolverV8TracingWrapperTest, TooManyEmptyAlerts) { |
TestCompletionCallback callback; |
ProxyInfo proxy_info; |
+ std::unique_ptr<ProxyResolver::Request> req; |
int rv = |
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
- callback.callback(), NULL, request_log.bound()); |
+ callback.callback(), &req, request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback.WaitForResult(), IsOk()); |
@@ -325,9 +329,10 @@ TEST_F(ProxyResolverV8TracingWrapperTest, Dns) { |
TestCompletionCallback callback; |
ProxyInfo proxy_info; |
+ std::unique_ptr<ProxyResolver::Request> req; |
int rv = |
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
- callback.callback(), NULL, request_log.bound()); |
+ callback.callback(), &req, request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback.WaitForResult(), IsOk()); |
@@ -391,9 +396,10 @@ TEST_F(ProxyResolverV8TracingWrapperTest, DnsChecksCache) { |
TestCompletionCallback callback2; |
ProxyInfo proxy_info; |
+ std::unique_ptr<ProxyResolver::Request> req; |
int rv = |
resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, |
- callback1.callback(), NULL, request_log.bound()); |
+ callback1.callback(), &req, request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
@@ -404,9 +410,10 @@ TEST_F(ProxyResolverV8TracingWrapperTest, DnsChecksCache) { |
// The first request took 2 restarts, hence on g_iteration=3. |
EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI()); |
- rv = |
- resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info, |
- callback2.callback(), NULL, request_log.bound()); |
+ std::unique_ptr<ProxyResolver::Request> req2; |
+ rv = resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info, |
+ callback2.callback(), &req2, |
+ request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
@@ -443,9 +450,10 @@ TEST_F(ProxyResolverV8TracingWrapperTest, FallBackToSynchronous1) { |
TestCompletionCallback callback; |
ProxyInfo proxy_info; |
+ std::unique_ptr<ProxyResolver::Request> req; |
int rv = |
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
- callback.callback(), NULL, request_log.bound()); |
+ callback.callback(), &req, request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback.WaitForResult(), IsOk()); |
@@ -498,9 +506,10 @@ TEST_F(ProxyResolverV8TracingWrapperTest, FallBackToSynchronous2) { |
TestCompletionCallback callback; |
ProxyInfo proxy_info; |
+ std::unique_ptr<ProxyResolver::Request> req; |
int rv = |
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
- callback.callback(), NULL, request_log.bound()); |
+ callback.callback(), &req, request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback.WaitForResult(), IsOk()); |
@@ -536,9 +545,11 @@ TEST_F(ProxyResolverV8TracingWrapperTest, InfiniteDNSSequence) { |
TestCompletionCallback callback; |
ProxyInfo proxy_info; |
+ std::unique_ptr<ProxyResolver::Request> req; |
int rv = |
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
- callback.callback(), NULL, request_log.bound()); |
+ |
+ callback.callback(), &req, request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback.WaitForResult(), IsOk()); |
@@ -581,9 +592,10 @@ TEST_F(ProxyResolverV8TracingWrapperTest, InfiniteDNSSequence2) { |
TestCompletionCallback callback; |
ProxyInfo proxy_info; |
+ std::unique_ptr<ProxyResolver::Request> req; |
int rv = |
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
- callback.callback(), NULL, request_log.bound()); |
+ callback.callback(), &req, request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback.WaitForResult(), IsOk()); |
@@ -625,9 +637,10 @@ void DnsDuringInitHelper(bool synchronous_host_resolver) { |
TestCompletionCallback callback; |
ProxyInfo proxy_info; |
+ std::unique_ptr<ProxyResolver::Request> req; |
int rv = |
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
- callback.callback(), NULL, request_log.bound()); |
+ callback.callback(), &req, request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback.WaitForResult(), IsOk()); |
@@ -683,7 +696,7 @@ TEST_F(ProxyResolverV8TracingWrapperTest, CancelAll) { |
const size_t kNumRequests = 5; |
ProxyInfo proxy_info[kNumRequests]; |
- ProxyResolver::RequestHandle request[kNumRequests]; |
+ std::unique_ptr<ProxyResolver::Request> request[kNumRequests]; |
for (size_t i = 0; i < kNumRequests; ++i) { |
int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i], |
@@ -693,7 +706,7 @@ TEST_F(ProxyResolverV8TracingWrapperTest, CancelAll) { |
} |
for (size_t i = 0; i < kNumRequests; ++i) { |
- resolver->CancelRequest(request[i]); |
+ request[i].reset(); |
} |
} |
@@ -711,8 +724,8 @@ TEST_F(ProxyResolverV8TracingWrapperTest, CancelSome) { |
ProxyInfo proxy_info1; |
ProxyInfo proxy_info2; |
- ProxyResolver::RequestHandle request1; |
- ProxyResolver::RequestHandle request2; |
+ std::unique_ptr<ProxyResolver::Request> request1; |
+ std::unique_ptr<ProxyResolver::Request> request2; |
TestCompletionCallback callback; |
int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1, |
@@ -725,7 +738,7 @@ TEST_F(ProxyResolverV8TracingWrapperTest, CancelSome) { |
NetLogWithSource()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
- resolver->CancelRequest(request1); |
+ request1.reset(); |
EXPECT_THAT(callback.WaitForResult(), IsOk()); |
} |
@@ -743,8 +756,8 @@ TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhilePendingCompletionTask) { |
ProxyInfo proxy_info1; |
ProxyInfo proxy_info2; |
- ProxyResolver::RequestHandle request1; |
- ProxyResolver::RequestHandle request2; |
+ std::unique_ptr<ProxyResolver::Request> request1; |
+ std::unique_ptr<ProxyResolver::Request> request2; |
TestCompletionCallback callback; |
int rv = resolver->GetProxyForURL(GURL("http://throw-an-error/"), |
@@ -754,10 +767,10 @@ TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhilePendingCompletionTask) { |
// Wait until the first request has finished running on the worker thread. |
// Cancel the first request, while it has a pending completion task on |
- // the origin thread. |
- error_observer->RunOnError(base::Bind(&ProxyResolver::CancelRequest, |
- base::Unretained(resolver.get()), |
- request1)); |
+ // the origin thread. Reset deletes Request object which cancels the request. |
+ error_observer->RunOnError( |
+ base::Bind(&std::unique_ptr<ProxyResolver::Request>::reset, |
+ base::Unretained(&request1), nullptr)); |
// Start another request, to make sure it is able to complete. |
rv = resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"), |
@@ -859,8 +872,8 @@ TEST_F(ProxyResolverV8TracingWrapperTest, |
ProxyInfo proxy_info1; |
ProxyInfo proxy_info2; |
- ProxyResolver::RequestHandle request1; |
- ProxyResolver::RequestHandle request2; |
+ std::unique_ptr<ProxyResolver::Request> request1; |
+ std::unique_ptr<ProxyResolver::Request> request2; |
int rv = resolver->GetProxyForURL(GURL("http://foo/req1"), &proxy_info1, |
base::Bind(&CrashCallback), &request1, |
@@ -878,8 +891,8 @@ TEST_F(ProxyResolverV8TracingWrapperTest, |
host_resolver.WaitUntilRequestIsReceived(); |
- resolver->CancelRequest(request1); |
- resolver->CancelRequest(request2); |
+ request1.reset(); |
+ request2.reset(); |
EXPECT_EQ(2, host_resolver.num_cancelled_requests()); |
@@ -888,9 +901,8 @@ TEST_F(ProxyResolverV8TracingWrapperTest, |
// should have been cancelled. |
} |
-void CancelRequestAndPause(ProxyResolver* resolver, |
- ProxyResolver::RequestHandle request) { |
- resolver->CancelRequest(request); |
+void CancelRequestAndPause(std::unique_ptr<ProxyResolver::Request>* request) { |
+ request->reset(); |
// Sleep for a little bit. This makes it more likely for the worker |
// thread to have returned from its call, and serves as a regression |
@@ -909,7 +921,7 @@ TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhileBlockedInNonBlockingDns) { |
nullptr, &host_resolver, base::WrapUnique(error_observer), "dns.js"); |
ProxyInfo proxy_info; |
- ProxyResolver::RequestHandle request; |
+ std::unique_ptr<ProxyResolver::Request> request; |
int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
base::Bind(&CrashCallback), &request, |
@@ -917,8 +929,7 @@ TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhileBlockedInNonBlockingDns) { |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
- host_resolver.SetAction( |
- base::Bind(CancelRequestAndPause, resolver.get(), request)); |
+ host_resolver.SetAction(base::Bind(CancelRequestAndPause, &request)); |
host_resolver.WaitUntilRequestIsReceived(); |
} |
@@ -933,7 +944,7 @@ TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhileBlockedInNonBlockingDns2) { |
nullptr, &host_resolver, base::WrapUnique(error_observer), "dns.js"); |
ProxyInfo proxy_info; |
- ProxyResolver::RequestHandle request; |
+ std::unique_ptr<ProxyResolver::Request> request; |
int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
base::Bind(&CrashCallback), &request, |
@@ -945,7 +956,7 @@ TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhileBlockedInNonBlockingDns2) { |
// work whatever the delay is here, but it is most useful if the delay |
// is large enough to allow a task to be posted back. |
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); |
- resolver->CancelRequest(request); |
+ request.reset(); |
EXPECT_EQ(0u, host_resolver.num_resolve()); |
} |
@@ -1032,9 +1043,10 @@ TEST_F(ProxyResolverV8TracingWrapperTest, Terminate) { |
TestCompletionCallback callback; |
ProxyInfo proxy_info; |
+ std::unique_ptr<ProxyResolver::Request> req; |
int rv = |
resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, |
- callback.callback(), NULL, request_log.bound()); |
+ callback.callback(), &req, request_log.bound()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
EXPECT_THAT(callback.WaitForResult(), IsOk()); |
@@ -1112,12 +1124,13 @@ TEST_F(ProxyResolverV8TracingWrapperTest, MultipleResolvers) { |
const size_t kNumResults = kNumResolvers * kNumIterations; |
TestCompletionCallback callback[kNumResults]; |
ProxyInfo proxy_info[kNumResults]; |
+ std::unique_ptr<ProxyResolver::Request> request[kNumResults]; |
for (size_t i = 0; i < kNumResults; ++i) { |
size_t resolver_i = i % kNumResolvers; |
int rv = resolver[resolver_i]->GetProxyForURL( |
- GURL("http://foo/"), &proxy_info[i], callback[i].callback(), NULL, |
- NetLogWithSource()); |
+ GURL("http://foo/"), &proxy_info[i], callback[i].callback(), |
+ &request[i], NetLogWithSource()); |
EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
} |