| Index: components/cronet/android/test/javatests/src/org/chromium/net/ExperimentalOptionsTest.java
|
| diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/ExperimentalOptionsTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/ExperimentalOptionsTest.java
|
| index 3509479f037f6b6be34c0312bedf5e5ae91507d6..a975239dfdb1b9e05a9eef143d5a4090ad7bd1f5 100644
|
| --- a/components/cronet/android/test/javatests/src/org/chromium/net/ExperimentalOptionsTest.java
|
| +++ b/components/cronet/android/test/javatests/src/org/chromium/net/ExperimentalOptionsTest.java
|
| @@ -10,7 +10,9 @@ import org.json.JSONObject;
|
|
|
| import org.chromium.base.Log;
|
| import org.chromium.base.PathUtils;
|
| +import org.chromium.base.annotations.JNINamespace;
|
| import org.chromium.base.test.util.Feature;
|
| +import org.chromium.net.impl.CronetUrlRequestContext;
|
|
|
| import java.io.File;
|
| import java.io.FileInputStream;
|
| @@ -20,6 +22,7 @@ import java.io.IOException;
|
| /**
|
| * Tests for experimental options.
|
| */
|
| +@JNINamespace("cronet")
|
| public class ExperimentalOptionsTest extends CronetTestBase {
|
| private static final String TAG = ExperimentalOptionsTest.class.getSimpleName();
|
| private ExperimentalCronetEngine.Builder mBuilder;
|
| @@ -135,4 +138,38 @@ public class ExperimentalOptionsTest extends CronetTestBase {
|
| }
|
| return false;
|
| }
|
| +
|
| + @MediumTest
|
| + @Feature({"Cronet"})
|
| + @OnlyRunNativeCronet
|
| + // Tests that basic Cronet functionality works when host cache persistence is enabled, and that
|
| + // persistence works.
|
| + public void testHostCachePersistence() throws Exception {
|
| + mBuilder.setStoragePath(getTestStorage(getContext()));
|
| +
|
| + // Set a short delay so the pref gets written quickly.
|
| + JSONObject staleDns = new JSONObject()
|
| + .put("enable", true)
|
| + .put("allow_other_network", true)
|
| + .put("persist_to_disk", true)
|
| + .put("persist_timer_ms", 0);
|
| + JSONObject experimentalOptions = new JSONObject().put("StaleDNS", staleDns);
|
| + mBuilder.setExperimentalOptions(experimentalOptions.toString());
|
| + CronetUrlRequestContext context = (CronetUrlRequestContext) mBuilder.build();
|
| +
|
| + // Normal test requests won't interact with the HostCache, so access it directly from native
|
| + // code instead, then wait for the write to prefs.
|
| + nativeWriteToHostCache(context.getUrlRequestContextAdapter());
|
| + Thread.sleep(100);
|
| +
|
| + // Shut down before reading prefs file to make sure prefs are flushed to disk.
|
| + context.shutdown();
|
| +
|
| + File file = new File(getTestStorage(getContext()) + "/prefs/local_prefs.json");
|
| + assertFileContainsString(file, "host_cache");
|
| + assertFileContainsString(file, "host-cache-test-host");
|
| + }
|
| +
|
| + // Sets a host cache entry with hostname "host-cache-test-host".
|
| + private static native void nativeWriteToHostCache(long adapter);
|
| }
|
|
|