mobile/android/base/tests/testJarReader.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     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