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

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

mercurial