Commit 0b856bd6 authored by Paul Miller's avatar Paul Miller Committed by Commit Bot

WebView: Remove prototype Finch services

These are being rewritten according to the "Finch Seed Dissemination in
WebView" design doc.

BUG=733857

Change-Id: Ie573c6aeebe7b37450c3a40c57f746f9fad96367
Reviewed-on: https://chromium-review.googlesource.com/959620Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Paul Miller <paulmiller@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542852}
parent fc31255b
...@@ -999,10 +999,6 @@ android_library("android_webview_services_java") { ...@@ -999,10 +999,6 @@ android_library("android_webview_services_java") {
java_files = [ java_files = [
"java/src/org/chromium/android_webview/services/AwMinidumpUploadJobService.java", "java/src/org/chromium/android_webview/services/AwMinidumpUploadJobService.java",
"java/src/org/chromium/android_webview/services/AwMinidumpUploaderDelegate.java", "java/src/org/chromium/android_webview/services/AwMinidumpUploaderDelegate.java",
"java/src/org/chromium/android_webview/services/AwVariationsConfigurationService.java",
"java/src/org/chromium/android_webview/services/AwVariationsSeedFetchService.java",
"java/src/org/chromium/android_webview/services/AwVariationsSeedHandler.java",
"java/src/org/chromium/android_webview/services/AwVariationsUtils.java",
"java/src/org/chromium/android_webview/services/CrashReceiverService.java", "java/src/org/chromium/android_webview/services/CrashReceiverService.java",
"java/src/org/chromium/android_webview/services/ServiceInit.java", "java/src/org/chromium/android_webview/services/ServiceInit.java",
] ]
...@@ -1013,7 +1009,6 @@ android_library("android_webview_services_java") { ...@@ -1013,7 +1009,6 @@ android_library("android_webview_services_java") {
"//base:base_java", "//base:base_java",
"//components/background_task_scheduler:background_task_scheduler_java", "//components/background_task_scheduler:background_task_scheduler_java",
"//components/minidump_uploader:minidump_uploader_java", "//components/minidump_uploader:minidump_uploader_java",
"//components/variations/android:variations_java",
] ]
srcjar_deps = [ ":crash_receiver_aidl" ] srcjar_deps = [ ":crash_receiver_aidl" ]
......
...@@ -40,13 +40,6 @@ ...@@ -40,13 +40,6 @@
android:exported="true" android:exported="true"
android:authorities="{{ manifest_package }}.LicenseContentProvider" /> android:authorities="{{ manifest_package }}.LicenseContentProvider" />
{% if donor_package is not defined %} {% if donor_package is not defined %}
<service android:name="org.chromium.android_webview.services.AwVariationsConfigurationService"
android:exported="true"
android:process=":webview_service" />
<service android:name="org.chromium.android_webview.services.AwVariationsSeedFetchService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false"
android:process=":webview_service" />
<service android:name="org.chromium.android_webview.services.CrashReceiverService" <service android:name="org.chromium.android_webview.services.CrashReceiverService"
android:exported="true" android:exported="true"
android:process=":webview_service" /> android:process=":webview_service" />
......
...@@ -30,13 +30,10 @@ import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy; ...@@ -30,13 +30,10 @@ import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy;
import org.chromium.android_webview.AwQuotaManagerBridge; import org.chromium.android_webview.AwQuotaManagerBridge;
import org.chromium.android_webview.AwResource; import org.chromium.android_webview.AwResource;
import org.chromium.android_webview.AwServiceWorkerController; import org.chromium.android_webview.AwServiceWorkerController;
import org.chromium.android_webview.AwSwitches;
import org.chromium.android_webview.AwTracingController; import org.chromium.android_webview.AwTracingController;
import org.chromium.android_webview.HttpAuthDatabase; import org.chromium.android_webview.HttpAuthDatabase;
import org.chromium.android_webview.command_line.CommandLineUtil; import org.chromium.android_webview.command_line.CommandLineUtil;
import org.chromium.android_webview.services.AwVariationsSeedHandler;
import org.chromium.base.BuildConfig; import org.chromium.base.BuildConfig;
import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.PathService; import org.chromium.base.PathService;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
...@@ -176,13 +173,6 @@ public class WebViewChromiumAwInit { ...@@ -176,13 +173,6 @@ public class WebViewChromiumAwInit {
mServiceWorkerController = awBrowserContext.getServiceWorkerController(); mServiceWorkerController = awBrowserContext.getServiceWorkerController();
mFactory.getRunQueue().drainQueue(); mFactory.getRunQueue().drainQueue();
boolean enableVariations =
CommandLine.getInstance().hasSwitch(AwSwitches.ENABLE_WEBVIEW_VARIATIONS);
if (enableVariations) {
AwVariationsSeedHandler.bindToVariationsService(
AwBrowserProcess.getWebViewPackageName());
}
} }
private void setUpResources(PackageInfo webViewPackageInfo, Context context) { private void setUpResources(PackageInfo webViewPackageInfo, Context context) {
......
// 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.services;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.components.variations.firstrun.VariationsSeedFetcher;
import org.chromium.components.variations.firstrun.VariationsSeedFetcher.SeedInfo;
import java.io.IOException;
import java.util.ArrayList;
/**
* AwVariationsSeedFetchService is a Job Service to fetch test seed data which is used by Variations
* to enable AB testing experiments in the native code. The fetched data is stored in WebView's data
* directory. The tryLock mechanism is just to make sure that
* no seed fetch job will be scheduled when there is one still running. This is a prototype of the
* Variations Seed Fetch Service which is one part of the work of adding Variations to Android
* WebView.
*/
public class AwVariationsSeedFetchService extends JobService {
private static final String TAG = "AwVartnsSeedFetchSvc";
private FetchVariationsSeedTask mFetchVariationsSeedTask;
@Override
public boolean onStartJob(JobParameters params) {
ServiceInit.init(getApplicationContext());
mFetchVariationsSeedTask = new FetchVariationsSeedTask(params);
mFetchVariationsSeedTask.execute();
return true;
}
@Override
public boolean onStopJob(JobParameters params) {
// This method is called by the JobScheduler to stop a job before it has finished. If the
// situation happens, we should cancel the running task.
if (mFetchVariationsSeedTask != null) {
mFetchVariationsSeedTask.cancel(true);
}
// TODO(paulmiller): Determine if we actually don't want to reschedule the job in the event
// it is stopped.
return false;
}
private class FetchVariationsSeedTask extends AsyncTask<Void, Void, Void> {
private JobParameters mJobParams;
FetchVariationsSeedTask(JobParameters params) {
mJobParams = params;
}
@Override
protected Void doInBackground(Void... params) {
fetchVariationsSeed();
return null;
}
@Override
protected void onPostExecute(Void success) {
jobFinished(mJobParams, false /* false -> don't reschedule */);
}
}
private void fetchVariationsSeed() {
assert !ThreadUtils.runningOnUiThread();
try {
// TODO(paulmiller): Addd milestone and channel information to seed request.
// crbug.com/784905
SeedInfo seedInfo = VariationsSeedFetcher.get().downloadContent(
VariationsSeedFetcher.VariationsPlatform.ANDROID_WEBVIEW, "", "", "");
transferFetchedSeed(seedInfo);
} catch (IOException e) {
// Exceptions are handled and logged in the downloadContent method, so we don't
// need any exception handling here. The only reason we need a catch-statement here
// is because those exceptions are re-thrown from downloadContent to skip the
// normal logic flow within that method.
}
}
private static class SeedTransferConnection implements ServiceConnection {
private SeedInfo mSeedInfo;
SeedTransferConnection(SeedInfo seedInfo) {
mSeedInfo = seedInfo;
}
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
Bundle bundle = new Bundle();
bundle.putByteArray(AwVariationsUtils.KEY_SEED_DATA, mSeedInfo.seedData);
ArrayList<String> list = new AwVariationsUtils.SeedPreference(mSeedInfo).toArrayList();
bundle.putStringArrayList(AwVariationsUtils.KEY_SEED_PREF, list);
// Directly set members of AwVariationsConfigurationService to prevent a malicious app
// from sending fake seed data.
AwVariationsConfigurationService.sMsgFromSeedFetchService = Message.obtain();
AwVariationsConfigurationService.sMsgFromSeedFetchService.setData(bundle);
Message msg = Message.obtain();
msg.what = AwVariationsUtils.MSG_SEED_TRANSFER;
try {
new Messenger(service).send(msg);
} catch (RemoteException e) {
Log.e(TAG, "Failed to send seed data to AwVariationsConfigurationService. " + e);
}
// After the data has been sent the AwVariationsConfigurationService can unbind from the
// current service.
ContextUtils.getApplicationContext().unbindService(this);
}
@Override
public void onServiceDisconnected(ComponentName name) {}
}
private void transferFetchedSeed(SeedInfo seedInfo) {
Intent intent = new Intent(this, AwVariationsConfigurationService.class);
ServiceConnection connection = new SeedTransferConnection(seedInfo);
Context context = ContextUtils.getApplicationContext();
if (!context.bindService(intent, connection, Context.BIND_AUTO_CREATE)) {
Log.w(TAG, "Could not bind to AwVariationsConfigurationService. " + intent);
}
}
}
// 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.services;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import org.chromium.base.ContextUtils;
import org.chromium.base.FileUtils;
import org.chromium.base.Log;
import org.chromium.base.PathUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import java.io.File;
import java.io.IOException;
/**
* AwVariationsSeedHandler is used to received the seed data from the
* AwVariationsConfigurationService on the WebView side. It will copy both the seed data and
* preference from the service directory into the app directory.
*/
public class AwVariationsSeedHandler extends Handler {
private static final String TAG = "AwVariatnsWVHdlr";
private ServiceConnection mConnection;
AwVariationsSeedHandler(ServiceConnection connection) {
mConnection = connection;
}
/**
* Method called when receiving a response from the VariationsConfigurationService, a response
* will be recieved even in the event there is no seed data.
*/
@Override
public void handleMessage(Message msg) {
if (msg.what == AwVariationsUtils.MSG_WITH_SEED_DATA) {
Bundle data = msg.getData();
ParcelFileDescriptor seedDataFileDescriptor =
data.getParcelable(AwVariationsUtils.KEY_SEED_DATA);
ParcelFileDescriptor seedPrefFileDescriptor =
data.getParcelable(AwVariationsUtils.KEY_SEED_PREF);
try {
File variationsDir = getOrCreateVariationsDirectory();
AwVariationsUtils.copyFileToVariationsDirectory(seedDataFileDescriptor,
variationsDir, AwVariationsUtils.SEED_DATA_FILENAME);
AwVariationsUtils.copyFileToVariationsDirectory(seedPrefFileDescriptor,
variationsDir, AwVariationsUtils.SEED_PREF_FILENAME);
} catch (IOException e) {
Log.e(TAG, "Failed to copy seed from seed directory to app directory. " + e);
}
}
// Unbind from the AwVariationsConfigurationService.
ContextUtils.getApplicationContext().unbindService(mConnection);
}
/**
* Bind to AwVariationsConfigurationService in the current context to ask for a seed.
*/
public static void bindToVariationsService(String webViewPackageName) {
File appWebViewVariationsDir = null;
try {
appWebViewVariationsDir = getOrCreateVariationsDirectory();
} catch (IOException e) {
Log.e(TAG, "Failed to create the WebView Variations directory. " + e);
return;
}
AwVariationsUtils.SeedPreference seedPref = null;
try {
seedPref = AwVariationsUtils.readSeedPreference(appWebViewVariationsDir);
} catch (IOException e) {
Log.e(TAG, "Failed to read seed preference file. " + e);
return;
}
if (!seedPref.seedNeedsUpdate()) {
Log.d(TAG,
"The current variations seed is not expired, no need to ask for a new seed.");
return;
}
ServiceConnection connection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Message msg = Message.obtain();
msg.what = AwVariationsUtils.MSG_SEED_REQUEST;
msg.replyTo = new Messenger(new AwVariationsSeedHandler(this));
try {
// Send a message to request for a new seed
new Messenger(service).send(msg);
} catch (RemoteException e) {
Log.e(TAG, "Failed to seed message to AwVariationsConfigurationService. " + e);
}
}
@Override
public void onServiceDisconnected(ComponentName name) {}
};
Intent intent = new Intent();
intent.setClassName(webViewPackageName, AwVariationsConfigurationService.class.getName());
Context context = ContextUtils.getApplicationContext();
if (!context.bindService(intent, connection, Context.BIND_AUTO_CREATE)) {
Log.w(TAG, "Could not bind to AwVariationsConfigurationService. " + intent);
}
}
/**
* Get or create the variations directory in the service directory.
* @return The variations directory path.
* @throws IOException if fail to create the directory and get the directory.
*/
@VisibleForTesting
public static File getOrCreateVariationsDirectory() throws IOException {
File dir = new File(PathUtils.getDataDirectory());
if (dir.mkdir() || dir.isDirectory()) {
return dir;
}
throw new IOException("Failed to get or create the WebView variations directory.");
}
/**
* Clear the test data.
* @throws IOException if fail to get or create the WebView variations directory.
*/
@VisibleForTesting
public static void clearDataForTesting() throws IOException {
ThreadUtils.setThreadAssertsDisabledForTesting(true);
File variationsDir = getOrCreateVariationsDirectory();
FileUtils.recursivelyDeleteFile(variationsDir);
}
}
// 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.services;
import android.os.ParcelFileDescriptor;
import org.chromium.base.CollectionUtil;
import org.chromium.base.FileUtils;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.components.variations.firstrun.VariationsSeedFetcher.SeedInfo;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
/**
* Constants and shared methods for fetching and storing the WebView variations seed.
*/
public class AwVariationsUtils {
private static final String TAG = "AwVariationsUtils";
// Types for the WebViews to identify the message. If it is MSG_WITH_SEED_DATA, the WebView will
// store the seed in the message to the app directory.
static final int MSG_WITHOUT_SEED_DATA = 0;
static final int MSG_WITH_SEED_DATA = 1;
// Types for the service to identify the message which Context binds to it.
static final int MSG_SEED_REQUEST = 2;
static final int MSG_SEED_TRANSFER = 3;
// The file names used to store the variations seed.
public static final String SEED_DATA_FILENAME = "variations_seed_data";
public static final String SEED_PREF_FILENAME = "variations_seed_pref";
// The key string used in the message to store the variations seed.
static final String KEY_SEED_DATA = "KEY_SEED_DATA";
static final String KEY_SEED_PREF = "KEY_SEED_PREF";
// The expiration time for the Finch seed.
static final long SEED_EXPIRATION_TIME_IN_MILLIS = TimeUnit.MINUTES.toMillis(30);
// Buffer size when copying seed from service directory to app directory.
static final int BUFFER_SIZE = 4096;
private static void copyBytes(FileInputStream in, FileOutputStream out) throws IOException {
byte[] buffer = new byte[BUFFER_SIZE];
int readCount = 0;
while ((readCount = in.read(buffer)) > 0) {
out.write(buffer, 0, readCount);
}
}
/**
* Copy the file in the parcel file descriptor to the variations directory in the app directory.
* @param fileDescriptor The file descriptor of an opened file.
* @param fileName The name for the destination file in the variations directory.
* @throws IOException if fail to get the directory or copy file to the aoo
*/
@VisibleForTesting
public static void copyFileToVariationsDirectory(ParcelFileDescriptor fileDescriptor,
File variationsDir, String fileName) throws IOException {
if (fileDescriptor == null) {
Log.e(TAG, "Variations seed file descriptor is null.");
return;
}
FileInputStream in = null;
FileOutputStream out = null;
File tempFile = null;
try {
tempFile = File.createTempFile(fileName, null, variationsDir);
if (!tempFile.setWritable(false /* writable */, false /* ownerOnly */)
|| !tempFile.setWritable(true /* writable */, true /* ownerOnly */)) {
Log.e(TAG, "Failed to set write permissions for temporary file. ");
}
in = new FileInputStream(fileDescriptor.getFileDescriptor());
out = new FileOutputStream(tempFile);
copyBytes(in, out);
} finally {
closeStream(in);
closeStream(out);
try {
fileDescriptor.close();
} catch (IOException e) {
Log.e(TAG, "Failed to close seed data file descriptor. " + e);
}
}
renameTempFile(tempFile, new File(variationsDir, fileName));
}
/**
* Rename a temp file to a new name.
* @param tempFile The temp file.
* @param newFile The new file.
*/
public static void renameTempFile(File tempFile, File newFile) {
// TODO(paulmiller): Fix running on UI thread.
ThreadUtils.setThreadAssertsDisabledForTesting(true);
try {
FileUtils.recursivelyDeleteFile(newFile);
} finally {
ThreadUtils.setThreadAssertsDisabledForTesting(false);
}
boolean isTempFileRenamed = tempFile.renameTo(newFile);
if (!isTempFileRenamed) {
Log.e(TAG,
"Failed to rename " + tempFile.getAbsolutePath() + " to "
+ newFile.getAbsolutePath() + ".");
}
}
/**
* Safely close a stream.
* @param stream The stream to be closed.
*/
public static void closeStream(Closeable stream) {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
Log.e(TAG, "Failed to close stream. " + e);
}
}
}
/**
* SeedPreference is used to serialize/deserialize related fields of seed data when reading or
* writing them into file.
*/
public static class SeedPreference {
// VariationsSeedFetcher shared between Chromium and WebView returns a gzip field that is
// unused by WebView.
public static final int FIELD_COUNT = 4;
public final String signature;
public final String country;
public final String date;
private SeedPreference(List<String> seedPrefAsList) {
signature = seedPrefAsList.get(0);
country = seedPrefAsList.get(1);
date = seedPrefAsList.get(2);
}
public SeedPreference(SeedInfo seedInfo) {
signature = seedInfo.signature;
country = seedInfo.country;
date = seedInfo.date;
}
public ArrayList<String> toArrayList() {
// Dummy field so that calls to toArrayList and fromList won't fail the FIELD_COUNT
// check.
String gzipDummy = "";
return CollectionUtil.newArrayList(signature, country, date, gzipDummy);
}
public static SeedPreference fromList(List<String> seedPrefAsList) {
if (seedPrefAsList.size() != FIELD_COUNT) {
Log.e(TAG, "Failed to validate the seed preference, field count is incorrect).");
return null;
}
return new SeedPreference(seedPrefAsList);
}
/**
* Judge if the current Finch seed in a given directory is expired.
* @return True if the seed is expired or missing, otherwise false.
*/
public boolean seedNeedsUpdate() {
Date lastSeedFetchTime = parseDateTimeString(date);
if (lastSeedFetchTime == null) return true;
return new Date().getTime() - lastSeedFetchTime.getTime()
> SEED_EXPIRATION_TIME_IN_MILLIS;
}
}
/**
* Get the variations seed preference in a given directory.
* @return The seed preference.
* @throws IOException if fail to read the seed preference file in the given directory.
*/
@VisibleForTesting
public static SeedPreference readSeedPreference(File variationsDir) throws IOException {
BufferedReader reader = null;
File seedPrefFile = new File(variationsDir, AwVariationsUtils.SEED_PREF_FILENAME);
try {
reader = new BufferedReader(new FileReader(seedPrefFile));
ArrayList<String> seedPrefAsList = new ArrayList<String>();
String line = null;
while ((line = reader.readLine()) != null) {
seedPrefAsList.add(line);
}
return AwVariationsUtils.SeedPreference.fromList(seedPrefAsList);
} finally {
closeStream(reader);
}
}
/**
* Parse the string containing date time info to a Date object.
* @param dateTimeStr The string holds the date time info.
* @return The Date object holds the date info from the input string, null if parse failed.
*/
private static Date parseDateTimeString(String dateTimeStr) {
Date lastSeedFetchTime = null;
try {
final SimpleDateFormat dateFormat =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
lastSeedFetchTime = dateFormat.parse(dateTimeStr);
} catch (ParseException e) {
Log.e(TAG, "Failed to parse the time. " + e);
}
return lastSeedFetchTime;
}
}
// 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.services;
import static org.chromium.android_webview.services.AwVariationsUtils.SEED_DATA_FILENAME;
import static org.chromium.android_webview.services.AwVariationsUtils.SEED_PREF_FILENAME;
import android.os.ParcelFileDescriptor;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.util.Base64;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.android_webview.AwBrowserProcess;
import org.chromium.android_webview.services.AwVariationsConfigurationService;
import org.chromium.android_webview.services.AwVariationsSeedHandler;
import org.chromium.android_webview.services.AwVariationsUtils;
import org.chromium.android_webview.services.AwVariationsUtils.SeedPreference;
import org.chromium.base.ContextUtils;
import org.chromium.base.PathUtils;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.components.variations.firstrun.VariationsSeedFetcher.SeedInfo;
import java.io.File;
import java.io.IOException;
/**
* Instrumentation tests for AwVariationsConfigurationService on Android L and above.
* Although AwVariationsConfigurationService is not a JobService, the test case still uses the
* AwVariationsSeedFetchService which can't work under Android L.
*/
@RunWith(BaseJUnit4ClassRunner.class)
public class AwVariationsConfigurationServiceTest {
private SeedInfo mSeedInfo;
@Before
public void setUp() throws Exception {
ContextUtils.initApplicationContextForTests(InstrumentationRegistry.getInstrumentation()
.getTargetContext()
.getApplicationContext());
PathUtils.setPrivateDataDirectorySuffix(AwBrowserProcess.WEBVIEW_DIR_BASENAME);
mSeedInfo = new SeedInfo();
mSeedInfo.seedData = "SeedData".getBytes();
mSeedInfo.signature = "SeedSignature";
mSeedInfo.country = "SeedCountry";
mSeedInfo.date = "SeedDate";
}
@After
public void tearDown() throws Exception {
AwVariationsConfigurationService.clearDataForTesting();
}
/**
* Ensure reading and writing seed data in app directory works correctly.
*/
@Test
@MediumTest
public void testReadAndWriteSeedData() throws IOException {
File variationsDir = AwVariationsConfigurationService.getOrCreateVariationsDirectory();
AwVariationsConfigurationService.storeSeedDataToFile(mSeedInfo.seedData, variationsDir);
String b64SeedData = AwVariationsConfigurationService.getSeedDataForTesting(variationsDir);
Assert.assertEquals(Base64.encodeToString(mSeedInfo.seedData, Base64.NO_WRAP), b64SeedData);
}
/**
* Ensure reading and writing seed preference in app directory works correctly.
*/
@Test
@MediumTest
public void testReadAndWriteSeedPref() throws IOException {
File variationsDir = AwVariationsConfigurationService.getOrCreateVariationsDirectory();
SeedPreference expect = new SeedPreference(mSeedInfo);
AwVariationsConfigurationService.storeSeedPrefToFile(expect, variationsDir);
SeedPreference actual = AwVariationsUtils.readSeedPreference(variationsDir);
Assert.assertNotNull(expect);
Assert.assertNotNull(actual);
Assert.assertEquals(expect.signature, actual.signature);
Assert.assertEquals(expect.country, actual.country);
Assert.assertEquals(expect.date, actual.date);
}
/**
* Ensure copying seed data from the service directory to the app directory works correctly.
*/
@Test
@MediumTest
public void testCopySeedData() throws IOException {
File serviceDir = AwVariationsConfigurationService.getOrCreateVariationsDirectory();
AwVariationsConfigurationService.storeSeedDataToFile(mSeedInfo.seedData, serviceDir);
ParcelFileDescriptor seedDataFileDescriptor =
AwVariationsConfigurationService.getSeedFileDescriptor(SEED_DATA_FILENAME);
File appDir = AwVariationsSeedHandler.getOrCreateVariationsDirectory();
AwVariationsUtils.copyFileToVariationsDirectory(
seedDataFileDescriptor, appDir, SEED_DATA_FILENAME);
String seedDataInServiceDir =
AwVariationsConfigurationService.getSeedDataForTesting(serviceDir);
String seedDataInAppDir = AwVariationsConfigurationService.getSeedDataForTesting(appDir);
Assert.assertEquals(seedDataInServiceDir, seedDataInAppDir);
}
/**
* Ensure copying seed preference from the service directory to the app directory works
* correctly.
*/
@Test
@MediumTest
public void testCopySeedPref() throws IOException {
File serviceDir = AwVariationsConfigurationService.getOrCreateVariationsDirectory();
SeedPreference seedPref = new SeedPreference(mSeedInfo);
AwVariationsConfigurationService.storeSeedPrefToFile(seedPref, serviceDir);
ParcelFileDescriptor seedPrefFileDescriptor =
AwVariationsConfigurationService.getSeedFileDescriptor(SEED_PREF_FILENAME);
File appDir = AwVariationsSeedHandler.getOrCreateVariationsDirectory();
AwVariationsUtils.copyFileToVariationsDirectory(
seedPrefFileDescriptor, appDir, SEED_PREF_FILENAME);
SeedPreference seedPrefInServiceDir = AwVariationsUtils.readSeedPreference(serviceDir);
SeedPreference seedPrefInAppDir = AwVariationsUtils.readSeedPreference(appDir);
Assert.assertNotNull(seedPrefInServiceDir);
Assert.assertNotNull(seedPrefInAppDir);
Assert.assertEquals(seedPrefInServiceDir.signature, seedPrefInAppDir.signature);
Assert.assertEquals(seedPrefInServiceDir.country, seedPrefInAppDir.country);
Assert.assertEquals(seedPrefInServiceDir.date, seedPrefInAppDir.date);
}
}
...@@ -130,7 +130,6 @@ instrumentation_test_apk("webview_instrumentation_test_apk") { ...@@ -130,7 +130,6 @@ instrumentation_test_apk("webview_instrumentation_test_apk") {
"//components/policy/android:policy_java", "//components/policy/android:policy_java",
"//components/policy/android:policy_java_test_support", "//components/policy/android:policy_java_test_support",
"//components/safe_browsing/android:safe_browsing_java", "//components/safe_browsing/android:safe_browsing_java",
"//components/variations/android:variations_java",
"//components/web_contents_delegate_android:web_contents_delegate_android_java", "//components/web_contents_delegate_android:web_contents_delegate_android_java",
"//content/public/android:content_java", "//content/public/android:content_java",
"//content/public/test/android:content_java_test_support", "//content/public/test/android:content_java_test_support",
...@@ -227,7 +226,6 @@ instrumentation_test_apk("webview_instrumentation_test_apk") { ...@@ -227,7 +226,6 @@ instrumentation_test_apk("webview_instrumentation_test_apk") {
"../javatests/src/org/chromium/android_webview/test/WebViewFindApisTestRule.java", "../javatests/src/org/chromium/android_webview/test/WebViewFindApisTestRule.java",
"../javatests/src/org/chromium/android_webview/test/WebViewModalDialogOverrideTest.java", "../javatests/src/org/chromium/android_webview/test/WebViewModalDialogOverrideTest.java",
"../javatests/src/org/chromium/android_webview/test/WebViewWebVrTest.java", "../javatests/src/org/chromium/android_webview/test/WebViewWebVrTest.java",
"../javatests/src/org/chromium/android_webview/test/services/AwVariationsConfigurationServiceTest.java",
"../javatests/src/org/chromium/android_webview/test/services/CrashReceiverServiceTest.java", "../javatests/src/org/chromium/android_webview/test/services/CrashReceiverServiceTest.java",
"../javatests/src/org/chromium/android_webview/test/services/MinidumpUploaderTest.java", "../javatests/src/org/chromium/android_webview/test/services/MinidumpUploaderTest.java",
"../javatests/src/org/chromium/android_webview/test/services/VisualStateCallbackTest.java", "../javatests/src/org/chromium/android_webview/test/services/VisualStateCallbackTest.java",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment