mobile/android/tests/background/junit3/src/db/TestCachedSQLiteOpenHelper.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 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 package org.mozilla.gecko.background.db;
     6 import org.mozilla.gecko.background.sync.helpers.HistoryHelpers;
     7 import org.mozilla.gecko.sync.repositories.NullCursorException;
     8 import org.mozilla.gecko.sync.repositories.android.AndroidBrowserHistoryDataExtender;
     9 import org.mozilla.gecko.sync.repositories.android.ClientsDatabase;
    10 import org.mozilla.gecko.sync.repositories.domain.ClientRecord;
    11 import org.mozilla.gecko.sync.repositories.domain.HistoryRecord;
    12 import org.mozilla.gecko.sync.setup.Constants;
    14 import android.database.Cursor;
    15 import android.test.AndroidTestCase;
    17 public class TestCachedSQLiteOpenHelper extends AndroidTestCase {
    19   protected ClientsDatabase clientsDB;
    20   protected AndroidBrowserHistoryDataExtender extender;
    22   public void setUp() {
    23     clientsDB = new ClientsDatabase(mContext);
    24     extender = new AndroidBrowserHistoryDataExtender(mContext);
    25   }
    27   public void tearDown() {
    28     clientsDB.close();
    29     extender.close();
    30   }
    32   public void testUnclosedDatabasesDontInteract() throws NullCursorException {
    33     // clientsDB gracefully does its thing and closes.
    34     clientsDB.wipeClientsTable();
    35     ClientRecord record = new ClientRecord();
    36     String profileConst = Constants.DEFAULT_PROFILE;
    37     clientsDB.store(profileConst, record);
    38     clientsDB.close();
    40     // extender does its thing but still hasn't closed.
    41     HistoryRecord h = HistoryHelpers.createHistory1();
    42     extender.store(h.guid, h.visits);
    44     // Ensure items in the clientsDB are still accessible nonetheless.
    45     Cursor cur = null;
    46     try {
    47       cur = clientsDB.fetchAllClients();
    48       assertTrue(cur.moveToFirst());
    49       assertEquals(1, cur.getCount());
    50     } finally {
    51       if (cur != null) {
    52         cur.close();
    53       }
    54     }
    55   }
    56 }

mercurial