summaryrefslogtreecommitdiffstats
path: root/net/proxy/single_threaded_proxy_resolver_unittest.cc
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-04 22:43:12 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-04 22:43:12 +0000
commit620f57148c311c4dc2cf680a4a5861fbdcd29993 (patch)
tree93408ed35ebbaccd8f45734c7267392c81d71ca9 /net/proxy/single_threaded_proxy_resolver_unittest.cc
parent289fdf862c649d17ddb2e08295304efb98f641f6 (diff)
downloadchromium_src-620f57148c311c4dc2cf680a4a5861fbdcd29993.zip
chromium_src-620f57148c311c4dc2cf680a4a5861fbdcd29993.tar.gz
chromium_src-620f57148c311c4dc2cf680a4a5861fbdcd29993.tar.bz2
Better match IE's proxy settings.
* When BOTH autodetect and custom PAC script are given, try both. * Use successful PAC parsing as the heuristic for determining when a script is valid (rather than first-request). * Only apply the proxy bypass list when using non-PAC. The high level explanation on how this works: http://sites.google.com/a/chromium.org/dev/developers/design-documents/proxy-settings-fallback BUG= http://crbug.com/18271, http://crbug.com/9985 TEST=unit tests. Review URL: http://codereview.chromium.org/160510 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22430 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/single_threaded_proxy_resolver_unittest.cc')
-rw-r--r--net/proxy/single_threaded_proxy_resolver_unittest.cc75
1 files changed, 66 insertions, 9 deletions
diff --git a/net/proxy/single_threaded_proxy_resolver_unittest.cc b/net/proxy/single_threaded_proxy_resolver_unittest.cc
index 6fe7995..da21ff1 100644
--- a/net/proxy/single_threaded_proxy_resolver_unittest.cc
+++ b/net/proxy/single_threaded_proxy_resolver_unittest.cc
@@ -47,9 +47,12 @@ class MockProxyResolver : public ProxyResolver {
NOTREACHED();
}
- virtual void SetPacScriptByDataInternal(const std::string& bytes) {
+ virtual int SetPacScript(const GURL& pac_url,
+ const std::string& bytes,
+ CompletionCallback* callback) {
CheckIsOnWorkerThread();
last_pac_bytes_ = bytes;
+ return OK;
}
const std::string& last_pac_bytes() const { return last_pac_bytes_; }
@@ -127,9 +130,13 @@ TEST(SingleThreadedProxyResolverTest, Basic) {
EXPECT_TRUE(resolver->expects_pac_bytes());
- // Call SetPacScriptByData() -- we will make sure it reaches the sync resolver
- // later on.
- resolver->SetPacScriptByData("pac script bytes");
+ // Call SetPacScriptByData() -- verify that it reaches the synchronous
+ // resolver.
+ TestCompletionCallback set_script_callback;
+ rv = resolver->SetPacScriptByData("pac script bytes", &set_script_callback);
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ EXPECT_EQ(OK, set_script_callback.WaitForResult());
+ EXPECT_EQ("pac script bytes", mock->last_pac_bytes());
// Start request 0.
TestCompletionCallback callback0;
@@ -143,11 +150,6 @@ TEST(SingleThreadedProxyResolverTest, Basic) {
EXPECT_EQ(0, rv);
EXPECT_EQ("PROXY request0:80", results0.ToPacString());
- // Verify that the data from SetPacScriptByData() reached the resolver.
- // (Since we waited for the first request to complete, we are guaranteed
- // that the earlier post completed).
- EXPECT_EQ("pac script bytes", mock->last_pac_bytes());
-
// Start 3 more requests (request1 to request3).
TestCompletionCallback callback1;
@@ -309,5 +311,60 @@ TEST(SingleThreadedProxyResolverTest, CancelRequestByDeleting) {
EXPECT_FALSE(callback2.have_result());
}
+// Cancel an outstanding call to SetPacScriptByData().
+TEST(SingleThreadedProxyResolverTest, CancelSetPacScript) {
+ BlockableProxyResolver* mock = new BlockableProxyResolver;
+ scoped_ptr<SingleThreadedProxyResolver> resolver(
+ new SingleThreadedProxyResolver(mock));
+
+ int rv;
+
+ // Block the proxy resolver, so no request can complete.
+ mock->Block();
+
+ // Start request 0.
+ ProxyResolver::RequestHandle request0;
+ TestCompletionCallback callback0;
+ ProxyInfo results0;
+ rv = resolver->GetProxyForURL(
+ GURL("http://request0"), &results0, &callback0, &request0);
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ // Wait until requests 0 reaches the worker thread.
+ mock->WaitUntilBlocked();
+
+ TestCompletionCallback set_pac_script_callback;
+ rv = resolver->SetPacScriptByData("data", &set_pac_script_callback);
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ // Cancel the SetPacScriptByData request (it can't have finished yet,
+ // since the single-thread is currently blocked).
+ resolver->CancelSetPacScript();
+
+ // Start 1 more request.
+
+ TestCompletionCallback callback1;
+ ProxyInfo results1;
+ rv = resolver->GetProxyForURL(
+ GURL("http://request1"), &results1, &callback1, NULL);
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ // Unblock the worker thread so the requests can continue running.
+ mock->Unblock();
+
+ // Wait for requests 0 and 1 to finish.
+
+ rv = callback0.WaitForResult();
+ EXPECT_EQ(0, rv);
+ EXPECT_EQ("PROXY request0:80", results0.ToPacString());
+
+ rv = callback1.WaitForResult();
+ EXPECT_EQ(1, rv);
+ EXPECT_EQ("PROXY request1:80", results1.ToPacString());
+
+ // The SetPacScript callback should never have been completed.
+ EXPECT_FALSE(set_pac_script_callback.have_result());
+}
+
} // namespace
} // namespace net