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

Side by Side Diff: content/browser/resolve_proxy_msg_helper_unittest.cc

Issue 24514003: Make BrowserMessageFilter not derive from IPC::ChannelProxy::MessageFilter. This allows us to hide … (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/resolve_proxy_msg_helper.h" 5 #include "content/browser/resolve_proxy_msg_helper.h"
6 6
7 #include "content/browser/browser_thread_impl.h" 7 #include "content/browser/browser_thread_impl.h"
8 #include "content/common/view_messages.h" 8 #include "content/common/view_messages.h"
9 #include "ipc/ipc_test_sink.h" 9 #include "ipc/ipc_test_sink.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/proxy/mock_proxy_resolver.h" 11 #include "net/proxy/mock_proxy_resolver.h"
12 #include "net/proxy/proxy_config_service.h" 12 #include "net/proxy/proxy_config_service.h"
13 #include "net/proxy/proxy_service.h" 13 #include "net/proxy/proxy_service.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 // This ProxyConfigService always returns "http://pac" as the PAC url to use. 18 // This ProxyConfigService always returns "http://pac" as the PAC url to use.
19 class MockProxyConfigService : public net::ProxyConfigService { 19 class MockProxyConfigService : public net::ProxyConfigService {
20 public: 20 public:
21 virtual void AddObserver(Observer* observer) OVERRIDE {} 21 virtual void AddObserver(Observer* observer) OVERRIDE {}
22 virtual void RemoveObserver(Observer* observer) OVERRIDE {} 22 virtual void RemoveObserver(Observer* observer) OVERRIDE {}
23 virtual ConfigAvailability GetLatestProxyConfig( 23 virtual ConfigAvailability GetLatestProxyConfig(
24 net::ProxyConfig* results) OVERRIDE { 24 net::ProxyConfig* results) OVERRIDE {
25 *results = net::ProxyConfig::CreateFromCustomPacURL(GURL("http://pac")); 25 *results = net::ProxyConfig::CreateFromCustomPacURL(GURL("http://pac"));
26 return CONFIG_VALID; 26 return CONFIG_VALID;
27 } 27 }
28 }; 28 };
29 29
30 class TestResolveProxyMsgHelper : public ResolveProxyMsgHelper {
31 public:
32 TestResolveProxyMsgHelper(
33 net::ProxyService* proxy_service,
34 IPC::Listener* listener)
35 : ResolveProxyMsgHelper(proxy_service),
36 listener_(listener) {}
37 virtual bool Send(IPC::Message* message) OVERRIDE {
38 listener_->OnMessageReceived(*message);
39 delete message;
40 return true;
41 }
42
43 protected:
44 virtual ~TestResolveProxyMsgHelper() {}
45
46 IPC::Listener* listener_;
47 };
48
30 class ResolveProxyMsgHelperTest : public testing::Test, public IPC::Listener { 49 class ResolveProxyMsgHelperTest : public testing::Test, public IPC::Listener {
31 public: 50 public:
32 struct PendingResult { 51 struct PendingResult {
33 PendingResult(bool result, 52 PendingResult(bool result,
34 const std::string& proxy_list) 53 const std::string& proxy_list)
35 : result(result), proxy_list(proxy_list) { 54 : result(result), proxy_list(proxy_list) {
36 } 55 }
37 56
38 bool result; 57 bool result;
39 std::string proxy_list; 58 std::string proxy_list;
40 }; 59 };
41 60
42 ResolveProxyMsgHelperTest() 61 ResolveProxyMsgHelperTest()
43 : resolver_(new net::MockAsyncProxyResolver), 62 : resolver_(new net::MockAsyncProxyResolver),
44 service_( 63 service_(
45 new net::ProxyService(new MockProxyConfigService, resolver_, NULL)), 64 new net::ProxyService(new MockProxyConfigService, resolver_, NULL)),
46 helper_(new ResolveProxyMsgHelper(service_.get())), 65 helper_(new TestResolveProxyMsgHelper(service_.get(), this)),
47 message_loop_(base::MessageLoop::TYPE_IO), 66 message_loop_(base::MessageLoop::TYPE_IO),
48 io_thread_(BrowserThread::IO, &message_loop_) { 67 io_thread_(BrowserThread::IO, &message_loop_) {
49 test_sink_.AddFilter(this); 68 test_sink_.AddFilter(this);
50 helper_->OnFilterAdded(&test_sink_);
51 } 69 }
52 70
53 protected: 71 protected:
54 const PendingResult* pending_result() const { return pending_result_.get(); } 72 const PendingResult* pending_result() const { return pending_result_.get(); }
55 73
56 void clear_pending_result() { 74 void clear_pending_result() {
57 pending_result_.reset(); 75 pending_result_.reset();
58 } 76 }
59 77
60 IPC::Message* GenerateReply() { 78 IPC::Message* GenerateReply() {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 248
231 EXPECT_EQ(0u, resolver_->pending_requests().size()); 249 EXPECT_EQ(0u, resolver_->pending_requests().size());
232 250
233 EXPECT_TRUE(pending_result() == NULL); 251 EXPECT_TRUE(pending_result() == NULL);
234 252
235 // It should also be the case that msg1, msg2, msg3 were deleted by the 253 // It should also be the case that msg1, msg2, msg3 were deleted by the
236 // cancellation. (Else will show up as a leak in Valgrind). 254 // cancellation. (Else will show up as a leak in Valgrind).
237 } 255 }
238 256
239 } // namespace content 257 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.cc ('k') | content/browser/tracing/trace_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698