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..139388908c22c4679255b338d5b7ba0ec49f32ab |
| --- /dev/null |
| +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwVariationsSeedFetchServiceTest.java |
| @@ -0,0 +1,73 @@ |
| +// 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.base.annotations.SuppressFBWarnings; |
| +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 { |
| + private File mSeedDataFile; |
| + private File mSeedPrefFile; |
| + |
| + protected void setUp() throws Exception { |
| + ContextUtils.initApplicationContextForTests( |
| + getInstrumentation().getTargetContext().getApplicationContext()); |
| + } |
| + |
| + @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") // ignoring File.delete() return |
| + protected void tearDown() throws Exception { |
| + if (mSeedDataFile != null) { |
| + mSeedDataFile.delete(); |
| + } |
| + if (mSeedPrefFile != null) { |
| + mSeedPrefFile.delete(); |
| + } |
| + } |
| + |
| + /** |
| + * Ensure reading and writing seed data and pref works correctly. |
| + */ |
| + @MediumTest |
| + public void testReadAndWriteSeedData() throws IOException, ClassNotFoundException { |
| + 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(); |
| + mSeedDataFile = new File(webViewFileDir, AwVariationsSeedFetchService.SEED_DATA_FILENAME); |
| + mSeedPrefFile = new File(webViewFileDir, AwVariationsSeedFetchService.SEED_PREF_FILENAME); |
| + assertTrue(mSeedDataFile.exists()); |
| + assertTrue(mSeedPrefFile.exists()); |
|
Alexei Svitkine (slow)
2017/07/18 19:09:40
I don't think the test needs to check this. It's a
yiyuny
2017/07/18 21:44:58
Done.
|
| + |
| + 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); |
| + } |
| +} |