OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/net/resolve_proxy_msg_helper.h" | 5 #include "chrome/browser/net/resolve_proxy_msg_helper.h" |
6 | 6 |
7 #include "base/waitable_event.h" | 7 #include "base/waitable_event.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 #include "net/proxy/mock_proxy_resolver.h" | 9 #include "net/proxy/mock_proxy_resolver.h" |
10 #include "net/proxy/proxy_config_service.h" | 10 #include "net/proxy/proxy_config_service.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 | 49 |
50 private: | 50 private: |
51 scoped_ptr<PendingResult> pending_result_; | 51 scoped_ptr<PendingResult> pending_result_; |
52 }; | 52 }; |
53 | 53 |
54 // Issue three sequential requests -- each should succeed. | 54 // Issue three sequential requests -- each should succeed. |
55 TEST(ResolveProxyMsgHelperTest, Sequential) { | 55 TEST(ResolveProxyMsgHelperTest, Sequential) { |
56 net::MockAsyncProxyResolver* resolver = new net::MockAsyncProxyResolver; | 56 net::MockAsyncProxyResolver* resolver = new net::MockAsyncProxyResolver; |
57 scoped_refptr<net::ProxyService> service( | 57 scoped_refptr<net::ProxyService> service( |
58 new net::ProxyService(new MockProxyConfigService, resolver, NULL, NULL)); | 58 new net::ProxyService(new MockProxyConfigService, resolver, NULL)); |
59 | 59 |
60 MyDelegate delegate; | 60 MyDelegate delegate; |
61 ResolveProxyMsgHelper helper(&delegate, service); | 61 ResolveProxyMsgHelper helper(&delegate, service); |
62 | 62 |
63 GURL url1("http://www.google1.com/"); | 63 GURL url1("http://www.google1.com/"); |
64 GURL url2("http://www.google2.com/"); | 64 GURL url2("http://www.google2.com/"); |
65 GURL url3("http://www.google3.com/"); | 65 GURL url3("http://www.google3.com/"); |
66 | 66 |
67 scoped_ptr<IPC::Message> msg1(new IPC::Message()); | 67 scoped_ptr<IPC::Message> msg1(new IPC::Message()); |
68 scoped_ptr<IPC::Message> msg2(new IPC::Message()); | 68 scoped_ptr<IPC::Message> msg2(new IPC::Message()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 EXPECT_EQ(msg3.get(), delegate.pending_result()->msg); | 111 EXPECT_EQ(msg3.get(), delegate.pending_result()->msg); |
112 EXPECT_EQ(net::OK, delegate.pending_result()->error_code); | 112 EXPECT_EQ(net::OK, delegate.pending_result()->error_code); |
113 EXPECT_EQ("PROXY result3:80", delegate.pending_result()->proxy_list); | 113 EXPECT_EQ("PROXY result3:80", delegate.pending_result()->proxy_list); |
114 delegate.clear_pending_result(); | 114 delegate.clear_pending_result(); |
115 } | 115 } |
116 | 116 |
117 // Issue a request while one is already in progress -- should be queued. | 117 // Issue a request while one is already in progress -- should be queued. |
118 TEST(ResolveProxyMsgHelperTest, QueueRequests) { | 118 TEST(ResolveProxyMsgHelperTest, QueueRequests) { |
119 net::MockAsyncProxyResolver* resolver = new net::MockAsyncProxyResolver; | 119 net::MockAsyncProxyResolver* resolver = new net::MockAsyncProxyResolver; |
120 scoped_refptr<net::ProxyService> service( | 120 scoped_refptr<net::ProxyService> service( |
121 new net::ProxyService(new MockProxyConfigService, resolver, NULL, NULL)); | 121 new net::ProxyService(new MockProxyConfigService, resolver, NULL)); |
122 | 122 |
123 MyDelegate delegate; | 123 MyDelegate delegate; |
124 ResolveProxyMsgHelper helper(&delegate, service); | 124 ResolveProxyMsgHelper helper(&delegate, service); |
125 | 125 |
126 GURL url1("http://www.google1.com/"); | 126 GURL url1("http://www.google1.com/"); |
127 GURL url2("http://www.google2.com/"); | 127 GURL url2("http://www.google2.com/"); |
128 GURL url3("http://www.google3.com/"); | 128 GURL url3("http://www.google3.com/"); |
129 | 129 |
130 scoped_ptr<IPC::Message> msg1(new IPC::Message()); | 130 scoped_ptr<IPC::Message> msg1(new IPC::Message()); |
131 scoped_ptr<IPC::Message> msg2(new IPC::Message()); | 131 scoped_ptr<IPC::Message> msg2(new IPC::Message()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 EXPECT_EQ(msg3.get(), delegate.pending_result()->msg); | 178 EXPECT_EQ(msg3.get(), delegate.pending_result()->msg); |
179 EXPECT_EQ(net::OK, delegate.pending_result()->error_code); | 179 EXPECT_EQ(net::OK, delegate.pending_result()->error_code); |
180 EXPECT_EQ("PROXY result3:80", delegate.pending_result()->proxy_list); | 180 EXPECT_EQ("PROXY result3:80", delegate.pending_result()->proxy_list); |
181 delegate.clear_pending_result(); | 181 delegate.clear_pending_result(); |
182 } | 182 } |
183 | 183 |
184 // Delete the helper while a request is in progress, and others are pending. | 184 // Delete the helper while a request is in progress, and others are pending. |
185 TEST(ResolveProxyMsgHelperTest, CancelPendingRequests) { | 185 TEST(ResolveProxyMsgHelperTest, CancelPendingRequests) { |
186 net::MockAsyncProxyResolver* resolver = new net::MockAsyncProxyResolver; | 186 net::MockAsyncProxyResolver* resolver = new net::MockAsyncProxyResolver; |
187 scoped_refptr<net::ProxyService> service( | 187 scoped_refptr<net::ProxyService> service( |
188 new net::ProxyService(new MockProxyConfigService, resolver, NULL, NULL)); | 188 new net::ProxyService(new MockProxyConfigService, resolver, NULL)); |
189 | 189 |
190 MyDelegate delegate; | 190 MyDelegate delegate; |
191 scoped_ptr<ResolveProxyMsgHelper> helper( | 191 scoped_ptr<ResolveProxyMsgHelper> helper( |
192 new ResolveProxyMsgHelper(&delegate, service)); | 192 new ResolveProxyMsgHelper(&delegate, service)); |
193 | 193 |
194 GURL url1("http://www.google1.com/"); | 194 GURL url1("http://www.google1.com/"); |
195 GURL url2("http://www.google2.com/"); | 195 GURL url2("http://www.google2.com/"); |
196 GURL url3("http://www.google3.com/"); | 196 GURL url3("http://www.google3.com/"); |
197 | 197 |
198 // NOTE: these are not scoped ptr, since they will be deleted by the | 198 // NOTE: these are not scoped ptr, since they will be deleted by the |
(...skipping 24 matching lines...) Expand all Loading... |
223 | 223 |
224 // The pending requests sent to the proxy resolver should have been cancelled. | 224 // The pending requests sent to the proxy resolver should have been cancelled. |
225 | 225 |
226 EXPECT_EQ(0u, resolver->pending_requests().size()); | 226 EXPECT_EQ(0u, resolver->pending_requests().size()); |
227 | 227 |
228 EXPECT_TRUE(delegate.pending_result() == NULL); | 228 EXPECT_TRUE(delegate.pending_result() == NULL); |
229 | 229 |
230 // It should also be the case that msg1, msg2, msg3 were deleted by the | 230 // It should also be the case that msg1, msg2, msg3 were deleted by the |
231 // cancellation. (Else will show up as a leak in Purify/Valgrind). | 231 // cancellation. (Else will show up as a leak in Purify/Valgrind). |
232 } | 232 } |
OLD | NEW |