OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/proxy/multi_threaded_proxy_resolver.h" | 5 #include "net/proxy/multi_threaded_proxy_resolver.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 202 |
203 // Wait for request 0 to finish. | 203 // Wait for request 0 to finish. |
204 rv = callback0.WaitForResult(); | 204 rv = callback0.WaitForResult(); |
205 EXPECT_EQ(0, rv); | 205 EXPECT_EQ(0, rv); |
206 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); | 206 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); |
207 | 207 |
208 // The mock proxy resolver should have written 1 log entry. And | 208 // The mock proxy resolver should have written 1 log entry. And |
209 // on completion, this should have been copied into |log0|. | 209 // on completion, this should have been copied into |log0|. |
210 // We also have 1 log entry that was emitted by the | 210 // We also have 1 log entry that was emitted by the |
211 // MultiThreadedProxyResolver. | 211 // MultiThreadedProxyResolver. |
212 CapturingNetLog::CapturedEntryList entries0; | 212 TestNetLog::CapturedEntryList entries0; |
213 log0.GetEntries(&entries0); | 213 log0.GetEntries(&entries0); |
214 | 214 |
215 ASSERT_EQ(2u, entries0.size()); | 215 ASSERT_EQ(2u, entries0.size()); |
216 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, entries0[0].type); | 216 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, entries0[0].type); |
217 | 217 |
218 // Start 3 more requests (request1 to request3). | 218 // Start 3 more requests (request1 to request3). |
219 | 219 |
220 TestCompletionCallback callback1; | 220 TestCompletionCallback callback1; |
221 ProxyInfo results1; | 221 ProxyInfo results1; |
222 rv = resolver.GetProxyForURL(GURL("http://request1"), &results1, | 222 rv = resolver.GetProxyForURL(GURL("http://request1"), &results1, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 // Unblock the worker thread so the requests can continue running. | 300 // Unblock the worker thread so the requests can continue running. |
301 mock->WaitUntilBlocked(); | 301 mock->WaitUntilBlocked(); |
302 mock->Unblock(); | 302 mock->Unblock(); |
303 | 303 |
304 // Check that request 0 completed as expected. | 304 // Check that request 0 completed as expected. |
305 // The NetLog has 1 entry that came from the MultiThreadedProxyResolver, and | 305 // The NetLog has 1 entry that came from the MultiThreadedProxyResolver, and |
306 // 1 entry from the mock proxy resolver. | 306 // 1 entry from the mock proxy resolver. |
307 EXPECT_EQ(0, callback0.WaitForResult()); | 307 EXPECT_EQ(0, callback0.WaitForResult()); |
308 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); | 308 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); |
309 | 309 |
310 CapturingNetLog::CapturedEntryList entries0; | 310 TestNetLog::CapturedEntryList entries0; |
311 log0.GetEntries(&entries0); | 311 log0.GetEntries(&entries0); |
312 | 312 |
313 ASSERT_EQ(2u, entries0.size()); | 313 ASSERT_EQ(2u, entries0.size()); |
314 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, | 314 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, |
315 entries0[0].type); | 315 entries0[0].type); |
316 | 316 |
317 // Check that request 1 completed as expected. | 317 // Check that request 1 completed as expected. |
318 EXPECT_EQ(1, callback1.WaitForResult()); | 318 EXPECT_EQ(1, callback1.WaitForResult()); |
319 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); | 319 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); |
320 | 320 |
321 CapturingNetLog::CapturedEntryList entries1; | 321 TestNetLog::CapturedEntryList entries1; |
322 log1.GetEntries(&entries1); | 322 log1.GetEntries(&entries1); |
323 | 323 |
324 ASSERT_EQ(4u, entries1.size()); | 324 ASSERT_EQ(4u, entries1.size()); |
325 EXPECT_TRUE(LogContainsBeginEvent( | 325 EXPECT_TRUE(LogContainsBeginEvent( |
326 entries1, 0, | 326 entries1, 0, |
327 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 327 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
328 EXPECT_TRUE(LogContainsEndEvent( | 328 EXPECT_TRUE(LogContainsEndEvent( |
329 entries1, 1, | 329 entries1, 1, |
330 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 330 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
331 | 331 |
332 // Check that request 2 completed as expected. | 332 // Check that request 2 completed as expected. |
333 EXPECT_EQ(2, callback2.WaitForResult()); | 333 EXPECT_EQ(2, callback2.WaitForResult()); |
334 EXPECT_EQ("PROXY request2:80", results2.ToPacString()); | 334 EXPECT_EQ("PROXY request2:80", results2.ToPacString()); |
335 | 335 |
336 CapturingNetLog::CapturedEntryList entries2; | 336 TestNetLog::CapturedEntryList entries2; |
337 log2.GetEntries(&entries2); | 337 log2.GetEntries(&entries2); |
338 | 338 |
339 ASSERT_EQ(4u, entries2.size()); | 339 ASSERT_EQ(4u, entries2.size()); |
340 EXPECT_TRUE(LogContainsBeginEvent( | 340 EXPECT_TRUE(LogContainsBeginEvent( |
341 entries2, 0, | 341 entries2, 0, |
342 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 342 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
343 EXPECT_TRUE(LogContainsEndEvent( | 343 EXPECT_TRUE(LogContainsEndEvent( |
344 entries2, 1, | 344 entries2, 1, |
345 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 345 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
346 } | 346 } |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 // All in all, the first thread should have seen just 1 request. And the | 694 // All in all, the first thread should have seen just 1 request. And the |
695 // second thread 3 requests. | 695 // second thread 3 requests. |
696 ASSERT_EQ(2u, factory->resolvers().size()); | 696 ASSERT_EQ(2u, factory->resolvers().size()); |
697 EXPECT_EQ(1, factory->resolvers()[0]->request_count()); | 697 EXPECT_EQ(1, factory->resolvers()[0]->request_count()); |
698 EXPECT_EQ(3, factory->resolvers()[1]->request_count()); | 698 EXPECT_EQ(3, factory->resolvers()[1]->request_count()); |
699 } | 699 } |
700 | 700 |
701 } // namespace | 701 } // namespace |
702 | 702 |
703 } // namespace net | 703 } // namespace net |
OLD | NEW |