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.Passwords; michael@0: michael@0: import android.content.ContentResolver; michael@0: import android.content.ContentValues; michael@0: import android.content.Context; michael@0: import android.database.Cursor; michael@0: import android.net.Uri; michael@0: michael@0: /** michael@0: * A basic password contentprovider test. michael@0: * - inserts a password when the database is not yet set up michael@0: * - inserts a password michael@0: * - updates a password michael@0: * - deletes a password michael@0: */ michael@0: public class testPasswordProvider extends BaseTest { michael@0: private static final String DB_NAME = "signons.sqlite"; michael@0: michael@0: public void testPasswordProvider() { 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: cvs[0].put("hostname", "http://www.example.com"); michael@0: cvs[0].put("httpRealm", "http://www.example.com"); michael@0: cvs[0].put("formSubmitURL", "http://www.example.com"); michael@0: cvs[0].put("usernameField", "usernameField"); michael@0: cvs[0].put("passwordField", "passwordField"); michael@0: cvs[0].put("encryptedUsername", "username"); michael@0: cvs[0].put("encryptedPassword", "password"); michael@0: cvs[0].put("encType", "1"); michael@0: michael@0: // Attempt to insert into the db michael@0: Uri passwordUri = Passwords.CONTENT_URI; michael@0: Uri.Builder builder = passwordUri.buildUpon(); michael@0: passwordUri = builder.appendQueryParameter("profilePath", mProfile).build(); michael@0: michael@0: Uri uri = cr.insert(passwordUri, cvs[0]); michael@0: Uri expectedUri = passwordUri.buildUpon().appendPath("1").build(); michael@0: mAsserter.is(uri.toString(), expectedUri.toString(), "Insert returned correct uri"); michael@0: Cursor c = cr.query(passwordUri, null, null, null, null); michael@0: SqliteCompare(c, cvs); michael@0: michael@0: cvs[0].put("usernameField", "usernameField2"); michael@0: cvs[0].put("passwordField", "passwordField2"); michael@0: michael@0: int numUpdated = cr.update(passwordUri, cvs[0], null, null); michael@0: mAsserter.is(1, numUpdated, "Correct number updated"); michael@0: c = cr.query(passwordUri, null, null, null, null); michael@0: SqliteCompare(c, cvs); michael@0: michael@0: int numDeleted = cr.delete(passwordUri, null, null); michael@0: mAsserter.is(1, numDeleted, "Correct number deleted"); michael@0: cvs = new ContentValues[0]; michael@0: c = cr.query(passwordUri, null, null, null, null); michael@0: SqliteCompare(c, 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, "signons.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: }