Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwVariationsSeedFetchServiceTest.java

Issue 2975693002: Add AwVariationsSeedFetchService and refactory VariationsSeedFetcher (Closed)
Patch Set: Update unit tests for read and write seed data Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « android_webview/javatests/DEPS ('k') | android_webview/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+ }
+}
« no previous file with comments | « android_webview/javatests/DEPS ('k') | android_webview/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698