| Index: net/proxy/sync_host_resolver_bridge_unittest.cc
|
| ===================================================================
|
| --- net/proxy/sync_host_resolver_bridge_unittest.cc (revision 51914)
|
| +++ net/proxy/sync_host_resolver_bridge_unittest.cc (working copy)
|
| @@ -9,10 +9,14 @@
|
| #include "net/base/address_list.h"
|
| #include "net/base/net_errors.h"
|
| #include "net/base/net_log.h"
|
| +#include "net/proxy/multi_threaded_proxy_resolver.h"
|
| #include "net/base/test_completion_callback.h"
|
| #include "net/proxy/proxy_info.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| +// TODO(eroman): This test should be moved into
|
| +// multi_threaded_proxy_resolver_unittest.cc.
|
| +
|
| namespace net {
|
|
|
| namespace {
|
| @@ -75,7 +79,7 @@
|
| // on |host_resolver| in response to GetProxyForURL().
|
| class SyncProxyResolver : public ProxyResolver {
|
| public:
|
| - explicit SyncProxyResolver(HostResolver* host_resolver)
|
| + explicit SyncProxyResolver(SyncHostResolverBridge* host_resolver)
|
| : ProxyResolver(false), host_resolver_(host_resolver) {}
|
|
|
| virtual int GetProxyForURL(const GURL& url,
|
| @@ -101,17 +105,35 @@
|
| NOTREACHED();
|
| }
|
|
|
| + virtual void Shutdown() {
|
| + host_resolver_->Shutdown();
|
| + }
|
| +
|
| private:
|
| virtual int SetPacScript(const GURL& pac_url,
|
| const string16& pac_script,
|
| CompletionCallback* callback) {
|
| - NOTREACHED();
|
| return OK;
|
| }
|
|
|
| - scoped_refptr<HostResolver> host_resolver_;
|
| + scoped_refptr<SyncHostResolverBridge> host_resolver_;
|
| };
|
|
|
| +class SyncProxyResolverFactory : public ProxyResolverFactory {
|
| + public:
|
| + explicit SyncProxyResolverFactory(SyncHostResolverBridge* sync_host_resolver)
|
| + : ProxyResolverFactory(false),
|
| + sync_host_resolver_(sync_host_resolver) {
|
| + }
|
| +
|
| + virtual ProxyResolver* CreateProxyResolver() {
|
| + return new SyncProxyResolver(sync_host_resolver_);
|
| + }
|
| +
|
| + private:
|
| + scoped_refptr<SyncHostResolverBridge> sync_host_resolver_;
|
| +};
|
| +
|
| // This helper thread is used to create the circumstances for the deadlock.
|
| // It is analagous to the "IO thread" which would be main thread running the
|
| // network stack.
|
| @@ -137,10 +159,15 @@
|
| new SyncHostResolverBridge(async_resolver_, message_loop());
|
|
|
| proxy_resolver_.reset(
|
| - new SingleThreadedProxyResolverUsingBridgedHostResolver(
|
| - new SyncProxyResolver(sync_resolver),
|
| - sync_resolver));
|
| + new MultiThreadedProxyResolver(
|
| + new SyncProxyResolverFactory(sync_resolver),
|
| + 1u));
|
|
|
| + // Initialize the resolver.
|
| + TestCompletionCallback callback;
|
| + proxy_resolver_->SetPacScriptByUrl(GURL(), &callback);
|
| + EXPECT_EQ(OK, callback.WaitForResult());
|
| +
|
| // Start an asynchronous request to the proxy resolver
|
| // (note that it will never complete).
|
| proxy_resolver_->GetProxyForURL(GURL("http://test/"), &results_,
|
| @@ -155,6 +182,10 @@
|
| // Delete the single threaded proxy resolver.
|
| proxy_resolver_.reset();
|
|
|
| + // (There may have been a completion posted back to origin thread, avoid
|
| + // leaking it by running).
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| // During the teardown sequence of the single threaded proxy resolver,
|
| // the outstanding host resolve should have been cancelled.
|
| EXPECT_TRUE(async_resolver_->was_request_cancelled());
|
| @@ -178,7 +209,7 @@
|
| // Test that a deadlock does not happen during shutdown when a host resolve
|
| // is outstanding on the SyncHostResolverBridge.
|
| // This is a regression test for http://crbug.com/41244.
|
| -TEST(SingleThreadedProxyResolverWithBridgedHostResolverTest, ShutdownDeadlock) {
|
| +TEST(MultiThreadedProxyResolverTest, ShutdownIsCalledBeforeThreadJoin) {
|
| IOThread io_thread;
|
| base::Thread::Options options;
|
| options.message_loop_type = MessageLoop::TYPE_IO;
|
|
|