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

Unified Diff: net/proxy/proxy_resolver_v8_tracing_unittest.cc

Issue 2299963002: Reland "Change ProxyResolver::GetProxyForURL() to take a unique_ptr<Request>* " (Closed)
Patch Set: remove fields proposed by eroman Created 4 years, 2 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/proxy/proxy_resolver_v8_tracing.cc ('k') | net/proxy/proxy_resolver_v8_tracing_wrapper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/proxy_resolver_v8_tracing_unittest.cc
diff --git a/net/proxy/proxy_resolver_v8_tracing_unittest.cc b/net/proxy/proxy_resolver_v8_tracing_unittest.cc
index 6967491881b1a27897bf7cb153d57e598094421f..3456f559d82a3ec7e183d97a78e29c867f2853d8 100644
--- a/net/proxy/proxy_resolver_v8_tracing_unittest.cc
+++ b/net/proxy/proxy_resolver_v8_tracing_unittest.cc
@@ -165,9 +165,10 @@ TEST_F(ProxyResolverV8TracingTest, Simple) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
+ std::unique_ptr<ProxyResolver::Request> req;
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL,
+ callback.callback(), &req,
mock_bindings.CreateBindings());
EXPECT_THAT(callback.WaitForResult(), IsOk());
@@ -191,8 +192,9 @@ TEST_F(ProxyResolverV8TracingTest, JavascriptError) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
+ std::unique_ptr<ProxyResolver::Request> req;
resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info,
- callback.callback(), NULL,
+ callback.callback(), &req,
mock_bindings.CreateBindings());
EXPECT_THAT(callback.WaitForResult(), IsError(ERR_PAC_SCRIPT_FAILED));
@@ -218,8 +220,9 @@ TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
+ std::unique_ptr<ProxyResolver::Request> req;
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL,
+ callback.callback(), &req,
mock_bindings.CreateBindings());
EXPECT_THAT(callback.WaitForResult(), IsOk());
@@ -254,8 +257,9 @@ TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
+ std::unique_ptr<ProxyResolver::Request> req;
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL,
+ callback.callback(), &req,
mock_bindings.CreateBindings());
EXPECT_THAT(callback.WaitForResult(), IsOk());
@@ -300,8 +304,9 @@ TEST_F(ProxyResolverV8TracingTest, Dns) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
+ std::unique_ptr<ProxyResolver::Request> req;
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL,
+ callback.callback(), &req,
mock_bindings.CreateBindings());
EXPECT_THAT(callback.WaitForResult(), IsOk());
@@ -352,8 +357,9 @@ TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) {
TestCompletionCallback callback2;
ProxyInfo proxy_info;
+ std::unique_ptr<ProxyResolver::Request> req;
resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info,
- callback1.callback(), NULL,
+ callback1.callback(), &req,
mock_bindings.CreateBindings());
EXPECT_THAT(callback1.WaitForResult(), IsOk());
@@ -364,8 +370,9 @@ TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) {
// The first request took 2 restarts, hence on g_iteration=3.
EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI());
+ std::unique_ptr<ProxyResolver::Request> req2;
resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info,
- callback2.callback(), NULL,
+ callback2.callback(), &req2,
mock_bindings.CreateBindings());
EXPECT_THAT(callback2.WaitForResult(), IsOk());
@@ -397,8 +404,9 @@ TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous1) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
+ std::unique_ptr<ProxyResolver::Request> req;
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL,
+ callback.callback(), &req,
mock_bindings.CreateBindings());
EXPECT_THAT(callback.WaitForResult(), IsOk());
@@ -436,8 +444,9 @@ TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
+ std::unique_ptr<ProxyResolver::Request> req;
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL,
+ callback.callback(), &req,
mock_bindings.CreateBindings());
EXPECT_THAT(callback.WaitForResult(), IsOk());
@@ -467,8 +476,9 @@ TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
+ std::unique_ptr<ProxyResolver::Request> req;
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL,
+ callback.callback(), &req,
mock_bindings.CreateBindings());
EXPECT_THAT(callback.WaitForResult(), IsOk());
@@ -507,8 +517,9 @@ TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
+ std::unique_ptr<ProxyResolver::Request> req;
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL,
+ callback.callback(), &req,
mock_bindings.CreateBindings());
EXPECT_THAT(callback.WaitForResult(), IsOk());
@@ -547,8 +558,9 @@ void DnsDuringInitHelper(bool synchronous_host_resolver) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
+ std::unique_ptr<ProxyResolver::Request> req;
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL,
+ callback.callback(), &req,
mock_bindings.CreateBindings());
EXPECT_THAT(callback.WaitForResult(), IsOk());
@@ -593,7 +605,7 @@ TEST_F(ProxyResolverV8TracingTest, 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) {
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i],
@@ -602,7 +614,7 @@ TEST_F(ProxyResolverV8TracingTest, CancelAll) {
}
for (size_t i = 0; i < kNumRequests; ++i) {
- resolver->CancelRequest(request[i]);
+ request[i].reset();
}
}
@@ -620,8 +632,8 @@ TEST_F(ProxyResolverV8TracingTest, 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;
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1,
@@ -631,7 +643,7 @@ TEST_F(ProxyResolverV8TracingTest, CancelSome) {
callback.callback(), &request2,
mock_bindings.CreateBindings());
- resolver->CancelRequest(request1);
+ request1.reset();
EXPECT_THAT(callback.WaitForResult(), IsOk());
}
@@ -649,8 +661,8 @@ TEST_F(ProxyResolverV8TracingTest, 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;
resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info1,
@@ -659,10 +671,10 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) {
// Wait until the first request has finished running on the worker thread.
// Cancel the first request, while it is running its completion task on
- // the origin thread.
- mock_bindings.RunOnError(base::Bind(&ProxyResolverV8Tracing::CancelRequest,
- base::Unretained(resolver.get()),
- request1));
+ // the origin thread. Reset deletes Request opject which cancels the request.
+ mock_bindings.RunOnError(
+ base::Bind(&std::unique_ptr<ProxyResolver::Request>::reset,
+ base::Unretained(&request1), nullptr));
// Start another request, to make sure it is able to complete.
resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"),
@@ -766,8 +778,8 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) {
ProxyInfo proxy_info1;
ProxyInfo proxy_info2;
- ProxyResolver::RequestHandle request1;
- ProxyResolver::RequestHandle request2;
+ std::unique_ptr<ProxyResolver::Request> request1;
+ std::unique_ptr<ProxyResolver::Request> request2;
resolver->GetProxyForURL(GURL("http://foo/req1"), &proxy_info1,
base::Bind(&CrashCallback), &request1,
@@ -781,8 +793,8 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) {
host_resolver.WaitUntilRequestIsReceived();
- resolver->CancelRequest(request1);
- resolver->CancelRequest(request2);
+ request1.reset();
+ request2.reset();
EXPECT_EQ(2, host_resolver.num_cancelled_requests());
@@ -791,9 +803,8 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) {
// should have been cancelled.
}
-void CancelRequestAndPause(ProxyResolverV8Tracing* 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
@@ -812,14 +823,13 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) {
CreateResolver(mock_bindings.CreateBindings(), "dns.js");
ProxyInfo proxy_info;
- ProxyResolver::RequestHandle request;
+ std::unique_ptr<ProxyResolver::Request> request;
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
base::Bind(&CrashCallback), &request,
mock_bindings.CreateBindings());
- host_resolver.SetAction(
- base::Bind(CancelRequestAndPause, resolver.get(), request));
+ host_resolver.SetAction(base::Bind(CancelRequestAndPause, &request));
host_resolver.WaitUntilRequestIsReceived();
}
@@ -834,7 +844,7 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) {
CreateResolver(mock_bindings.CreateBindings(), "dns.js");
ProxyInfo proxy_info;
- ProxyResolver::RequestHandle request;
+ std::unique_ptr<ProxyResolver::Request> request;
resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
base::Bind(&CrashCallback), &request,
@@ -844,7 +854,7 @@ TEST_F(ProxyResolverV8TracingTest, 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());
}
@@ -918,8 +928,9 @@ TEST_F(ProxyResolverV8TracingTest, Terminate) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
+ std::unique_ptr<ProxyResolver::Request> req;
resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info,
- callback.callback(), NULL,
+ callback.callback(), &req,
mock_bindings.CreateBindings());
EXPECT_THAT(callback.WaitForResult(), IsOk());
@@ -991,13 +1002,14 @@ TEST_F(ProxyResolverV8TracingTest, 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;
resolver[resolver_i]->GetProxyForURL(
- GURL("http://foo/"), &proxy_info[i], callback[i].callback(), NULL,
- resolver_i == 3 ? mock_bindings3.CreateBindings()
- : mock_bindings0.CreateBindings());
+ GURL("http://foo/"), &proxy_info[i], callback[i].callback(),
+ &request[i], resolver_i == 3 ? mock_bindings3.CreateBindings()
+ : mock_bindings0.CreateBindings());
}
// ------------------------
« no previous file with comments | « net/proxy/proxy_resolver_v8_tracing.cc ('k') | net/proxy/proxy_resolver_v8_tracing_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698