Bug 739415 - Add ability to have raw files as test assets. r=jmaher
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 27 Mar 2012 16:16:13 -0400
changeset 90443 fcf521827011c6387480b7105379ab3d22ec588c
parent 90442 bfd56e7aa7c18fd9c0959c6b6e97f0111cc34917
child 90444 5fb45a56e2afed7f7a035f8bb3f0c8f584a374e6
push id22358
push userkhuey@mozilla.com
push dateWed, 28 Mar 2012 14:41:10 +0000
treeherdermozilla-central@c3fd0768d46a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs739415
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 739415 - Add ability to have raw files as test assets. r=jmaher
build/mobile/robocop/Makefile.in
mobile/android/base/tests/BaseTest.java.in
mobile/android/base/tests/assets/README
--- a/build/mobile/robocop/Makefile.in
+++ b/build/mobile/robocop/Makefile.in
@@ -122,18 +122,18 @@ tools:: robocop.apk
 classes.dex: robocop.ap_
 classes.dex: $(_ROBOCOP_TOOLS)
 classes.dex: $(_JAVA_HARNESS)
 classes.dex: $(_JAVA_TESTS)
 	$(NSINSTALL) -D classes
 	$(JAVAC) $(JAVAC_FLAGS) -d classes $(JAVAFILES) $(_JAVA_HARNESS) $(addprefix $(DEPTH)/mobile/android/base/tests/,$(_JAVA_TESTS))
 	$(DX) --dex --output=$@ classes $(ROBOTIUM_PATH)
 
-robocop.ap_: AndroidManifest.xml
-	$(AAPT) package -f -M AndroidManifest.xml -I $(ANDROID_SDK)/android.jar -I . -S res -F $@ -J ./
+robocop.ap_: AndroidManifest.xml $(TESTPATH)/assets/*
+	$(AAPT) package -f -M AndroidManifest.xml -I $(ANDROID_SDK)/android.jar -I . -S res -A $(TESTPATH)/assets -F $@ -J ./
 
 robocop.apk: robocop.ap_ classes.dex
 	cp $(TESTPATH)/robocop.ini robocop.ini
 	cp $(srcdir)/parse_ids.py parse_ids.py
 
 export::
 	$(NSINSTALL) -D res
 	@(cd $(srcdir)/res && tar $(TAR_CREATE_FLAGS) - *) | (cd $(DEPTH)/build/mobile/robocop/res && tar -xf -)
--- a/mobile/android/base/tests/BaseTest.java.in
+++ b/mobile/android/base/tests/BaseTest.java.in
@@ -1,22 +1,25 @@
 #filter substitution
 package @ANDROID_PACKAGE_NAME@.tests;
 
 import com.jayway.android.robotium.solo.Solo;
 import @ANDROID_PACKAGE_NAME@.*;
 
 import android.app.Activity;
 import android.app.Instrumentation;
-import android.database.Cursor;
 import android.content.ContentValues;
 import android.content.Intent;
+import android.content.res.AssetManager;
+import android.database.Cursor;
 import android.os.SystemClock;
 import android.test.ActivityInstrumentationTestCase2;
 import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
 
 import java.util.HashMap;
 
 abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
     private static final String TARGET_PACKAGE_ID = "org.mozilla.gecko";
     private static final String LAUNCH_ACTIVITY_FULL_CLASSNAME="@ANDROID_PACKAGE_NAME@.App";
 
     private static Class<Activity> mLauncherActivityClass;
@@ -199,9 +202,14 @@ abstract class BaseTest extends Activity
                 mAsserter.info("Pass","Column value " + c.getString(i) + " ?= " + cv.get(column).toString());
                 if (!cv.get(column).toString().equals(c.getString(i))) {
                     return false;
                 }
             }
         }
         return true;
     }
+
+    public InputStream getAsset(String filename) throws IOException {
+        AssetManager assets = getInstrumentation().getContext().getAssets();
+        return assets.open(filename);
+    }
 }
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/assets/README
@@ -0,0 +1,4 @@
+You can place test assets in this file.
+They can be read as raw InputStreams with the getAsset() method in BaseTest.
+
+(This file is a placeholder to ensure that the assets/ directory exists, as it is referenced in the robocop Makefile.)