mobile/android/base/tests/testJarReader.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 package org.mozilla.gecko.tests;
michael@0 2
michael@0 3 import java.io.InputStream;
michael@0 4
michael@0 5 import org.mozilla.gecko.AppConstants;
michael@0 6 import org.mozilla.gecko.util.GeckoJarReader;
michael@0 7
michael@0 8 /**
michael@0 9 * A basic jar reader test. Tests reading a png from fennec's apk, as well
michael@0 10 * as loading some invalid jar urls.
michael@0 11 */
michael@0 12 public class testJarReader extends BaseTest {
michael@0 13 public void testJarReader() {
michael@0 14 String appPath = getActivity().getApplication().getPackageResourcePath();
michael@0 15 mAsserter.isnot(appPath, null, "getPackageResourcePath is non-null");
michael@0 16
michael@0 17 // Test reading a file from a jar url that looks correct.
michael@0 18 String url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME;
michael@0 19 InputStream stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
michael@0 20 mAsserter.isnot(stream, null, "JarReader returned non-null for valid file in valid jar");
michael@0 21
michael@0 22 // Test looking for an non-existent file in a jar.
michael@0 23 url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME;
michael@0 24 stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png");
michael@0 25 mAsserter.is(stream, null, "JarReader returned null for non-existent file in valid jar");
michael@0 26
michael@0 27 // Test looking for a file that doesn't exist in the APK.
michael@0 28 url = "jar:file://" + appPath + "!/" + "BAD" + AppConstants.OMNIJAR_NAME;
michael@0 29 stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
michael@0 30 mAsserter.is(stream, null, "JarReader returned null for valid file in invalid jar file");
michael@0 31
michael@0 32 // Test looking for an jar with an invalid url.
michael@0 33 url = "jar:file://" + appPath + "!" + "!/" + AppConstants.OMNIJAR_NAME;
michael@0 34 stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png");
michael@0 35 mAsserter.is(stream, null, "JarReader returned null for bad jar url");
michael@0 36
michael@0 37 // Test looking for a file that doesn't exist on disk.
michael@0 38 url = "jar:file://" + appPath + "BAD" + "!/" + AppConstants.OMNIJAR_NAME;
michael@0 39 stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
michael@0 40 mAsserter.is(stream, null, "JarReader returned null for a non-existent APK");
michael@0 41
michael@0 42 // This test completes very quickly. If it completes too soon, the
michael@0 43 // minidumps directory may not be created before the process is
michael@0 44 // taken down, causing bug 722166.
michael@0 45 blockForGeckoReady();
michael@0 46 }
michael@0 47
michael@0 48 private String getData(InputStream stream) {
michael@0 49 return new java.util.Scanner(stream).useDelimiter("\\A").next();
michael@0 50 }
michael@0 51
michael@0 52 }

mercurial