|
1 package org.mozilla.gecko.tests; |
|
2 |
|
3 import java.io.InputStream; |
|
4 |
|
5 import org.mozilla.gecko.AppConstants; |
|
6 import org.mozilla.gecko.util.GeckoJarReader; |
|
7 |
|
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"); |
|
16 |
|
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"); |
|
21 |
|
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"); |
|
26 |
|
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"); |
|
31 |
|
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"); |
|
36 |
|
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"); |
|
41 |
|
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 } |
|
47 |
|
48 private String getData(InputStream stream) { |
|
49 return new java.util.Scanner(stream).useDelimiter("\\A").next(); |
|
50 } |
|
51 |
|
52 } |