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

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: 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 private:
44 IPC::Listener* listener_;
45 };
46
30 class ResolveProxyMsgHelperTest : public testing::Test, public IPC::Listener { 47 class ResolveProxyMsgHelperTest : public testing::Test, public IPC::Listener {
31 public: 48 public:
32 struct PendingResult { 49 struct PendingResult {
33 PendingResult(bool result, 50 PendingResult(bool result,
34 const std::string& proxy_list) 51 const std::string& proxy_list)
35 : result(result), proxy_list(proxy_list) { 52 : result(result), proxy_list(proxy_list) {
36 } 53 }
37 54
38 bool result; 55 bool result;
39 std::string proxy_list; 56 std::string proxy_list;
40 }; 57 };
41 58
42 ResolveProxyMsgHelperTest() 59 ResolveProxyMsgHelperTest()
43 : resolver_(new net::MockAsyncProxyResolver), 60 : resolver_(new net::MockAsyncProxyResolver),
44 service_( 61 service_(
45 new net::ProxyService(new MockProxyConfigService, resolver_, NULL)), 62 new net::ProxyService(new MockProxyConfigService, resolver_, NULL)),
46 helper_(new ResolveProxyMsgHelper(service_.get())), 63 helper_(new TestResolveProxyMsgHelper(service_.get(), this)),
47 message_loop_(base::MessageLoop::TYPE_IO), 64 message_loop_(base::MessageLoop::TYPE_IO),
48 io_thread_(BrowserThread::IO, &message_loop_) { 65 io_thread_(BrowserThread::IO, &message_loop_) {
49 test_sink_.AddFilter(this); 66 test_sink_.AddFilter(this);
50 helper_->OnFilterAdded(&test_sink_);
51 } 67 }
52 68
53 protected: 69 protected:
54 const PendingResult* pending_result() const { return pending_result_.get(); } 70 const PendingResult* pending_result() const { return pending_result_.get(); }
55 71
56 void clear_pending_result() { 72 void clear_pending_result() {
57 pending_result_.reset(); 73 pending_result_.reset();
58 } 74 }
59 75
60 IPC::Message* GenerateReply() { 76 IPC::Message* GenerateReply() {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 246
231 EXPECT_EQ(0u, resolver_->pending_requests().size()); 247 EXPECT_EQ(0u, resolver_->pending_requests().size());
232 248
233 EXPECT_TRUE(pending_result() == NULL); 249 EXPECT_TRUE(pending_result() == NULL);
234 250
235 // It should also be the case that msg1, msg2, msg3 were deleted by the 251 // 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). 252 // cancellation. (Else will show up as a leak in Valgrind).
237 } 253 }
238 254
239 } // namespace content 255 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698