mobile/android/base/tests/testJarReader.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testJarReader.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import java.io.InputStream;
     1.7 +
     1.8 +import org.mozilla.gecko.AppConstants;
     1.9 +import org.mozilla.gecko.util.GeckoJarReader;
    1.10 +
    1.11 +/**
    1.12 + * A basic jar reader test. Tests reading a png from fennec's apk, as well
    1.13 + * as loading some invalid jar urls.
    1.14 + */
    1.15 +public class testJarReader extends BaseTest {
    1.16 +    public void testJarReader() {
    1.17 +        String appPath = getActivity().getApplication().getPackageResourcePath();
    1.18 +        mAsserter.isnot(appPath, null, "getPackageResourcePath is non-null");
    1.19 +
    1.20 +        // Test reading a file from a jar url that looks correct.
    1.21 +        String url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME;
    1.22 +        InputStream stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
    1.23 +        mAsserter.isnot(stream, null, "JarReader returned non-null for valid file in valid jar");
    1.24 +
    1.25 +        // Test looking for an non-existent file in a jar.
    1.26 +        url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME;
    1.27 +        stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png");
    1.28 +        mAsserter.is(stream, null, "JarReader returned null for non-existent file in valid jar");
    1.29 +
    1.30 +        // Test looking for a file that doesn't exist in the APK.
    1.31 +        url = "jar:file://" + appPath + "!/" + "BAD" + AppConstants.OMNIJAR_NAME;
    1.32 +        stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
    1.33 +        mAsserter.is(stream, null, "JarReader returned null for valid file in invalid jar file");
    1.34 +
    1.35 +        // Test looking for an jar with an invalid url.
    1.36 +        url = "jar:file://" + appPath + "!" + "!/" + AppConstants.OMNIJAR_NAME;
    1.37 +        stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png");
    1.38 +        mAsserter.is(stream, null, "JarReader returned null for bad jar url");
    1.39 +
    1.40 +        // Test looking for a file that doesn't exist on disk.
    1.41 +        url = "jar:file://" + appPath + "BAD" + "!/" + AppConstants.OMNIJAR_NAME;
    1.42 +        stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
    1.43 +        mAsserter.is(stream, null, "JarReader returned null for a non-existent APK");
    1.44 +
    1.45 +        // This test completes very quickly. If it completes too soon, the
    1.46 +        // minidumps directory may not be created before the process is
    1.47 +        // taken down, causing bug 722166.
    1.48 +        blockForGeckoReady();
    1.49 +    }
    1.50 +
    1.51 +    private String getData(InputStream stream) {
    1.52 +        return new java.util.Scanner(stream).useDelimiter("\\A").next();
    1.53 +    }
    1.54 +
    1.55 +}

mercurial