Loading build/mobile/robocop/Actions.java.in +8 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,9 @@ package @ANDROID_PACKAGE_NAME@; import java.util.List; import java.util.ArrayList; import android.database.Cursor; public interface Actions { Loading Loading @@ -92,4 +95,9 @@ public interface Actions { void sendSpecialKey(SpecialKey key); void drag(int startingX, int endingX, int startingY, int endingY); /** * Run a sql query on the specified database */ public Cursor querySql(String dbPath, String sql); } build/mobile/robocop/FennecMochitestAssert.java.in +44 −23 Original line number Diff line number Diff line Loading @@ -166,21 +166,13 @@ public class FennecMochitestAssert implements Assert { } public void is(Object a, Object b, String name) { boolean pass = a.equals(b); String diag = "got " + a.toString() + ", expected " + b.toString(); if (pass) { diag = a.toString() + " should equal " + b.toString(); } ok(pass, name, diag); boolean pass = checkObjectsEqual(a,b); ok(pass, name, getEqualString(a,b, pass)); } public void isnot(Object a, Object b, String name) { boolean pass = !a.equals(b); String diag = "didn't expect " + a.toString() + ", but got it"; if (pass) { diag = a.toString() + " should not equal " + b.toString(); } ok(pass, name, diag); boolean pass = checkObjectsNotEqual(a,b); ok(pass, name, getNotEqualString(a,b,pass)); } public void ispixel(int actual, int r, int g, int b, String name) { Loading @@ -207,21 +199,50 @@ public class FennecMochitestAssert implements Assert { } public void todo_is(Object a, Object b, String name) { boolean pass = a.equals(b); String diag = "got " + a.toString() + ", expected " + b.toString(); boolean pass = checkObjectsEqual(a,b); todo(pass, name, getEqualString(a,b,pass)); } public void todo_isnot(Object a, Object b, String name) { boolean pass = checkObjectsNotEqual(a,b); todo(pass, name, getNotEqualString(a,b,pass)); } private boolean checkObjectsEqual(Object a, Object b) { if (a == null || b == null) { if (a == null && b == null) { return true; } return false; } else { return a.equals(b); } } private String getEqualString(Object a, Object b, boolean pass) { if (pass) { diag = a.toString() + " should equal " + b.toString(); return a + " should equal " + b; } todo(pass, name, diag); return "got " + a + ", expected " + b; } public void todo_isnot(Object a, Object b, String name) { boolean pass = !a.equals(b); String diag = "didn't expect " + a.toString() + ", but got it"; private boolean checkObjectsNotEqual(Object a, Object b) { if (a == null || b == null) { if ((a == null && b != null) || (a != null && b == null)) { return true; } else { return false; } } else { return !a.equals(b); } } private String getNotEqualString(Object a, Object b, boolean pass) { if(pass) { diag = a.toString() + " should not equal " + b.toString(); return a + " should not equal " + b; } todo(pass, name, diag); return "didn't expect " + a + ", but got it"; } public void info(String name, String message) { Loading build/mobile/robocop/FennecNativeActions.java.in +40 −2 Original line number Diff line number Diff line Loading @@ -40,19 +40,24 @@ package @ANDROID_PACKAGE_NAME@; import java.lang.Class; import java.lang.ClassLoader; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.lang.reflect.InvocationHandler; import java.lang.Long; import java.util.concurrent.SynchronousQueue; import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.app.Instrumentation; import android.database.Cursor; import android.os.SystemClock; import android.view.View; import android.view.KeyEvent; import java.util.concurrent.SynchronousQueue; import android.util.Log; import org.json.*; Loading @@ -74,6 +79,7 @@ public class FennecNativeActions implements Actions { private Method mSendGE; private Method mGetLayerClient; private Method mSetDrawListener; private static final String LOGTAG = "FennecNativeActions"; public FennecNativeActions(Activity activity, Solo robocop, Instrumentation instrumentation) { mSolo = robocop; Loading Loading @@ -349,4 +355,36 @@ public class FennecNativeActions implements Actions { public void drag(int startingX, int endingX, int startingY, int endingY) { mSolo.drag(startingX, endingX, startingY, endingY, 10); } public Cursor querySql(String dbPath, String sql) { try { ClassLoader classLoader = mGeckoApp.getClassLoader(); Class sqlClass = classLoader.loadClass("org.mozilla.gecko.sqlite.SQLiteBridge"); Class stringClass = String.class; Class stringArrayClass = String[].class; Class appshell = classLoader.loadClass("org.mozilla.gecko.GeckoAppShell"); Class contextClass = Context.class; Constructor bridgeConstructor = sqlClass.getConstructor(stringClass); Method query = sqlClass.getMethod("rawQuery", stringClass, stringArrayClass); Method loadSQLiteLibs = appshell.getMethod("loadSQLiteLibs", contextClass, stringClass); Object bridge = bridgeConstructor.newInstance(dbPath); String resourcePath = mGeckoApp.getApplication().getPackageResourcePath(); loadSQLiteLibs.invoke(null, mGeckoApp, resourcePath); return (Cursor)query.invoke(bridge, sql, null); } catch(ClassNotFoundException ex) { Log.e(LOGTAG, "Error getting class", ex); } catch(NoSuchMethodException ex) { Log.e(LOGTAG, "Error getting method", ex); } catch(InvocationTargetException ex) { Log.e(LOGTAG, "Error invoking method", ex); } catch(InstantiationException ex) { Log.e(LOGTAG, "Error calling constructor", ex); } catch(IllegalAccessException ex) { Log.e(LOGTAG, "Error using field", ex); } return null; } } mobile/android/base/db/PasswordsProvider.java.in +0 −3 Original line number Diff line number Diff line Loading @@ -168,9 +168,6 @@ public class PasswordsProvider extends GeckoProvider { values.put(Passwords.GUID, guid); } String nowString = new Long(now).toString(); DBUtils.replaceKey(values, CommonColumns._ID, Passwords.ID, ""); DBUtils.replaceKey(values, SyncColumns.DATE_CREATED, Passwords.TIME_CREATED, nowString); DBUtils.replaceKey(values, SyncColumns.DATE_MODIFIED, Passwords.TIME_PASSWORD_CHANGED, nowString); DBUtils.replaceKey(values, null, Passwords.HOSTNAME, ""); DBUtils.replaceKey(values, null, Passwords.HTTP_REALM, ""); DBUtils.replaceKey(values, null, Passwords.FORM_SUBMIT_URL, ""); Loading mobile/android/base/tests/BaseTest.java.in +57 −1 Original line number Diff line number Diff line Loading @@ -6,9 +6,12 @@ import @ANDROID_PACKAGE_NAME@.*; import android.app.Activity; import android.app.Instrumentation; import android.database.Cursor; import android.content.ContentValues; import android.content.Intent; import android.os.SystemClock; import android.test.ActivityInstrumentationTestCase2; import java.io.File; import java.util.HashMap; Loading @@ -25,6 +28,7 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> { protected String mBaseUrl; private String mTestType; private String mLogFile; protected String mProfile; static { try { Loading @@ -46,7 +50,8 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> { // Create the intent to be used with all the important arguments. Intent i = new Intent(Intent.ACTION_MAIN); i.putExtra("args", "-no-remote -profile " + (String)config.get("profile")); mProfile = (String)config.get("profile"); i.putExtra("args", "-no-remote -profile " + mProfile); // Start the activity setActivityIntent(i); Loading Loading @@ -148,4 +153,55 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> { protected interface BooleanTest { public boolean test(); } @SuppressWarnings({"unchecked", "non-varargs"}) public void SqliteCompare(String dbName, String sqlCommand, ContentValues[] cvs) { File profile = new File(mProfile); String dbPath = new File(profile, dbName).getPath(); Cursor c = mActions.querySql(dbPath, sqlCommand); SqliteCompare(c, cvs); } private boolean CursorMatches(Cursor c, String[] columns, ContentValues cv) { for (int i = 0; i < columns.length; i++) { String column = columns[i]; if (cv.containsKey(column)) { mAsserter.info("Comparing", "Column value " + c.getString(i) + " ?= " + cv.get(column).toString()); if (!cv.get(column).toString().equals(c.getString(i))) { return false; } } } return true; } @SuppressWarnings({"unchecked", "non-varargs"}) public void SqliteCompare(Cursor c, ContentValues[] cvs) { mAsserter.is(c.getCount(), cvs.length, "List is correct length"); if (c.moveToFirst()) { do { boolean found = false; for (int i = 0; !found && i < cvs.length; i++) { if (CursorMatches(c, cvs[i])) { found = true; } } mAsserter.is(found, true, "Password was found"); } while(c.moveToNext()); } } public boolean CursorMatches(Cursor c, ContentValues cv) { for (int i = 0; i < c.getColumnCount(); i++) { String column = c.getColumnName(i); if (cv.containsKey(column)) { mAsserter.info("Pass","Column value " + c.getString(i) + " ?= " + cv.get(column).toString()); if (!cv.get(column).toString().equals(c.getString(i))) { return false; } } } return true; } } Loading
build/mobile/robocop/Actions.java.in +8 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,9 @@ package @ANDROID_PACKAGE_NAME@; import java.util.List; import java.util.ArrayList; import android.database.Cursor; public interface Actions { Loading Loading @@ -92,4 +95,9 @@ public interface Actions { void sendSpecialKey(SpecialKey key); void drag(int startingX, int endingX, int startingY, int endingY); /** * Run a sql query on the specified database */ public Cursor querySql(String dbPath, String sql); }
build/mobile/robocop/FennecMochitestAssert.java.in +44 −23 Original line number Diff line number Diff line Loading @@ -166,21 +166,13 @@ public class FennecMochitestAssert implements Assert { } public void is(Object a, Object b, String name) { boolean pass = a.equals(b); String diag = "got " + a.toString() + ", expected " + b.toString(); if (pass) { diag = a.toString() + " should equal " + b.toString(); } ok(pass, name, diag); boolean pass = checkObjectsEqual(a,b); ok(pass, name, getEqualString(a,b, pass)); } public void isnot(Object a, Object b, String name) { boolean pass = !a.equals(b); String diag = "didn't expect " + a.toString() + ", but got it"; if (pass) { diag = a.toString() + " should not equal " + b.toString(); } ok(pass, name, diag); boolean pass = checkObjectsNotEqual(a,b); ok(pass, name, getNotEqualString(a,b,pass)); } public void ispixel(int actual, int r, int g, int b, String name) { Loading @@ -207,21 +199,50 @@ public class FennecMochitestAssert implements Assert { } public void todo_is(Object a, Object b, String name) { boolean pass = a.equals(b); String diag = "got " + a.toString() + ", expected " + b.toString(); boolean pass = checkObjectsEqual(a,b); todo(pass, name, getEqualString(a,b,pass)); } public void todo_isnot(Object a, Object b, String name) { boolean pass = checkObjectsNotEqual(a,b); todo(pass, name, getNotEqualString(a,b,pass)); } private boolean checkObjectsEqual(Object a, Object b) { if (a == null || b == null) { if (a == null && b == null) { return true; } return false; } else { return a.equals(b); } } private String getEqualString(Object a, Object b, boolean pass) { if (pass) { diag = a.toString() + " should equal " + b.toString(); return a + " should equal " + b; } todo(pass, name, diag); return "got " + a + ", expected " + b; } public void todo_isnot(Object a, Object b, String name) { boolean pass = !a.equals(b); String diag = "didn't expect " + a.toString() + ", but got it"; private boolean checkObjectsNotEqual(Object a, Object b) { if (a == null || b == null) { if ((a == null && b != null) || (a != null && b == null)) { return true; } else { return false; } } else { return !a.equals(b); } } private String getNotEqualString(Object a, Object b, boolean pass) { if(pass) { diag = a.toString() + " should not equal " + b.toString(); return a + " should not equal " + b; } todo(pass, name, diag); return "didn't expect " + a + ", but got it"; } public void info(String name, String message) { Loading
build/mobile/robocop/FennecNativeActions.java.in +40 −2 Original line number Diff line number Diff line Loading @@ -40,19 +40,24 @@ package @ANDROID_PACKAGE_NAME@; import java.lang.Class; import java.lang.ClassLoader; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.lang.reflect.InvocationHandler; import java.lang.Long; import java.util.concurrent.SynchronousQueue; import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.app.Instrumentation; import android.database.Cursor; import android.os.SystemClock; import android.view.View; import android.view.KeyEvent; import java.util.concurrent.SynchronousQueue; import android.util.Log; import org.json.*; Loading @@ -74,6 +79,7 @@ public class FennecNativeActions implements Actions { private Method mSendGE; private Method mGetLayerClient; private Method mSetDrawListener; private static final String LOGTAG = "FennecNativeActions"; public FennecNativeActions(Activity activity, Solo robocop, Instrumentation instrumentation) { mSolo = robocop; Loading Loading @@ -349,4 +355,36 @@ public class FennecNativeActions implements Actions { public void drag(int startingX, int endingX, int startingY, int endingY) { mSolo.drag(startingX, endingX, startingY, endingY, 10); } public Cursor querySql(String dbPath, String sql) { try { ClassLoader classLoader = mGeckoApp.getClassLoader(); Class sqlClass = classLoader.loadClass("org.mozilla.gecko.sqlite.SQLiteBridge"); Class stringClass = String.class; Class stringArrayClass = String[].class; Class appshell = classLoader.loadClass("org.mozilla.gecko.GeckoAppShell"); Class contextClass = Context.class; Constructor bridgeConstructor = sqlClass.getConstructor(stringClass); Method query = sqlClass.getMethod("rawQuery", stringClass, stringArrayClass); Method loadSQLiteLibs = appshell.getMethod("loadSQLiteLibs", contextClass, stringClass); Object bridge = bridgeConstructor.newInstance(dbPath); String resourcePath = mGeckoApp.getApplication().getPackageResourcePath(); loadSQLiteLibs.invoke(null, mGeckoApp, resourcePath); return (Cursor)query.invoke(bridge, sql, null); } catch(ClassNotFoundException ex) { Log.e(LOGTAG, "Error getting class", ex); } catch(NoSuchMethodException ex) { Log.e(LOGTAG, "Error getting method", ex); } catch(InvocationTargetException ex) { Log.e(LOGTAG, "Error invoking method", ex); } catch(InstantiationException ex) { Log.e(LOGTAG, "Error calling constructor", ex); } catch(IllegalAccessException ex) { Log.e(LOGTAG, "Error using field", ex); } return null; } }
mobile/android/base/db/PasswordsProvider.java.in +0 −3 Original line number Diff line number Diff line Loading @@ -168,9 +168,6 @@ public class PasswordsProvider extends GeckoProvider { values.put(Passwords.GUID, guid); } String nowString = new Long(now).toString(); DBUtils.replaceKey(values, CommonColumns._ID, Passwords.ID, ""); DBUtils.replaceKey(values, SyncColumns.DATE_CREATED, Passwords.TIME_CREATED, nowString); DBUtils.replaceKey(values, SyncColumns.DATE_MODIFIED, Passwords.TIME_PASSWORD_CHANGED, nowString); DBUtils.replaceKey(values, null, Passwords.HOSTNAME, ""); DBUtils.replaceKey(values, null, Passwords.HTTP_REALM, ""); DBUtils.replaceKey(values, null, Passwords.FORM_SUBMIT_URL, ""); Loading
mobile/android/base/tests/BaseTest.java.in +57 −1 Original line number Diff line number Diff line Loading @@ -6,9 +6,12 @@ import @ANDROID_PACKAGE_NAME@.*; import android.app.Activity; import android.app.Instrumentation; import android.database.Cursor; import android.content.ContentValues; import android.content.Intent; import android.os.SystemClock; import android.test.ActivityInstrumentationTestCase2; import java.io.File; import java.util.HashMap; Loading @@ -25,6 +28,7 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> { protected String mBaseUrl; private String mTestType; private String mLogFile; protected String mProfile; static { try { Loading @@ -46,7 +50,8 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> { // Create the intent to be used with all the important arguments. Intent i = new Intent(Intent.ACTION_MAIN); i.putExtra("args", "-no-remote -profile " + (String)config.get("profile")); mProfile = (String)config.get("profile"); i.putExtra("args", "-no-remote -profile " + mProfile); // Start the activity setActivityIntent(i); Loading Loading @@ -148,4 +153,55 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> { protected interface BooleanTest { public boolean test(); } @SuppressWarnings({"unchecked", "non-varargs"}) public void SqliteCompare(String dbName, String sqlCommand, ContentValues[] cvs) { File profile = new File(mProfile); String dbPath = new File(profile, dbName).getPath(); Cursor c = mActions.querySql(dbPath, sqlCommand); SqliteCompare(c, cvs); } private boolean CursorMatches(Cursor c, String[] columns, ContentValues cv) { for (int i = 0; i < columns.length; i++) { String column = columns[i]; if (cv.containsKey(column)) { mAsserter.info("Comparing", "Column value " + c.getString(i) + " ?= " + cv.get(column).toString()); if (!cv.get(column).toString().equals(c.getString(i))) { return false; } } } return true; } @SuppressWarnings({"unchecked", "non-varargs"}) public void SqliteCompare(Cursor c, ContentValues[] cvs) { mAsserter.is(c.getCount(), cvs.length, "List is correct length"); if (c.moveToFirst()) { do { boolean found = false; for (int i = 0; !found && i < cvs.length; i++) { if (CursorMatches(c, cvs[i])) { found = true; } } mAsserter.is(found, true, "Password was found"); } while(c.moveToNext()); } } public boolean CursorMatches(Cursor c, ContentValues cv) { for (int i = 0; i < c.getColumnCount(); i++) { String column = c.getColumnName(i); if (cv.containsKey(column)) { mAsserter.info("Pass","Column value " + c.getString(i) + " ?= " + cv.get(column).toString()); if (!cv.get(column).toString().equals(c.getString(i))) { return false; } } } return true; } }