michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import java.io.InputStream; michael@0: michael@0: import org.mozilla.gecko.AppConstants; michael@0: import org.mozilla.gecko.util.GeckoJarReader; michael@0: michael@0: /** michael@0: * A basic jar reader test. Tests reading a png from fennec's apk, as well michael@0: * as loading some invalid jar urls. michael@0: */ michael@0: public class testJarReader extends BaseTest { michael@0: public void testJarReader() { michael@0: String appPath = getActivity().getApplication().getPackageResourcePath(); michael@0: mAsserter.isnot(appPath, null, "getPackageResourcePath is non-null"); michael@0: michael@0: // Test reading a file from a jar url that looks correct. michael@0: String url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME; michael@0: InputStream stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png"); michael@0: mAsserter.isnot(stream, null, "JarReader returned non-null for valid file in valid jar"); michael@0: michael@0: // Test looking for an non-existent file in a jar. michael@0: url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME; michael@0: stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png"); michael@0: mAsserter.is(stream, null, "JarReader returned null for non-existent file in valid jar"); michael@0: michael@0: // Test looking for a file that doesn't exist in the APK. michael@0: url = "jar:file://" + appPath + "!/" + "BAD" + AppConstants.OMNIJAR_NAME; michael@0: stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png"); michael@0: mAsserter.is(stream, null, "JarReader returned null for valid file in invalid jar file"); michael@0: michael@0: // Test looking for an jar with an invalid url. michael@0: url = "jar:file://" + appPath + "!" + "!/" + AppConstants.OMNIJAR_NAME; michael@0: stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png"); michael@0: mAsserter.is(stream, null, "JarReader returned null for bad jar url"); michael@0: michael@0: // Test looking for a file that doesn't exist on disk. michael@0: url = "jar:file://" + appPath + "BAD" + "!/" + AppConstants.OMNIJAR_NAME; michael@0: stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png"); michael@0: mAsserter.is(stream, null, "JarReader returned null for a non-existent APK"); michael@0: michael@0: // This test completes very quickly. If it completes too soon, the michael@0: // minidumps directory may not be created before the process is michael@0: // taken down, causing bug 722166. michael@0: blockForGeckoReady(); michael@0: } michael@0: michael@0: private String getData(InputStream stream) { michael@0: return new java.util.Scanner(stream).useDelimiter("\\A").next(); michael@0: } michael@0: michael@0: }