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

Unified Diff: net/proxy/proxy_resolver_v8_tracing_unittest.cc

Issue 1126513002: Add ProxyResolverFactoryV8Tracing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-proxy-refactor
Patch Set: Created 5 years, 8 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
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 729493775416729fc41066d029b19a9c8d452c4f..5add8baed24e239b0334dfdf27ecadb60a137fce 100644
--- a/net/proxy/proxy_resolver_v8_tracing_unittest.cc
+++ b/net/proxy/proxy_resolver_v8_tracing_unittest.cc
@@ -4,6 +4,8 @@
#include "net/proxy/proxy_resolver_v8_tracing.h"
+#include <string>
+
#include "base/files/file_util.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
@@ -60,12 +62,28 @@ scoped_refptr<ProxyResolverScriptData> LoadScriptData(const char* filename) {
return ProxyResolverScriptData::FromUTF8(file_contents);
}
-void InitResolver(ProxyResolverV8Tracing* resolver, const char* filename) {
+scoped_ptr<ProxyResolverErrorObserver> ReturnErrorObserver(
+ scoped_ptr<ProxyResolverErrorObserver> error_observer) {
+ return error_observer;
+}
+
+scoped_ptr<ProxyResolver> CreateResolver(
+ NetLog* net_log,
+ HostResolver* host_resolver,
+ scoped_ptr<ProxyResolverErrorObserver> error_observer,
+ const char* filename) {
+ scoped_ptr<ProxyResolver> resolver;
+ ProxyResolverFactoryV8Tracing factory(
+ host_resolver, net_log, ProxyResolver::LoadStateChangedCallback(),
+ base::Bind(&ReturnErrorObserver, base::Passed(&error_observer)));
TestCompletionCallback callback;
- int rv =
- resolver->SetPacScript(LoadScriptData(filename), callback.callback());
+ scoped_ptr<ProxyResolverFactory::Request> request;
+ int rv = factory.CreateProxyResolver(LoadScriptData(filename), &resolver,
+ callback.callback(), &request);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_TRUE(resolver);
+ return resolver.Pass();
}
class MockErrorObserver : public ProxyResolverErrorObserver {
@@ -102,16 +120,16 @@ TEST_F(ProxyResolverV8TracingTest, Simple) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
- InitResolver(&resolver, "simple.js");
+ scoped_ptr<ProxyResolver> resolver = CreateResolver(
+ &log, &host_resolver, make_scoped_ptr(error_observer), "simple.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"), &proxy_info, callback.callback(),
- NULL, request_log.bound());
+ int rv =
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -133,16 +151,16 @@ TEST_F(ProxyResolverV8TracingTest, JavascriptError) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
- InitResolver(&resolver, "error.js");
+ scoped_ptr<ProxyResolver> resolver = CreateResolver(
+ &log, &host_resolver, make_scoped_ptr(error_observer), "error.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv = resolver.GetProxyForURL(
- GURL("http://throw-an-error/"), &proxy_info, callback.callback(), NULL,
- request_log.bound());
+ int rv =
+ resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info,
+ callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult());
@@ -179,19 +197,17 @@ TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
- InitResolver(&resolver, "too_many_alerts.js");
+ scoped_ptr<ProxyResolver> resolver =
+ CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
+ "too_many_alerts.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"),
- &proxy_info,
- callback.callback(),
- NULL,
- request_log.bound());
+ int rv =
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -230,19 +246,17 @@ TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
- InitResolver(&resolver, "too_many_empty_alerts.js");
+ scoped_ptr<ProxyResolver> resolver =
+ CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
+ "too_many_empty_alerts.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"),
- &proxy_info,
- callback.callback(),
- NULL,
- request_log.bound());
+ int rv =
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -279,7 +293,6 @@ TEST_F(ProxyResolverV8TracingTest, Dns) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRuleForAddressFamily(
"host1", ADDRESS_FAMILY_IPV4, "166.155.144.44");
@@ -293,17 +306,15 @@ TEST_F(ProxyResolverV8TracingTest, Dns) {
"*", ADDRESS_FAMILY_IPV4, "122.133.144.155");
host_resolver.rules()->AddRule("*", "133.122.100.200");
- InitResolver(&resolver, "dns.js");
+ scoped_ptr<ProxyResolver> resolver = CreateResolver(
+ &log, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"),
- &proxy_info,
- callback.callback(),
- NULL,
- request_log.bound());
+ int rv =
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -356,23 +367,20 @@ TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("foopy", "166.155.144.11");
host_resolver.rules()->AddRule("*", "122.133.144.155");
- InitResolver(&resolver, "simple_dns.js");
+ scoped_ptr<ProxyResolver> resolver = CreateResolver(
+ &log, &host_resolver, make_scoped_ptr(error_observer), "simple_dns.js");
TestCompletionCallback callback1;
TestCompletionCallback callback2;
ProxyInfo proxy_info;
- int rv = resolver.GetProxyForURL(
- GURL("http://foopy/req1"),
- &proxy_info,
- callback1.callback(),
- NULL,
- request_log.bound());
+ int rv =
+ resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info,
+ callback1.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback1.WaitForResult());
@@ -383,12 +391,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());
- rv = resolver.GetProxyForURL(
- GURL("http://foopy/req2"),
- &proxy_info,
- callback2.callback(),
- NULL,
- request_log.bound());
+ rv =
+ resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info,
+ callback2.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback2.WaitForResult());
@@ -413,20 +418,21 @@ TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous1) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("host1", "166.155.144.11");
host_resolver.rules()->AddRule("crazy4", "133.199.111.4");
host_resolver.rules()->AddRule("*", "122.133.144.155");
- InitResolver(&resolver, "global_sideffects1.js");
+ scoped_ptr<ProxyResolver> resolver =
+ CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
+ "global_sideffects1.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"), &proxy_info, callback.callback(), NULL,
- request_log.bound());
+ int rv =
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -465,7 +471,6 @@ TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("host1", "166.155.144.11");
host_resolver.rules()->AddRule("host2", "166.155.144.22");
@@ -473,14 +478,16 @@ TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) {
host_resolver.rules()->AddRule("host4", "166.155.144.44");
host_resolver.rules()->AddRule("*", "122.133.144.155");
- InitResolver(&resolver, "global_sideffects2.js");
+ scoped_ptr<ProxyResolver> resolver =
+ CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
+ "global_sideffects2.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"), &proxy_info, callback.callback(), NULL,
- request_log.bound());
+ int rv =
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -505,19 +512,20 @@ TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("host*", "166.155.144.11");
host_resolver.rules()->AddRule("*", "122.133.144.155");
- InitResolver(&resolver, "global_sideffects3.js");
+ scoped_ptr<ProxyResolver> resolver =
+ CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
+ "global_sideffects3.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"), &proxy_info, callback.callback(), NULL,
- request_log.bound());
+ int rv =
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -548,19 +556,20 @@ TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("host*", "166.155.144.11");
host_resolver.rules()->AddRule("*", "122.133.144.155");
- InitResolver(&resolver, "global_sideffects4.js");
+ scoped_ptr<ProxyResolver> resolver =
+ CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
+ "global_sideffects4.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"), &proxy_info, callback.callback(), NULL,
- request_log.bound());
+ int rv =
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -582,12 +591,13 @@ void DnsDuringInitHelper(bool synchronous_host_resolver) {
MockCachingHostResolver host_resolver;
host_resolver.set_synchronous_mode(synchronous_host_resolver);
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("host1", "91.13.12.1");
host_resolver.rules()->AddRule("host2", "91.13.12.2");
- InitResolver(&resolver, "dns_during_init.js");
+ scoped_ptr<ProxyResolver> resolver =
+ CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
+ "dns_during_init.js");
// Initialization did 2 dnsResolves.
EXPECT_EQ(2u, host_resolver.num_resolve());
@@ -601,9 +611,9 @@ void DnsDuringInitHelper(bool synchronous_host_resolver) {
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"), &proxy_info, callback.callback(), NULL,
- request_log.bound());
+ int rv =
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -651,25 +661,25 @@ void CrashCallback(int) {
TEST_F(ProxyResolverV8TracingTest, CancelAll) {
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
host_resolver.rules()->AddSimulatedFailure("*");
- InitResolver(&resolver, "dns.js");
+ scoped_ptr<ProxyResolver> resolver = CreateResolver(
+ nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
const size_t kNumRequests = 5;
ProxyInfo proxy_info[kNumRequests];
ProxyResolver::RequestHandle request[kNumRequests];
for (size_t i = 0; i < kNumRequests; ++i) {
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"), &proxy_info[i],
- base::Bind(&CrashCallback), &request[i], BoundNetLog());
+ int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i],
+ base::Bind(&CrashCallback), &request[i],
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
}
for (size_t i = 0; i < kNumRequests; ++i) {
- resolver.CancelRequest(request[i]);
+ resolver->CancelRequest(request[i]);
}
}
@@ -679,11 +689,11 @@ TEST_F(ProxyResolverV8TracingTest, CancelAll) {
TEST_F(ProxyResolverV8TracingTest, CancelSome) {
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
host_resolver.rules()->AddSimulatedFailure("*");
- InitResolver(&resolver, "dns.js");
+ scoped_ptr<ProxyResolver> resolver = CreateResolver(
+ nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
ProxyInfo proxy_info1;
ProxyInfo proxy_info2;
@@ -691,17 +701,16 @@ TEST_F(ProxyResolverV8TracingTest, CancelSome) {
ProxyResolver::RequestHandle request2;
TestCompletionCallback callback;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"), &proxy_info1,
- base::Bind(&CrashCallback), &request1, BoundNetLog());
+ int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1,
+ base::Bind(&CrashCallback), &request1,
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- rv = resolver.GetProxyForURL(
- GURL("http://foo/"), &proxy_info2,
- callback.callback(), &request2, BoundNetLog());
+ rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info2,
+ callback.callback(), &request2, BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- resolver.CancelRequest(request1);
+ resolver->CancelRequest(request1);
EXPECT_EQ(OK, callback.WaitForResult());
}
@@ -711,11 +720,11 @@ TEST_F(ProxyResolverV8TracingTest, CancelSome) {
TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) {
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
host_resolver.rules()->AddSimulatedFailure("*");
- InitResolver(&resolver, "error.js");
+ scoped_ptr<ProxyResolver> resolver = CreateResolver(
+ nullptr, &host_resolver, make_scoped_ptr(error_observer), "error.js");
ProxyInfo proxy_info1;
ProxyInfo proxy_info2;
@@ -725,14 +734,13 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) {
ProxyResolver::RequestHandle request3;
TestCompletionCallback callback;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"), &proxy_info1,
- base::Bind(&CrashCallback), &request1, BoundNetLog());
+ int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1,
+ base::Bind(&CrashCallback), &request1,
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
- rv = resolver.GetProxyForURL(
- GURL("http://throw-an-error/"), &proxy_info2,
- callback.callback(), &request2, BoundNetLog());
+ rv = resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info2,
+ callback.callback(), &request2, BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
// Wait until the first request has finished running on the worker thread.
@@ -741,14 +749,14 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) {
// Cancel the first request, while it has a pending completion task on
// the origin thread.
- resolver.CancelRequest(request1);
+ resolver->CancelRequest(request1);
EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult());
// Start another request, to make sure it is able to complete.
- rv = resolver.GetProxyForURL(
- GURL("http://i-have-no-idea-what-im-doing/"), &proxy_info3,
- callback.callback(), &request3, BoundNetLog());
+ rv = resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"),
+ &proxy_info3, callback.callback(), &request3,
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -829,33 +837,33 @@ class BlockableHostResolver : public HostResolver {
TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) {
BlockableHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
- InitResolver(&resolver, "dns.js");
+ scoped_ptr<ProxyResolver> resolver = CreateResolver(
+ nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
ProxyInfo proxy_info1;
ProxyInfo proxy_info2;
ProxyResolver::RequestHandle request1;
ProxyResolver::RequestHandle request2;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/req1"), &proxy_info1,
- base::Bind(&CrashCallback), &request1, BoundNetLog());
+ int rv = resolver->GetProxyForURL(GURL("http://foo/req1"), &proxy_info1,
+ base::Bind(&CrashCallback), &request1,
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
host_resolver.WaitUntilRequestIsReceived();
- rv = resolver.GetProxyForURL(
- GURL("http://foo/req2"), &proxy_info2,
- base::Bind(&CrashCallback), &request2, BoundNetLog());
+ rv = resolver->GetProxyForURL(GURL("http://foo/req2"), &proxy_info2,
+ base::Bind(&CrashCallback), &request2,
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
host_resolver.WaitUntilRequestIsReceived();
- resolver.CancelRequest(request1);
- resolver.CancelRequest(request2);
+ resolver->CancelRequest(request1);
+ resolver->CancelRequest(request2);
EXPECT_EQ(2, host_resolver.num_cancelled_requests());
@@ -864,7 +872,7 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) {
// should have been cancelled.
}
-void CancelRequestAndPause(ProxyResolverV8Tracing* resolver,
+void CancelRequestAndPause(ProxyResolver* resolver,
ProxyResolver::RequestHandle request) {
resolver->CancelRequest(request);
@@ -880,21 +888,21 @@ void CancelRequestAndPause(ProxyResolverV8Tracing* resolver,
TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) {
BlockableHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
- InitResolver(&resolver, "dns.js");
+ scoped_ptr<ProxyResolver> resolver = CreateResolver(
+ nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
ProxyInfo proxy_info;
ProxyResolver::RequestHandle request;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"), &proxy_info,
- base::Bind(&CrashCallback), &request, BoundNetLog());
+ int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ base::Bind(&CrashCallback), &request,
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
host_resolver.SetAction(
- base::Bind(CancelRequestAndPause, &resolver, request));
+ base::Bind(CancelRequestAndPause, resolver.get(), request));
host_resolver.WaitUntilRequestIsReceived();
@@ -909,16 +917,16 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) {
TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) {
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
- InitResolver(&resolver, "dns.js");
+ scoped_ptr<ProxyResolver> resolver = CreateResolver(
+ nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
ProxyInfo proxy_info;
ProxyResolver::RequestHandle request;
- int rv = resolver.GetProxyForURL(
- GURL("http://foo/"), &proxy_info,
- base::Bind(&CrashCallback), &request, BoundNetLog());
+ int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ base::Bind(&CrashCallback), &request,
+ BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
@@ -926,28 +934,75 @@ 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);
+ resolver->CancelRequest(request);
EXPECT_EQ(0u, host_resolver.num_resolve());
}
-TEST_F(ProxyResolverV8TracingTest, CancelSetPacWhileOutstandingBlockingDns) {
+TEST_F(ProxyResolverV8TracingTest,
+ CancelCreateResolverWhileOutstandingBlockingDns) {
BlockableHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
+ ProxyResolverFactoryV8Tracing factory(
+ &host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(),
+ base::Bind(&ReturnErrorObserver,
+ base::Passed(make_scoped_ptr(error_observer))));
- int rv =
- resolver.SetPacScript(LoadScriptData("dns_during_init.js"),
- base::Bind(&CrashCallback));
+ scoped_ptr<ProxyResolver> resolver;
+ scoped_ptr<ProxyResolverFactory::Request> request;
+ int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"),
+ &resolver, base::Bind(&CrashCallback),
+ &request);
EXPECT_EQ(ERR_IO_PENDING, rv);
host_resolver.WaitUntilRequestIsReceived();
- resolver.CancelSetPacScript();
+ request.reset();
+ EXPECT_EQ(1, host_resolver.num_cancelled_requests());
+}
+
+TEST_F(ProxyResolverV8TracingTest, DeleteFactoryWhileOutstandingBlockingDns) {
+ BlockableHostResolver host_resolver;
+ MockErrorObserver* error_observer = new MockErrorObserver;
+
+ scoped_ptr<ProxyResolver> resolver;
+ scoped_ptr<ProxyResolverFactory::Request> request;
+ {
+ ProxyResolverFactoryV8Tracing factory(
+ &host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(),
+ base::Bind(&ReturnErrorObserver,
+ base::Passed(make_scoped_ptr(error_observer))));
+
+ int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"),
+ &resolver, base::Bind(&CrashCallback),
+ &request);
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ host_resolver.WaitUntilRequestIsReceived();
+ }
EXPECT_EQ(1, host_resolver.num_cancelled_requests());
}
+TEST_F(ProxyResolverV8TracingTest, ErrorLoadingScript) {
+ BlockableHostResolver host_resolver;
+ MockErrorObserver* error_observer = new MockErrorObserver;
+
+ ProxyResolverFactoryV8Tracing factory(
+ &host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(),
+ base::Bind(&ReturnErrorObserver,
+ base::Passed(make_scoped_ptr(error_observer))));
+
+ scoped_ptr<ProxyResolver> resolver;
+ scoped_ptr<ProxyResolverFactory::Request> request;
+ TestCompletionCallback callback;
+ int rv =
+ factory.CreateProxyResolver(LoadScriptData("error_on_load.js"), &resolver,
+ callback.callback(), &request);
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult());
+ EXPECT_FALSE(resolver);
+}
+
// This tests that the execution of a PAC script is terminated when the DNS
// dependencies are missing. If the test fails, then it will hang.
TEST_F(ProxyResolverV8TracingTest, Terminate) {
@@ -955,22 +1010,19 @@ TEST_F(ProxyResolverV8TracingTest, Terminate) {
BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
MockErrorObserver* error_observer = new MockErrorObserver;
- ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log);
host_resolver.rules()->AddRule("host1", "182.111.0.222");
host_resolver.rules()->AddRule("host2", "111.33.44.55");
- InitResolver(&resolver, "terminate.js");
+ scoped_ptr<ProxyResolver> resolver = CreateResolver(
+ &log, &host_resolver, make_scoped_ptr(error_observer), "terminate.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv = resolver.GetProxyForURL(
- GURL("http://foopy/req1"),
- &proxy_info,
- callback.callback(),
- NULL,
- request_log.bound());
+ int rv =
+ resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info,
+ callback.callback(), NULL, request_log.bound());
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -1007,39 +1059,39 @@ TEST_F(ProxyResolverV8TracingTest, MultipleResolvers) {
host_resolver0.rules()->AddRuleForAddressFamily(
"*", ADDRESS_FAMILY_IPV4, "122.133.144.155");
host_resolver0.rules()->AddRule("*", "133.122.100.200");
- ProxyResolverV8Tracing resolver0(
- &host_resolver0, new MockErrorObserver, NULL);
- InitResolver(&resolver0, "dns.js");
+ scoped_ptr<ProxyResolver> resolver0 =
+ CreateResolver(nullptr, &host_resolver0,
+ make_scoped_ptr(new MockErrorObserver), "dns.js");
// ------------------------
// Setup resolver1
// ------------------------
- ProxyResolverV8Tracing resolver1(
- &host_resolver0, new MockErrorObserver, NULL);
- InitResolver(&resolver1, "dns.js");
+ scoped_ptr<ProxyResolver> resolver1 =
+ CreateResolver(nullptr, &host_resolver0,
+ make_scoped_ptr(new MockErrorObserver), "dns.js");
// ------------------------
// Setup resolver2
// ------------------------
- ProxyResolverV8Tracing resolver2(
- &host_resolver0, new MockErrorObserver, NULL);
- InitResolver(&resolver2, "simple.js");
+ scoped_ptr<ProxyResolver> resolver2 =
+ CreateResolver(nullptr, &host_resolver0,
+ make_scoped_ptr(new MockErrorObserver), "simple.js");
// ------------------------
// Setup resolver3
// ------------------------
MockHostResolver host_resolver3;
host_resolver3.rules()->AddRule("foo", "166.155.144.33");
- ProxyResolverV8Tracing resolver3(
- &host_resolver3, new MockErrorObserver, NULL);
- InitResolver(&resolver3, "simple_dns.js");
+ scoped_ptr<ProxyResolver> resolver3 =
+ CreateResolver(nullptr, &host_resolver3,
+ make_scoped_ptr(new MockErrorObserver), "simple_dns.js");
// ------------------------
// Queue up work for each resolver (which will be running in parallel).
// ------------------------
- ProxyResolverV8Tracing* resolver[] = {
- &resolver0, &resolver1, &resolver2, &resolver3,
+ ProxyResolver* resolver[] = {
+ resolver0.get(), resolver1.get(), resolver2.get(), resolver3.get(),
};
const size_t kNumResolvers = arraysize(resolver);

Powered by Google App Engine
This is Rietveld 408576698