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

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

mercurial