michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: package org.mozilla.gecko.background.db; michael@0: michael@0: import org.mozilla.gecko.background.sync.helpers.HistoryHelpers; michael@0: import org.mozilla.gecko.sync.repositories.NullCursorException; michael@0: import org.mozilla.gecko.sync.repositories.android.AndroidBrowserHistoryDataExtender; michael@0: import org.mozilla.gecko.sync.repositories.android.ClientsDatabase; michael@0: import org.mozilla.gecko.sync.repositories.domain.ClientRecord; michael@0: import org.mozilla.gecko.sync.repositories.domain.HistoryRecord; michael@0: import org.mozilla.gecko.sync.setup.Constants; michael@0: michael@0: import android.database.Cursor; michael@0: import android.test.AndroidTestCase; michael@0: michael@0: public class TestCachedSQLiteOpenHelper extends AndroidTestCase { michael@0: michael@0: protected ClientsDatabase clientsDB; michael@0: protected AndroidBrowserHistoryDataExtender extender; michael@0: michael@0: public void setUp() { michael@0: clientsDB = new ClientsDatabase(mContext); michael@0: extender = new AndroidBrowserHistoryDataExtender(mContext); michael@0: } michael@0: michael@0: public void tearDown() { michael@0: clientsDB.close(); michael@0: extender.close(); michael@0: } michael@0: michael@0: public void testUnclosedDatabasesDontInteract() throws NullCursorException { michael@0: // clientsDB gracefully does its thing and closes. michael@0: clientsDB.wipeClientsTable(); michael@0: ClientRecord record = new ClientRecord(); michael@0: String profileConst = Constants.DEFAULT_PROFILE; michael@0: clientsDB.store(profileConst, record); michael@0: clientsDB.close(); michael@0: michael@0: // extender does its thing but still hasn't closed. michael@0: HistoryRecord h = HistoryHelpers.createHistory1(); michael@0: extender.store(h.guid, h.visits); michael@0: michael@0: // Ensure items in the clientsDB are still accessible nonetheless. michael@0: Cursor cur = null; michael@0: try { michael@0: cur = clientsDB.fetchAllClients(); michael@0: assertTrue(cur.moveToFirst()); michael@0: assertEquals(1, cur.getCount()); michael@0: } finally { michael@0: if (cur != null) { michael@0: cur.close(); michael@0: } michael@0: } michael@0: } michael@0: }