|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 package org.mozilla.gecko.background.db; |
|
5 |
|
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; |
|
13 |
|
14 import android.database.Cursor; |
|
15 import android.test.AndroidTestCase; |
|
16 |
|
17 public class TestCachedSQLiteOpenHelper extends AndroidTestCase { |
|
18 |
|
19 protected ClientsDatabase clientsDB; |
|
20 protected AndroidBrowserHistoryDataExtender extender; |
|
21 |
|
22 public void setUp() { |
|
23 clientsDB = new ClientsDatabase(mContext); |
|
24 extender = new AndroidBrowserHistoryDataExtender(mContext); |
|
25 } |
|
26 |
|
27 public void tearDown() { |
|
28 clientsDB.close(); |
|
29 extender.close(); |
|
30 } |
|
31 |
|
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(); |
|
39 |
|
40 // extender does its thing but still hasn't closed. |
|
41 HistoryRecord h = HistoryHelpers.createHistory1(); |
|
42 extender.store(h.guid, h.visits); |
|
43 |
|
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 } |