| 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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
| 16 #include "net/log/captured_net_log_entry.h" |
| 16 #include "net/log/net_log.h" | 17 #include "net/log/net_log.h" |
| 17 #include "net/log/net_log_unittest.h" | 18 #include "net/log/net_log_unittest.h" |
| 19 #include "net/log/test_net_log.h" |
| 18 #include "net/proxy/mock_proxy_resolver.h" | 20 #include "net/proxy/mock_proxy_resolver.h" |
| 19 #include "net/proxy/proxy_info.h" | 21 #include "net/proxy/proxy_info.h" |
| 20 #include "net/proxy/proxy_resolver_factory.h" | 22 #include "net/proxy/proxy_resolver_factory.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 23 | 25 |
| 24 using base::ASCIIToUTF16; | 26 using base::ASCIIToUTF16; |
| 25 | 27 |
| 26 namespace net { | 28 namespace net { |
| 27 | 29 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 204 |
| 203 // Wait for request 0 to finish. | 205 // Wait for request 0 to finish. |
| 204 rv = callback0.WaitForResult(); | 206 rv = callback0.WaitForResult(); |
| 205 EXPECT_EQ(0, rv); | 207 EXPECT_EQ(0, rv); |
| 206 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); | 208 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); |
| 207 | 209 |
| 208 // The mock proxy resolver should have written 1 log entry. And | 210 // The mock proxy resolver should have written 1 log entry. And |
| 209 // on completion, this should have been copied into |log0|. | 211 // on completion, this should have been copied into |log0|. |
| 210 // We also have 1 log entry that was emitted by the | 212 // We also have 1 log entry that was emitted by the |
| 211 // MultiThreadedProxyResolver. | 213 // MultiThreadedProxyResolver. |
| 212 TestNetLog::CapturedEntryList entries0; | 214 CapturedNetLogEntry::List entries0; |
| 213 log0.GetEntries(&entries0); | 215 log0.GetEntries(&entries0); |
| 214 | 216 |
| 215 ASSERT_EQ(2u, entries0.size()); | 217 ASSERT_EQ(2u, entries0.size()); |
| 216 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, entries0[0].type); | 218 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, entries0[0].type); |
| 217 | 219 |
| 218 // Start 3 more requests (request1 to request3). | 220 // Start 3 more requests (request1 to request3). |
| 219 | 221 |
| 220 TestCompletionCallback callback1; | 222 TestCompletionCallback callback1; |
| 221 ProxyInfo results1; | 223 ProxyInfo results1; |
| 222 rv = resolver.GetProxyForURL(GURL("http://request1"), &results1, | 224 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. | 302 // Unblock the worker thread so the requests can continue running. |
| 301 mock->WaitUntilBlocked(); | 303 mock->WaitUntilBlocked(); |
| 302 mock->Unblock(); | 304 mock->Unblock(); |
| 303 | 305 |
| 304 // Check that request 0 completed as expected. | 306 // Check that request 0 completed as expected. |
| 305 // The NetLog has 1 entry that came from the MultiThreadedProxyResolver, and | 307 // The NetLog has 1 entry that came from the MultiThreadedProxyResolver, and |
| 306 // 1 entry from the mock proxy resolver. | 308 // 1 entry from the mock proxy resolver. |
| 307 EXPECT_EQ(0, callback0.WaitForResult()); | 309 EXPECT_EQ(0, callback0.WaitForResult()); |
| 308 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); | 310 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); |
| 309 | 311 |
| 310 TestNetLog::CapturedEntryList entries0; | 312 CapturedNetLogEntry::List entries0; |
| 311 log0.GetEntries(&entries0); | 313 log0.GetEntries(&entries0); |
| 312 | 314 |
| 313 ASSERT_EQ(2u, entries0.size()); | 315 ASSERT_EQ(2u, entries0.size()); |
| 314 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, | 316 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, |
| 315 entries0[0].type); | 317 entries0[0].type); |
| 316 | 318 |
| 317 // Check that request 1 completed as expected. | 319 // Check that request 1 completed as expected. |
| 318 EXPECT_EQ(1, callback1.WaitForResult()); | 320 EXPECT_EQ(1, callback1.WaitForResult()); |
| 319 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); | 321 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); |
| 320 | 322 |
| 321 TestNetLog::CapturedEntryList entries1; | 323 CapturedNetLogEntry::List entries1; |
| 322 log1.GetEntries(&entries1); | 324 log1.GetEntries(&entries1); |
| 323 | 325 |
| 324 ASSERT_EQ(4u, entries1.size()); | 326 ASSERT_EQ(4u, entries1.size()); |
| 325 EXPECT_TRUE(LogContainsBeginEvent( | 327 EXPECT_TRUE(LogContainsBeginEvent( |
| 326 entries1, 0, | 328 entries1, 0, |
| 327 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 329 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
| 328 EXPECT_TRUE(LogContainsEndEvent( | 330 EXPECT_TRUE(LogContainsEndEvent( |
| 329 entries1, 1, | 331 entries1, 1, |
| 330 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 332 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
| 331 | 333 |
| 332 // Check that request 2 completed as expected. | 334 // Check that request 2 completed as expected. |
| 333 EXPECT_EQ(2, callback2.WaitForResult()); | 335 EXPECT_EQ(2, callback2.WaitForResult()); |
| 334 EXPECT_EQ("PROXY request2:80", results2.ToPacString()); | 336 EXPECT_EQ("PROXY request2:80", results2.ToPacString()); |
| 335 | 337 |
| 336 TestNetLog::CapturedEntryList entries2; | 338 CapturedNetLogEntry::List entries2; |
| 337 log2.GetEntries(&entries2); | 339 log2.GetEntries(&entries2); |
| 338 | 340 |
| 339 ASSERT_EQ(4u, entries2.size()); | 341 ASSERT_EQ(4u, entries2.size()); |
| 340 EXPECT_TRUE(LogContainsBeginEvent( | 342 EXPECT_TRUE(LogContainsBeginEvent( |
| 341 entries2, 0, | 343 entries2, 0, |
| 342 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 344 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
| 343 EXPECT_TRUE(LogContainsEndEvent( | 345 EXPECT_TRUE(LogContainsEndEvent( |
| 344 entries2, 1, | 346 entries2, 1, |
| 345 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); | 347 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); |
| 346 } | 348 } |
| (...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 | 696 // All in all, the first thread should have seen just 1 request. And the |
| 695 // second thread 3 requests. | 697 // second thread 3 requests. |
| 696 ASSERT_EQ(2u, factory->resolvers().size()); | 698 ASSERT_EQ(2u, factory->resolvers().size()); |
| 697 EXPECT_EQ(1, factory->resolvers()[0]->request_count()); | 699 EXPECT_EQ(1, factory->resolvers()[0]->request_count()); |
| 698 EXPECT_EQ(3, factory->resolvers()[1]->request_count()); | 700 EXPECT_EQ(3, factory->resolvers()[1]->request_count()); |
| 699 } | 701 } |
| 700 | 702 |
| 701 } // namespace | 703 } // namespace |
| 702 | 704 |
| 703 } // namespace net | 705 } // namespace net |
| OLD | NEW |