Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | package org.mozilla.gecko.browser.tests; |
michael@0 | 5 | |
michael@0 | 6 | import java.io.InputStream; |
michael@0 | 7 | |
michael@0 | 8 | import org.mozilla.gecko.AppConstants; |
michael@0 | 9 | import org.mozilla.gecko.util.GeckoJarReader; |
michael@0 | 10 | |
michael@0 | 11 | /** |
michael@0 | 12 | * A basic jar reader test. Tests reading a png from fennec's apk, as well as |
michael@0 | 13 | * loading some invalid jar urls. |
michael@0 | 14 | */ |
michael@0 | 15 | public class TestJarReader extends BrowserTestCase { |
michael@0 | 16 | public void testJarReader() { |
michael@0 | 17 | String appPath = getActivity().getApplication().getPackageResourcePath(); |
michael@0 | 18 | assertNotNull(appPath); |
michael@0 | 19 | |
michael@0 | 20 | // Test reading a file from a jar url that looks correct. |
michael@0 | 21 | String url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME; |
michael@0 | 22 | InputStream stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png"); |
michael@0 | 23 | assertNotNull(stream); |
michael@0 | 24 | |
michael@0 | 25 | // Test looking for an non-existent file in a jar. |
michael@0 | 26 | url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME; |
michael@0 | 27 | stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png"); |
michael@0 | 28 | assertNull(stream); |
michael@0 | 29 | |
michael@0 | 30 | // Test looking for a file that doesn't exist in the APK. |
michael@0 | 31 | url = "jar:file://" + appPath + "!/" + "BAD" + AppConstants.OMNIJAR_NAME; |
michael@0 | 32 | stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png"); |
michael@0 | 33 | assertNull(stream); |
michael@0 | 34 | |
michael@0 | 35 | // Test looking for an jar with an invalid url. |
michael@0 | 36 | url = "jar:file://" + appPath + "!" + "!/" + AppConstants.OMNIJAR_NAME; |
michael@0 | 37 | stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png"); |
michael@0 | 38 | assertNull(stream); |
michael@0 | 39 | |
michael@0 | 40 | // Test looking for a file that doesn't exist on disk. |
michael@0 | 41 | url = "jar:file://" + appPath + "BAD" + "!/" + AppConstants.OMNIJAR_NAME; |
michael@0 | 42 | stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png"); |
michael@0 | 43 | assertNull(stream); |
michael@0 | 44 | } |
michael@0 | 45 | } |