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.

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

mercurial