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

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

Issue 1783008: Cleanup: Remove the implicit constructor for BoundNetLog that allowed passing... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Sync Created 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/net/resolve_proxy_msg_helper.cc ('k') | net/base/net_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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 }; 163 };
164 164
165 ResolveRequest(HostResolver* resolver, 165 ResolveRequest(HostResolver* resolver,
166 const std::string& hostname, 166 const std::string& hostname,
167 int port, 167 int port,
168 Delegate* delegate) 168 Delegate* delegate)
169 : info_(hostname, port), resolver_(resolver), delegate_(delegate), 169 : info_(hostname, port), resolver_(resolver), delegate_(delegate),
170 ALLOW_THIS_IN_INITIALIZER_LIST( 170 ALLOW_THIS_IN_INITIALIZER_LIST(
171 callback_(this, &ResolveRequest::OnLookupFinished)) { 171 callback_(this, &ResolveRequest::OnLookupFinished)) {
172 // Start the request. 172 // Start the request.
173 int err = resolver->Resolve(info_, &addrlist_, &callback_, &req_, NULL); 173 int err = resolver->Resolve(info_, &addrlist_, &callback_, &req_,
174 BoundNetLog());
174 EXPECT_EQ(ERR_IO_PENDING, err); 175 EXPECT_EQ(ERR_IO_PENDING, err);
175 } 176 }
176 177
177 ResolveRequest(HostResolver* resolver, 178 ResolveRequest(HostResolver* resolver,
178 const HostResolver::RequestInfo& info, 179 const HostResolver::RequestInfo& info,
179 Delegate* delegate) 180 Delegate* delegate)
180 : info_(info), resolver_(resolver), delegate_(delegate), 181 : info_(info), resolver_(resolver), delegate_(delegate),
181 ALLOW_THIS_IN_INITIALIZER_LIST( 182 ALLOW_THIS_IN_INITIALIZER_LIST(
182 callback_(this, &ResolveRequest::OnLookupFinished)) { 183 callback_(this, &ResolveRequest::OnLookupFinished)) {
183 // Start the request. 184 // Start the request.
184 int err = resolver->Resolve(info, &addrlist_, &callback_, &req_, NULL); 185 int err = resolver->Resolve(info, &addrlist_, &callback_, &req_,
186 BoundNetLog());
185 EXPECT_EQ(ERR_IO_PENDING, err); 187 EXPECT_EQ(ERR_IO_PENDING, err);
186 } 188 }
187 189
188 void Cancel() { 190 void Cancel() {
189 resolver_->CancelRequest(req_); 191 resolver_->CancelRequest(req_);
190 } 192 }
191 193
192 const std::string& hostname() const { 194 const std::string& hostname() const {
193 return info_.hostname(); 195 return info_.hostname();
194 } 196 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 369
368 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = 370 scoped_refptr<RuleBasedHostResolverProc> resolver_proc =
369 new RuleBasedHostResolverProc(NULL); 371 new RuleBasedHostResolverProc(NULL);
370 resolver_proc->AllowDirectLookup("*"); 372 resolver_proc->AllowDirectLookup("*");
371 373
372 scoped_refptr<HostResolver> host_resolver( 374 scoped_refptr<HostResolver> host_resolver(
373 CreateHostResolverImpl(resolver_proc)); 375 CreateHostResolverImpl(resolver_proc));
374 AddressList adrlist; 376 AddressList adrlist;
375 const int kPortnum = 5555; 377 const int kPortnum = 5555;
376 HostResolver::RequestInfo info("127.1.2.3", kPortnum); 378 HostResolver::RequestInfo info("127.1.2.3", kPortnum);
377 int err = host_resolver->Resolve(info, &adrlist, NULL, NULL, NULL); 379 int err = host_resolver->Resolve(info, &adrlist, NULL, NULL, BoundNetLog());
378 EXPECT_EQ(OK, err); 380 EXPECT_EQ(OK, err);
379 381
380 const struct addrinfo* ainfo = adrlist.head(); 382 const struct addrinfo* ainfo = adrlist.head();
381 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); 383 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next);
382 EXPECT_EQ(sizeof(struct sockaddr_in), ainfo->ai_addrlen); 384 EXPECT_EQ(sizeof(struct sockaddr_in), ainfo->ai_addrlen);
383 385
384 const struct sockaddr* sa = ainfo->ai_addr; 386 const struct sockaddr* sa = ainfo->ai_addr;
385 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa; 387 const struct sockaddr_in* sa_in = (const struct sockaddr_in*) sa;
386 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port); 388 EXPECT_TRUE(htons(kPortnum) == sa_in->sin_port);
387 EXPECT_TRUE(htonl(0x7f010203) == sa_in->sin_addr.s_addr); 389 EXPECT_TRUE(htonl(0x7f010203) == sa_in->sin_addr.s_addr);
388 } 390 }
389 391
390 TEST_F(HostResolverImplTest, NumericIPv6Address) { 392 TEST_F(HostResolverImplTest, NumericIPv6Address) {
391 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = 393 scoped_refptr<RuleBasedHostResolverProc> resolver_proc =
392 new RuleBasedHostResolverProc(NULL); 394 new RuleBasedHostResolverProc(NULL);
393 resolver_proc->AllowDirectLookup("*"); 395 resolver_proc->AllowDirectLookup("*");
394 396
395 // Resolve a plain IPv6 address. Don't worry about [brackets], because 397 // Resolve a plain IPv6 address. Don't worry about [brackets], because
396 // the caller should have removed them. 398 // the caller should have removed them.
397 scoped_refptr<HostResolver> host_resolver( 399 scoped_refptr<HostResolver> host_resolver(
398 CreateHostResolverImpl(resolver_proc)); 400 CreateHostResolverImpl(resolver_proc));
399 AddressList adrlist; 401 AddressList adrlist;
400 const int kPortnum = 5555; 402 const int kPortnum = 5555;
401 HostResolver::RequestInfo info("2001:db8::1", kPortnum); 403 HostResolver::RequestInfo info("2001:db8::1", kPortnum);
402 int err = host_resolver->Resolve(info, &adrlist, NULL, NULL, NULL); 404 int err = host_resolver->Resolve(info, &adrlist, NULL, NULL, BoundNetLog());
403 // On computers without IPv6 support, getaddrinfo cannot convert IPv6 405 // On computers without IPv6 support, getaddrinfo cannot convert IPv6
404 // address literals to addresses (getaddrinfo returns EAI_NONAME). So this 406 // address literals to addresses (getaddrinfo returns EAI_NONAME). So this
405 // test has to allow host_resolver->Resolve to fail. 407 // test has to allow host_resolver->Resolve to fail.
406 if (err == ERR_NAME_NOT_RESOLVED) 408 if (err == ERR_NAME_NOT_RESOLVED)
407 return; 409 return;
408 EXPECT_EQ(OK, err); 410 EXPECT_EQ(OK, err);
409 411
410 const struct addrinfo* ainfo = adrlist.head(); 412 const struct addrinfo* ainfo = adrlist.head();
411 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next); 413 EXPECT_EQ(static_cast<addrinfo*>(NULL), ainfo->ai_next);
412 EXPECT_EQ(sizeof(struct sockaddr_in6), ainfo->ai_addrlen); 414 EXPECT_EQ(sizeof(struct sockaddr_in6), ainfo->ai_addrlen);
(...skipping 14 matching lines...) Expand all
427 TEST_F(HostResolverImplTest, EmptyHost) { 429 TEST_F(HostResolverImplTest, EmptyHost) {
428 scoped_refptr<RuleBasedHostResolverProc> resolver_proc = 430 scoped_refptr<RuleBasedHostResolverProc> resolver_proc =
429 new RuleBasedHostResolverProc(NULL); 431 new RuleBasedHostResolverProc(NULL);
430 resolver_proc->AllowDirectLookup("*"); 432 resolver_proc->AllowDirectLookup("*");
431 433
432 scoped_refptr<HostResolver> host_resolver( 434 scoped_refptr<HostResolver> host_resolver(
433 CreateHostResolverImpl(resolver_proc)); 435 CreateHostResolverImpl(resolver_proc));
434 AddressList adrlist; 436 AddressList adrlist;
435 const int kPortnum = 5555; 437 const int kPortnum = 5555;
436 HostResolver::RequestInfo info("", kPortnum); 438 HostResolver::RequestInfo info("", kPortnum);
437 int err = host_resolver->Resolve(info, &adrlist, NULL, NULL, NULL); 439 int err = host_resolver->Resolve(info, &adrlist, NULL, NULL, BoundNetLog());
438 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, err); 440 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, err);
439 } 441 }
440 442
441 // Helper class used by HostResolverImplTest.DeDupeRequests. It receives request 443 // Helper class used by HostResolverImplTest.DeDupeRequests. It receives request
442 // completion notifications for all the resolves, so it can tally up and 444 // completion notifications for all the resolves, so it can tally up and
443 // determine when we are done. 445 // determine when we are done.
444 class DeDupeRequestsVerifier : public ResolveRequest::Delegate { 446 class DeDupeRequestsVerifier : public ResolveRequest::Delegate {
445 public: 447 public:
446 explicit DeDupeRequestsVerifier(CapturingHostResolverProc* resolver_proc) 448 explicit DeDupeRequestsVerifier(CapturingHostResolverProc* resolver_proc)
447 : count_a_(0), count_b_(0), resolver_proc_(resolver_proc) {} 449 : count_a_(0), count_b_(0), resolver_proc_(resolver_proc) {}
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 // Since caching is enabled, this should complete synchronously. 781 // Since caching is enabled, this should complete synchronously.
780 782
781 // Note that |junk_callback| shouldn't be used since we are going to 783 // Note that |junk_callback| shouldn't be used since we are going to
782 // complete synchronously. We can't specify NULL though since that would 784 // complete synchronously. We can't specify NULL though since that would
783 // mean synchronous mode so we give it a value of 1. 785 // mean synchronous mode so we give it a value of 1.
784 CompletionCallback* junk_callback = 786 CompletionCallback* junk_callback =
785 reinterpret_cast<CompletionCallback*> (1); 787 reinterpret_cast<CompletionCallback*> (1);
786 AddressList addrlist; 788 AddressList addrlist;
787 789
788 HostResolver::RequestInfo info("a", 70); 790 HostResolver::RequestInfo info("a", 70);
789 int error = resolver->Resolve(info, &addrlist, junk_callback, NULL, NULL); 791 int error = resolver->Resolve(info, &addrlist, junk_callback, NULL,
792 BoundNetLog());
790 EXPECT_EQ(OK, error); 793 EXPECT_EQ(OK, error);
791 794
792 // Ok good. Now make sure that if we ask to bypass the cache, it can no 795 // Ok good. Now make sure that if we ask to bypass the cache, it can no
793 // longer service the request synchronously. 796 // longer service the request synchronously.
794 info = HostResolver::RequestInfo("a", 71); 797 info = HostResolver::RequestInfo("a", 71);
795 info.set_allow_cached_response(false); 798 info.set_allow_cached_response(false);
796 final_request_.reset(new ResolveRequest(resolver, info, this)); 799 final_request_.reset(new ResolveRequest(resolver, info, this));
797 } else if (71 == resolve->port()) { 800 } else if (71 == resolve->port()) {
798 // Test is done. 801 // Test is done.
799 MessageLoop::current()->Quit(); 802 MessageLoop::current()->Quit();
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 EXPECT_EQ(1U, observer.finish_log.size()); 929 EXPECT_EQ(1U, observer.finish_log.size());
927 EXPECT_EQ(0U, observer.cancel_log.size()); 930 EXPECT_EQ(0U, observer.cancel_log.size());
928 EXPECT_TRUE(observer.start_log[0] == 931 EXPECT_TRUE(observer.start_log[0] ==
929 CapturingObserver::StartOrCancelEntry(0, info1)); 932 CapturingObserver::StartOrCancelEntry(0, info1));
930 EXPECT_TRUE(observer.finish_log[0] == 933 EXPECT_TRUE(observer.finish_log[0] ==
931 CapturingObserver::FinishEntry(0, true, info1)); 934 CapturingObserver::FinishEntry(0, true, info1));
932 935
933 // Resolve "host1" again -- this time it will be served from cache, but it 936 // Resolve "host1" again -- this time it will be served from cache, but it
934 // should still notify of completion. 937 // should still notify of completion.
935 TestCompletionCallback callback; 938 TestCompletionCallback callback;
936 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL); 939 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog());
937 ASSERT_EQ(OK, rv); // Should complete synchronously. 940 ASSERT_EQ(OK, rv); // Should complete synchronously.
938 941
939 EXPECT_EQ(2U, observer.start_log.size()); 942 EXPECT_EQ(2U, observer.start_log.size());
940 EXPECT_EQ(2U, observer.finish_log.size()); 943 EXPECT_EQ(2U, observer.finish_log.size());
941 EXPECT_EQ(0U, observer.cancel_log.size()); 944 EXPECT_EQ(0U, observer.cancel_log.size());
942 EXPECT_TRUE(observer.start_log[1] == 945 EXPECT_TRUE(observer.start_log[1] ==
943 CapturingObserver::StartOrCancelEntry(1, info1)); 946 CapturingObserver::StartOrCancelEntry(1, info1));
944 EXPECT_TRUE(observer.finish_log[1] == 947 EXPECT_TRUE(observer.finish_log[1] ==
945 CapturingObserver::FinishEntry(1, true, info1)); 948 CapturingObserver::FinishEntry(1, true, info1));
946 949
947 // Resolve "host2", setting referrer to "http://foobar.com" 950 // Resolve "host2", setting referrer to "http://foobar.com"
948 HostResolver::RequestInfo info2("host2", 70); 951 HostResolver::RequestInfo info2("host2", 70);
949 info2.set_referrer(GURL("http://foobar.com")); 952 info2.set_referrer(GURL("http://foobar.com"));
950 rv = host_resolver->Resolve(info2, &addrlist, NULL, NULL, NULL); 953 rv = host_resolver->Resolve(info2, &addrlist, NULL, NULL, BoundNetLog());
951 EXPECT_EQ(OK, rv); 954 EXPECT_EQ(OK, rv);
952 955
953 EXPECT_EQ(3U, observer.start_log.size()); 956 EXPECT_EQ(3U, observer.start_log.size());
954 EXPECT_EQ(3U, observer.finish_log.size()); 957 EXPECT_EQ(3U, observer.finish_log.size());
955 EXPECT_EQ(0U, observer.cancel_log.size()); 958 EXPECT_EQ(0U, observer.cancel_log.size());
956 EXPECT_TRUE(observer.start_log[2] == 959 EXPECT_TRUE(observer.start_log[2] ==
957 CapturingObserver::StartOrCancelEntry(2, info2)); 960 CapturingObserver::StartOrCancelEntry(2, info2));
958 EXPECT_TRUE(observer.finish_log[2] == 961 EXPECT_TRUE(observer.finish_log[2] ==
959 CapturingObserver::FinishEntry(2, true, info2)); 962 CapturingObserver::FinishEntry(2, true, info2));
960 963
961 // Unregister the observer. 964 // Unregister the observer.
962 host_resolver->RemoveObserver(&observer); 965 host_resolver->RemoveObserver(&observer);
963 966
964 // Resolve "host3" 967 // Resolve "host3"
965 HostResolver::RequestInfo info3("host3", 70); 968 HostResolver::RequestInfo info3("host3", 70);
966 host_resolver->Resolve(info3, &addrlist, NULL, NULL, NULL); 969 host_resolver->Resolve(info3, &addrlist, NULL, NULL, BoundNetLog());
967 970
968 // No effect this time, since observer was removed. 971 // No effect this time, since observer was removed.
969 EXPECT_EQ(3U, observer.start_log.size()); 972 EXPECT_EQ(3U, observer.start_log.size());
970 EXPECT_EQ(3U, observer.finish_log.size()); 973 EXPECT_EQ(3U, observer.finish_log.size());
971 EXPECT_EQ(0U, observer.cancel_log.size()); 974 EXPECT_EQ(0U, observer.cancel_log.size());
972 } 975 }
973 976
974 // Tests that observers are sent OnCancelResolution() whenever a request is 977 // Tests that observers are sent OnCancelResolution() whenever a request is
975 // cancelled. There are two ways to cancel a request: 978 // cancelled. There are two ways to cancel a request:
976 // (1) Delete the HostResolver while job is outstanding. 979 // (1) Delete the HostResolver while job is outstanding.
977 // (2) Call HostResolver::CancelRequest() while a request is outstanding. 980 // (2) Call HostResolver::CancelRequest() while a request is outstanding.
978 TEST_F(HostResolverImplTest, CancellationObserver) { 981 TEST_F(HostResolverImplTest, CancellationObserver) {
979 CapturingObserver observer; 982 CapturingObserver observer;
980 { 983 {
981 // Create a host resolver and attach an observer. 984 // Create a host resolver and attach an observer.
982 scoped_refptr<HostResolver> host_resolver( 985 scoped_refptr<HostResolver> host_resolver(
983 CreateHostResolverImpl(NULL)); 986 CreateHostResolverImpl(NULL));
984 host_resolver->AddObserver(&observer); 987 host_resolver->AddObserver(&observer);
985 988
986 TestCompletionCallback callback; 989 TestCompletionCallback callback;
987 990
988 EXPECT_EQ(0U, observer.start_log.size()); 991 EXPECT_EQ(0U, observer.start_log.size());
989 EXPECT_EQ(0U, observer.finish_log.size()); 992 EXPECT_EQ(0U, observer.finish_log.size());
990 EXPECT_EQ(0U, observer.cancel_log.size()); 993 EXPECT_EQ(0U, observer.cancel_log.size());
991 994
992 // Start an async resolve for (host1:70). 995 // Start an async resolve for (host1:70).
993 HostResolver::RequestInfo info1("host1", 70); 996 HostResolver::RequestInfo info1("host1", 70);
994 HostResolver::RequestHandle req = NULL; 997 HostResolver::RequestHandle req = NULL;
995 AddressList addrlist; 998 AddressList addrlist;
996 int rv = host_resolver->Resolve(info1, &addrlist, &callback, &req, NULL); 999 int rv = host_resolver->Resolve(info1, &addrlist, &callback, &req,
1000 BoundNetLog());
997 EXPECT_EQ(ERR_IO_PENDING, rv); 1001 EXPECT_EQ(ERR_IO_PENDING, rv);
998 EXPECT_TRUE(NULL != req); 1002 EXPECT_TRUE(NULL != req);
999 1003
1000 EXPECT_EQ(1U, observer.start_log.size()); 1004 EXPECT_EQ(1U, observer.start_log.size());
1001 EXPECT_EQ(0U, observer.finish_log.size()); 1005 EXPECT_EQ(0U, observer.finish_log.size());
1002 EXPECT_EQ(0U, observer.cancel_log.size()); 1006 EXPECT_EQ(0U, observer.cancel_log.size());
1003 1007
1004 EXPECT_TRUE(observer.start_log[0] == 1008 EXPECT_TRUE(observer.start_log[0] ==
1005 CapturingObserver::StartOrCancelEntry(0, info1)); 1009 CapturingObserver::StartOrCancelEntry(0, info1));
1006 1010
1007 // Cancel the request. 1011 // Cancel the request.
1008 host_resolver->CancelRequest(req); 1012 host_resolver->CancelRequest(req);
1009 1013
1010 EXPECT_EQ(1U, observer.start_log.size()); 1014 EXPECT_EQ(1U, observer.start_log.size());
1011 EXPECT_EQ(0U, observer.finish_log.size()); 1015 EXPECT_EQ(0U, observer.finish_log.size());
1012 EXPECT_EQ(1U, observer.cancel_log.size()); 1016 EXPECT_EQ(1U, observer.cancel_log.size());
1013 1017
1014 EXPECT_TRUE(observer.cancel_log[0] == 1018 EXPECT_TRUE(observer.cancel_log[0] ==
1015 CapturingObserver::StartOrCancelEntry(0, info1)); 1019 CapturingObserver::StartOrCancelEntry(0, info1));
1016 1020
1017 // Start an async request for (host2:60) 1021 // Start an async request for (host2:60)
1018 HostResolver::RequestInfo info2("host2", 60); 1022 HostResolver::RequestInfo info2("host2", 60);
1019 rv = host_resolver->Resolve(info2, &addrlist, &callback, NULL, NULL); 1023 rv = host_resolver->Resolve(info2, &addrlist, &callback, NULL,
1024 BoundNetLog());
1020 EXPECT_EQ(ERR_IO_PENDING, rv); 1025 EXPECT_EQ(ERR_IO_PENDING, rv);
1021 EXPECT_TRUE(NULL != req); 1026 EXPECT_TRUE(NULL != req);
1022 1027
1023 EXPECT_EQ(2U, observer.start_log.size()); 1028 EXPECT_EQ(2U, observer.start_log.size());
1024 EXPECT_EQ(0U, observer.finish_log.size()); 1029 EXPECT_EQ(0U, observer.finish_log.size());
1025 EXPECT_EQ(1U, observer.cancel_log.size()); 1030 EXPECT_EQ(1U, observer.cancel_log.size());
1026 1031
1027 EXPECT_TRUE(observer.start_log[1] == 1032 EXPECT_TRUE(observer.start_log[1] ==
1028 CapturingObserver::StartOrCancelEntry(1, info2)); 1033 CapturingObserver::StartOrCancelEntry(1, info2));
1029 1034
(...skipping 19 matching lines...) Expand all
1049 scoped_refptr<HostResolver> host_resolver( 1054 scoped_refptr<HostResolver> host_resolver(
1050 new HostResolverImpl(NULL, CreateDefaultCache(), 1055 new HostResolverImpl(NULL, CreateDefaultCache(),
1051 &mock_network_change_notifier, 1056 &mock_network_change_notifier,
1052 kMaxJobs)); 1057 kMaxJobs));
1053 1058
1054 AddressList addrlist; 1059 AddressList addrlist;
1055 1060
1056 // Resolve "host1". 1061 // Resolve "host1".
1057 HostResolver::RequestInfo info1("host1", 70); 1062 HostResolver::RequestInfo info1("host1", 70);
1058 TestCompletionCallback callback; 1063 TestCompletionCallback callback;
1059 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL); 1064 int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL,
1065 BoundNetLog());
1060 EXPECT_EQ(ERR_IO_PENDING, rv); 1066 EXPECT_EQ(ERR_IO_PENDING, rv);
1061 EXPECT_EQ(OK, callback.WaitForResult()); 1067 EXPECT_EQ(OK, callback.WaitForResult());
1062 1068
1063 // Resolve "host1" again -- this time it will be served from cache, but it 1069 // Resolve "host1" again -- this time it will be served from cache, but it
1064 // should still notify of completion. 1070 // should still notify of completion.
1065 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL); 1071 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog());
1066 ASSERT_EQ(OK, rv); // Should complete synchronously. 1072 ASSERT_EQ(OK, rv); // Should complete synchronously.
1067 1073
1068 // Flush cache by triggering an IP address change. 1074 // Flush cache by triggering an IP address change.
1069 mock_network_change_notifier.NotifyIPAddressChange(); 1075 mock_network_change_notifier.NotifyIPAddressChange();
1070 1076
1071 // Resolve "host1" again -- this time it won't be served from cache, so it 1077 // Resolve "host1" again -- this time it won't be served from cache, so it
1072 // will complete asynchronously. 1078 // will complete asynchronously.
1073 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL); 1079 rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, BoundNetLog());
1074 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. 1080 ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously.
1075 EXPECT_EQ(OK, callback.WaitForResult()); 1081 EXPECT_EQ(OK, callback.WaitForResult());
1076 } 1082 }
1077 1083
1078 // Tests that when the maximum threads is set to 1, requests are dequeued 1084 // Tests that when the maximum threads is set to 1, requests are dequeued
1079 // in order of priority. 1085 // in order of priority.
1080 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { 1086 TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) {
1081 scoped_refptr<CapturingHostResolverProc> resolver_proc = 1087 scoped_refptr<CapturingHostResolverProc> resolver_proc =
1082 new CapturingHostResolverProc(NULL); 1088 new CapturingHostResolverProc(NULL);
1083 1089
(...skipping 19 matching lines...) Expand all
1103 CreateResolverRequest("req6", LOW), 1109 CreateResolverRequest("req6", LOW),
1104 CreateResolverRequest("req5", HIGHEST), 1110 CreateResolverRequest("req5", HIGHEST),
1105 }; 1111 };
1106 1112
1107 TestCompletionCallback callback[arraysize(req)]; 1113 TestCompletionCallback callback[arraysize(req)];
1108 AddressList addrlist[arraysize(req)]; 1114 AddressList addrlist[arraysize(req)];
1109 1115
1110 // Start all of the requests. 1116 // Start all of the requests.
1111 for (size_t i = 0; i < arraysize(req); ++i) { 1117 for (size_t i = 0; i < arraysize(req); ++i) {
1112 int rv = host_resolver->Resolve(req[i], &addrlist[i], 1118 int rv = host_resolver->Resolve(req[i], &addrlist[i],
1113 &callback[i], NULL, NULL); 1119 &callback[i], NULL, BoundNetLog());
1114 EXPECT_EQ(ERR_IO_PENDING, rv); 1120 EXPECT_EQ(ERR_IO_PENDING, rv);
1115 } 1121 }
1116 1122
1117 // Unblock the resolver thread so the requests can run. 1123 // Unblock the resolver thread so the requests can run.
1118 resolver_proc->Signal(); 1124 resolver_proc->Signal();
1119 1125
1120 // Wait for all the requests to complete succesfully. 1126 // Wait for all the requests to complete succesfully.
1121 for (size_t i = 0; i < arraysize(req); ++i) { 1127 for (size_t i = 0; i < arraysize(req); ++i) {
1122 EXPECT_EQ(OK, callback[i].WaitForResult()) << "i=" << i; 1128 EXPECT_EQ(OK, callback[i].WaitForResult()) << "i=" << i;
1123 } 1129 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 CreateResolverRequest("req6", MEDIUM), 1191 CreateResolverRequest("req6", MEDIUM),
1186 }; 1192 };
1187 1193
1188 TestCompletionCallback callback[arraysize(req)]; 1194 TestCompletionCallback callback[arraysize(req)];
1189 AddressList addrlist[arraysize(req)]; 1195 AddressList addrlist[arraysize(req)];
1190 HostResolver::RequestHandle handle[arraysize(req)]; 1196 HostResolver::RequestHandle handle[arraysize(req)];
1191 1197
1192 // Start all of the requests. 1198 // Start all of the requests.
1193 for (size_t i = 0; i < arraysize(req); ++i) { 1199 for (size_t i = 0; i < arraysize(req); ++i) {
1194 int rv = host_resolver->Resolve(req[i], &addrlist[i], 1200 int rv = host_resolver->Resolve(req[i], &addrlist[i],
1195 &callback[i], &handle[i], NULL); 1201 &callback[i], &handle[i], BoundNetLog());
1196 EXPECT_EQ(ERR_IO_PENDING, rv); 1202 EXPECT_EQ(ERR_IO_PENDING, rv);
1197 } 1203 }
1198 1204
1199 // Cancel some requests 1205 // Cancel some requests
1200 host_resolver->CancelRequest(handle[1]); 1206 host_resolver->CancelRequest(handle[1]);
1201 host_resolver->CancelRequest(handle[4]); 1207 host_resolver->CancelRequest(handle[4]);
1202 host_resolver->CancelRequest(handle[5]); 1208 host_resolver->CancelRequest(handle[5]);
1203 handle[1] = handle[4] = handle[5] = NULL; 1209 handle[1] = handle[4] = handle[5] = NULL;
1204 1210
1205 // Unblock the resolver thread so the requests can run. 1211 // Unblock the resolver thread so the requests can run.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 CreateResolverRequest("req7", MEDIUM), // Evicts req2. 1266 CreateResolverRequest("req7", MEDIUM), // Evicts req2.
1261 }; 1267 };
1262 1268
1263 TestCompletionCallback callback[arraysize(req)]; 1269 TestCompletionCallback callback[arraysize(req)];
1264 AddressList addrlist[arraysize(req)]; 1270 AddressList addrlist[arraysize(req)];
1265 HostResolver::RequestHandle handle[arraysize(req)]; 1271 HostResolver::RequestHandle handle[arraysize(req)];
1266 1272
1267 // Start all of the requests. 1273 // Start all of the requests.
1268 for (size_t i = 0; i < arraysize(req); ++i) { 1274 for (size_t i = 0; i < arraysize(req); ++i) {
1269 int rv = host_resolver->Resolve(req[i], &addrlist[i], 1275 int rv = host_resolver->Resolve(req[i], &addrlist[i],
1270 &callback[i], &handle[i], NULL); 1276 &callback[i], &handle[i], BoundNetLog());
1271 if (i == 4u) 1277 if (i == 4u)
1272 EXPECT_EQ(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE, rv); 1278 EXPECT_EQ(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE, rv);
1273 else 1279 else
1274 EXPECT_EQ(ERR_IO_PENDING, rv) << i; 1280 EXPECT_EQ(ERR_IO_PENDING, rv) << i;
1275 } 1281 }
1276 1282
1277 // Unblock the resolver thread so the requests can run. 1283 // Unblock the resolver thread so the requests can run.
1278 resolver_proc->Signal(); 1284 resolver_proc->Signal();
1279 1285
1280 // Requests 3, 5, 2 will have been evicted due to queue overflow. 1286 // Requests 3, 5, 2 will have been evicted due to queue overflow.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6), 1332 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV6),
1327 }; 1333 };
1328 1334
1329 TestCompletionCallback callback[arraysize(req)]; 1335 TestCompletionCallback callback[arraysize(req)];
1330 AddressList addrlist[arraysize(req)]; 1336 AddressList addrlist[arraysize(req)];
1331 HostResolver::RequestHandle handle[arraysize(req)]; 1337 HostResolver::RequestHandle handle[arraysize(req)];
1332 1338
1333 // Start all of the requests. 1339 // Start all of the requests.
1334 for (size_t i = 0; i < arraysize(req); ++i) { 1340 for (size_t i = 0; i < arraysize(req); ++i) {
1335 int rv = host_resolver->Resolve(req[i], &addrlist[i], 1341 int rv = host_resolver->Resolve(req[i], &addrlist[i],
1336 &callback[i], &handle[i], NULL); 1342 &callback[i], &handle[i], BoundNetLog());
1337 EXPECT_EQ(ERR_IO_PENDING, rv) << i; 1343 EXPECT_EQ(ERR_IO_PENDING, rv) << i;
1338 } 1344 }
1339 1345
1340 // Unblock the resolver thread so the requests can run. 1346 // Unblock the resolver thread so the requests can run.
1341 resolver_proc->Signal(); 1347 resolver_proc->Signal();
1342 1348
1343 // Wait for all the requests to complete. 1349 // Wait for all the requests to complete.
1344 for (size_t i = 0u; i < arraysize(req); ++i) { 1350 for (size_t i = 0u; i < arraysize(req); ++i) {
1345 EXPECT_EQ(OK, callback[i].WaitForResult()); 1351 EXPECT_EQ(OK, callback[i].WaitForResult());
1346 } 1352 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4), 1401 CreateResolverRequestForAddressFamily("h1", MEDIUM, ADDRESS_FAMILY_IPV4),
1396 }; 1402 };
1397 1403
1398 TestCompletionCallback callback[arraysize(req)]; 1404 TestCompletionCallback callback[arraysize(req)];
1399 AddressList addrlist[arraysize(req)]; 1405 AddressList addrlist[arraysize(req)];
1400 HostResolver::RequestHandle handle[arraysize(req)]; 1406 HostResolver::RequestHandle handle[arraysize(req)];
1401 1407
1402 // Start all of the requests. 1408 // Start all of the requests.
1403 for (size_t i = 0; i < arraysize(req); ++i) { 1409 for (size_t i = 0; i < arraysize(req); ++i) {
1404 int rv = host_resolver->Resolve(req[i], &addrlist[i], 1410 int rv = host_resolver->Resolve(req[i], &addrlist[i],
1405 &callback[i], &handle[i], NULL); 1411 &callback[i], &handle[i], BoundNetLog());
1406 EXPECT_EQ(ERR_IO_PENDING, rv) << i; 1412 EXPECT_EQ(ERR_IO_PENDING, rv) << i;
1407 } 1413 }
1408 1414
1409 // Unblock the resolver thread so the requests can run. 1415 // Unblock the resolver thread so the requests can run.
1410 resolver_proc->Signal(); 1416 resolver_proc->Signal();
1411 1417
1412 // Wait for all the requests to complete. 1418 // Wait for all the requests to complete.
1413 for (size_t i = 0u; i < arraysize(req); ++i) { 1419 for (size_t i = 0u; i < arraysize(req); ++i) {
1414 EXPECT_EQ(OK, callback[i].WaitForResult()); 1420 EXPECT_EQ(OK, callback[i].WaitForResult());
1415 } 1421 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 CreateResolverRequestForAddressFamily("b", MEDIUM, ADDRESS_FAMILY_IPV6), 1467 CreateResolverRequestForAddressFamily("b", MEDIUM, ADDRESS_FAMILY_IPV6),
1462 CreateResolverRequestForAddressFamily("b", MEDIUM, 1468 CreateResolverRequestForAddressFamily("b", MEDIUM,
1463 ADDRESS_FAMILY_UNSPECIFIED), 1469 ADDRESS_FAMILY_UNSPECIFIED),
1464 CreateResolverRequestForAddressFamily("b", MEDIUM, ADDRESS_FAMILY_IPV4), 1470 CreateResolverRequestForAddressFamily("b", MEDIUM, ADDRESS_FAMILY_IPV4),
1465 }; 1471 };
1466 AddressList addrlist[arraysize(req)]; 1472 AddressList addrlist[arraysize(req)];
1467 1473
1468 // Start and run all of the requests synchronously. 1474 // Start and run all of the requests synchronously.
1469 for (size_t i = 0; i < arraysize(req); ++i) { 1475 for (size_t i = 0; i < arraysize(req); ++i) {
1470 int rv = host_resolver->Resolve(req[i], &addrlist[i], 1476 int rv = host_resolver->Resolve(req[i], &addrlist[i],
1471 NULL, NULL, NULL); 1477 NULL, NULL, BoundNetLog());
1472 EXPECT_EQ(OK, rv) << i; 1478 EXPECT_EQ(OK, rv) << i;
1473 } 1479 }
1474 1480
1475 // We should have sent 2 requests to the resolver -- 1481 // We should have sent 2 requests to the resolver --
1476 // one for (b, IPv4), and one for (b, IPv6). 1482 // one for (b, IPv4), and one for (b, IPv6).
1477 CapturingHostResolverProc::CaptureList capture_list = 1483 CapturingHostResolverProc::CaptureList capture_list =
1478 resolver_proc->GetCaptureList(); 1484 resolver_proc->GetCaptureList();
1479 ASSERT_EQ(2u, capture_list.size()); 1485 ASSERT_EQ(2u, capture_list.size());
1480 1486
1481 EXPECT_EQ("b", capture_list[0].hostname); 1487 EXPECT_EQ("b", capture_list[0].hostname);
(...skipping 11 matching lines...) Expand all
1493 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); 1499 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head()));
1494 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); 1500 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head()));
1495 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); 1501 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head()));
1496 } 1502 }
1497 1503
1498 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. 1504 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags.
1499 1505
1500 } // namespace 1506 } // namespace
1501 1507
1502 } // namespace net 1508 } // namespace net
OLDNEW
« no previous file with comments | « chrome/browser/net/resolve_proxy_msg_helper.cc ('k') | net/base/net_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698