Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.android_webview.test; | |
| 6 | |
| 7 import android.annotation.TargetApi; | |
| 8 import android.os.Build; | |
| 9 import android.support.test.filters.MediumTest; | |
| 10 import android.test.InstrumentationTestCase; | |
| 11 | |
| 12 import org.chromium.android_webview.AwVariationsSeedFetchService; | |
| 13 import org.chromium.android_webview.AwVariationsSeedFetchService.SeedPreference; | |
| 14 import org.chromium.base.ContextUtils; | |
| 15 import org.chromium.components.variations.firstrun.VariationsSeedFetcher.SeedInf o; | |
| 16 | |
| 17 import java.io.File; | |
| 18 import java.io.IOException; | |
| 19 import java.util.Arrays; | |
| 20 | |
| 21 /** | |
| 22 * Instrumentation tests for AwVariationsSeedFetchService. | |
| 23 */ | |
| 24 @TargetApi(Build.VERSION_CODES.LOLLIPOP) // JobService requires API level 21. | |
| 25 public class AwVariationsSeedFetchServiceTest extends InstrumentationTestCase { | |
| 26 protected void setUp() throws Exception { | |
| 27 ContextUtils.initApplicationContextForTests( | |
| 28 getInstrumentation().getTargetContext().getApplicationContext()) ; | |
| 29 } | |
| 30 | |
| 31 /** | |
| 32 * Ensure reading and writing seed data and pref works correctly. | |
| 33 */ | |
| 34 @MediumTest | |
| 35 public void testReadAndWriteSeedData() throws IOException, ClassNotFoundExce ption { | |
|
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.
| |
| 36 SeedInfo seedInfo = new SeedInfo(); | |
| 37 seedInfo.seedData = "SeedData".getBytes(); | |
| 38 seedInfo.signature = "SeedSignature"; | |
| 39 seedInfo.country = "SeedCountry"; | |
| 40 seedInfo.date = "SeedDate"; | |
| 41 seedInfo.isGzipCompressed = true; | |
| 42 AwVariationsSeedFetchService.storeVariationsSeed(seedInfo); | |
| 43 | |
| 44 File webViewFileDir = AwVariationsSeedFetchService.getOrCreateWebViewVar iationsDir(); | |
| 45 File testSeedData = | |
| 46 new File(webViewFileDir, AwVariationsSeedFetchService.SEED_DATA_ FILENAME); | |
| 47 File testSeedPref = | |
| 48 new File(webViewFileDir, AwVariationsSeedFetchService.SEED_PREF_ FILENAME); | |
| 49 assertTrue(testSeedData.exists()); | |
| 50 assertTrue(testSeedPref.exists()); | |
| 51 | |
| 52 byte[] seedData = AwVariationsSeedFetchService.getVariationsSeedData(); | |
| 53 assertTrue(Arrays.equals(seedData, seedInfo.seedData)); | |
| 54 | |
| 55 SeedPreference seedPreference = AwVariationsSeedFetchService.getVariatio nsSeedPreference(); | |
| 56 assertEquals(seedPreference.signature, seedInfo.signature); | |
| 57 assertEquals(seedPreference.country, seedInfo.country); | |
| 58 assertEquals(seedPreference.date, seedInfo.date); | |
| 59 assertEquals(seedPreference.isGzipCompressed, seedInfo.isGzipCompressed) ; | |
| 60 } | |
| 61 } | |
| OLD | NEW |