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

Side by Side Diff: net/proxy/proxy_service_unittest.cc

Issue 1084533002: Rename NetLogLogger and CapturingNetLog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
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"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, 254 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL,
255 log.bound()); 255 log.bound());
256 EXPECT_EQ(OK, rv); 256 EXPECT_EQ(OK, rv);
257 EXPECT_TRUE(resolver.pending_requests().empty()); 257 EXPECT_TRUE(resolver.pending_requests().empty());
258 258
259 EXPECT_TRUE(info.is_direct()); 259 EXPECT_TRUE(info.is_direct());
260 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); 260 EXPECT_TRUE(info.proxy_resolve_start_time().is_null());
261 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); 261 EXPECT_TRUE(info.proxy_resolve_end_time().is_null());
262 262
263 // Check the NetLog was filled correctly. 263 // Check the NetLog was filled correctly.
264 CapturingNetLog::CapturedEntryList entries; 264 TestNetLog::CapturedEntryList entries;
265 log.GetEntries(&entries); 265 log.GetEntries(&entries);
266 266
267 EXPECT_EQ(3u, entries.size()); 267 EXPECT_EQ(3u, entries.size());
268 EXPECT_TRUE(LogContainsBeginEvent( 268 EXPECT_TRUE(LogContainsBeginEvent(
269 entries, 0, NetLog::TYPE_PROXY_SERVICE)); 269 entries, 0, NetLog::TYPE_PROXY_SERVICE));
270 EXPECT_TRUE(LogContainsEvent( 270 EXPECT_TRUE(LogContainsEvent(
271 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, 271 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST,
272 NetLog::PHASE_NONE)); 272 NetLog::PHASE_NONE));
273 EXPECT_TRUE(LogContainsEndEvent( 273 EXPECT_TRUE(LogContainsEndEvent(
274 entries, 2, NetLog::TYPE_PROXY_SERVICE)); 274 entries, 2, NetLog::TYPE_PROXY_SERVICE));
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 EXPECT_EQ(OK, callback.WaitForResult()); 416 EXPECT_EQ(OK, callback.WaitForResult());
417 EXPECT_FALSE(info.is_direct()); 417 EXPECT_FALSE(info.is_direct());
418 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); 418 EXPECT_EQ("foopy:80", info.proxy_server().ToURI());
419 EXPECT_TRUE(info.did_use_pac_script()); 419 EXPECT_TRUE(info.did_use_pac_script());
420 420
421 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); 421 EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
422 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); 422 EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
423 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); 423 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
424 424
425 // Check the NetLog was filled correctly. 425 // Check the NetLog was filled correctly.
426 CapturingNetLog::CapturedEntryList entries; 426 TestNetLog::CapturedEntryList entries;
427 log.GetEntries(&entries); 427 log.GetEntries(&entries);
428 428
429 EXPECT_EQ(5u, entries.size()); 429 EXPECT_EQ(5u, entries.size());
430 EXPECT_TRUE(LogContainsBeginEvent( 430 EXPECT_TRUE(LogContainsBeginEvent(
431 entries, 0, NetLog::TYPE_PROXY_SERVICE)); 431 entries, 0, NetLog::TYPE_PROXY_SERVICE));
432 EXPECT_TRUE(LogContainsBeginEvent( 432 EXPECT_TRUE(LogContainsBeginEvent(
433 entries, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); 433 entries, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC));
434 EXPECT_TRUE(LogContainsEndEvent( 434 EXPECT_TRUE(LogContainsEndEvent(
435 entries, 2, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); 435 entries, 2, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC));
436 EXPECT_TRUE(LogContainsEndEvent( 436 EXPECT_TRUE(LogContainsEndEvent(
(...skipping 1526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 resolver.pending_requests()[0]->CompleteNow(OK); 1963 resolver.pending_requests()[0]->CompleteNow(OK);
1964 1964
1965 EXPECT_EQ(OK, callback3.WaitForResult()); 1965 EXPECT_EQ(OK, callback3.WaitForResult());
1966 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); 1966 EXPECT_EQ("request3:80", info3.proxy_server().ToURI());
1967 1967
1968 EXPECT_TRUE(resolver.cancelled_requests().empty()); 1968 EXPECT_TRUE(resolver.cancelled_requests().empty());
1969 1969
1970 EXPECT_FALSE(callback1.have_result()); // Cancelled. 1970 EXPECT_FALSE(callback1.have_result()); // Cancelled.
1971 EXPECT_FALSE(callback2.have_result()); // Cancelled. 1971 EXPECT_FALSE(callback2.have_result()); // Cancelled.
1972 1972
1973 CapturingNetLog::CapturedEntryList entries1; 1973 TestNetLog::CapturedEntryList entries1;
1974 log1.GetEntries(&entries1); 1974 log1.GetEntries(&entries1);
1975 1975
1976 // Check the NetLog for request 1 (which was cancelled) got filled properly. 1976 // Check the NetLog for request 1 (which was cancelled) got filled properly.
1977 EXPECT_EQ(4u, entries1.size()); 1977 EXPECT_EQ(4u, entries1.size());
1978 EXPECT_TRUE(LogContainsBeginEvent( 1978 EXPECT_TRUE(LogContainsBeginEvent(
1979 entries1, 0, NetLog::TYPE_PROXY_SERVICE)); 1979 entries1, 0, NetLog::TYPE_PROXY_SERVICE));
1980 EXPECT_TRUE(LogContainsBeginEvent( 1980 EXPECT_TRUE(LogContainsBeginEvent(
1981 entries1, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC)); 1981 entries1, 1, NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC));
1982 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before 1982 // Note that TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC is never completed before
1983 // the cancellation occured. 1983 // the cancellation occured.
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
2416 2416
2417 EXPECT_TRUE(info2.is_direct()); 2417 EXPECT_TRUE(info2.is_direct());
2418 } 2418 }
2419 2419
2420 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { 2420 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) {
2421 MockProxyConfigService* config_service = 2421 MockProxyConfigService* config_service =
2422 new MockProxyConfigService("http://foopy/proxy.pac"); 2422 new MockProxyConfigService("http://foopy/proxy.pac");
2423 2423
2424 MockAsyncProxyResolverExpectsBytes resolver; 2424 MockAsyncProxyResolverExpectsBytes resolver;
2425 2425
2426 CapturingNetLog log; 2426 TestNetLog log;
2427 2427
2428 ProxyService service( 2428 ProxyService service(
2429 config_service, 2429 config_service,
2430 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), &log); 2430 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), &log);
2431 2431
2432 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2432 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2433 service.SetProxyScriptFetchers(fetcher, 2433 service.SetProxyScriptFetchers(fetcher,
2434 new DoNothingDhcpProxyScriptFetcher()); 2434 new DoNothingDhcpProxyScriptFetcher());
2435 2435
2436 // Disable the "wait after IP address changes" hack, so this unit-test can 2436 // Disable the "wait after IP address changes" hack, so this unit-test can
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2513 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); 2513 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80");
2514 resolver.pending_requests()[0]->CompleteNow(OK); 2514 resolver.pending_requests()[0]->CompleteNow(OK);
2515 2515
2516 // Wait for completion callback, and verify that the request ran as expected. 2516 // Wait for completion callback, and verify that the request ran as expected.
2517 EXPECT_EQ(OK, callback2.WaitForResult()); 2517 EXPECT_EQ(OK, callback2.WaitForResult());
2518 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); 2518 EXPECT_EQ("request2:80", info2.proxy_server().ToURI());
2519 2519
2520 // Check that the expected events were output to the log stream. In particular 2520 // Check that the expected events were output to the log stream. In particular
2521 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial 2521 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial
2522 // setup), and NOT a second time when the IP address changed. 2522 // setup), and NOT a second time when the IP address changed.
2523 CapturingNetLog::CapturedEntryList entries; 2523 TestNetLog::CapturedEntryList entries;
2524 log.GetEntries(&entries); 2524 log.GetEntries(&entries);
2525 2525
2526 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, 2526 EXPECT_TRUE(LogContainsEntryWithType(entries, 0,
2527 NetLog::TYPE_PROXY_CONFIG_CHANGED)); 2527 NetLog::TYPE_PROXY_CONFIG_CHANGED));
2528 ASSERT_EQ(9u, entries.size()); 2528 ASSERT_EQ(9u, entries.size());
2529 for (size_t i = 1; i < entries.size(); ++i) 2529 for (size_t i = 1; i < entries.size(); ++i)
2530 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type); 2530 EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, entries[i].type);
2531 } 2531 }
2532 2532
2533 // This test verifies that the PAC script specified by the settings is 2533 // This test verifies that the PAC script specified by the settings is
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
3166 url, net::LOAD_NORMAL, &info, NULL, log.bound()); 3166 url, net::LOAD_NORMAL, &info, NULL, log.bound());
3167 EXPECT_TRUE(synchronous_success); 3167 EXPECT_TRUE(synchronous_success);
3168 EXPECT_FALSE(info.is_direct()); 3168 EXPECT_FALSE(info.is_direct());
3169 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); 3169 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host());
3170 3170
3171 // No request should have been queued. 3171 // No request should have been queued.
3172 EXPECT_EQ(0u, resolver.pending_requests().size()); 3172 EXPECT_EQ(0u, resolver.pending_requests().size());
3173 } 3173 }
3174 3174
3175 } // namespace net 3175 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698