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

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

Issue 10546071: CapturingNetLog - remove maximum entries constructor argument. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 8 years, 6 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 | Annotate | Revision Log
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_resolver_js_bindings.h" 5 #include "net/proxy/proxy_resolver_js_bindings.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/address_list.h" 10 #include "net/base/address_list.h"
(...skipping 15 matching lines...) Expand all
26 // This is a HostResolver that synchronously resolves all hosts to the 26 // This is a HostResolver that synchronously resolves all hosts to the
27 // following address list of length 3: 27 // following address list of length 3:
28 // 192.168.1.1 28 // 192.168.1.1
29 // 172.22.34.1 29 // 172.22.34.1
30 // 200.100.1.2 30 // 200.100.1.2
31 class MockHostResolverWithMultipleResults : public SyncHostResolver { 31 class MockHostResolverWithMultipleResults : public SyncHostResolver {
32 public: 32 public:
33 // HostResolver methods: 33 // HostResolver methods:
34 virtual int Resolve(const HostResolver::RequestInfo& info, 34 virtual int Resolve(const HostResolver::RequestInfo& info,
35 AddressList* addresses, 35 AddressList* addresses,
36 const net::BoundNetLog& bound_net_log) OVERRIDE { 36 const BoundNetLog& bound_net_log) OVERRIDE {
37 return ParseAddressList("192.168.1.1,172.22.34.1,200.100.1.2", "", 37 return ParseAddressList("192.168.1.1,172.22.34.1,200.100.1.2", "",
38 addresses); 38 addresses);
39 } 39 }
40 40
41 virtual void Shutdown() OVERRIDE {} 41 virtual void Shutdown() OVERRIDE {}
42 42
43 private: 43 private:
44 virtual ~MockHostResolverWithMultipleResults() {} 44 virtual ~MockHostResolverWithMultipleResults() {}
45 }; 45 };
46 46
47 class MockFailingHostResolver : public SyncHostResolver { 47 class MockFailingHostResolver : public SyncHostResolver {
48 public: 48 public:
49 MockFailingHostResolver() : count_(0) {} 49 MockFailingHostResolver() : count_(0) {}
50 50
51 // HostResolver methods: 51 // HostResolver methods:
52 virtual int Resolve(const HostResolver::RequestInfo& info, 52 virtual int Resolve(const HostResolver::RequestInfo& info,
53 AddressList* addresses, 53 AddressList* addresses,
54 const net::BoundNetLog& bound_net_log) OVERRIDE { 54 const BoundNetLog& bound_net_log) OVERRIDE {
55 count_++; 55 count_++;
56 return ERR_NAME_NOT_RESOLVED; 56 return ERR_NAME_NOT_RESOLVED;
57 } 57 }
58 58
59 virtual void Shutdown() OVERRIDE {} 59 virtual void Shutdown() OVERRIDE {}
60 60
61 // Returns the number of times Resolve() has been called. 61 // Returns the number of times Resolve() has been called.
62 int count() const { return count_; } 62 int count() const { return count_; }
63 void ResetCount() { count_ = 0; } 63 void ResetCount() { count_ = 0; }
64 64
65 private: 65 private:
66 int count_; 66 int count_;
67 }; 67 };
68 68
69 class MockSyncHostResolver : public SyncHostResolver { 69 class MockSyncHostResolver : public SyncHostResolver {
70 public: 70 public:
71 MockSyncHostResolver() { 71 MockSyncHostResolver() {
72 resolver_.set_synchronous_mode(true); 72 resolver_.set_synchronous_mode(true);
73 } 73 }
74 74
75 virtual int Resolve(const HostResolver::RequestInfo& info, 75 virtual int Resolve(const HostResolver::RequestInfo& info,
76 AddressList* addresses, 76 AddressList* addresses,
77 const net::BoundNetLog& bound_net_log) OVERRIDE { 77 const BoundNetLog& bound_net_log) OVERRIDE {
78 return resolver_.Resolve(info, addresses, CompletionCallback(), NULL, 78 return resolver_.Resolve(info, addresses, CompletionCallback(), NULL,
79 bound_net_log); 79 bound_net_log);
80 } 80 }
81 81
82 virtual void Shutdown() OVERRIDE {} 82 virtual void Shutdown() OVERRIDE {}
83 83
84 RuleBasedHostResolverProc* rules() { 84 RuleBasedHostResolverProc* rules() {
85 return resolver_.rules(); 85 return resolver_.rules();
86 } 86 }
87 87
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 EXPECT_FALSE(bindings->DnsResolveEx("foo", &ip_address)); 260 EXPECT_FALSE(bindings->DnsResolveEx("foo", &ip_address));
261 EXPECT_EQ(1, host_resolver->count()); 261 EXPECT_EQ(1, host_resolver->count());
262 262
263 bindings->set_current_request_context(NULL); 263 bindings->set_current_request_context(NULL);
264 } 264 }
265 265
266 // Test that when a binding is called, it logs to the per-request NetLog. 266 // Test that when a binding is called, it logs to the per-request NetLog.
267 TEST(ProxyResolverJSBindingsTest, NetLog) { 267 TEST(ProxyResolverJSBindingsTest, NetLog) {
268 MockFailingHostResolver* host_resolver = new MockFailingHostResolver; 268 MockFailingHostResolver* host_resolver = new MockFailingHostResolver;
269 269
270 CapturingNetLog global_log(CapturingNetLog::kUnbounded); 270 CapturingNetLog global_log;
271 271
272 // Get a hold of a DefaultJSBindings* (it is a hidden impl class). 272 // Get a hold of a DefaultJSBindings* (it is a hidden impl class).
273 scoped_ptr<ProxyResolverJSBindings> bindings( 273 scoped_ptr<ProxyResolverJSBindings> bindings(
274 ProxyResolverJSBindings::CreateDefault( 274 ProxyResolverJSBindings::CreateDefault(
275 host_resolver, &global_log, NULL)); 275 host_resolver, &global_log, NULL));
276 276
277 // Attach a capturing NetLog as the current request's log stream. 277 // Attach a capturing NetLog as the current request's log stream.
278 CapturingNetLog log(CapturingNetLog::kUnbounded); 278 CapturingNetLog log;
279 BoundNetLog bound_log(BoundNetLog::Make(&log, NetLog::SOURCE_NONE)); 279 BoundNetLog bound_log(BoundNetLog::Make(&log, NetLog::SOURCE_NONE));
280 ProxyResolverRequestContext context(&bound_log, NULL); 280 ProxyResolverRequestContext context(&bound_log, NULL);
281 bindings->set_current_request_context(&context); 281 bindings->set_current_request_context(&context);
282 282
283 std::string ip_address; 283 std::string ip_address;
284 net::CapturingNetLog::CapturedEntryList entries; 284 net::CapturingNetLog::CapturedEntryList entries;
285 log.GetEntries(&entries); 285 log.GetEntries(&entries);
286 ASSERT_EQ(0u, entries.size()); 286 ASSERT_EQ(0u, entries.size());
287 287
288 // Call all the bindings. Each call should be logging something to 288 // Call all the bindings. Each call should be logging something to
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 global_log.GetEntries(&global_log_entries); 356 global_log.GetEntries(&global_log_entries);
357 EXPECT_EQ(2u, global_log_entries.size()); 357 EXPECT_EQ(2u, global_log_entries.size());
358 EXPECT_TRUE(LogContainsEvent( 358 EXPECT_TRUE(LogContainsEvent(
359 global_log_entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, 359 global_log_entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT,
360 NetLog::PHASE_NONE)); 360 NetLog::PHASE_NONE));
361 } 361 }
362 362
363 } // namespace 363 } // namespace
364 364
365 } // namespace net 365 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/multi_threaded_proxy_resolver_unittest.cc ('k') | net/proxy/proxy_resolver_v8_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698