OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 package org.chromium.net; | 5 package org.chromium.net; |
6 | 6 |
7 import android.support.test.filters.MediumTest; | 7 import android.support.test.filters.MediumTest; |
8 | 8 |
9 import org.json.JSONObject; | 9 import org.json.JSONObject; |
10 | 10 |
11 import org.chromium.base.Log; | 11 import org.chromium.base.Log; |
12 import org.chromium.base.PathUtils; | 12 import org.chromium.base.PathUtils; |
| 13 import org.chromium.base.annotations.JNINamespace; |
13 import org.chromium.base.test.util.Feature; | 14 import org.chromium.base.test.util.Feature; |
| 15 import org.chromium.net.impl.CronetUrlRequestContext; |
14 | 16 |
15 import java.io.File; | 17 import java.io.File; |
16 import java.io.FileInputStream; | 18 import java.io.FileInputStream; |
17 import java.io.FileNotFoundException; | 19 import java.io.FileNotFoundException; |
18 import java.io.IOException; | 20 import java.io.IOException; |
19 | 21 |
20 /** | 22 /** |
21 * Tests for experimental options. | 23 * Tests for experimental options. |
22 */ | 24 */ |
| 25 @JNINamespace("cronet") |
23 public class ExperimentalOptionsTest extends CronetTestBase { | 26 public class ExperimentalOptionsTest extends CronetTestBase { |
24 private static final String TAG = ExperimentalOptionsTest.class.getSimpleNam
e(); | 27 private static final String TAG = ExperimentalOptionsTest.class.getSimpleNam
e(); |
25 private ExperimentalCronetEngine.Builder mBuilder; | 28 private ExperimentalCronetEngine.Builder mBuilder; |
26 | 29 |
27 @Override | 30 @Override |
28 protected void setUp() throws Exception { | 31 protected void setUp() throws Exception { |
29 super.setUp(); | 32 super.setUp(); |
30 mBuilder = new ExperimentalCronetEngine.Builder(getContext()); | 33 mBuilder = new ExperimentalCronetEngine.Builder(getContext()); |
31 CronetTestUtil.setMockCertVerifierForTesting( | 34 CronetTestUtil.setMockCertVerifierForTesting( |
32 mBuilder, QuicTestServer.createMockCertVerifier()); | 35 mBuilder, QuicTestServer.createMockCertVerifier()); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Ignored this exception since the file will only be created when u
pdates are | 131 // Ignored this exception since the file will only be created when u
pdates are |
129 // flushed to the disk. | 132 // flushed to the disk. |
130 Log.i(TAG, "file not found"); | 133 Log.i(TAG, "file not found"); |
131 } finally { | 134 } finally { |
132 if (fileInputStream != null) { | 135 if (fileInputStream != null) { |
133 fileInputStream.close(); | 136 fileInputStream.close(); |
134 } | 137 } |
135 } | 138 } |
136 return false; | 139 return false; |
137 } | 140 } |
| 141 |
| 142 @MediumTest |
| 143 @Feature({"Cronet"}) |
| 144 @OnlyRunNativeCronet |
| 145 // Tests that basic Cronet functionality works when host cache persistence i
s enabled, and that |
| 146 // persistence works. |
| 147 public void testHostCachePersistence() throws Exception { |
| 148 mBuilder.setStoragePath(getTestStorage(getContext())); |
| 149 |
| 150 // Set a short delay so the pref gets written quickly. |
| 151 JSONObject staleDns = new JSONObject() |
| 152 .put("enable", true) |
| 153 .put("allow_other_network", true) |
| 154 .put("persist_to_disk", true) |
| 155 .put("persist_timer_ms", 0); |
| 156 JSONObject experimentalOptions = new JSONObject().put("StaleDNS", staleD
ns); |
| 157 mBuilder.setExperimentalOptions(experimentalOptions.toString()); |
| 158 CronetUrlRequestContext context = (CronetUrlRequestContext) mBuilder.bui
ld(); |
| 159 |
| 160 // Normal test requests won't interact with the HostCache, so access it
directly from native |
| 161 // code instead, then wait for the write to prefs. |
| 162 nativeWriteToHostCache(context.getUrlRequestContextAdapter()); |
| 163 Thread.sleep(100); |
| 164 |
| 165 // Shut down before reading prefs file to make sure prefs are flushed to
disk. |
| 166 context.shutdown(); |
| 167 |
| 168 File file = new File(getTestStorage(getContext()) + "/prefs/local_prefs.
json"); |
| 169 assertFileContainsString(file, "host_cache"); |
| 170 assertFileContainsString(file, "host-cache-test-host"); |
| 171 } |
| 172 |
| 173 // Sets a host cache entry with hostname "host-cache-test-host". |
| 174 private static native void nativeWriteToHostCache(long adapter); |
138 } | 175 } |
OLD | NEW |