mobile/android/base/tests/testPasswordProvider.java

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:03759442a893
1 package org.mozilla.gecko.tests;
2
3 import java.io.File;
4
5 import org.mozilla.gecko.db.BrowserContract.Passwords;
6
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;
12
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";
22
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();
28
29 blockForGeckoReady();
30
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");
39
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();
44
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);
50
51 cvs[0].put("usernameField", "usernameField2");
52 cvs[0].put("passwordField", "passwordField2");
53
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);
58
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 }
65
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 }
76
77 super.tearDown();
78 }
79 }

mercurial