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.test.util.MinAndroidSdkLevel; |
| 16 import org.chromium.components.variations.firstrun.VariationsSeedFetcher.SeedInf
o; |
| 17 |
| 18 import java.io.IOException; |
| 19 import java.util.Arrays; |
| 20 |
| 21 /** |
| 22 * Instrumentation tests for AwVariationsSeedFetchService. |
| 23 */ |
| 24 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP) // Android versions under L do
n't have JobService. |
| 25 @TargetApi(Build.VERSION_CODES.LOLLIPOP) // JobService requires API level 21. |
| 26 public class AwVariationsSeedFetchServiceTest extends InstrumentationTestCase { |
| 27 protected void setUp() throws Exception { |
| 28 ContextUtils.initApplicationContextForTests( |
| 29 getInstrumentation().getTargetContext().getApplicationContext())
; |
| 30 } |
| 31 |
| 32 protected void tearDown() throws Exception { |
| 33 AwVariationsSeedFetchService.clearDataForTesting(); |
| 34 } |
| 35 |
| 36 /** |
| 37 * Ensure reading and writing seed data and pref works correctly. |
| 38 */ |
| 39 @MediumTest |
| 40 public void testReadAndWriteVariationsSeed() throws IOException, ClassNotFou
ndException { |
| 41 SeedInfo seedInfo = new SeedInfo(); |
| 42 seedInfo.seedData = "SeedData".getBytes(); |
| 43 seedInfo.signature = "SeedSignature"; |
| 44 seedInfo.country = "SeedCountry"; |
| 45 seedInfo.date = "SeedDate"; |
| 46 seedInfo.isGzipCompressed = true; |
| 47 AwVariationsSeedFetchService.storeVariationsSeed(seedInfo); |
| 48 |
| 49 byte[] seedData = AwVariationsSeedFetchService.getVariationsSeedData(); |
| 50 assertTrue(Arrays.equals(seedData, seedInfo.seedData)); |
| 51 |
| 52 SeedPreference seedPreference = AwVariationsSeedFetchService.getVariatio
nsSeedPreference(); |
| 53 assertEquals(seedPreference.signature, seedInfo.signature); |
| 54 assertEquals(seedPreference.country, seedInfo.country); |
| 55 assertEquals(seedPreference.date, seedInfo.date); |
| 56 assertEquals(seedPreference.isGzipCompressed, seedInfo.isGzipCompressed)
; |
| 57 } |
| 58 } |
OLD | NEW |