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/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 #include "net/base/network_delegate_impl.h" | 15 #include "net/base/network_delegate_impl.h" |
16 #include "net/base/test_completion_callback.h" | 16 #include "net/base/test_completion_callback.h" |
| 17 #include "net/log/captured_net_log_entry.h" |
17 #include "net/log/net_log.h" | 18 #include "net/log/net_log.h" |
18 #include "net/log/net_log_unittest.h" | 19 #include "net/log/net_log_unittest.h" |
| 20 #include "net/log/test_net_log.h" |
19 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 21 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
20 #include "net/proxy/mock_proxy_resolver.h" | 22 #include "net/proxy/mock_proxy_resolver.h" |
21 #include "net/proxy/mock_proxy_script_fetcher.h" | 23 #include "net/proxy/mock_proxy_script_fetcher.h" |
22 #include "net/proxy/proxy_config_service.h" | 24 #include "net/proxy/proxy_config_service.h" |
23 #include "net/proxy/proxy_resolver.h" | 25 #include "net/proxy/proxy_resolver.h" |
24 #include "net/proxy/proxy_script_fetcher.h" | 26 #include "net/proxy/proxy_script_fetcher.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "url/gurl.h" | 28 #include "url/gurl.h" |
27 | 29 |
28 using base::ASCIIToUTF16; | 30 using base::ASCIIToUTF16; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), | 255 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), |
254 NULL, NULL, log.bound()); | 256 NULL, NULL, log.bound()); |
255 EXPECT_EQ(OK, rv); | 257 EXPECT_EQ(OK, rv); |
256 EXPECT_TRUE(resolver.pending_requests().empty()); | 258 EXPECT_TRUE(resolver.pending_requests().empty()); |
257 | 259 |
258 EXPECT_TRUE(info.is_direct()); | 260 EXPECT_TRUE(info.is_direct()); |
259 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); | 261 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); |
260 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); | 262 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); |
261 | 263 |
262 // Check the NetLog was filled correctly. | 264 // Check the NetLog was filled correctly. |
263 TestNetLog::CapturedEntryList entries; | 265 CapturedNetLogEntry::List entries; |
264 log.GetEntries(&entries); | 266 log.GetEntries(&entries); |
265 | 267 |
266 EXPECT_EQ(3u, entries.size()); | 268 EXPECT_EQ(3u, entries.size()); |
267 EXPECT_TRUE(LogContainsBeginEvent( | 269 EXPECT_TRUE(LogContainsBeginEvent( |
268 entries, 0, NetLog::TYPE_PROXY_SERVICE)); | 270 entries, 0, NetLog::TYPE_PROXY_SERVICE)); |
269 EXPECT_TRUE(LogContainsEvent( | 271 EXPECT_TRUE(LogContainsEvent( |
270 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, | 272 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, |
271 NetLog::PHASE_NONE)); | 273 NetLog::PHASE_NONE)); |
272 EXPECT_TRUE(LogContainsEndEvent( | 274 EXPECT_TRUE(LogContainsEndEvent( |
273 entries, 2, NetLog::TYPE_PROXY_SERVICE)); | 275 entries, 2, NetLog::TYPE_PROXY_SERVICE)); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 EXPECT_EQ(OK, callback.WaitForResult()); | 407 EXPECT_EQ(OK, callback.WaitForResult()); |
406 EXPECT_FALSE(info.is_direct()); | 408 EXPECT_FALSE(info.is_direct()); |
407 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); | 409 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); |
408 EXPECT_TRUE(info.did_use_pac_script()); | 410 EXPECT_TRUE(info.did_use_pac_script()); |
409 | 411 |
410 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 412 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
411 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 413 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
412 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 414 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
413 | 415 |
414 // Check the NetLog was filled correctly. | 416 // Check the NetLog was filled correctly. |
415 TestNetLog::CapturedEntryList entries; | 417 CapturedNetLogEntry::List entries; |
416 log.GetEntries(&entries); | 418 log.GetEntries(&entries); |
417 | 419 |
418 EXPECT_EQ(5u, entries.size()); | 420 EXPECT_EQ(5u, entries.size()); |
419 EXPECT_TRUE(LogContainsBeginEvent( | 421 EXPECT_TRUE(LogContainsBeginEvent( |
420 entries, 0, NetLog::TYPE_PROXY_SERVICE)); | 422 entries, 0, NetLog::TYPE_PROXY_SERVICE)); |
421 EXPECT_TRUE(LogContainsBeginEvent( | 423 EXPECT_TRUE(LogContainsBeginEvent( |
422 entries, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 424 entries, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
423 EXPECT_TRUE(LogContainsEndEvent( | 425 EXPECT_TRUE(LogContainsEndEvent( |
424 entries, 2, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 426 entries, 2, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
425 EXPECT_TRUE(LogContainsEndEvent( | 427 EXPECT_TRUE(LogContainsEndEvent( |
(...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1912 resolver.pending_requests()[0]->CompleteNow(OK); | 1914 resolver.pending_requests()[0]->CompleteNow(OK); |
1913 | 1915 |
1914 EXPECT_EQ(OK, callback3.WaitForResult()); | 1916 EXPECT_EQ(OK, callback3.WaitForResult()); |
1915 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 1917 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
1916 | 1918 |
1917 EXPECT_TRUE(resolver.cancelled_requests().empty()); | 1919 EXPECT_TRUE(resolver.cancelled_requests().empty()); |
1918 | 1920 |
1919 EXPECT_FALSE(callback1.have_result()); // Cancelled. | 1921 EXPECT_FALSE(callback1.have_result()); // Cancelled. |
1920 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 1922 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
1921 | 1923 |
1922 TestNetLog::CapturedEntryList entries1; | 1924 CapturedNetLogEntry::List entries1; |
1923 log1.GetEntries(&entries1); | 1925 log1.GetEntries(&entries1); |
1924 | 1926 |
1925 // Check the NetLog for request 1 (which was cancelled) got filled properly. | 1927 // Check the NetLog for request 1 (which was cancelled) got filled properly. |
1926 EXPECT_EQ(4u, entries1.size()); | 1928 EXPECT_EQ(4u, entries1.size()); |
1927 EXPECT_TRUE(LogContainsBeginEvent( | 1929 EXPECT_TRUE(LogContainsBeginEvent( |
1928 entries1, 0, NetLog::TYPE_PROXY_SERVICE)); | 1930 entries1, 0, NetLog::TYPE_PROXY_SERVICE)); |
1929 EXPECT_TRUE(LogContainsBeginEvent( | 1931 EXPECT_TRUE(LogContainsBeginEvent( |
1930 entries1, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); | 1932 entries1, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); |
1931 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before | 1933 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before |
1932 // the cancellation occured. | 1934 // the cancellation occured. |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2459 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2461 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2460 resolver.pending_requests()[0]->CompleteNow(OK); | 2462 resolver.pending_requests()[0]->CompleteNow(OK); |
2461 | 2463 |
2462 // Wait for completion callback, and verify that the request ran as expected. | 2464 // Wait for completion callback, and verify that the request ran as expected. |
2463 EXPECT_EQ(OK, callback2.WaitForResult()); | 2465 EXPECT_EQ(OK, callback2.WaitForResult()); |
2464 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2466 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2465 | 2467 |
2466 // Check that the expected events were output to the log stream. In particular | 2468 // Check that the expected events were output to the log stream. In particular |
2467 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial | 2469 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial |
2468 // setup), and NOT a second time when the IP address changed. | 2470 // setup), and NOT a second time when the IP address changed. |
2469 TestNetLog::CapturedEntryList entries; | 2471 CapturedNetLogEntry::List entries; |
2470 log.GetEntries(&entries); | 2472 log.GetEntries(&entries); |
2471 | 2473 |
2472 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, | 2474 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, |
2473 NetLog::TYPE_PROXY_CONFIG_CHANGED)); | 2475 NetLog::TYPE_PROXY_CONFIG_CHANGED)); |
2474 ASSERT_EQ(9u, entries.size()); | 2476 ASSERT_EQ(9u, entries.size()); |
2475 for (size_t i = 1; i < entries.size(); ++i) | 2477 for (size_t i = 1; i < entries.size(); ++i) |
2476 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); | 2478 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); |
2477 } | 2479 } |
2478 | 2480 |
2479 // This test verifies that the PAC script specified by the settings is | 2481 // This test verifies that the PAC script specified by the settings is |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3106 url, LOAD_NORMAL, &info, NULL, log.bound()); | 3108 url, LOAD_NORMAL, &info, NULL, log.bound()); |
3107 EXPECT_TRUE(synchronous_success); | 3109 EXPECT_TRUE(synchronous_success); |
3108 EXPECT_FALSE(info.is_direct()); | 3110 EXPECT_FALSE(info.is_direct()); |
3109 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); | 3111 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); |
3110 | 3112 |
3111 // No request should have been queued. | 3113 // No request should have been queued. |
3112 EXPECT_EQ(0u, resolver.pending_requests().size()); | 3114 EXPECT_EQ(0u, resolver.pending_requests().size()); |
3113 } | 3115 } |
3114 | 3116 |
3115 } // namespace net | 3117 } // namespace net |
OLD | NEW |