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.base.annotations.SuppressFBWarnings; | |
| 16 import org.chromium.components.variations.firstrun.VariationsSeedFetcher.SeedInf o; | |
| 17 | |
| 18 import java.io.File; | |
| 19 import java.io.IOException; | |
| 20 import java.util.Arrays; | |
| 21 | |
| 22 /** | |
| 23 * Instrumentation tests for AwVariationsSeedFetchService. | |
| 24 */ | |
| 25 @TargetApi(Build.VERSION_CODES.LOLLIPOP) // JobService requires API level 21. | |
| 26 public class AwVariationsSeedFetchServiceTest extends InstrumentationTestCase { | |
| 27 private File mSeedDataFile; | |
| 28 private File mSeedPrefFile; | |
| 29 | |
| 30 protected void setUp() throws Exception { | |
| 31 ContextUtils.initApplicationContextForTests( | |
| 32 getInstrumentation().getTargetContext().getApplicationContext()) ; | |
| 33 } | |
| 34 | |
| 35 @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") // ignoring File .delete() return | |
| 36 protected void tearDown() throws Exception { | |
| 37 if (mSeedDataFile != null) { | |
| 38 mSeedDataFile.delete(); | |
| 39 } | |
| 40 if (mSeedPrefFile != null) { | |
| 41 mSeedPrefFile.delete(); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 /** | |
| 46 * Ensure reading and writing seed data and pref works correctly. | |
| 47 */ | |
| 48 @MediumTest | |
| 49 public void testReadAndWriteSeedData() throws IOException, ClassNotFoundExce ption { | |
| 50 SeedInfo seedInfo = new SeedInfo(); | |
| 51 seedInfo.seedData = "SeedData".getBytes(); | |
| 52 seedInfo.signature = "SeedSignature"; | |
| 53 seedInfo.country = "SeedCountry"; | |
| 54 seedInfo.date = "SeedDate"; | |
| 55 seedInfo.isGzipCompressed = true; | |
| 56 AwVariationsSeedFetchService.storeVariationsSeed(seedInfo); | |
| 57 | |
| 58 File webViewFileDir = AwVariationsSeedFetchService.getOrCreateWebViewVar iationsDir(); | |
| 59 mSeedDataFile = new File(webViewFileDir, AwVariationsSeedFetchService.SE ED_DATA_FILENAME); | |
| 60 mSeedPrefFile = new File(webViewFileDir, AwVariationsSeedFetchService.SE ED_PREF_FILENAME); | |
| 61 assertTrue(mSeedDataFile.exists()); | |
| 62 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.
| |
| 63 | |
| 64 byte[] seedData = AwVariationsSeedFetchService.getVariationsSeedData(); | |
| 65 assertTrue(Arrays.equals(seedData, seedInfo.seedData)); | |
| 66 | |
| 67 SeedPreference seedPreference = AwVariationsSeedFetchService.getVariatio nsSeedPreference(); | |
| 68 assertEquals(seedPreference.signature, seedInfo.signature); | |
| 69 assertEquals(seedPreference.country, seedInfo.country); | |
| 70 assertEquals(seedPreference.date, seedInfo.date); | |
| 71 assertEquals(seedPreference.isGzipCompressed, seedInfo.isGzipCompressed) ; | |
| 72 } | |
| 73 } | |
| OLD | NEW |