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

Side by Side Diff: net/base/host_resolver_impl_unittest.cc

Issue 363025: Improve the display of LoadLogs when truncation occurs.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Change -1 to be a constant instead Created 11 years, 1 month 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
« no previous file with comments | « no previous file | net/base/load_log.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/base/host_resolver_impl.h" 5 #include "net/base/host_resolver_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <ws2tcpip.h> 8 #include <ws2tcpip.h>
9 #include <wspiapi.h> 9 #include <wspiapi.h>
10 #elif defined(OS_POSIX) 10 #elif defined(OS_POSIX)
(...skipping 12 matching lines...) Expand all
23 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
24 #include "net/base/test_completion_callback.h" 24 #include "net/base/test_completion_callback.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 // TODO(eroman): 27 // TODO(eroman):
28 // - Test mixing async with sync (in particular how does sync update the 28 // - Test mixing async with sync (in particular how does sync update the
29 // cache while an async is already pending). 29 // cache while an async is already pending).
30 30
31 namespace net { 31 namespace net {
32 namespace { 32 namespace {
33 static const int kMaxCacheEntries = 100; 33 const int kMaxCacheEntries = 100;
34 static const int kMaxCacheAgeMs = 60000; 34 const int kMaxCacheAgeMs = 60000;
35 35
36 // A variant of WaitingHostResolverProc that pushes each host mapped into a 36 // A variant of WaitingHostResolverProc that pushes each host mapped into a
37 // list. 37 // list.
38 // (and uses a manual-reset event rather than auto-reset). 38 // (and uses a manual-reset event rather than auto-reset).
39 class CapturingHostResolverProc : public HostResolverProc { 39 class CapturingHostResolverProc : public HostResolverProc {
40 public: 40 public:
41 explicit CapturingHostResolverProc(HostResolverProc* previous) 41 explicit CapturingHostResolverProc(HostResolverProc* previous)
42 : HostResolverProc(previous), event_(true, false) { 42 : HostResolverProc(previous), event_(true, false) {
43 } 43 }
44 44
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 const int kPortnum = 80; 182 const int kPortnum = 80;
183 183
184 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = 184 scoped_refptr<RuleBasedHostResolverProc> resolver_proc =
185 new RuleBasedHostResolverProc(NULL); 185 new RuleBasedHostResolverProc(NULL);
186 resolver_proc->AddRule("just.testing", "192.168.1.42"); 186 resolver_proc->AddRule("just.testing", "192.168.1.42");
187 187
188 scoped_refptr<HostResolver> host_resolver( 188 scoped_refptr<HostResolver> host_resolver(
189 new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); 189 new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs));
190 190
191 HostResolver::RequestInfo info("just.testing", kPortnum); 191 HostResolver::RequestInfo info("just.testing", kPortnum);
192 scoped_refptr<LoadLog> log(new LoadLog); 192 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded));
193 int err = host_resolver->Resolve(info, &adrlist, NULL, NULL, log); 193 int err = host_resolver->Resolve(info, &adrlist, NULL, NULL, log);
194 EXPECT_EQ(OK, err); 194 EXPECT_EQ(OK, err);
195 195
196 EXPECT_EQ(2u, log->events().size()); 196 EXPECT_EQ(2u, log->events().size());
197 ExpectLogContains(log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL, 197 ExpectLogContains(log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL,
198 LoadLog::PHASE_BEGIN); 198 LoadLog::PHASE_BEGIN);
199 ExpectLogContains(log, 1, LoadLog::TYPE_HOST_RESOLVER_IMPL, 199 ExpectLogContains(log, 1, LoadLog::TYPE_HOST_RESOLVER_IMPL,
200 LoadLog::PHASE_END); 200 LoadLog::PHASE_END);
201 201
202 const struct addrinfo* ainfo = adrlist.head(); 202 const struct addrinfo* ainfo = adrlist.head();
(...skipping 11 matching lines...) Expand all
214 const int kPortnum = 80; 214 const int kPortnum = 80;
215 215
216 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = 216 scoped_refptr<RuleBasedHostResolverProc> resolver_proc =
217 new RuleBasedHostResolverProc(NULL); 217 new RuleBasedHostResolverProc(NULL);
218 resolver_proc->AddRule("just.testing", "192.168.1.42"); 218 resolver_proc->AddRule("just.testing", "192.168.1.42");
219 219
220 scoped_refptr<HostResolver> host_resolver( 220 scoped_refptr<HostResolver> host_resolver(
221 new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); 221 new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs));
222 222
223 HostResolver::RequestInfo info("just.testing", kPortnum); 223 HostResolver::RequestInfo info("just.testing", kPortnum);
224 scoped_refptr<LoadLog> log(new LoadLog); 224 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded));
225 int err = host_resolver->Resolve(info, &adrlist, &callback_, NULL, log); 225 int err = host_resolver->Resolve(info, &adrlist, &callback_, NULL, log);
226 EXPECT_EQ(ERR_IO_PENDING, err); 226 EXPECT_EQ(ERR_IO_PENDING, err);
227 227
228 EXPECT_EQ(1u, log->events().size()); 228 EXPECT_EQ(1u, log->events().size());
229 ExpectLogContains(log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL, 229 ExpectLogContains(log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL,
230 LoadLog::PHASE_BEGIN); 230 LoadLog::PHASE_BEGIN);
231 231
232 MessageLoop::current()->Run(); 232 MessageLoop::current()->Run();
233 233
234 ASSERT_TRUE(callback_called_); 234 ASSERT_TRUE(callback_called_);
(...skipping 10 matching lines...) Expand all
245 const struct sockaddr* sa = ainfo->ai_addr; 245 const struct sockaddr* sa = ainfo->ai_addr;
246 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; 246 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa;
247 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port); 247 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port);
248 EXPECT_TRUE(htonl(0xc0a8012a) == sa_in->sin_addr.s_addr); 248 EXPECT_TRUE(htonl(0xc0a8012a) == sa_in->sin_addr.s_addr);
249 } 249 }
250 250
251 TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { 251 TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) {
252 scoped_refptr<WaitingHostResolverProc> resolver_proc = 252 scoped_refptr<WaitingHostResolverProc> resolver_proc =
253 new WaitingHostResolverProc(NULL); 253 new WaitingHostResolverProc(NULL);
254 254
255 scoped_refptr<LoadLog> log(new LoadLog); 255 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded));
256 { 256 {
257 scoped_refptr<HostResolver> host_resolver( 257 scoped_refptr<HostResolver> host_resolver(
258 new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); 258 new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs));
259 AddressList adrlist; 259 AddressList adrlist;
260 const int kPortnum = 80; 260 const int kPortnum = 80;
261 261
262 HostResolver::RequestInfo info("just.testing", kPortnum); 262 HostResolver::RequestInfo info("just.testing", kPortnum);
263 int err = host_resolver->Resolve(info, &adrlist, &callback_, NULL, log); 263 int err = host_resolver->Resolve(info, &adrlist, &callback_, NULL, log);
264 EXPECT_EQ(ERR_IO_PENDING, err); 264 EXPECT_EQ(ERR_IO_PENDING, err);
265 265
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 new HostResolverImpl(NULL, kMaxCacheEntries, kMaxCacheAgeMs)); 815 new HostResolverImpl(NULL, kMaxCacheEntries, kMaxCacheAgeMs));
816 816
817 CapturingObserver observer; 817 CapturingObserver observer;
818 818
819 host_resolver->AddObserver(&observer); 819 host_resolver->AddObserver(&observer);
820 820
821 AddressList addrlist; 821 AddressList addrlist;
822 822
823 // Resolve "host1". 823 // Resolve "host1".
824 HostResolver::RequestInfo info1("host1", 70); 824 HostResolver::RequestInfo info1("host1", 70);
825 scoped_refptr<LoadLog> log(new LoadLog); 825 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded));
826 int rv = host_resolver->Resolve(info1, &addrlist, NULL, NULL, log); 826 int rv = host_resolver->Resolve(info1, &addrlist, NULL, NULL, log);
827 EXPECT_EQ(OK, rv); 827 EXPECT_EQ(OK, rv);
828 828
829 EXPECT_EQ(6u, log->events().size()); 829 EXPECT_EQ(6u, log->events().size());
830 ExpectLogContains(log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL, 830 ExpectLogContains(log, 0, LoadLog::TYPE_HOST_RESOLVER_IMPL,
831 LoadLog::PHASE_BEGIN); 831 LoadLog::PHASE_BEGIN);
832 ExpectLogContains(log, 1, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, 832 ExpectLogContains(log, 1, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
833 LoadLog::PHASE_BEGIN); 833 LoadLog::PHASE_BEGIN);
834 ExpectLogContains(log, 2, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, 834 ExpectLogContains(log, 2, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
835 LoadLog::PHASE_END); 835 LoadLog::PHASE_END);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 EXPECT_EQ(0U, observer.finish_log.size()); 956 EXPECT_EQ(0U, observer.finish_log.size());
957 EXPECT_EQ(2U, observer.cancel_log.size()); 957 EXPECT_EQ(2U, observer.cancel_log.size());
958 958
959 HostResolver::RequestInfo info("host2", 60); 959 HostResolver::RequestInfo info("host2", 60);
960 EXPECT_TRUE(observer.cancel_log[1] == 960 EXPECT_TRUE(observer.cancel_log[1] ==
961 CapturingObserver::StartOrCancelEntry(1, info)); 961 CapturingObserver::StartOrCancelEntry(1, info));
962 } 962 }
963 963
964 } // namespace 964 } // namespace
965 } // namespace net 965 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/load_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698