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

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

Issue 2083643003: DNS: Let requests specify a callback for future cache hits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, add unit test. Created 4 years, 4 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
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | no next file » | 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) 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/dns/host_resolver_impl.h" 5 #include "net/dns/host_resolver_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <tuple> 10 #include <tuple>
(...skipping 2380 matching lines...) Expand 10 before | Expand all | Expand 10 after
2391 &addresses)); 2391 &addresses));
2392 EXPECT_FALSE(ResolveLocalHostname("::1:1", kLocalhostLookupPort, &addresses)); 2392 EXPECT_FALSE(ResolveLocalHostname("::1:1", kLocalhostLookupPort, &addresses));
2393 EXPECT_FALSE(ResolveLocalHostname("0:0:0:0:0:0:0:0:1", kLocalhostLookupPort, 2393 EXPECT_FALSE(ResolveLocalHostname("0:0:0:0:0:0:0:0:1", kLocalhostLookupPort,
2394 &addresses)); 2394 &addresses));
2395 EXPECT_FALSE(ResolveLocalHostname("foo.localhost.com", kLocalhostLookupPort, 2395 EXPECT_FALSE(ResolveLocalHostname("foo.localhost.com", kLocalhostLookupPort,
2396 &addresses)); 2396 &addresses));
2397 EXPECT_FALSE( 2397 EXPECT_FALSE(
2398 ResolveLocalHostname("foo.localhoste", kLocalhostLookupPort, &addresses)); 2398 ResolveLocalHostname("foo.localhoste", kLocalhostLookupPort, &addresses));
2399 } 2399 }
2400 2400
2401 void TestCacheHitCallback(int* callback_count,
2402 HostResolver::RequestInfo* last_request_info,
2403 const HostResolver::RequestInfo& request_info) {
2404 ++*callback_count;
2405 *last_request_info = request_info;
2406 }
2407
2408 TEST_F(HostResolverImplTest, CacheHitCallback) {
2409 proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42");
2410 proc_->SignalMultiple(5u);
2411
2412 HostResolver::RequestInfo last_request_info(HostPortPair("unassigned", 80));
2413
2414 // Set a cache hit callback.
2415 int count1 = 0;
2416 HostResolver::RequestInfo info_callback1(HostPortPair("just.testing", 80));
2417 info_callback1.set_cache_hit_callback(
2418 base::Bind(&TestCacheHitCallback, &count1, &last_request_info));
2419 Request* req = CreateRequest(info_callback1, MEDIUM);
2420 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING));
2421 EXPECT_THAT(req->WaitForResult(), IsOk());
2422 EXPECT_EQ(0, count1);
2423
2424 // Make sure the cache hit callback is called, and set another one.
2425 // Future requests should call *both* callbacks.
2426 int count2 = 0;
2427 HostResolver::RequestInfo info_callback2(HostPortPair("just.testing", 80));
2428 info_callback2.set_cache_hit_callback(
2429 base::Bind(&TestCacheHitCallback, &count2, &last_request_info));
2430 req = CreateRequest(info_callback2, MEDIUM);
2431 EXPECT_THAT(req->Resolve(), IsOk());
2432 EXPECT_EQ(1, count1);
2433 EXPECT_EQ(0, count2);
2434
2435 // Make another request to make sure both callbacks are called.
2436 req = CreateRequest("just.testing", 80);
2437 EXPECT_THAT(req->Resolve(), IsOk());
2438 EXPECT_EQ(2, count1);
2439 EXPECT_EQ(1, count2);
2440
2441 // Make an uncached request to clear the cache hit callbacks.
Charlie Harrison 2016/08/02 17:15:41 Is this because it evicts the entries?
Julia Tuttle 2016/08/02 17:22:50 Yes. Not necessarily *evicts*, really, but certain
2442 // It should not call the callbacks itself, since it doesn't hit the cache.
2443 HostResolver::RequestInfo info_uncached(HostPortPair("just.testing", 80));
2444 info_uncached.set_allow_cached_response(false);
2445 req = CreateRequest(info_uncached, MEDIUM);
2446 EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING));
2447 EXPECT_THAT(req->WaitForResult(), IsOk());
2448 EXPECT_EQ(2, count1);
2449 EXPECT_EQ(1, count2);
2450
2451 // Make another request to make sure neither callback is cleared.
Charlie Harrison 2016/08/02 17:15:41 s/neither callback is/both callbacks are/?
Julia Tuttle 2016/08/02 17:22:50 Done.
2452 req = CreateRequest("just.testing", 80);
2453 EXPECT_THAT(req->Resolve(), IsOk());
2454 EXPECT_EQ(2, count1);
2455 EXPECT_EQ(1, count2);
2456 }
2457
2401 } // namespace net 2458 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698