Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 package org.mozilla.gecko.tests;
3 import android.content.ContentUris;
4 import android.content.ContentValues;
5 import android.database.Cursor;
6 import android.net.Uri;
8 public class testHomeListsProvider extends ContentProviderTest {
9 // This test does not run, so it just needs to compile. The test was
10 // disabled at the time the real Contract was removed; to leave a skeleton
11 // for a future re-implementor, we include this dummy Contract class.
12 private static class Contract {
13 public static final Uri CONTENT_URI = null;
14 public static final Uri CONTENT_FAKE_URI = null;
16 public static final String _ID = null;
17 public static final String PROVIDER_ID = null;
18 public static final String TITLE = null;
19 public static final String URL = null;
20 }
22 @SuppressWarnings("unused")
23 private void ensureEmptyDatabase() throws Exception {
24 // Delete all the list entries.
25 mProvider.delete(Contract.CONTENT_URI, null, null);
27 final Cursor c = mProvider.query(Contract.CONTENT_URI, null, null, null, null);
28 mAsserter.is(c.getCount(), 0, "All list entries were deleted");
29 c.close();
30 }
32 @Override
33 public void setUp() throws Exception {
34 // This test is disabled, so this just needs to compile.
35 super.setUp(null, null, "homelists.db");
37 mTests.add(new TestFakeItems());
39 // Disabled until database support lands
40 //mTests.add(new TestInsertItem());
41 }
43 public void testListsProvider() throws Exception {
44 for (int i = 0; i < mTests.size(); i++) {
45 Runnable test = mTests.get(i);
47 setTestName(test.getClass().getSimpleName());
48 // Disabled until database support lands
49 //ensureEmptyDatabase();
50 test.run();
51 }
52 }
54 abstract class Test implements Runnable {
55 @Override
56 public void run() {
57 try {
58 test();
59 } catch (Exception e) {
60 mAsserter.is(true, false, "Test " + this.getClass().getName() +
61 " threw exception: " + e);
62 }
63 }
65 public abstract void test() throws Exception;
66 }
68 class TestFakeItems extends Test {
69 @Override
70 public void test() throws Exception {
71 final long id = 1;
72 final String providerId = "fake-provider";
73 final String title = "Example";
74 final String url = "http://example.com";
76 final Cursor c = mProvider.query(Contract.CONTENT_FAKE_URI, null, null, null, null);
77 mAsserter.is(c.moveToFirst(), true, "Fake list item found");
79 mAsserter.is(c.getLong(c.getColumnIndex(Contract._ID)), id, "Fake list item has correct ID");
80 mAsserter.is(c.getString(c.getColumnIndex(Contract.PROVIDER_ID)), providerId, "Fake list item has correct provider ID");
81 mAsserter.is(c.getString(c.getColumnIndex(Contract.TITLE)), title, "Fake list item has correct title");
82 mAsserter.is(c.getString(c.getColumnIndex(Contract.URL)), url, "Fake list item has correct URL");
84 c.close();
85 }
86 }
88 class TestInsertItem extends Test {
89 @Override
90 public void test() throws Exception {
91 final String providerId = "{c77da387-4c80-0c45-9f22-70276c29b3ed}";
92 final String title = "Mozilla";
93 final String url = "https://mozilla.org";
95 // Insert a new list item with test values.
96 final ContentValues cv = new ContentValues();
97 cv.put(Contract.PROVIDER_ID, providerId);
98 cv.put(Contract.TITLE, title);
99 cv.put(Contract.URL, url);
101 final long id = ContentUris.parseId(mProvider.insert(Contract.CONTENT_URI, cv));
103 // Check that the item was inserted correctly.
104 final Cursor c = mProvider.query(Contract.CONTENT_URI, null, Contract._ID + " = ?", new String[] { String.valueOf(id) }, null);
105 mAsserter.is(c.moveToFirst(), true, "Inserted list item found");
107 mAsserter.is(c.getString(c.getColumnIndex(Contract.PROVIDER_ID)), providerId, "Inserted list item has correct provider ID");
108 mAsserter.is(c.getString(c.getColumnIndex(Contract.TITLE)), title, "Inserted list item has correct title");
109 mAsserter.is(c.getString(c.getColumnIndex(Contract.URL)), url, "Inserted list item has correct URL");
111 c.close();
112 }
113 }
114 }