michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import android.content.ContentUris; michael@0: import android.content.ContentValues; michael@0: import android.database.Cursor; michael@0: import android.net.Uri; michael@0: michael@0: public class testHomeListsProvider extends ContentProviderTest { michael@0: // This test does not run, so it just needs to compile. The test was michael@0: // disabled at the time the real Contract was removed; to leave a skeleton michael@0: // for a future re-implementor, we include this dummy Contract class. michael@0: private static class Contract { michael@0: public static final Uri CONTENT_URI = null; michael@0: public static final Uri CONTENT_FAKE_URI = null; michael@0: michael@0: public static final String _ID = null; michael@0: public static final String PROVIDER_ID = null; michael@0: public static final String TITLE = null; michael@0: public static final String URL = null; michael@0: } michael@0: michael@0: @SuppressWarnings("unused") michael@0: private void ensureEmptyDatabase() throws Exception { michael@0: // Delete all the list entries. michael@0: mProvider.delete(Contract.CONTENT_URI, null, null); michael@0: michael@0: final Cursor c = mProvider.query(Contract.CONTENT_URI, null, null, null, null); michael@0: mAsserter.is(c.getCount(), 0, "All list entries were deleted"); michael@0: c.close(); michael@0: } michael@0: michael@0: @Override michael@0: public void setUp() throws Exception { michael@0: // This test is disabled, so this just needs to compile. michael@0: super.setUp(null, null, "homelists.db"); michael@0: michael@0: mTests.add(new TestFakeItems()); michael@0: michael@0: // Disabled until database support lands michael@0: //mTests.add(new TestInsertItem()); michael@0: } michael@0: michael@0: public void testListsProvider() throws Exception { michael@0: for (int i = 0; i < mTests.size(); i++) { michael@0: Runnable test = mTests.get(i); michael@0: michael@0: setTestName(test.getClass().getSimpleName()); michael@0: // Disabled until database support lands michael@0: //ensureEmptyDatabase(); michael@0: test.run(); michael@0: } michael@0: } michael@0: michael@0: abstract class Test implements Runnable { michael@0: @Override michael@0: public void run() { michael@0: try { michael@0: test(); michael@0: } catch (Exception e) { michael@0: mAsserter.is(true, false, "Test " + this.getClass().getName() + michael@0: " threw exception: " + e); michael@0: } michael@0: } michael@0: michael@0: public abstract void test() throws Exception; michael@0: } michael@0: michael@0: class TestFakeItems extends Test { michael@0: @Override michael@0: public void test() throws Exception { michael@0: final long id = 1; michael@0: final String providerId = "fake-provider"; michael@0: final String title = "Example"; michael@0: final String url = "http://example.com"; michael@0: michael@0: final Cursor c = mProvider.query(Contract.CONTENT_FAKE_URI, null, null, null, null); michael@0: mAsserter.is(c.moveToFirst(), true, "Fake list item found"); michael@0: michael@0: mAsserter.is(c.getLong(c.getColumnIndex(Contract._ID)), id, "Fake list item has correct ID"); michael@0: mAsserter.is(c.getString(c.getColumnIndex(Contract.PROVIDER_ID)), providerId, "Fake list item has correct provider ID"); michael@0: mAsserter.is(c.getString(c.getColumnIndex(Contract.TITLE)), title, "Fake list item has correct title"); michael@0: mAsserter.is(c.getString(c.getColumnIndex(Contract.URL)), url, "Fake list item has correct URL"); michael@0: michael@0: c.close(); michael@0: } michael@0: } michael@0: michael@0: class TestInsertItem extends Test { michael@0: @Override michael@0: public void test() throws Exception { michael@0: final String providerId = "{c77da387-4c80-0c45-9f22-70276c29b3ed}"; michael@0: final String title = "Mozilla"; michael@0: final String url = "https://mozilla.org"; michael@0: michael@0: // Insert a new list item with test values. michael@0: final ContentValues cv = new ContentValues(); michael@0: cv.put(Contract.PROVIDER_ID, providerId); michael@0: cv.put(Contract.TITLE, title); michael@0: cv.put(Contract.URL, url); michael@0: michael@0: final long id = ContentUris.parseId(mProvider.insert(Contract.CONTENT_URI, cv)); michael@0: michael@0: // Check that the item was inserted correctly. michael@0: final Cursor c = mProvider.query(Contract.CONTENT_URI, null, Contract._ID + " = ?", new String[] { String.valueOf(id) }, null); michael@0: mAsserter.is(c.moveToFirst(), true, "Inserted list item found"); michael@0: michael@0: mAsserter.is(c.getString(c.getColumnIndex(Contract.PROVIDER_ID)), providerId, "Inserted list item has correct provider ID"); michael@0: mAsserter.is(c.getString(c.getColumnIndex(Contract.TITLE)), title, "Inserted list item has correct title"); michael@0: mAsserter.is(c.getString(c.getColumnIndex(Contract.URL)), url, "Inserted list item has correct URL"); michael@0: michael@0: c.close(); michael@0: } michael@0: } michael@0: }