mobile/android/base/tests/testPasswordProvider.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 package org.mozilla.gecko.tests;
michael@0 2
michael@0 3 import java.io.File;
michael@0 4
michael@0 5 import org.mozilla.gecko.db.BrowserContract.Passwords;
michael@0 6
michael@0 7 import android.content.ContentResolver;
michael@0 8 import android.content.ContentValues;
michael@0 9 import android.content.Context;
michael@0 10 import android.database.Cursor;
michael@0 11 import android.net.Uri;
michael@0 12
michael@0 13 /**
michael@0 14 * A basic password contentprovider test.
michael@0 15 * - inserts a password when the database is not yet set up
michael@0 16 * - inserts a password
michael@0 17 * - updates a password
michael@0 18 * - deletes a password
michael@0 19 */
michael@0 20 public class testPasswordProvider extends BaseTest {
michael@0 21 private static final String DB_NAME = "signons.sqlite";
michael@0 22
michael@0 23 public void testPasswordProvider() {
michael@0 24 Context context = (Context)getActivity();
michael@0 25 ContentResolver cr = context.getContentResolver();
michael@0 26 ContentValues[] cvs = new ContentValues[1];
michael@0 27 cvs[0] = new ContentValues();
michael@0 28
michael@0 29 blockForGeckoReady();
michael@0 30
michael@0 31 cvs[0].put("hostname", "http://www.example.com");
michael@0 32 cvs[0].put("httpRealm", "http://www.example.com");
michael@0 33 cvs[0].put("formSubmitURL", "http://www.example.com");
michael@0 34 cvs[0].put("usernameField", "usernameField");
michael@0 35 cvs[0].put("passwordField", "passwordField");
michael@0 36 cvs[0].put("encryptedUsername", "username");
michael@0 37 cvs[0].put("encryptedPassword", "password");
michael@0 38 cvs[0].put("encType", "1");
michael@0 39
michael@0 40 // Attempt to insert into the db
michael@0 41 Uri passwordUri = Passwords.CONTENT_URI;
michael@0 42 Uri.Builder builder = passwordUri.buildUpon();
michael@0 43 passwordUri = builder.appendQueryParameter("profilePath", mProfile).build();
michael@0 44
michael@0 45 Uri uri = cr.insert(passwordUri, cvs[0]);
michael@0 46 Uri expectedUri = passwordUri.buildUpon().appendPath("1").build();
michael@0 47 mAsserter.is(uri.toString(), expectedUri.toString(), "Insert returned correct uri");
michael@0 48 Cursor c = cr.query(passwordUri, null, null, null, null);
michael@0 49 SqliteCompare(c, cvs);
michael@0 50
michael@0 51 cvs[0].put("usernameField", "usernameField2");
michael@0 52 cvs[0].put("passwordField", "passwordField2");
michael@0 53
michael@0 54 int numUpdated = cr.update(passwordUri, cvs[0], null, null);
michael@0 55 mAsserter.is(1, numUpdated, "Correct number updated");
michael@0 56 c = cr.query(passwordUri, null, null, null, null);
michael@0 57 SqliteCompare(c, cvs);
michael@0 58
michael@0 59 int numDeleted = cr.delete(passwordUri, null, null);
michael@0 60 mAsserter.is(1, numDeleted, "Correct number deleted");
michael@0 61 cvs = new ContentValues[0];
michael@0 62 c = cr.query(passwordUri, null, null, null, null);
michael@0 63 SqliteCompare(c, cvs);
michael@0 64 }
michael@0 65
michael@0 66 @Override
michael@0 67 public void tearDown() throws Exception {
michael@0 68 // remove the entire signons.sqlite file
michael@0 69 File profile = new File(mProfile);
michael@0 70 File db = new File(profile, "signons.sqlite");
michael@0 71 if (db.delete()) {
michael@0 72 mAsserter.dumpLog("tearDown deleted "+db.toString());
michael@0 73 } else {
michael@0 74 mAsserter.dumpLog("tearDown did not delete "+db.toString());
michael@0 75 }
michael@0 76
michael@0 77 super.tearDown();
michael@0 78 }
michael@0 79 }

mercurial