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

Unified Diff: net/proxy/proxy_resolver_v8_tracing_unittest.cc

Issue 1145153004: Split ProxyResolverV8Tracing into an implementation and a wrapper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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.h » ('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 296853c29bd9fcfca02f398ce50675640d256e7e..6eda3b854205b7bda20c2ded2dcbe99d233111e8 100644
--- a/net/proxy/proxy_resolver_v8_tracing_unittest.cc
+++ b/net/proxy/proxy_resolver_v8_tracing_unittest.cc
@@ -7,11 +7,8 @@
#include <string>
#include "base/files/file_util.h"
-#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
-#include "base/stl_util.h"
-#include "base/strings/string_util.h"
-#include "base/strings/stringprintf.h"
+#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/platform_thread.h"
@@ -21,11 +18,7 @@
#include "net/dns/host_cache.h"
#include "net/dns/mock_host_resolver.h"
#include "net/log/net_log.h"
-#include "net/log/test_net_log.h"
-#include "net/log/test_net_log_entry.h"
-#include "net/log/test_net_log_util.h"
#include "net/proxy/proxy_info.h"
-#include "net/proxy/proxy_resolver_error_observer.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
@@ -39,7 +32,7 @@ class ProxyResolverV8TracingTest : public testing::Test {
// Drain any pending messages, which may be left over from cancellation.
// This way they get reliably run as part of the current test, rather than
// spilling into the next test's execution.
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
};
@@ -62,154 +55,153 @@ scoped_refptr<ProxyResolverScriptData> LoadScriptData(const char* filename) {
return ProxyResolverScriptData::FromUTF8(file_contents);
}
-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;
- 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 {
+class MockBindings {
public:
- MockErrorObserver() : event_(true, false) {}
+ explicit MockBindings(HostResolver* host_resolver)
+ : host_resolver_(host_resolver), event_(true, false) {}
- void OnPACScriptError(int line_number, const base::string16& error) override {
- {
- base::AutoLock l(lock_);
- output += base::StringPrintf("Error: line %d: %s\n", line_number,
- base::UTF16ToASCII(error).c_str());
- }
+ void Alert(const base::string16& message) {
+ base::AutoLock l(lock_);
+ alerts_.push_back(base::UTF16ToASCII(message));
+ }
+ void OnError(int line_number, const base::string16& error) {
+ base::AutoLock l(lock_);
+ errors_.push_back(std::make_pair(line_number, base::UTF16ToASCII(error)));
event_.Signal();
}
- std::string GetOutput() {
+ HostResolver* host_resolver() { return host_resolver_; }
+
+ std::vector<std::string> GetAlerts() {
+ base::AutoLock l(lock_);
+ return alerts_;
+ }
+
+ std::vector<std::pair<int, std::string>> GetErrors() {
base::AutoLock l(lock_);
- return output;
+ return errors_;
}
- void WaitForOutput() {
- event_.Wait();
+ void WaitForError() { event_.Wait(); }
+
+ scoped_ptr<ProxyResolverV8Tracing::Bindings> CreateBindings() {
+ return make_scoped_ptr(new ForwardingBindings(this));
}
private:
+ class ForwardingBindings : public ProxyResolverV8Tracing::Bindings {
+ public:
+ ForwardingBindings(MockBindings* bindings) : bindings_(bindings) {}
+
+ // ProxyResolverV8Tracing::Bindings overrides.
+ void Alert(const base::string16& message) override {
+ bindings_->Alert(message);
+ }
+
+ void OnError(int line_number, const base::string16& error) override {
+ bindings_->OnError(line_number, error);
+ }
+
+ BoundNetLog GetBoundNetLog() override { return BoundNetLog(); }
+
+ HostResolver* GetHostResolver() override {
+ return bindings_->host_resolver();
+ }
+
+ private:
+ MockBindings* bindings_;
+ };
+
base::Lock lock_;
- std::string output;
+ std::vector<std::string> alerts_;
+ std::vector<std::pair<int, std::string>> errors_;
+ HostResolver* const host_resolver_;
base::WaitableEvent event_;
};
+scoped_ptr<ProxyResolverV8Tracing> CreateResolver(
+ scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings,
+ const char* filename) {
+ scoped_ptr<ProxyResolverV8Tracing> resolver;
+ scoped_ptr<ProxyResolverV8TracingFactory> factory(
+ ProxyResolverV8TracingFactory::Create());
+ TestCompletionCallback callback;
+ scoped_ptr<ProxyResolverFactory::Request> request;
+ factory->CreateProxyResolverV8Tracing(LoadScriptData(filename),
+ bindings.Pass(), &resolver,
+ callback.callback(), &request);
+ EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_TRUE(resolver);
+ return resolver.Pass();
+}
+
TEST_F(ProxyResolverV8TracingTest, Simple) {
- TestNetLog log;
- BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
- scoped_ptr<ProxyResolver> resolver = CreateResolver(
- &log, &host_resolver, make_scoped_ptr(error_observer), "simple.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "simple.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv =
- resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL, request_log.bound());
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL,
+ mock_bindings.CreateBindings());
- EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI());
EXPECT_EQ(0u, host_resolver.num_resolve());
- // There were no errors.
- EXPECT_EQ("", error_observer->GetOutput());
-
- // Check the NetLogs -- nothing was logged.
- EXPECT_EQ(0u, log.GetSize());
- EXPECT_EQ(0u, request_log.GetSize());
+ // There were no alerts or errors.
+ EXPECT_TRUE(mock_bindings.GetAlerts().empty());
+ EXPECT_TRUE(mock_bindings.GetErrors().empty());
}
TEST_F(ProxyResolverV8TracingTest, JavascriptError) {
- TestNetLog log;
- BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
- scoped_ptr<ProxyResolver> resolver = CreateResolver(
- &log, &host_resolver, make_scoped_ptr(error_observer), "error.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "error.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv =
- resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info,
- callback.callback(), NULL, request_log.bound());
+ resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info,
+ callback.callback(), NULL,
+ mock_bindings.CreateBindings());
- EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult());
EXPECT_EQ(0u, host_resolver.num_resolve());
- EXPECT_EQ("Error: line 5: Uncaught TypeError: Cannot read property 'split' "
- "of null\n", error_observer->GetOutput());
-
- // Check the NetLogs -- there was 1 alert and 1 javascript error, and they
- // were output to both the global log, and per-request log.
- TestNetLogEntry::List entries_list[2];
- log.GetEntries(&entries_list[0]);
- request_log.GetEntries(&entries_list[1]);
-
- for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) {
- const TestNetLogEntry::List& entries = entries_list[list_i];
- EXPECT_EQ(2u, entries.size());
- EXPECT_TRUE(
- LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT,
- NetLog::PHASE_NONE));
- EXPECT_TRUE(
- LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ERROR,
- NetLog::PHASE_NONE));
-
- EXPECT_EQ("{\"message\":\"Prepare to DIE!\"}", entries[0].GetParamsJson());
- EXPECT_EQ("{\"line_number\":5,\"message\":\"Uncaught TypeError: Cannot "
- "read property 'split' of null\"}", entries[1].GetParamsJson());
- }
+ // Check the output -- there was 1 alert and 1 javascript error.
+ ASSERT_EQ(1u, mock_bindings.GetAlerts().size());
+ EXPECT_EQ("Prepare to DIE!", mock_bindings.GetAlerts()[0]);
+ ASSERT_EQ(1u, mock_bindings.GetErrors().size());
+ EXPECT_EQ(5, mock_bindings.GetErrors()[0].first);
+ EXPECT_EQ("Uncaught TypeError: Cannot read property 'split' of null",
+ mock_bindings.GetErrors()[0].second);
}
TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) {
- TestNetLog log;
- BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
- scoped_ptr<ProxyResolver> resolver =
- CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
- "too_many_alerts.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "too_many_alerts.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv =
- resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL, request_log.bound());
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL,
+ mock_bindings.CreateBindings());
- EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
// Iteration1 does a DNS resolve
@@ -220,45 +212,32 @@ TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) {
EXPECT_EQ(1u, host_resolver.num_resolve());
// No errors.
- EXPECT_EQ("", error_observer->GetOutput());
-
- // Check the NetLogs -- the script generated 50 alerts, which were mirrored
- // to both the global and per-request logs.
- TestNetLogEntry::List entries_list[2];
- log.GetEntries(&entries_list[0]);
- request_log.GetEntries(&entries_list[1]);
-
- for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) {
- const TestNetLogEntry::List& entries = entries_list[list_i];
- EXPECT_EQ(50u, entries.size());
- for (size_t i = 0; i < entries.size(); ++i) {
- ASSERT_TRUE(
- LogContainsEvent(entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT,
- NetLog::PHASE_NONE));
- }
+ EXPECT_TRUE(mock_bindings.GetErrors().empty());
+
+ // Check the alerts -- the script generated 50 alerts.
+ std::vector<std::string> alerts = mock_bindings.GetAlerts();
+ ASSERT_EQ(50u, alerts.size());
+ for (size_t i = 0; i < alerts.size(); i++) {
+ EXPECT_EQ("Gee, all these alerts are silly!", alerts[i]);
}
}
// Verify that buffered alerts cannot grow unboundedly, even when the message is
// empty string.
TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) {
- TestNetLog log;
- BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
- scoped_ptr<ProxyResolver> resolver =
- CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
- "too_many_empty_alerts.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver = CreateResolver(
+ mock_bindings.CreateBindings(), "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());
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL,
+ mock_bindings.CreateBindings());
- EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI());
@@ -266,22 +245,13 @@ TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) {
EXPECT_EQ(1u, host_resolver.num_resolve());
// No errors.
- EXPECT_EQ("", error_observer->GetOutput());
-
- // Check the NetLogs -- the script generated 50 alerts, which were mirrored
- // to both the global and per-request logs.
- TestNetLogEntry::List entries_list[2];
- log.GetEntries(&entries_list[0]);
- request_log.GetEntries(&entries_list[1]);
-
- for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) {
- const TestNetLogEntry::List& entries = entries_list[list_i];
- EXPECT_EQ(1000u, entries.size());
- for (size_t i = 0; i < entries.size(); ++i) {
- ASSERT_TRUE(
- LogContainsEvent(entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT,
- NetLog::PHASE_NONE));
- }
+ EXPECT_TRUE(mock_bindings.GetErrors().empty());
+
+ // Check the alerts -- the script generated 1000 alerts.
+ std::vector<std::string> alerts = mock_bindings.GetAlerts();
+ ASSERT_EQ(1000u, alerts.size());
+ for (size_t i = 0; i < alerts.size(); i++) {
+ EXPECT_EQ("", alerts[i]);
}
}
@@ -289,10 +259,8 @@ TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) {
// verifies the final result, and that the underlying DNS resolver received
// the correct set of queries.
TEST_F(ProxyResolverV8TracingTest, Dns) {
- TestNetLog log;
- BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
host_resolver.rules()->AddRuleForAddressFamily(
"host1", ADDRESS_FAMILY_IPV4, "166.155.144.44");
@@ -306,17 +274,16 @@ TEST_F(ProxyResolverV8TracingTest, Dns) {
"*", ADDRESS_FAMILY_IPV4, "122.133.144.155");
host_resolver.rules()->AddRule("*", "133.122.100.200");
- scoped_ptr<ProxyResolver> resolver = CreateResolver(
- &log, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "dns.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv =
- resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL, request_log.bound());
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL,
+ mock_bindings.CreateBindings());
- EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
// The test does 13 DNS resolution, however only 7 of them are unique.
@@ -341,48 +308,34 @@ TEST_F(ProxyResolverV8TracingTest, Dns) {
EXPECT_EQ(kExpectedResult, proxy_info.proxy_server().ToURI());
// No errors.
- EXPECT_EQ("", error_observer->GetOutput());
-
- // Check the NetLogs -- the script generated 1 alert, mirrored to both
- // the per-request and global logs.
- TestNetLogEntry::List entries_list[2];
- log.GetEntries(&entries_list[0]);
- request_log.GetEntries(&entries_list[1]);
-
- for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) {
- const TestNetLogEntry::List& entries = entries_list[list_i];
- EXPECT_EQ(1u, entries.size());
- EXPECT_TRUE(
- LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT,
- NetLog::PHASE_NONE));
- EXPECT_EQ("{\"message\":\"iteration: 7\"}", entries[0].GetParamsJson());
- }
+ EXPECT_TRUE(mock_bindings.GetErrors().empty());
+
+ // The script generated 1 alert.
+ ASSERT_EQ(1u, mock_bindings.GetAlerts().size());
+ EXPECT_EQ("iteration: 7", mock_bindings.GetAlerts()[0]);
}
// This test runs a PAC script that does "myIpAddress()" followed by
// "dnsResolve()". This requires 2 restarts. However once the HostResolver's
// cache is warmed, subsequent calls should take 0 restarts.
TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) {
- TestNetLog log;
- BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
host_resolver.rules()->AddRule("foopy", "166.155.144.11");
host_resolver.rules()->AddRule("*", "122.133.144.155");
- scoped_ptr<ProxyResolver> resolver = CreateResolver(
- &log, &host_resolver, make_scoped_ptr(error_observer), "simple_dns.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "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());
+ resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info,
+ callback1.callback(), NULL,
+ mock_bindings.CreateBindings());
- EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback1.WaitForResult());
// The test does 2 DNS resolutions.
@@ -391,11 +344,10 @@ 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());
+ resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info,
+ callback2.callback(), NULL,
+ mock_bindings.CreateBindings());
- EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback2.WaitForResult());
EXPECT_EQ(4u, host_resolver.num_resolve());
@@ -403,37 +355,31 @@ TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) {
// This time no restarts were required, so g_iteration incremented by 1.
EXPECT_EQ("166.155.144.11:4", proxy_info.proxy_server().ToURI());
- // No errors.
- EXPECT_EQ("", error_observer->GetOutput());
-
- EXPECT_EQ(0u, log.GetSize());
- EXPECT_EQ(0u, request_log.GetSize());
+ // There were no alerts or errors.
+ EXPECT_TRUE(mock_bindings.GetAlerts().empty());
+ EXPECT_TRUE(mock_bindings.GetErrors().empty());
}
// This test runs a weird PAC script that was designed to defeat the DNS tracing
// optimization. The proxy resolver should detect the inconsistency and
// fall-back to synchronous mode execution.
TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous1) {
- TestNetLog log;
- BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
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");
- scoped_ptr<ProxyResolver> resolver =
- CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
- "global_sideffects1.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "global_sideffects1.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv =
- resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL, request_log.bound());
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL,
+ mock_bindings.CreateBindings());
EXPECT_EQ(OK, callback.WaitForResult());
// The script itself only does 2 DNS resolves per execution, however it
@@ -445,32 +391,18 @@ TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous1) {
proxy_info.proxy_server().ToURI());
// No errors.
- EXPECT_EQ("", error_observer->GetOutput());
-
- // Check the NetLogs -- the script generated 1 alert, mirrored to both
- // the per-request and global logs.
- TestNetLogEntry::List entries_list[2];
- log.GetEntries(&entries_list[0]);
- request_log.GetEntries(&entries_list[1]);
-
- for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) {
- const TestNetLogEntry::List& entries = entries_list[list_i];
- EXPECT_EQ(1u, entries.size());
- EXPECT_TRUE(
- LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT,
- NetLog::PHASE_NONE));
- EXPECT_EQ("{\"message\":\"iteration: 4\"}", entries[0].GetParamsJson());
- }
+ EXPECT_TRUE(mock_bindings.GetErrors().empty());
+
+ ASSERT_EQ(1u, mock_bindings.GetAlerts().size());
+ EXPECT_EQ("iteration: 4", mock_bindings.GetAlerts()[0]);
}
// This test runs a weird PAC script that was designed to defeat the DNS tracing
// optimization. The proxy resolver should detect the inconsistency and
// fall-back to synchronous mode execution.
TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) {
- TestNetLog log;
- BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
host_resolver.rules()->AddRule("host1", "166.155.144.11");
host_resolver.rules()->AddRule("host2", "166.155.144.22");
@@ -478,29 +410,24 @@ TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) {
host_resolver.rules()->AddRule("host4", "166.155.144.44");
host_resolver.rules()->AddRule("*", "122.133.144.155");
- scoped_ptr<ProxyResolver> resolver =
- CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
- "global_sideffects2.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "global_sideffects2.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv =
- resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL, request_log.bound());
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL,
+ mock_bindings.CreateBindings());
EXPECT_EQ(OK, callback.WaitForResult());
EXPECT_EQ(3u, host_resolver.num_resolve());
EXPECT_EQ("166.155.144.44:100", proxy_info.proxy_server().ToURI());
- // No errors.
- EXPECT_EQ("", error_observer->GetOutput());
-
- // Check the NetLogs -- nothing was logged.
- EXPECT_EQ(0u, log.GetSize());
- EXPECT_EQ(0u, request_log.GetSize());
+ // There were no alerts or errors.
+ EXPECT_TRUE(mock_bindings.GetAlerts().empty());
+ EXPECT_TRUE(mock_bindings.GetErrors().empty());
}
// This test runs a weird PAC script that yields a never ending sequence
@@ -508,25 +435,21 @@ TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) {
// DNS resolves per request limit (20) after which every DNS resolve will
// fail.
TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) {
- TestNetLog log;
- BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
host_resolver.rules()->AddRule("host*", "166.155.144.11");
host_resolver.rules()->AddRule("*", "122.133.144.155");
- scoped_ptr<ProxyResolver> resolver =
- CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
- "global_sideffects3.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "global_sideffects3.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv =
- resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL, request_log.bound());
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL,
+ mock_bindings.CreateBindings());
EXPECT_EQ(OK, callback.WaitForResult());
EXPECT_EQ(20u, host_resolver.num_resolve());
@@ -540,11 +463,11 @@ TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) {
"null:21", proxy_info.proxy_server().ToURI());
// No errors.
- EXPECT_EQ("", error_observer->GetOutput());
+ EXPECT_TRUE(mock_bindings.GetErrors().empty());
- // Check the NetLogs -- 1 alert was logged.
- EXPECT_EQ(1u, log.GetSize());
- EXPECT_EQ(1u, request_log.GetSize());
+ // 1 alert.
+ EXPECT_EQ(1u, mock_bindings.GetAlerts().size());
+ EXPECT_EQ("iteration: 21", mock_bindings.GetAlerts()[0]);
}
// This test runs a weird PAC script that yields a never ending sequence
@@ -552,25 +475,21 @@ TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) {
// DNS resolves per request limit (20) after which every DNS resolve will
// fail.
TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) {
- TestNetLog log;
- BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
host_resolver.rules()->AddRule("host*", "166.155.144.11");
host_resolver.rules()->AddRule("*", "122.133.144.155");
- scoped_ptr<ProxyResolver> resolver =
- CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
- "global_sideffects4.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "global_sideffects4.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv =
- resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- callback.callback(), NULL, request_log.bound());
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL,
+ mock_bindings.CreateBindings());
EXPECT_EQ(OK, callback.WaitForResult());
EXPECT_EQ(20u, host_resolver.num_resolve());
@@ -578,26 +497,23 @@ TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) {
EXPECT_EQ("null21:34", proxy_info.proxy_server().ToURI());
// No errors.
- EXPECT_EQ("", error_observer->GetOutput());
+ EXPECT_TRUE(mock_bindings.GetErrors().empty());
- // Check the NetLogs -- 1 alert was logged.
- EXPECT_EQ(1u, log.GetSize());
- EXPECT_EQ(1u, request_log.GetSize());
+ // 1 alert.
+ EXPECT_EQ(1u, mock_bindings.GetAlerts().size());
+ EXPECT_EQ("iteration: 21", mock_bindings.GetAlerts()[0]);
}
void DnsDuringInitHelper(bool synchronous_host_resolver) {
- TestNetLog log;
- BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
+ MockBindings mock_bindings(&host_resolver);
host_resolver.set_synchronous_mode(synchronous_host_resolver);
- MockErrorObserver* error_observer = new MockErrorObserver;
host_resolver.rules()->AddRule("host1", "91.13.12.1");
host_resolver.rules()->AddRule("host2", "91.13.12.2");
- scoped_ptr<ProxyResolver> resolver =
- CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer),
- "dns_during_init.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "dns_during_init.js");
// Initialization did 2 dnsResolves.
EXPECT_EQ(2u, host_resolver.num_resolve());
@@ -611,10 +527,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());
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ callback.callback(), NULL,
+ mock_bindings.CreateBindings());
EXPECT_EQ(OK, callback.WaitForResult());
// Fetched host1 and host2 again, since the ones done during initialization
@@ -624,21 +539,10 @@ void DnsDuringInitHelper(bool synchronous_host_resolver) {
EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99",
proxy_info.proxy_server().ToURI());
- // Check the NetLogs -- the script generated 2 alerts during initialization.
- EXPECT_EQ(0u, request_log.GetSize());
- TestNetLogEntry::List entries;
- log.GetEntries(&entries);
-
- ASSERT_EQ(2u, entries.size());
- EXPECT_TRUE(
- LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT,
- NetLog::PHASE_NONE));
- EXPECT_TRUE(
- LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT,
- NetLog::PHASE_NONE));
-
- EXPECT_EQ("{\"message\":\"Watsup\"}", entries[0].GetParamsJson());
- EXPECT_EQ("{\"message\":\"Watsup2\"}", entries[1].GetParamsJson());
+ // 2 alerts.
+ ASSERT_EQ(2u, mock_bindings.GetAlerts().size());
+ EXPECT_EQ("Watsup", mock_bindings.GetAlerts()[0]);
+ EXPECT_EQ("Watsup2", mock_bindings.GetAlerts()[1]);
}
// Tests a PAC script which does DNS resolves during initialization.
@@ -660,22 +564,21 @@ void CrashCallback(int) {
// times.
TEST_F(ProxyResolverV8TracingTest, CancelAll) {
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
host_resolver.rules()->AddSimulatedFailure("*");
- scoped_ptr<ProxyResolver> resolver = CreateResolver(
- nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "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());
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i],
+ base::Bind(&CrashCallback), &request[i],
+ mock_bindings.CreateBindings());
}
for (size_t i = 0; i < kNumRequests; ++i) {
@@ -688,12 +591,12 @@ TEST_F(ProxyResolverV8TracingTest, CancelAll) {
// times.
TEST_F(ProxyResolverV8TracingTest, CancelSome) {
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
host_resolver.rules()->AddSimulatedFailure("*");
- scoped_ptr<ProxyResolver> resolver = CreateResolver(
- nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "dns.js");
ProxyInfo proxy_info1;
ProxyInfo proxy_info2;
@@ -701,14 +604,12 @@ TEST_F(ProxyResolverV8TracingTest, CancelSome) {
ProxyResolver::RequestHandle request2;
TestCompletionCallback callback;
- 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());
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1,
+ base::Bind(&CrashCallback), &request1,
+ mock_bindings.CreateBindings());
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info2,
+ callback.callback(), &request2,
+ mock_bindings.CreateBindings());
resolver->CancelRequest(request1);
@@ -719,12 +620,12 @@ TEST_F(ProxyResolverV8TracingTest, CancelSome) {
// posted a task the completion task back to origin thread.
TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) {
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
host_resolver.rules()->AddSimulatedFailure("*");
- scoped_ptr<ProxyResolver> resolver = CreateResolver(
- nullptr, &host_resolver, make_scoped_ptr(error_observer), "error.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "error.js");
ProxyInfo proxy_info1;
ProxyInfo proxy_info2;
@@ -734,18 +635,17 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) {
ProxyResolver::RequestHandle request3;
TestCompletionCallback callback;
- int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1,
- base::Bind(&CrashCallback), &request1,
- BoundNetLog());
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1,
+ base::Bind(&CrashCallback), &request1,
+ mock_bindings.CreateBindings());
- rv = resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info2,
- callback.callback(), &request2, BoundNetLog());
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://throw-an-error"), &proxy_info2,
+ callback.callback(), &request2,
+ mock_bindings.CreateBindings());
// Wait until the first request has finished running on the worker thread.
// (The second request will output an error).
- error_observer->WaitForOutput();
+ mock_bindings.WaitForError();
// Cancel the first request, while it has a pending completion task on
// the origin thread.
@@ -754,10 +654,9 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) {
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());
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"),
+ &proxy_info3, callback.callback(), &request3,
+ mock_bindings.CreateBindings());
EXPECT_EQ(OK, callback.WaitForResult());
@@ -836,29 +735,25 @@ class BlockableHostResolver : public HostResolver {
// when the request has an outstanding DNS request in flight.
TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) {
BlockableHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
- scoped_ptr<ProxyResolver> resolver = CreateResolver(
- nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "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());
-
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foo/req1"), &proxy_info1,
+ base::Bind(&CrashCallback), &request1,
+ mock_bindings.CreateBindings());
host_resolver.WaitUntilRequestIsReceived();
- rv = resolver->GetProxyForURL(GURL("http://foo/req2"), &proxy_info2,
- base::Bind(&CrashCallback), &request2,
- BoundNetLog());
-
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foo/req2"), &proxy_info2,
+ base::Bind(&CrashCallback), &request2,
+ mock_bindings.CreateBindings());
host_resolver.WaitUntilRequestIsReceived();
@@ -872,7 +767,7 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) {
// should have been cancelled.
}
-void CancelRequestAndPause(ProxyResolver* resolver,
+void CancelRequestAndPause(ProxyResolverV8Tracing* resolver,
ProxyResolver::RequestHandle request) {
resolver->CancelRequest(request);
@@ -887,19 +782,17 @@ void CancelRequestAndPause(ProxyResolver* resolver,
// cancellation while the worker thread is waiting on this event.
TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) {
BlockableHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
- scoped_ptr<ProxyResolver> resolver = CreateResolver(
- nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "dns.js");
ProxyInfo proxy_info;
ProxyResolver::RequestHandle request;
- int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- base::Bind(&CrashCallback), &request,
- BoundNetLog());
-
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ base::Bind(&CrashCallback), &request,
+ mock_bindings.CreateBindings());
host_resolver.SetAction(
base::Bind(CancelRequestAndPause, resolver.get(), request));
@@ -916,19 +809,17 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) {
// the request is sent to the host resolver.
TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) {
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
- scoped_ptr<ProxyResolver> resolver = CreateResolver(
- nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "dns.js");
ProxyInfo proxy_info;
ProxyResolver::RequestHandle request;
- int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
- base::Bind(&CrashCallback), &request,
- BoundNetLog());
-
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
+ base::Bind(&CrashCallback), &request,
+ mock_bindings.CreateBindings());
// Wait a bit, so the DNS task has hopefully been posted. The test will
// work whatever the delay is here, but it is most useful if the delay
@@ -942,19 +833,15 @@ TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) {
TEST_F(ProxyResolverV8TracingTest,
CancelCreateResolverWhileOutstandingBlockingDns) {
BlockableHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
- ProxyResolverFactoryV8Tracing factory(
- &host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(),
- base::Bind(&ReturnErrorObserver,
- base::Passed(make_scoped_ptr(error_observer))));
-
- scoped_ptr<ProxyResolver> resolver;
+ scoped_ptr<ProxyResolverV8TracingFactory> factory(
+ ProxyResolverV8TracingFactory::Create());
+ scoped_ptr<ProxyResolverV8Tracing> 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);
+ factory->CreateProxyResolverV8Tracing(
+ LoadScriptData("dns_during_init.js"), mock_bindings.CreateBindings(),
+ &resolver, base::Bind(&CrashCallback), &request);
host_resolver.WaitUntilRequestIsReceived();
@@ -964,20 +851,17 @@ TEST_F(ProxyResolverV8TracingTest,
TEST_F(ProxyResolverV8TracingTest, DeleteFactoryWhileOutstandingBlockingDns) {
BlockableHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
- scoped_ptr<ProxyResolver> resolver;
+ scoped_ptr<ProxyResolverV8Tracing> 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);
+ scoped_ptr<ProxyResolverV8TracingFactory> factory(
+ ProxyResolverV8TracingFactory::Create());
+
+ factory->CreateProxyResolverV8Tracing(
+ LoadScriptData("dns_during_init.js"), mock_bindings.CreateBindings(),
+ &resolver, base::Bind(&CrashCallback), &request);
host_resolver.WaitUntilRequestIsReceived();
}
EXPECT_EQ(1, host_resolver.num_cancelled_requests());
@@ -985,20 +869,17 @@ TEST_F(ProxyResolverV8TracingTest, DeleteFactoryWhileOutstandingBlockingDns) {
TEST_F(ProxyResolverV8TracingTest, ErrorLoadingScript) {
BlockableHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
- ProxyResolverFactoryV8Tracing factory(
- &host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(),
- base::Bind(&ReturnErrorObserver,
- base::Passed(make_scoped_ptr(error_observer))));
-
- scoped_ptr<ProxyResolver> resolver;
+ scoped_ptr<ProxyResolverV8TracingFactory> factory(
+ ProxyResolverV8TracingFactory::Create());
+ scoped_ptr<ProxyResolverV8Tracing> 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);
+ factory->CreateProxyResolverV8Tracing(
+ LoadScriptData("error_on_load.js"), mock_bindings.CreateBindings(),
+ &resolver, callback.callback(), &request);
+
EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult());
EXPECT_FALSE(resolver);
}
@@ -1006,25 +887,21 @@ TEST_F(ProxyResolverV8TracingTest, ErrorLoadingScript) {
// 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) {
- TestNetLog log;
- BoundTestNetLog request_log;
MockCachingHostResolver host_resolver;
- MockErrorObserver* error_observer = new MockErrorObserver;
+ MockBindings mock_bindings(&host_resolver);
host_resolver.rules()->AddRule("host1", "182.111.0.222");
host_resolver.rules()->AddRule("host2", "111.33.44.55");
- scoped_ptr<ProxyResolver> resolver = CreateResolver(
- &log, &host_resolver, make_scoped_ptr(error_observer), "terminate.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver =
+ CreateResolver(mock_bindings.CreateBindings(), "terminate.js");
TestCompletionCallback callback;
ProxyInfo proxy_info;
- int rv =
- resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info,
- callback.callback(), NULL, request_log.bound());
-
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info,
+ callback.callback(), NULL,
+ mock_bindings.CreateBindings());
EXPECT_EQ(OK, callback.WaitForResult());
// The test does 2 DNS resolutions.
@@ -1032,11 +909,9 @@ TEST_F(ProxyResolverV8TracingTest, Terminate) {
EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI());
- // No errors.
- EXPECT_EQ("", error_observer->GetOutput());
-
- EXPECT_EQ(0u, log.GetSize());
- EXPECT_EQ(0u, request_log.GetSize());
+ // No errors or alerts.
+ EXPECT_TRUE(mock_bindings.GetErrors().empty());
+ EXPECT_TRUE(mock_bindings.GetAlerts().empty());
}
// Tests that multiple instances of ProxyResolverV8Tracing can coexist and run
@@ -1048,6 +923,7 @@ TEST_F(ProxyResolverV8TracingTest, MultipleResolvers) {
// Setup resolver0
// ------------------------
MockHostResolver host_resolver0;
+ MockBindings mock_bindings0(&host_resolver0);
host_resolver0.rules()->AddRuleForAddressFamily(
"host1", ADDRESS_FAMILY_IPV4, "166.155.144.44");
host_resolver0.rules()
@@ -1059,38 +935,35 @@ TEST_F(ProxyResolverV8TracingTest, MultipleResolvers) {
host_resolver0.rules()->AddRuleForAddressFamily(
"*", ADDRESS_FAMILY_IPV4, "122.133.144.155");
host_resolver0.rules()->AddRule("*", "133.122.100.200");
- scoped_ptr<ProxyResolver> resolver0 =
- CreateResolver(nullptr, &host_resolver0,
- make_scoped_ptr(new MockErrorObserver), "dns.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver0 =
+ CreateResolver(mock_bindings0.CreateBindings(), "dns.js");
// ------------------------
// Setup resolver1
// ------------------------
- scoped_ptr<ProxyResolver> resolver1 =
- CreateResolver(nullptr, &host_resolver0,
- make_scoped_ptr(new MockErrorObserver), "dns.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver1 =
+ CreateResolver(mock_bindings0.CreateBindings(), "dns.js");
// ------------------------
// Setup resolver2
// ------------------------
- scoped_ptr<ProxyResolver> resolver2 =
- CreateResolver(nullptr, &host_resolver0,
- make_scoped_ptr(new MockErrorObserver), "simple.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver2 =
+ CreateResolver(mock_bindings0.CreateBindings(), "simple.js");
// ------------------------
// Setup resolver3
// ------------------------
MockHostResolver host_resolver3;
+ MockBindings mock_bindings3(&host_resolver3);
host_resolver3.rules()->AddRule("foo", "166.155.144.33");
- scoped_ptr<ProxyResolver> resolver3 =
- CreateResolver(nullptr, &host_resolver3,
- make_scoped_ptr(new MockErrorObserver), "simple_dns.js");
+ scoped_ptr<ProxyResolverV8Tracing> resolver3 =
+ CreateResolver(mock_bindings3.CreateBindings(), "simple_dns.js");
// ------------------------
// Queue up work for each resolver (which will be running in parallel).
// ------------------------
- ProxyResolver* resolver[] = {
+ ProxyResolverV8Tracing* resolver[] = {
resolver0.get(), resolver1.get(), resolver2.get(), resolver3.get(),
};
@@ -1102,10 +975,10 @@ TEST_F(ProxyResolverV8TracingTest, MultipleResolvers) {
for (size_t i = 0; i < kNumResults; ++i) {
size_t resolver_i = i % kNumResolvers;
- int rv = resolver[resolver_i]->GetProxyForURL(
+ resolver[resolver_i]->GetProxyForURL(
GURL("http://foo/"), &proxy_info[i], callback[i].callback(), NULL,
- BoundNetLog());
- EXPECT_EQ(ERR_IO_PENDING, rv);
+ 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.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698