mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 14:45:29 +00:00
fe44f36220
--HG-- extra : rebase_source : 376574e0c41b91c16a6be335584a4a61768bb4a9
119 lines
4.3 KiB
Java
119 lines
4.3 KiB
Java
#filter substitution
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
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.
|
|
* - inserts an element in form history when it is not yet set up
|
|
* - inserts an element in form history
|
|
* - updates an element in form history
|
|
* - deletes an element in form history
|
|
*/
|
|
public class testFormHistory extends BaseTest {
|
|
private static final String DB_NAME = "formhistory.sqlite";
|
|
|
|
@Override
|
|
protected int getTestType() {
|
|
return TEST_MOCHITEST;
|
|
}
|
|
|
|
public void testFormHistory() {
|
|
Context context = (Context)getActivity();
|
|
ContentResolver cr = context.getContentResolver();
|
|
ContentValues[] cvs = new ContentValues[1];
|
|
cvs[0] = new ContentValues();
|
|
|
|
blockForGeckoReady();
|
|
|
|
Uri formHistoryUri;
|
|
Uri insertUri;
|
|
Uri expectedUri;
|
|
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;
|
|
}
|
|
|
|
insertUri = cr.insert(formHistoryUri, cvs[0]);
|
|
expectedUri = formHistoryUri.buildUpon().appendPath("1").build();
|
|
mAsserter.is(expectedUri.toString(), insertUri.toString(), "Insert returned correct uri");
|
|
SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs);
|
|
|
|
cvs[0].put("fieldname", "fieldname2");
|
|
cvs[0].putNull("guid");
|
|
|
|
numUpdated = cr.update(formHistoryUri, cvs[0], null, null);
|
|
mAsserter.is(1, numUpdated, "Correct number updated");
|
|
SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs);
|
|
|
|
numDeleted = cr.delete(formHistoryUri, null, null);
|
|
mAsserter.is(1, numDeleted, "Correct number deleted");
|
|
cvs = new ContentValues[0];
|
|
SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs);
|
|
|
|
cvs = new ContentValues[1];
|
|
cvs[0] = new ContentValues();
|
|
cvs[0].put("fieldname", "fieldname");
|
|
cvs[0].put("value", "value");
|
|
cvs[0].put("timesUsed", "0");
|
|
cvs[0].putNull("guid");
|
|
|
|
insertUri = cr.insert(formHistoryUri, cvs[0]);
|
|
expectedUri = formHistoryUri.buildUpon().appendPath("1").build();
|
|
mAsserter.is(expectedUri.toString(), insertUri.toString(), "Insert returned correct uri");
|
|
SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs);
|
|
|
|
cvs[0].put("guid", "guid");
|
|
|
|
numUpdated = cr.update(formHistoryUri, cvs[0], null, null);
|
|
mAsserter.is(1, numUpdated, "Correct number updated");
|
|
SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs);
|
|
|
|
numDeleted = cr.delete(formHistoryUri, null, null);
|
|
mAsserter.is(1, numDeleted, "Correct number deleted");
|
|
cvs = new ContentValues[0];
|
|
SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs);
|
|
}
|
|
|
|
@Override
|
|
public void tearDown() throws Exception {
|
|
// remove the entire signons.sqlite file
|
|
File profile = new File(mProfile);
|
|
File db = new File(profile, "formhistory.sqlite");
|
|
if (db.delete()) {
|
|
mAsserter.dumpLog("tearDown deleted "+db.toString());
|
|
} else {
|
|
mAsserter.dumpLog("tearDown did not delete "+db.toString());
|
|
}
|
|
|
|
super.tearDown();
|
|
}
|
|
}
|