Chromium Code Reviews| Index: android_webview/javatests/src/org/chromium/android_webview/test/AwVariationsSeedFetchServiceTest.java |
| diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwVariationsSeedFetchServiceTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwVariationsSeedFetchServiceTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4dd1f37ccd2245c29b32d8b9e1e32f36d4536471 |
| --- /dev/null |
| +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwVariationsSeedFetchServiceTest.java |
| @@ -0,0 +1,61 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.android_webview.test; |
| + |
| +import android.annotation.TargetApi; |
| +import android.os.Build; |
| +import android.support.test.filters.MediumTest; |
| +import android.test.InstrumentationTestCase; |
| + |
| +import org.chromium.android_webview.AwVariationsSeedFetchService; |
| +import org.chromium.android_webview.AwVariationsSeedFetchService.SeedPreference; |
| +import org.chromium.base.ContextUtils; |
| +import org.chromium.components.variations.firstrun.VariationsSeedFetcher.SeedInfo; |
| + |
| +import java.io.File; |
| +import java.io.IOException; |
| +import java.util.Arrays; |
| + |
| +/** |
| + * Instrumentation tests for AwVariationsSeedFetchService. |
| + */ |
| +@TargetApi(Build.VERSION_CODES.LOLLIPOP) // JobService requires API level 21. |
| +public class AwVariationsSeedFetchServiceTest extends InstrumentationTestCase { |
| + protected void setUp() throws Exception { |
| + ContextUtils.initApplicationContextForTests( |
| + getInstrumentation().getTargetContext().getApplicationContext()); |
| + } |
| + |
| + /** |
| + * Ensure reading and writing seed data and pref works correctly. |
| + */ |
| + @MediumTest |
| + public void testReadAndWriteSeedData() throws IOException, ClassNotFoundException { |
|
gsennton
2017/07/18 07:38:57
You probably want to clean up the files that were
yiyuny
2017/07/18 21:44:57
Done.
|
| + SeedInfo seedInfo = new SeedInfo(); |
| + seedInfo.seedData = "SeedData".getBytes(); |
| + seedInfo.signature = "SeedSignature"; |
| + seedInfo.country = "SeedCountry"; |
| + seedInfo.date = "SeedDate"; |
| + seedInfo.isGzipCompressed = true; |
| + AwVariationsSeedFetchService.storeVariationsSeed(seedInfo); |
| + |
| + File webViewFileDir = AwVariationsSeedFetchService.getOrCreateWebViewVariationsDir(); |
| + File testSeedData = |
| + new File(webViewFileDir, AwVariationsSeedFetchService.SEED_DATA_FILENAME); |
| + File testSeedPref = |
| + new File(webViewFileDir, AwVariationsSeedFetchService.SEED_PREF_FILENAME); |
| + assertTrue(testSeedData.exists()); |
| + assertTrue(testSeedPref.exists()); |
| + |
| + byte[] seedData = AwVariationsSeedFetchService.getVariationsSeedData(); |
| + assertTrue(Arrays.equals(seedData, seedInfo.seedData)); |
| + |
| + SeedPreference seedPreference = AwVariationsSeedFetchService.getVariationsSeedPreference(); |
| + assertEquals(seedPreference.signature, seedInfo.signature); |
| + assertEquals(seedPreference.country, seedInfo.country); |
| + assertEquals(seedPreference.date, seedInfo.date); |
| + assertEquals(seedPreference.isGzipCompressed, seedInfo.isGzipCompressed); |
| + } |
| +} |