michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import java.io.File; michael@0: michael@0: import org.mozilla.gecko.db.BrowserContract.FormHistory; michael@0: michael@0: import android.content.ContentResolver; michael@0: import android.content.ContentValues; michael@0: import android.content.Context; michael@0: import android.net.Uri; michael@0: michael@0: /** michael@0: * A basic form history contentprovider test. michael@0: * - inserts an element in form history when it is not yet set up michael@0: * - inserts an element in form history michael@0: * - updates an element in form history michael@0: * - deletes an element in form history michael@0: */ michael@0: public class testFormHistory extends BaseTest { michael@0: private static final String DB_NAME = "formhistory.sqlite"; michael@0: michael@0: public void testFormHistory() { michael@0: Context context = (Context)getActivity(); michael@0: ContentResolver cr = context.getContentResolver(); michael@0: ContentValues[] cvs = new ContentValues[1]; michael@0: cvs[0] = new ContentValues(); michael@0: michael@0: blockForGeckoReady(); michael@0: michael@0: Uri formHistoryUri; michael@0: Uri insertUri; michael@0: Uri expectedUri; michael@0: int numUpdated; michael@0: int numDeleted; michael@0: michael@0: cvs[0].put("fieldname", "fieldname"); michael@0: cvs[0].put("value", "value"); michael@0: cvs[0].put("timesUsed", "0"); michael@0: cvs[0].put("guid", "guid"); michael@0: michael@0: // Attempt to insert into the db michael@0: formHistoryUri = FormHistory.CONTENT_URI; michael@0: Uri.Builder builder = formHistoryUri.buildUpon(); michael@0: formHistoryUri = builder.appendQueryParameter("profilePath", mProfile).build(); michael@0: michael@0: insertUri = cr.insert(formHistoryUri, cvs[0]); michael@0: expectedUri = formHistoryUri.buildUpon().appendPath("1").build(); michael@0: mAsserter.is(expectedUri.toString(), insertUri.toString(), "Insert returned correct uri"); michael@0: SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs); michael@0: michael@0: cvs[0].put("fieldname", "fieldname2"); michael@0: cvs[0].putNull("guid"); michael@0: michael@0: numUpdated = cr.update(formHistoryUri, cvs[0], null, null); michael@0: mAsserter.is(1, numUpdated, "Correct number updated"); michael@0: SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs); michael@0: michael@0: numDeleted = cr.delete(formHistoryUri, null, null); michael@0: mAsserter.is(1, numDeleted, "Correct number deleted"); michael@0: cvs = new ContentValues[0]; michael@0: SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs); michael@0: michael@0: cvs = new ContentValues[1]; michael@0: cvs[0] = new ContentValues(); michael@0: cvs[0].put("fieldname", "fieldname"); michael@0: cvs[0].put("value", "value"); michael@0: cvs[0].put("timesUsed", "0"); michael@0: cvs[0].putNull("guid"); michael@0: michael@0: insertUri = cr.insert(formHistoryUri, cvs[0]); michael@0: expectedUri = formHistoryUri.buildUpon().appendPath("1").build(); michael@0: mAsserter.is(expectedUri.toString(), insertUri.toString(), "Insert returned correct uri"); michael@0: SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs); michael@0: michael@0: cvs[0].put("guid", "guid"); michael@0: michael@0: numUpdated = cr.update(formHistoryUri, cvs[0], null, null); michael@0: mAsserter.is(1, numUpdated, "Correct number updated"); michael@0: SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs); michael@0: michael@0: numDeleted = cr.delete(formHistoryUri, null, null); michael@0: mAsserter.is(1, numDeleted, "Correct number deleted"); michael@0: cvs = new ContentValues[0]; michael@0: SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs); michael@0: } michael@0: michael@0: @Override michael@0: public void tearDown() throws Exception { michael@0: // remove the entire signons.sqlite file michael@0: File profile = new File(mProfile); michael@0: File db = new File(profile, "formhistory.sqlite"); michael@0: if (db.delete()) { michael@0: mAsserter.dumpLog("tearDown deleted "+db.toString()); michael@0: } else { michael@0: mAsserter.dumpLog("tearDown did not delete "+db.toString()); michael@0: } michael@0: michael@0: super.tearDown(); michael@0: } michael@0: }