Bug 709250 - Tets for jar reader. r=lucasr

This commit is contained in:
Wes Johnston 2012-03-22 11:12:08 -07:00
parent ddf6fc4032
commit d61c61b17a
2 changed files with 72 additions and 0 deletions

View File

@ -14,6 +14,7 @@
[testPasswordEncrypt]
[testFormHistory]
[testBrowserProvider]
[testJarReader]
# Used for Talos, please don't use in mochitest
#[testPan]

View File

@ -0,0 +1,71 @@
#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.Bitmap;
import java.lang.ClassLoader;
import java.util.ArrayList;
import java.io.Writer;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.lang.reflect.Method;
import java.io.StringWriter;
/**
* A basic jar reader test. Tests reading a png from fennec's apk, as well
* as loading some invalid jar urls.
*/
public class testJarReader extends BaseTest {
public void testJarReader() {
setTestType("mochitest");
try {
ClassLoader classLoader = getActivity().getClassLoader();
Class gjrClass = classLoader.loadClass("org.mozilla.gecko.GeckoJarReader");
Method getStreamMethod = gjrClass.getMethod("getStream", String.class);
String appPath = getActivity().getApplication().getPackageResourcePath();
// Test reading a file from a jar url
String url = "jar:file://" + getActivity().getApplication().getPackageResourcePath() + "!/omni.ja";
InputStream stream = (InputStream)getStreamMethod.invoke(null, "jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
mAsserter.isnot(stream, null, "JarReader returned null for invalid jar file");
// Test looking for a jar that doesn't exist
url = "jar:file://" + getActivity().getApplication().getPackageResourcePath() + "2!/omni.ja";
stream = (InputStream)getStreamMethod.invoke(null, "jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
mAsserter.is(stream, null, "JarReader returned null for invalid jar file");
// Test looking for an non-existant file in a jar
url = "jar:file://" + getActivity().getApplication().getPackageResourcePath() + "2!/omni.ja";
stream = (InputStream)getStreamMethod.invoke(null, "jar:" + url + "!/chrome/chrome/content/branding/nonexistant_file.png");
mAsserter.is(stream, null, "JarReader returned null for non-existant file in jar");
// Test looking for an jar with an invalid url
url = "jar:file://" + getActivity().getApplication().getPackageResourcePath() + "2!!/omni.ja";
stream = (InputStream)getStreamMethod.invoke(null, "jar:" + url + "!/chrome/chrome/content/branding/nonexistant_file.png");
mAsserter.is(stream, null, "JarReader returned null for bar jar url");
} catch (java.lang.ClassNotFoundException ex) {
mAsserter.is(false, true, "Error getting class");
return;
} catch (java.lang.NoSuchMethodException ex) {
mAsserter.is(false, true, "Error getting method");
return;
} catch (java.lang.IllegalAccessException ex) {
mAsserter.is(false, true, "Error calling method");
return;
} catch (java.lang.reflect.InvocationTargetException ex) {
mAsserter.is(false, true, "Invocation target exception " + ex.getTargetException());
return;
}
}
private String getData(InputStream stream) {
return new java.util.Scanner(stream).useDelimiter("\\A").next();
}
public void tearDown() throws Exception {
super.tearDown();
}
}