1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/tests/testPasswordProvider.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +package org.mozilla.gecko.tests; 1.5 + 1.6 +import java.io.File; 1.7 + 1.8 +import org.mozilla.gecko.db.BrowserContract.Passwords; 1.9 + 1.10 +import android.content.ContentResolver; 1.11 +import android.content.ContentValues; 1.12 +import android.content.Context; 1.13 +import android.database.Cursor; 1.14 +import android.net.Uri; 1.15 + 1.16 +/** 1.17 + * A basic password contentprovider test. 1.18 + * - inserts a password when the database is not yet set up 1.19 + * - inserts a password 1.20 + * - updates a password 1.21 + * - deletes a password 1.22 + */ 1.23 +public class testPasswordProvider extends BaseTest { 1.24 + private static final String DB_NAME = "signons.sqlite"; 1.25 + 1.26 + public void testPasswordProvider() { 1.27 + Context context = (Context)getActivity(); 1.28 + ContentResolver cr = context.getContentResolver(); 1.29 + ContentValues[] cvs = new ContentValues[1]; 1.30 + cvs[0] = new ContentValues(); 1.31 + 1.32 + blockForGeckoReady(); 1.33 + 1.34 + cvs[0].put("hostname", "http://www.example.com"); 1.35 + cvs[0].put("httpRealm", "http://www.example.com"); 1.36 + cvs[0].put("formSubmitURL", "http://www.example.com"); 1.37 + cvs[0].put("usernameField", "usernameField"); 1.38 + cvs[0].put("passwordField", "passwordField"); 1.39 + cvs[0].put("encryptedUsername", "username"); 1.40 + cvs[0].put("encryptedPassword", "password"); 1.41 + cvs[0].put("encType", "1"); 1.42 + 1.43 + // Attempt to insert into the db 1.44 + Uri passwordUri = Passwords.CONTENT_URI; 1.45 + Uri.Builder builder = passwordUri.buildUpon(); 1.46 + passwordUri = builder.appendQueryParameter("profilePath", mProfile).build(); 1.47 + 1.48 + Uri uri = cr.insert(passwordUri, cvs[0]); 1.49 + Uri expectedUri = passwordUri.buildUpon().appendPath("1").build(); 1.50 + mAsserter.is(uri.toString(), expectedUri.toString(), "Insert returned correct uri"); 1.51 + Cursor c = cr.query(passwordUri, null, null, null, null); 1.52 + SqliteCompare(c, cvs); 1.53 + 1.54 + cvs[0].put("usernameField", "usernameField2"); 1.55 + cvs[0].put("passwordField", "passwordField2"); 1.56 + 1.57 + int numUpdated = cr.update(passwordUri, cvs[0], null, null); 1.58 + mAsserter.is(1, numUpdated, "Correct number updated"); 1.59 + c = cr.query(passwordUri, null, null, null, null); 1.60 + SqliteCompare(c, cvs); 1.61 + 1.62 + int numDeleted = cr.delete(passwordUri, null, null); 1.63 + mAsserter.is(1, numDeleted, "Correct number deleted"); 1.64 + cvs = new ContentValues[0]; 1.65 + c = cr.query(passwordUri, null, null, null, null); 1.66 + SqliteCompare(c, cvs); 1.67 + } 1.68 + 1.69 + @Override 1.70 + public void tearDown() throws Exception { 1.71 + // remove the entire signons.sqlite file 1.72 + File profile = new File(mProfile); 1.73 + File db = new File(profile, "signons.sqlite"); 1.74 + if (db.delete()) { 1.75 + mAsserter.dumpLog("tearDown deleted "+db.toString()); 1.76 + } else { 1.77 + mAsserter.dumpLog("tearDown did not delete "+db.toString()); 1.78 + } 1.79 + 1.80 + super.tearDown(); 1.81 + } 1.82 +}