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

Side by Side Diff: components/cronet/android/test/experimental_options_test.cc

Issue 2970563002: Fix hostCachePersistenceTest for devices with no IPv6 connectivity (Closed)
Patch Set: Created 3 years, 5 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 | « no previous file | 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/cronet/android/test/experimental_options_test.h" 5 #include "components/cronet/android/test/experimental_options_test.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 10 matching lines...) Expand all
21 using base::android::JavaParamRef; 21 using base::android::JavaParamRef;
22 22
23 namespace cronet { 23 namespace cronet {
24 24
25 namespace { 25 namespace {
26 void WriteToHostCacheOnNetworkThread(jlong jcontext_adapter, 26 void WriteToHostCacheOnNetworkThread(jlong jcontext_adapter,
27 const std::string& address_string) { 27 const std::string& address_string) {
28 net::URLRequestContext* context = 28 net::URLRequestContext* context =
29 TestUtil::GetURLRequestContext(jcontext_adapter); 29 TestUtil::GetURLRequestContext(jcontext_adapter);
30 net::HostCache* cache = context->host_resolver()->GetHostCache(); 30 net::HostCache* cache = context->host_resolver()->GetHostCache();
31 net::HostCache::Key key("host-cache-test-host", 31 const std::string hostname = "host-cache-test-host";
32 net::ADDRESS_FAMILY_UNSPECIFIED, 0); 32
33 // Create multiple keys to ensure the test works in a variety of network
34 // conditions.
35 net::HostCache::Key key1(hostname, net::ADDRESS_FAMILY_UNSPECIFIED, 0);
36 net::HostCache::Key key2(
37 hostname, net::ADDRESS_FAMILY_IPV4,
38 net::HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6);
39
33 net::IPAddress address; 40 net::IPAddress address;
34 CHECK(address.AssignFromIPLiteral(address_string)); 41 CHECK(address.AssignFromIPLiteral(address_string));
35 net::AddressList address_list = 42 net::AddressList address_list =
36 net::AddressList::CreateFromIPAddress(address, 0); 43 net::AddressList::CreateFromIPAddress(address, 0);
37 net::HostCache::Entry entry(net::OK, address_list); 44 net::HostCache::Entry entry(net::OK, address_list);
38 cache->Set(key, entry, base::TimeTicks::Now(), 45 cache->Set(key1, entry, base::TimeTicks::Now(),
46 base::TimeDelta::FromSeconds(1));
47 cache->Set(key2, entry, base::TimeTicks::Now(),
39 base::TimeDelta::FromSeconds(1)); 48 base::TimeDelta::FromSeconds(1));
40 } 49 }
41 } // namespace 50 } // namespace
42 51
43 static void WriteToHostCache(JNIEnv* env, 52 static void WriteToHostCache(JNIEnv* env,
44 const JavaParamRef<jclass>& jcaller, 53 const JavaParamRef<jclass>& jcaller,
45 jlong jcontext_adapter, 54 jlong jcontext_adapter,
46 const JavaParamRef<jstring>& jaddress) { 55 const JavaParamRef<jstring>& jaddress) {
47 TestUtil::RunAfterContextInit( 56 TestUtil::RunAfterContextInit(
48 jcontext_adapter, 57 jcontext_adapter,
49 base::Bind(&WriteToHostCacheOnNetworkThread, jcontext_adapter, 58 base::Bind(&WriteToHostCacheOnNetworkThread, jcontext_adapter,
50 base::android::ConvertJavaStringToUTF8(env, jaddress))); 59 base::android::ConvertJavaStringToUTF8(env, jaddress)));
51 } 60 }
52 61
53 bool RegisterExperimentalOptionsTest(JNIEnv* env) { 62 bool RegisterExperimentalOptionsTest(JNIEnv* env) {
54 return RegisterNativesImpl(env); 63 return RegisterNativesImpl(env);
55 } 64 }
56 65
57 } // namespace cronet 66 } // namespace cronet
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698