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

Unified Diff: net/proxy/single_threaded_proxy_resolver_unittest.cc

Issue 160510: Better match IE's proxy settings.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix merge conflict Created 11 years, 4 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/single_threaded_proxy_resolver.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/single_threaded_proxy_resolver_unittest.cc
===================================================================
--- net/proxy/single_threaded_proxy_resolver_unittest.cc (revision 22399)
+++ net/proxy/single_threaded_proxy_resolver_unittest.cc (working copy)
@@ -47,9 +47,12 @@
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 @@
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 @@
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 @@
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
« no previous file with comments | « net/proxy/single_threaded_proxy_resolver.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698