mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 916507 - Part 4: Remove reflection from tests. r=nalexander
This commit is contained in:
parent
338766978b
commit
68e62f449a
@ -1,10 +1,11 @@
|
||||
package org.mozilla.gecko.tests;
|
||||
|
||||
import org.mozilla.gecko.*;
|
||||
import org.mozilla.gecko.util.Clipboard;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* This class covers interactions with the context menu opened from web content
|
||||
@ -53,18 +54,9 @@ abstract class ContentContextMenuTest extends PixelTest {
|
||||
boolean correctText = waitForTest(new BooleanTest() {
|
||||
@Override
|
||||
public boolean test() {
|
||||
try {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Class Clipboard = classLoader.loadClass("org.mozilla.gecko.util.Clipboard");
|
||||
Method getText = Clipboard.getMethod("getText");
|
||||
String clipboardText = (String)getText.invoke(null);
|
||||
mAsserter.dumpLog("Clipboard text = " + clipboardText + " , expected text = " + copiedText);
|
||||
return clipboardText.contains(copiedText);
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "Exception getting the clipboard text ", e.toString()); // Fail before returning
|
||||
return false;
|
||||
}
|
||||
final String clipboardText = Clipboard.getText();
|
||||
mAsserter.dumpLog("Clipboard text = " + clipboardText + " , expected text = " + copiedText);
|
||||
return clipboardText.contains(copiedText);
|
||||
}
|
||||
}, MAX_TEST_TIMEOUT);
|
||||
mAsserter.ok(correctText, "Checking if the text is correctly copied", "The text was correctly copied");
|
||||
|
@ -231,6 +231,7 @@ abstract class ContentProviderTest extends BaseTest {
|
||||
throw new Exception("You should call setUp(providerClassName, authorityUriField) instead");
|
||||
}
|
||||
|
||||
// TODO: Take the actual class as an arg.
|
||||
public void setUp(String providerClassName, String authorityUriField) throws Exception {
|
||||
super.setUp();
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.mozilla.gecko.tests;
|
||||
|
||||
import org.mozilla.gecko.*;
|
||||
import org.mozilla.gecko.sync.Utils;
|
||||
|
||||
import com.jayway.android.robotium.solo.Condition;
|
||||
|
||||
@ -14,7 +15,6 @@ import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -140,15 +140,7 @@ public class testBookmarkFolders extends AboutHomeTest {
|
||||
Long desktopFolderId = mDatabaseHelper.getFolderIdFromGuid("toolbar");
|
||||
|
||||
// Generate a Guid for the bookmark
|
||||
String generatedGuid = null;
|
||||
try {
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Class syncUtilityClass = classLoader.loadClass("org.mozilla.gecko.sync.Utils");
|
||||
Method generateGuid = syncUtilityClass.getMethod("generateGuid", (Class[]) null);
|
||||
generatedGuid = (String)generateGuid.invoke(null);
|
||||
} catch (Exception e) {
|
||||
mAsserter.dumpLog("Exception in setUpDesktopBookmarks" + e);
|
||||
}
|
||||
final String generatedGuid = Utils.generateGuid();
|
||||
mAsserter.ok((generatedGuid != null), "Generating a random Guid for the bookmark", "We could not generate a Guid for the bookmark");
|
||||
|
||||
// Insert the bookmark
|
||||
|
@ -5,10 +5,11 @@ import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.SystemClock;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
import java.util.Random;
|
||||
|
||||
import org.mozilla.gecko.db.BrowserDB;
|
||||
|
||||
/*
|
||||
* This test is meant to exercise the performance of Fennec's
|
||||
* history and bookmarks content provider.
|
||||
@ -25,7 +26,6 @@ public class testBrowserProviderPerf extends ContentProviderTest {
|
||||
// multiple constraint words
|
||||
private final String KNOWN_PREFIX = "my mozilla test ";
|
||||
|
||||
private Method mFilterMethod;
|
||||
private Random mGenerator;
|
||||
|
||||
private final String MOBILE_FOLDER_GUID = "mobile";
|
||||
@ -61,22 +61,6 @@ public class testBrowserProviderPerf extends ContentProviderTest {
|
||||
return TEST_TALOS;
|
||||
}
|
||||
|
||||
private void loadFilterMethod() throws Exception {
|
||||
Class browserDBClass = mClassLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
|
||||
|
||||
mFilterMethod =
|
||||
browserDBClass.getDeclaredMethod("filter", ContentResolver.class,
|
||||
CharSequence.class, int.class);
|
||||
}
|
||||
|
||||
private void initializeBrowserProvider() throws Exception {
|
||||
Class browserDBClass = mClassLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
|
||||
|
||||
Method initializeMethod =
|
||||
browserDBClass.getDeclaredMethod("initialize", String.class);
|
||||
initializeMethod.invoke(null, "default");
|
||||
}
|
||||
|
||||
private void loadContractInfo() throws Exception {
|
||||
mBookmarksUri = getContentUri("Bookmarks");
|
||||
mHistoryUri = getContentUri("History");
|
||||
@ -254,18 +238,17 @@ public class testBrowserProviderPerf extends ContentProviderTest {
|
||||
mGenerator = new Random(19580427);
|
||||
|
||||
loadContractInfo();
|
||||
loadFilterMethod();
|
||||
}
|
||||
|
||||
public void testBrowserProviderPerf() throws Exception {
|
||||
initializeBrowserProvider();
|
||||
BrowserDB.initialize("default");
|
||||
|
||||
loadMobileFolderId();
|
||||
addTonsOfUrls();
|
||||
|
||||
long start = SystemClock.uptimeMillis();
|
||||
|
||||
Cursor c = (Cursor) mFilterMethod.invoke(null, mResolver, KNOWN_PREFIX, 100);
|
||||
final Cursor c = BrowserDB.filter(mResolver, KNOWN_PREFIX, 100);
|
||||
c.getCount(); // ensure query is not lazy loaded
|
||||
|
||||
long end = SystemClock.uptimeMillis();
|
||||
|
@ -8,9 +8,6 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.KeyEvent;
|
||||
import android.widget.TextView;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.RuntimeException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.mozilla.gecko.tests;
|
||||
|
||||
import org.mozilla.gecko.*;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
@ -9,8 +10,6 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.ClassLoader;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -50,25 +49,22 @@ public class testDistribution extends ContentProviderTest {
|
||||
* writes prefs -- to finish before we begin the test.
|
||||
*/
|
||||
private void waitForBackgroundHappiness() {
|
||||
try {
|
||||
ClassLoader classLoader = mActivity.getClassLoader();
|
||||
Class threadUtilsClass = classLoader.loadClass("org.mozilla.gecko.util.ThreadUtils");
|
||||
Method postToBackgroundThread = threadUtilsClass.getMethod("postToBackgroundThread", Runnable.class);
|
||||
final Object signal = new Object();
|
||||
final Runnable done = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (signal) {
|
||||
signal.notify();
|
||||
}
|
||||
final Object signal = new Object();
|
||||
final Runnable done = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (signal) {
|
||||
signal.notify();
|
||||
}
|
||||
};
|
||||
synchronized (signal) {
|
||||
postToBackgroundThread.invoke(null, done);
|
||||
signal.wait();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "Exception waiting on background thread.", e.toString());
|
||||
};
|
||||
synchronized (signal) {
|
||||
ThreadUtils.postToBackgroundThread(done);
|
||||
try {
|
||||
signal.wait();
|
||||
} catch (InterruptedException e) {
|
||||
mAsserter.ok(false, "InterruptedException waiting on background thread.", e.toString());
|
||||
}
|
||||
}
|
||||
mAsserter.dumpLog("Background task completed. Proceeding.");
|
||||
}
|
||||
@ -99,19 +95,11 @@ public class testDistribution extends ContentProviderTest {
|
||||
|
||||
// Initialize the distribution from the mock package.
|
||||
private void initDistribution(String aPackagePath) {
|
||||
try {
|
||||
// Call Distribution.init with the mock package.
|
||||
ClassLoader classLoader = mActivity.getClassLoader();
|
||||
Class distributionClass = classLoader.loadClass("org.mozilla.gecko.Distribution");
|
||||
Method init = distributionClass.getMethod("init", Context.class, String.class, String.class);
|
||||
|
||||
Actions.EventExpecter distributionSetExpecter = mActions.expectGeckoEvent("Distribution:Set:OK");
|
||||
init.invoke(null, mActivity, aPackagePath, "prefs-" + System.currentTimeMillis());
|
||||
distributionSetExpecter.blockForEvent();
|
||||
distributionSetExpecter.unregisterListener();
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "exception initializing distribution", e.toString());
|
||||
}
|
||||
// Call Distribution.init with the mock package.
|
||||
Actions.EventExpecter distributionSetExpecter = mActions.expectGeckoEvent("Distribution:Set:OK");
|
||||
Distribution.init(mActivity, aPackagePath, "prefs-" + System.currentTimeMillis());
|
||||
distributionSetExpecter.blockForEvent();
|
||||
distributionSetExpecter.unregisterListener();
|
||||
}
|
||||
|
||||
// Test distribution and preferences values stored in preferences.json
|
||||
|
@ -4,7 +4,6 @@ import org.mozilla.gecko.*;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -1,11 +1,12 @@
|
||||
package org.mozilla.gecko.tests;
|
||||
|
||||
import org.mozilla.gecko.db.BrowserContract.FormHistory;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import java.io.File;
|
||||
import java.lang.ClassLoader;
|
||||
|
||||
/**
|
||||
* A basic form history contentprovider test.
|
||||
@ -36,29 +37,15 @@ public class testFormHistory extends BaseTest {
|
||||
int numUpdated;
|
||||
int numDeleted;
|
||||
|
||||
try {
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Class fh = classLoader.loadClass("org.mozilla.gecko.db.BrowserContract$FormHistory");
|
||||
|
||||
cvs[0].put("fieldname", "fieldname");
|
||||
cvs[0].put("value", "value");
|
||||
cvs[0].put("timesUsed", "0");
|
||||
cvs[0].put("guid", "guid");
|
||||
|
||||
// Attempt to insert into the db
|
||||
formHistoryUri = (Uri)fh.getField("CONTENT_URI").get(null);
|
||||
Uri.Builder builder = formHistoryUri.buildUpon();
|
||||
formHistoryUri = builder.appendQueryParameter("profilePath", mProfile).build();
|
||||
} catch(ClassNotFoundException ex) {
|
||||
mAsserter.is(false, true, "Error getting class");
|
||||
return;
|
||||
} catch(NoSuchFieldException ex) {
|
||||
mAsserter.is(false, true, "Error getting field");
|
||||
return;
|
||||
} catch(IllegalAccessException ex) {
|
||||
mAsserter.is(false, true, "Error using field");
|
||||
return;
|
||||
}
|
||||
cvs[0].put("fieldname", "fieldname");
|
||||
cvs[0].put("value", "value");
|
||||
cvs[0].put("timesUsed", "0");
|
||||
cvs[0].put("guid", "guid");
|
||||
|
||||
// Attempt to insert into the db
|
||||
formHistoryUri = FormHistory.CONTENT_URI;
|
||||
Uri.Builder builder = formHistoryUri.buildUpon();
|
||||
formHistoryUri = builder.appendQueryParameter("profilePath", mProfile).build();
|
||||
|
||||
insertUri = cr.insert(formHistoryUri, cvs[0]);
|
||||
expectedUri = formHistoryUri.buildUpon().appendPath("1").build();
|
||||
|
@ -5,7 +5,6 @@ import org.mozilla.gecko.*;
|
||||
import android.app.Activity;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Build;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class testGetUserMedia extends BaseTest {
|
||||
@Override
|
||||
|
@ -1,9 +1,9 @@
|
||||
package org.mozilla.gecko.tests;
|
||||
|
||||
import java.lang.ClassLoader;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.util.GeckoJarReader;
|
||||
|
||||
/**
|
||||
* A basic jar reader test. Tests reading a png from fennec's apk, as well
|
||||
@ -16,54 +16,34 @@ public class testJarReader extends BaseTest {
|
||||
}
|
||||
|
||||
public void testJarReader() {
|
||||
try {
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
String appPath = getActivity().getApplication().getPackageResourcePath();
|
||||
mAsserter.isnot(appPath, null, "getPackageResourcePath is non-null");
|
||||
|
||||
Class appConstantsClass = classLoader.loadClass("org.mozilla.gecko.AppConstants");
|
||||
String omniJarName = (String) appConstantsClass.getField("OMNIJAR_NAME").get(null);
|
||||
// Test reading a file from a jar url that looks correct.
|
||||
String url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME;
|
||||
InputStream stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
|
||||
mAsserter.isnot(stream, null, "JarReader returned non-null for valid file in valid jar");
|
||||
|
||||
Class gjrClass = classLoader.loadClass("org.mozilla.gecko.util.GeckoJarReader");
|
||||
Method getStreamMethod = gjrClass.getMethod("getStream", String.class);
|
||||
String appPath = getActivity().getApplication().getPackageResourcePath();
|
||||
mAsserter.isnot(appPath, null, "getPackageResourcePath is non-null");
|
||||
// Test looking for an non-existent file in a jar.
|
||||
url = "jar:file://" + appPath + "!/" + AppConstants.OMNIJAR_NAME;
|
||||
stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png");
|
||||
mAsserter.is(stream, null, "JarReader returned null for non-existent file in valid jar");
|
||||
|
||||
// Test reading a file from a jar url that looks correct.
|
||||
String url = "jar:file://" + appPath + "!/" + omniJarName;
|
||||
InputStream stream = (InputStream) getStreamMethod.invoke(null, "jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
|
||||
mAsserter.isnot(stream, null, "JarReader returned non-null for valid file in valid jar");
|
||||
// Test looking for a file that doesn't exist in the APK.
|
||||
url = "jar:file://" + appPath + "!/" + "BAD" + AppConstants.OMNIJAR_NAME;
|
||||
stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
|
||||
mAsserter.is(stream, null, "JarReader returned null for valid file in invalid jar file");
|
||||
|
||||
// Test looking for an non-existent file in a jar.
|
||||
url = "jar:file://" + appPath + "!/" + omniJarName;
|
||||
stream = (InputStream) getStreamMethod.invoke(null, "jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png");
|
||||
mAsserter.is(stream, null, "JarReader returned null for non-existent file in valid jar");
|
||||
// Test looking for an jar with an invalid url.
|
||||
url = "jar:file://" + appPath + "!" + "!/" + AppConstants.OMNIJAR_NAME;
|
||||
stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png");
|
||||
mAsserter.is(stream, null, "JarReader returned null for bad jar url");
|
||||
|
||||
// Test looking for a file that doesn't exist in the APK.
|
||||
url = "jar:file://" + appPath + "!/" + "BAD" + omniJarName;
|
||||
stream = (InputStream) getStreamMethod.invoke(null, "jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
|
||||
mAsserter.is(stream, null, "JarReader returned null for valid file in invalid jar file");
|
||||
// Test looking for a file that doesn't exist on disk.
|
||||
url = "jar:file://" + appPath + "BAD" + "!/" + AppConstants.OMNIJAR_NAME;
|
||||
stream = GeckoJarReader.getStream("jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
|
||||
mAsserter.is(stream, null, "JarReader returned null for a non-existent APK");
|
||||
|
||||
// Test looking for an jar with an invalid url.
|
||||
url = "jar:file://" + appPath + "!" + "!/" + omniJarName;
|
||||
stream = (InputStream) getStreamMethod.invoke(null, "jar:" + url + "!/chrome/chrome/content/branding/nonexistent_file.png");
|
||||
mAsserter.is(stream, null, "JarReader returned null for bad jar url");
|
||||
|
||||
// Test looking for a file that doesn't exist on disk.
|
||||
url = "jar:file://" + appPath + "BAD" + "!/" + omniJarName;
|
||||
stream = (InputStream) getStreamMethod.invoke(null, "jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
|
||||
mAsserter.is(stream, null, "JarReader returned null for a non-existent APK");
|
||||
} catch (java.lang.ClassCastException ex) {
|
||||
mAsserter.is(false, true, "Error getting OMNIJAR_NAME");
|
||||
} catch (java.lang.NoSuchFieldException ex) {
|
||||
mAsserter.is(false, true, "Error getting field");
|
||||
} catch (java.lang.ClassNotFoundException ex) {
|
||||
mAsserter.is(false, true, "Error getting class");
|
||||
} catch (java.lang.NoSuchMethodException ex) {
|
||||
mAsserter.is(false, true, "Error getting method");
|
||||
} catch (java.lang.IllegalAccessException ex) {
|
||||
mAsserter.is(false, true, "Error calling method");
|
||||
} catch (java.lang.reflect.InvocationTargetException ex) {
|
||||
mAsserter.is(false, true, "Invocation target exception " + ex.getTargetException());
|
||||
}
|
||||
// This test completes very quickly. If it completes too soon, the
|
||||
// minidumps directory may not be created before the process is
|
||||
// taken down, causing bug 722166.
|
||||
|
@ -1,13 +1,14 @@
|
||||
package org.mozilla.gecko.tests;
|
||||
|
||||
import org.mozilla.gecko.*;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.ContentResolver;
|
||||
import android.database.Cursor;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
@ -19,101 +20,91 @@ public class testPasswordEncrypt extends BaseTest {
|
||||
}
|
||||
|
||||
public void testPasswordEncrypt() {
|
||||
Context context = (Context)getActivity();
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
mAsserter.isnot(cr, null, "Found a content resolver");
|
||||
ContentValues cvs = new ContentValues();
|
||||
Context context = (Context)getActivity();
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
mAsserter.isnot(cr, null, "Found a content resolver");
|
||||
ContentValues cvs = new ContentValues();
|
||||
|
||||
blockForGeckoReady();
|
||||
blockForGeckoReady();
|
||||
|
||||
File db = new File(mProfile, "signons.sqlite");
|
||||
String dbPath = db.getPath();
|
||||
File db = new File(mProfile, "signons.sqlite");
|
||||
String dbPath = db.getPath();
|
||||
|
||||
Uri passwordUri;
|
||||
try {
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Class pwds = classLoader.loadClass("org.mozilla.gecko.db.BrowserContract$Passwords");
|
||||
Class nss = classLoader.loadClass("org.mozilla.gecko.NSSBridge");
|
||||
Class contextClass = classLoader.loadClass("android.content.Context");
|
||||
Class stringClass = classLoader.loadClass("java.lang.String");
|
||||
Class appshell = classLoader.loadClass("org.mozilla.gecko.GeckoAppShell");
|
||||
Uri passwordUri;
|
||||
cvs.put("hostname", "http://www.example.com");
|
||||
cvs.put("encryptedUsername", "username");
|
||||
cvs.put("encryptedPassword", "password");
|
||||
|
||||
Method decrypt = nss.getMethod("decrypt", contextClass, stringClass, stringClass);
|
||||
Method encrypt = nss.getMethod("encrypt", contextClass, stringClass, stringClass);
|
||||
|
||||
cvs.put("hostname", "http://www.example.com");
|
||||
cvs.put("encryptedUsername", "username");
|
||||
cvs.put("encryptedPassword", "password");
|
||||
// Attempt to insert into the db
|
||||
passwordUri = BrowserContract.Passwords.CONTENT_URI;
|
||||
Uri.Builder builder = passwordUri.buildUpon();
|
||||
passwordUri = builder.appendQueryParameter("profilePath", mProfile).build();
|
||||
|
||||
// Attempt to insert into the db
|
||||
passwordUri = (Uri)pwds.getField("CONTENT_URI").get(null);
|
||||
Uri.Builder builder = passwordUri.buildUpon();
|
||||
passwordUri = builder.appendQueryParameter("profilePath", mProfile).build();
|
||||
Uri uri = cr.insert(passwordUri, cvs);
|
||||
Uri expectedUri = passwordUri.buildUpon().appendPath("1").build();
|
||||
mAsserter.is(uri.toString(), expectedUri.toString(), "Insert returned correct uri");
|
||||
|
||||
Uri uri = cr.insert(passwordUri, cvs);
|
||||
Uri expectedUri = passwordUri.buildUpon().appendPath("1").build();
|
||||
mAsserter.is(uri.toString(), expectedUri.toString(), "Insert returned correct uri");
|
||||
Cursor list = mActions.querySql(dbPath, "SELECT encryptedUsername FROM moz_logins");
|
||||
list.moveToFirst();
|
||||
String decryptedU = null;
|
||||
try {
|
||||
decryptedU = NSSBridge.decrypt(context, mProfile, list.getString(0));
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "NSSBridge.decrypt through Exception " + e, ""); // TODO: What is diag?
|
||||
}
|
||||
mAsserter.is(decryptedU, "username", "Username was encrypted correctly when inserting");
|
||||
|
||||
Cursor list = mActions.querySql(dbPath, "SELECT encryptedUsername FROM moz_logins");
|
||||
list.moveToFirst();
|
||||
String decryptedU = (String)decrypt.invoke(null, context, mProfile, list.getString(0));
|
||||
mAsserter.is(decryptedU, "username", "Username was encrypted correctly when inserting");
|
||||
list = mActions.querySql(dbPath, "SELECT encryptedPassword, encType FROM moz_logins");
|
||||
list.moveToFirst();
|
||||
String decryptedP = null;
|
||||
try {
|
||||
decryptedP = NSSBridge.decrypt(context, mProfile, list.getString(0));
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "NSSBridge.decrypt through Exception " + e, ""); // TODO: What is diag?
|
||||
}
|
||||
mAsserter.is(decryptedP, "password", "Password was encrypted correctly when inserting");
|
||||
mAsserter.is(list.getInt(1), 1, "Password has correct encryption type");
|
||||
|
||||
list = mActions.querySql(dbPath, "SELECT encryptedPassword, encType FROM moz_logins");
|
||||
list.moveToFirst();
|
||||
String decryptedP = (String)decrypt.invoke(null, context, mProfile, list.getString(0));
|
||||
mAsserter.is(decryptedP, "password", "Password was encrypted correctly when inserting");
|
||||
mAsserter.is(list.getInt(1), 1, "Password has correct encryption type");
|
||||
|
||||
cvs.put("encryptedUsername", "username2");
|
||||
cvs.put("encryptedPassword", "password2");
|
||||
cr.update(passwordUri, cvs, null, null);
|
||||
cvs.put("encryptedUsername", "username2");
|
||||
cvs.put("encryptedPassword", "password2");
|
||||
cr.update(passwordUri, cvs, null, null);
|
||||
|
||||
list = mActions.querySql(dbPath, "SELECT encryptedUsername FROM moz_logins");
|
||||
list.moveToFirst();
|
||||
decryptedU = (String)decrypt.invoke(null, context, mProfile, list.getString(0));
|
||||
mAsserter.is(decryptedU, "username2", "Username was encrypted when updating");
|
||||
list = mActions.querySql(dbPath, "SELECT encryptedUsername FROM moz_logins");
|
||||
list.moveToFirst();
|
||||
try {
|
||||
decryptedU = NSSBridge.decrypt(context, mProfile, list.getString(0));
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "NSSBridge.decrypt through Exception " + e, ""); // TODO: What is diag?
|
||||
}
|
||||
mAsserter.is(decryptedU, "username2", "Username was encrypted when updating");
|
||||
|
||||
list = mActions.querySql(dbPath, "SELECT encryptedPassword FROM moz_logins");
|
||||
list.moveToFirst();
|
||||
decryptedP = (String)decrypt.invoke(null, context, mProfile, list.getString(0));
|
||||
mAsserter.is(decryptedP, "password2", "Password was encrypted when updating");
|
||||
list = mActions.querySql(dbPath, "SELECT encryptedPassword FROM moz_logins");
|
||||
list.moveToFirst();
|
||||
try {
|
||||
decryptedP = NSSBridge.decrypt(context, mProfile, list.getString(0));
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "NSSBridge.decrypt through Exception " + e, ""); // TODO: What is diag?
|
||||
}
|
||||
mAsserter.is(decryptedP, "password2", "Password was encrypted when updating");
|
||||
|
||||
// Trying to store a password while master password is enabled should throw,
|
||||
// but because Android can't send Exceptions across processes
|
||||
// it just results in a null uri/cursor being returned.
|
||||
toggleMasterPassword("password");
|
||||
try {
|
||||
uri = cr.insert(passwordUri, cvs);
|
||||
// TODO: restore this assertion -- see bug 764901
|
||||
// mAsserter.is(uri, null, "Storing a password while MP was set should fail");
|
||||
// Trying to store a password while master password is enabled should throw,
|
||||
// but because Android can't send Exceptions across processes
|
||||
// it just results in a null uri/cursor being returned.
|
||||
toggleMasterPassword("password");
|
||||
try {
|
||||
uri = cr.insert(passwordUri, cvs);
|
||||
// TODO: restore this assertion -- see bug 764901
|
||||
// mAsserter.is(uri, null, "Storing a password while MP was set should fail");
|
||||
|
||||
Cursor c = cr.query(passwordUri, null, null, null, null);
|
||||
// TODO: restore this assertion -- see bug 764901
|
||||
// mAsserter.is(c, null, "Querying passwords while MP was set should fail");
|
||||
} catch (Exception ex) {
|
||||
// Password provider currently can not throw across process
|
||||
// so we should not catch this exception here
|
||||
mAsserter.ok(false, "Caught exception", ex.toString());
|
||||
}
|
||||
toggleMasterPassword("password");
|
||||
|
||||
} catch(ClassNotFoundException ex) {
|
||||
mAsserter.ok(false, "Error getting class", ex.toString());
|
||||
return;
|
||||
} catch(NoSuchFieldException ex) {
|
||||
mAsserter.ok(false, "Error getting field", ex.toString());
|
||||
return;
|
||||
} catch(IllegalAccessException ex) {
|
||||
mAsserter.ok(false, "Error using field", ex.toString());
|
||||
return;
|
||||
} catch(java.lang.NoSuchMethodException ex) {
|
||||
mAsserter.ok(false, "Error getting method", ex.toString());
|
||||
return;
|
||||
} catch(java.lang.reflect.InvocationTargetException ex) {
|
||||
mAsserter.ok(false, "Error invoking method", ex.toString());
|
||||
return;
|
||||
}
|
||||
Cursor c = cr.query(passwordUri, null, null, null, null);
|
||||
// TODO: restore this assertion -- see bug 764901
|
||||
// mAsserter.is(c, null, "Querying passwords while MP was set should fail");
|
||||
} catch (Exception ex) {
|
||||
// Password provider currently can not throw across process
|
||||
// so we should not catch this exception here
|
||||
mAsserter.ok(false, "Caught exception", ex.toString());
|
||||
}
|
||||
toggleMasterPassword("password");
|
||||
}
|
||||
|
||||
private void toggleMasterPassword(String passwd) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.mozilla.gecko.tests;
|
||||
|
||||
import org.mozilla.gecko.db.BrowserContract.Passwords;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.ContentResolver;
|
||||
import android.database.Cursor;
|
||||
@ -30,34 +32,19 @@ public class testPasswordProvider extends BaseTest {
|
||||
|
||||
blockForGeckoReady();
|
||||
|
||||
Uri passwordUri;
|
||||
try {
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Class pwds = classLoader.loadClass("org.mozilla.gecko.db.BrowserContract$Passwords");
|
||||
|
||||
cvs[0].put("hostname", "http://www.example.com");
|
||||
cvs[0].put("httpRealm", "http://www.example.com");
|
||||
cvs[0].put("formSubmitURL", "http://www.example.com");
|
||||
cvs[0].put("usernameField", "usernameField");
|
||||
cvs[0].put("passwordField", "passwordField");
|
||||
cvs[0].put("encryptedUsername", "username");
|
||||
cvs[0].put("encryptedPassword", "password");
|
||||
cvs[0].put("encType", "1");
|
||||
|
||||
// Attempt to insert into the db
|
||||
passwordUri = (Uri)pwds.getField("CONTENT_URI").get(null);
|
||||
Uri.Builder builder = passwordUri.buildUpon();
|
||||
passwordUri = builder.appendQueryParameter("profilePath", mProfile).build();
|
||||
} catch(ClassNotFoundException ex) {
|
||||
mAsserter.is(false, true, "Error getting class");
|
||||
return;
|
||||
} catch(NoSuchFieldException ex) {
|
||||
mAsserter.is(false, true, "Error getting field");
|
||||
return;
|
||||
} catch(IllegalAccessException ex) {
|
||||
mAsserter.is(false, true, "Error using field");
|
||||
return;
|
||||
}
|
||||
cvs[0].put("hostname", "http://www.example.com");
|
||||
cvs[0].put("httpRealm", "http://www.example.com");
|
||||
cvs[0].put("formSubmitURL", "http://www.example.com");
|
||||
cvs[0].put("usernameField", "usernameField");
|
||||
cvs[0].put("passwordField", "passwordField");
|
||||
cvs[0].put("encryptedUsername", "username");
|
||||
cvs[0].put("encryptedPassword", "password");
|
||||
cvs[0].put("encType", "1");
|
||||
|
||||
// Attempt to insert into the db
|
||||
Uri passwordUri = Passwords.CONTENT_URI;
|
||||
Uri.Builder builder = passwordUri.buildUpon();
|
||||
passwordUri = builder.appendQueryParameter("profilePath", mProfile).build();
|
||||
|
||||
Uri uri = cr.insert(passwordUri, cvs[0]);
|
||||
Uri expectedUri = passwordUri.buildUpon().appendPath("1").build();
|
||||
|
@ -2,7 +2,6 @@ package org.mozilla.gecko.tests;
|
||||
|
||||
import org.mozilla.gecko.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -138,56 +137,34 @@ public class testSettingsMenuItems extends PixelTest {
|
||||
* if they are present.
|
||||
*/
|
||||
public void addConditionalSettings(Map<String, List<String[]>> settingsMap) {
|
||||
try {
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Class appConstants = classLoader.loadClass("org.mozilla.gecko.AppConstants");
|
||||
// Preferences dependent on RELEASE_BUILD
|
||||
if (!AppConstants.RELEASE_BUILD) {
|
||||
// Text reflow - only built if *not* release build
|
||||
String[] textReflowUi = { "Text reflow" };
|
||||
settingsMap.get("Display").add(textReflowUi);
|
||||
|
||||
// Preferences dependent on RELEASE_BUILD
|
||||
Field releaseBuildField = appConstants.getField("RELEASE_BUILD");
|
||||
boolean releaseBuild = releaseBuildField.getBoolean(appConstants);
|
||||
if (!releaseBuild) {
|
||||
// Text reflow - only built if *not* release build
|
||||
String[] textReflowUi = { "Text reflow" };
|
||||
settingsMap.get("Display").add(textReflowUi);
|
||||
// Anonymous cell tower/wifi collection - only built if *not* release build
|
||||
String[] networkReportingUi = { "Mozilla location services", "Help improve geolocation services for the Open Web by letting " + BRAND_NAME + " collect and send anonymous cellular tower data" };
|
||||
settingsMap.get("Mozilla").add(networkReportingUi);
|
||||
|
||||
// Anonymous cell tower/wifi collection - only built if *not* release build
|
||||
String[] networkReportingUi = { "Mozilla location services", "Help improve geolocation services for the Open Web by letting " + BRAND_NAME + " collect and send anonymous cellular tower data" };
|
||||
settingsMap.get("Mozilla").add(networkReportingUi);
|
||||
}
|
||||
|
||||
}
|
||||
// Automatic updates
|
||||
if (AppConstants.MOZ_UPDATER) {
|
||||
String[] autoUpdateUi = { "Automatic updates", "Only over Wi-Fi", "Enabled", "Only over Wi-Fi", "Disabled" };
|
||||
settingsMap.get("Customize").add(autoUpdateUi);
|
||||
}
|
||||
|
||||
// Automatic updates
|
||||
Field autoUpdateField = appConstants.getField("MOZ_UPDATER");
|
||||
boolean autoUpdate = autoUpdateField.getBoolean(appConstants);
|
||||
if (autoUpdate) {
|
||||
String[] autoUpdateUi = { "Automatic updates", "Only over Wi-Fi", "Enabled", "Only over Wi-Fi", "Disabled" };
|
||||
settingsMap.get("Customize").add(autoUpdateUi);
|
||||
}
|
||||
|
||||
// Crash reporter
|
||||
Field crashReportingField = appConstants.getField("MOZ_CRASHREPORTER");
|
||||
boolean crashReporter = crashReportingField.getBoolean(appConstants);
|
||||
if (crashReporter) {
|
||||
String[] crashReporterUi = { "Crash Reporter", BRAND_NAME + " submits crash reports to help Mozilla make your browser more stable and secure" };
|
||||
settingsMap.get("Mozilla").add(crashReporterUi);
|
||||
}
|
||||
|
||||
// Telemetry
|
||||
Field telemetryField = appConstants.getField("MOZ_TELEMETRY_REPORTING");
|
||||
boolean telemetry = telemetryField.getBoolean(appConstants);
|
||||
if (telemetry) {
|
||||
String[] telemetryUi = { "Telemetry", "Shares performance, usage, hardware and customization data about your browser with Mozilla to help us make " + BRAND_NAME + " better" };
|
||||
settingsMap.get("Mozilla").add(telemetryUi);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
mAsserter.ok(false, "Class not found in setting conditional settings", e.toString());
|
||||
|
||||
} catch (NoSuchFieldException e) {
|
||||
mAsserter.ok(false, "Field not found in setting conditional settings", e.toString());
|
||||
|
||||
} catch (IllegalAccessException e) {
|
||||
mAsserter.ok(false, "Field cannot be accessed in setting conditional settings", e.toString());
|
||||
// Crash reporter
|
||||
if (AppConstants.MOZ_CRASHREPORTER) {
|
||||
String[] crashReporterUi = { "Crash Reporter", BRAND_NAME + " submits crash reports to help Mozilla make your browser more stable and secure" };
|
||||
settingsMap.get("Mozilla").add(crashReporterUi);
|
||||
}
|
||||
|
||||
// Telemetry
|
||||
if (AppConstants.MOZ_TELEMETRY_REPORTING) {
|
||||
String[] telemetryUi = { "Telemetry", "Shares performance, usage, hardware and customization data about your browser with Mozilla to help us make " + BRAND_NAME + " better" };
|
||||
settingsMap.get("Mozilla").add(telemetryUi);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.mozilla.gecko.tests;
|
||||
|
||||
import org.mozilla.gecko.db.BrowserDB;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
@ -67,26 +69,15 @@ public class testThumbnails extends BaseTest {
|
||||
mAsserter.is(getTopSiteThumbnailColor(site2Title), Color.GREEN, "Top site thumbnail not updated for HTTP 404");
|
||||
|
||||
// test dropping thumbnails
|
||||
try {
|
||||
ClassLoader cl = getActivity().getApplicationContext().getClassLoader();
|
||||
Class browserDB = cl.loadClass("org.mozilla.gecko.db.BrowserDB");
|
||||
// check that the thumbnail is non-null
|
||||
byte[] thumbnailData = (byte[])browserDB
|
||||
.getMethod("getThumbnailForUrl", ContentResolver.class, String.class)
|
||||
.invoke(null, getActivity().getContentResolver(), site1Url);
|
||||
mAsserter.ok(thumbnailData != null && thumbnailData.length > 0, "Checking for thumbnail data", "No thumbnail data found");
|
||||
// drop thumbnails
|
||||
browserDB.getMethod("removeThumbnails", ContentResolver.class)
|
||||
.invoke(null, getActivity().getContentResolver());
|
||||
// check that the thumbnail is now null
|
||||
thumbnailData = (byte[])browserDB
|
||||
.getMethod("getThumbnailForUrl", ContentResolver.class, String.class)
|
||||
.invoke(null, getActivity().getContentResolver(), site1Url);
|
||||
mAsserter.ok(thumbnailData == null || thumbnailData.length == 0, "Checking for thumbnail data", "Thumbnail data found");
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "Testing removing thumbnails", e.toString());
|
||||
mAsserter.dumpLog(e.toString(), e);
|
||||
}
|
||||
final ContentResolver resolver = getActivity().getContentResolver();
|
||||
// check that the thumbnail is non-null
|
||||
byte[] thumbnailData = BrowserDB.getThumbnailForUrl(resolver, site1Url);
|
||||
mAsserter.ok(thumbnailData != null && thumbnailData.length > 0, "Checking for thumbnail data", "No thumbnail data found");
|
||||
// drop thumbnails
|
||||
BrowserDB.removeThumbnails(resolver);
|
||||
// check that the thumbnail is now null
|
||||
thumbnailData = BrowserDB.getThumbnailForUrl(resolver, site1Url);
|
||||
mAsserter.ok(thumbnailData == null || thumbnailData.length == 0, "Checking for thumbnail data", "Thumbnail data found");
|
||||
}
|
||||
|
||||
private class ThumbnailTest implements BooleanTest {
|
||||
|
Loading…
Reference in New Issue
Block a user