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

Unified Diff: components/cronet/android/test/src/org/chromium/cronet_test_apk/CronetTestActivity.java

Issue 558333007: Setup initial mock url request job tests for Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 6 years, 3 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 | « components/cronet/android/test/mock_url_request_job_test.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/android/test/src/org/chromium/cronet_test_apk/CronetTestActivity.java
diff --git a/components/cronet/android/test/src/org/chromium/cronet_test_apk/CronetTestActivity.java b/components/cronet/android/test/src/org/chromium/cronet_test_apk/CronetTestActivity.java
index dc532e792c45f224c7c6a5147b049900f713ca3d..ea83ef8fbbdb3ad788a9bf846665affa5c87fe5e 100644
--- a/components/cronet/android/test/src/org/chromium/cronet_test_apk/CronetTestActivity.java
+++ b/components/cronet/android/test/src/org/chromium/cronet_test_apk/CronetTestActivity.java
@@ -6,10 +6,12 @@ package org.chromium.cronet_test_apk;
import android.app.Activity;
import android.content.Intent;
+import android.content.res.AssetManager;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
+import org.chromium.base.PathUtils;
import org.chromium.net.ChromiumUrlRequestFactory;
import org.chromium.net.HttpUrlRequest;
import org.chromium.net.HttpUrlRequestFactory;
@@ -17,7 +19,9 @@ import org.chromium.net.HttpUrlRequestFactoryConfig;
import org.chromium.net.HttpUrlRequestListener;
import java.io.ByteArrayInputStream;
+import java.io.FileOutputStream;
import java.io.InputStream;
+import java.io.OutputStream;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
@@ -61,6 +65,19 @@ public class CronetTestActivity extends Activity {
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ if (!loadTestFiles()) {
+ Log.e(TAG, "Loading test files failed");
+ return;
+ }
+
+ try {
+ System.loadLibrary("cronet_tests");
+ } catch (UnsatisfiedLinkError e) {
+ Log.e(TAG, "libcronet_test initialization failed.", e);
+ finish();
+ return;
+ }
+
HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig();
config.enableHttpCache(HttpUrlRequestFactoryConfig.HttpCache.IN_MEMORY,
100 * 1024)
@@ -95,6 +112,50 @@ public class CronetTestActivity extends Activity {
}
}
+ private boolean loadTestFiles() {
+ String testFilePath = "test";
+ String toPath = PathUtils.getDataDirectory(getApplicationContext());
+ AssetManager assetManager = getAssets();
+ try {
+ String[] files = assetManager.list(testFilePath);
+ Log.i(TAG, "Begin loading " + files.length + " test files.");
+ for (String file : files) {
+ Log.i(TAG, "Loading " + file);
+ if (!copyTestFile(assetManager,
+ testFilePath + "/" + file,
+ toPath + "/" + file)) {
+ return false;
+ }
+ }
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ // Helper function to copy a file to a destination.
+ private static boolean copyTestFile(AssetManager assetManager,
+ String testFile,
+ String testFileCopy) {
+ try {
+ InputStream in = assetManager.open(testFile);
+ OutputStream out = new FileOutputStream(testFileCopy);
+ byte[] buffer = new byte[1024];
+ int read;
+ while ((read = in.read(buffer)) != -1) {
+ out.write(buffer, 0, read);
+ }
+ in.close();
+ out.flush();
+ out.close();
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
private static String getUrlFromIntent(Intent intent) {
return intent != null ? intent.getDataString() : null;
}
« no previous file with comments | « components/cronet/android/test/mock_url_request_job_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698