mobile/android/base/tests/testFormHistory.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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.FormHistory;
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.net.Uri;
michael@0 11
michael@0 12 /**
michael@0 13 * A basic form history contentprovider test.
michael@0 14 * - inserts an element in form history when it is not yet set up
michael@0 15 * - inserts an element in form history
michael@0 16 * - updates an element in form history
michael@0 17 * - deletes an element in form history
michael@0 18 */
michael@0 19 public class testFormHistory extends BaseTest {
michael@0 20 private static final String DB_NAME = "formhistory.sqlite";
michael@0 21
michael@0 22 public void testFormHistory() {
michael@0 23 Context context = (Context)getActivity();
michael@0 24 ContentResolver cr = context.getContentResolver();
michael@0 25 ContentValues[] cvs = new ContentValues[1];
michael@0 26 cvs[0] = new ContentValues();
michael@0 27
michael@0 28 blockForGeckoReady();
michael@0 29
michael@0 30 Uri formHistoryUri;
michael@0 31 Uri insertUri;
michael@0 32 Uri expectedUri;
michael@0 33 int numUpdated;
michael@0 34 int numDeleted;
michael@0 35
michael@0 36 cvs[0].put("fieldname", "fieldname");
michael@0 37 cvs[0].put("value", "value");
michael@0 38 cvs[0].put("timesUsed", "0");
michael@0 39 cvs[0].put("guid", "guid");
michael@0 40
michael@0 41 // Attempt to insert into the db
michael@0 42 formHistoryUri = FormHistory.CONTENT_URI;
michael@0 43 Uri.Builder builder = formHistoryUri.buildUpon();
michael@0 44 formHistoryUri = builder.appendQueryParameter("profilePath", mProfile).build();
michael@0 45
michael@0 46 insertUri = cr.insert(formHistoryUri, cvs[0]);
michael@0 47 expectedUri = formHistoryUri.buildUpon().appendPath("1").build();
michael@0 48 mAsserter.is(expectedUri.toString(), insertUri.toString(), "Insert returned correct uri");
michael@0 49 SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs);
michael@0 50
michael@0 51 cvs[0].put("fieldname", "fieldname2");
michael@0 52 cvs[0].putNull("guid");
michael@0 53
michael@0 54 numUpdated = cr.update(formHistoryUri, cvs[0], null, null);
michael@0 55 mAsserter.is(1, numUpdated, "Correct number updated");
michael@0 56 SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs);
michael@0 57
michael@0 58 numDeleted = cr.delete(formHistoryUri, null, null);
michael@0 59 mAsserter.is(1, numDeleted, "Correct number deleted");
michael@0 60 cvs = new ContentValues[0];
michael@0 61 SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs);
michael@0 62
michael@0 63 cvs = new ContentValues[1];
michael@0 64 cvs[0] = new ContentValues();
michael@0 65 cvs[0].put("fieldname", "fieldname");
michael@0 66 cvs[0].put("value", "value");
michael@0 67 cvs[0].put("timesUsed", "0");
michael@0 68 cvs[0].putNull("guid");
michael@0 69
michael@0 70 insertUri = cr.insert(formHistoryUri, cvs[0]);
michael@0 71 expectedUri = formHistoryUri.buildUpon().appendPath("1").build();
michael@0 72 mAsserter.is(expectedUri.toString(), insertUri.toString(), "Insert returned correct uri");
michael@0 73 SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs);
michael@0 74
michael@0 75 cvs[0].put("guid", "guid");
michael@0 76
michael@0 77 numUpdated = cr.update(formHistoryUri, cvs[0], null, null);
michael@0 78 mAsserter.is(1, numUpdated, "Correct number updated");
michael@0 79 SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs);
michael@0 80
michael@0 81 numDeleted = cr.delete(formHistoryUri, null, null);
michael@0 82 mAsserter.is(1, numDeleted, "Correct number deleted");
michael@0 83 cvs = new ContentValues[0];
michael@0 84 SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs);
michael@0 85 }
michael@0 86
michael@0 87 @Override
michael@0 88 public void tearDown() throws Exception {
michael@0 89 // remove the entire signons.sqlite file
michael@0 90 File profile = new File(mProfile);
michael@0 91 File db = new File(profile, "formhistory.sqlite");
michael@0 92 if (db.delete()) {
michael@0 93 mAsserter.dumpLog("tearDown deleted "+db.toString());
michael@0 94 } else {
michael@0 95 mAsserter.dumpLog("tearDown did not delete "+db.toString());
michael@0 96 }
michael@0 97
michael@0 98 super.tearDown();
michael@0 99 }
michael@0 100 }

mercurial