diff options
author | John Reck <jreck@google.com> | 2011-07-27 17:43:43 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2011-07-28 10:46:28 -0700 |
commit | ad662f04ed7fbd9ce464fed54fd7764290e800e8 (patch) | |
tree | b5619932799f786e4123c486140a095395ac0d45 /tests/src/com/android | |
parent | 56e7068864733e18c666f689c5667d49dcc7b241 (diff) | |
download | packages_apps_browser-ad662f04ed7fbd9ce464fed54fd7764290e800e8.zip packages_apps_browser-ad662f04ed7fbd9ce464fed54fd7764290e800e8.tar.gz packages_apps_browser-ad662f04ed7fbd9ce464fed54fd7764290e800e8.tar.bz2 |
Tests for BP1->BP2 upgrade
Bug: 5087957
Change-Id: Idf70c488baa515222ce8ed905aa5c80a529fd15f
Diffstat (limited to 'tests/src/com/android')
-rw-r--r-- | tests/src/com/android/browser/tests/BP1to2UpgradeTests.java | 148 | ||||
-rw-r--r-- | tests/src/com/android/browser/tests/utils/ProviderTestCase3.java | 15 |
2 files changed, 162 insertions, 1 deletions
diff --git a/tests/src/com/android/browser/tests/BP1to2UpgradeTests.java b/tests/src/com/android/browser/tests/BP1to2UpgradeTests.java new file mode 100644 index 0000000..36f7aba --- /dev/null +++ b/tests/src/com/android/browser/tests/BP1to2UpgradeTests.java @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.browser.tests; + +import com.android.browser.provider.BrowserProvider; +import com.android.browser.tests.utils.BP2TestCaseHelper; + +import android.content.ContentUris; +import android.content.ContentValues; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.Bitmap.Config; +import android.net.Uri; +import android.provider.Browser; +import android.provider.Browser.BookmarkColumns; +import android.provider.BrowserContract; +import android.provider.BrowserContract.Bookmarks; +import android.provider.BrowserContract.History; +import android.provider.BrowserContract.Images; +import android.test.suitebuilder.annotation.SmallTest; + +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; + +@SmallTest +public class BP1to2UpgradeTests extends BP2TestCaseHelper { + + BrowserProvider mBp1; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mBp1 = new BrowserProvider(); + mBp1.attachInfo(getMockContext(), null); + } + + /** + * Test that simply makes sure BP1->BP2 with no changes works as intended + */ + public void testStockUpgrade() { + Cursor c = mBp1.query(Browser.BOOKMARKS_URI, + new String[] { BookmarkColumns.URL }, null, null, + BookmarkColumns.URL + " DESC"); + ArrayList<String> urls = new ArrayList<String>(c.getCount()); + while (c.moveToNext()) { + urls.add(c.getString(0)); + } + c.close(); + // First, test the public API (which will hit BP2) + c = getMockContentResolver().query(Browser.BOOKMARKS_URI, + new String[] { BookmarkColumns.URL }, null, null, + BookmarkColumns.URL + " DESC"); + assertEquals(urls.size(), c.getCount()); + int i = 0; + while (c.moveToNext()) { + assertEquals(urls.get(i++), c.getString(0)); + } + c.close(); + // Next, test BP2's new API (not a public API) + c = getMockContentResolver().query(Bookmarks.CONTENT_URI, + new String[] { Bookmarks.URL }, null, null, + Bookmarks.URL + " DESC"); + assertEquals(urls.size(), c.getCount()); + i = 0; + while (c.moveToNext()) { + assertEquals(urls.get(i++), c.getString(0)); + } + c.close(); + } + + public void testPreserveHistory() { + ContentValues values = new ContentValues(); + values.put(BookmarkColumns.URL, "http://slashdot.org/"); + values.put(BookmarkColumns.BOOKMARK, 0); + values.put(BookmarkColumns.DATE, 123456); + mBp1.insert(Browser.BOOKMARKS_URI, values); + // First, test internal API + Cursor c = getMockContentResolver().query(History.CONTENT_URI, + new String[] { History.URL, History.DATE_LAST_VISITED }, + null, null, null); + assertEquals(1, c.getCount()); + assertTrue(c.moveToFirst()); + assertEquals("http://slashdot.org/", c.getString(0)); + assertEquals(123456, c.getInt(1)); + c.close(); + // Next, test public API + c = getMockContentResolver().query(Browser.BOOKMARKS_URI, + Browser.HISTORY_PROJECTION, BookmarkColumns.BOOKMARK + " = ?", + new String[] { "0" }, null); + assertEquals("public API", 1, c.getCount()); + assertTrue(c.moveToFirst()); + assertEquals("http://slashdot.org/", + c.getString(Browser.HISTORY_PROJECTION_URL_INDEX)); + assertEquals(123456, c.getInt(Browser.HISTORY_PROJECTION_DATE_INDEX)); + c.close(); + } + + public void testPreserveBookmarks() { + // First, nuke 'er (deletes stock bookmarks) + mBp1.delete(Browser.BOOKMARKS_URI, null, null); + ContentValues values = new ContentValues(); + values.put(BookmarkColumns.URL, "http://slashdot.org/"); + values.put(BookmarkColumns.BOOKMARK, 1); + values.put(BookmarkColumns.CREATED, 123456); + mBp1.insert(Browser.BOOKMARKS_URI, values); + // First, test internal API + Cursor c = getMockContentResolver().query(Bookmarks.CONTENT_URI, + new String[] { Bookmarks.URL, Bookmarks.DATE_CREATED }, + null, null, null); + assertEquals(1, c.getCount()); + assertTrue(c.moveToFirst()); + assertEquals("http://slashdot.org/", c.getString(0)); + assertEquals(123456, c.getInt(1)); + c.close(); + // Next, test public API + c = getMockContentResolver().query(Browser.BOOKMARKS_URI, + new String[] { BookmarkColumns.URL, BookmarkColumns.CREATED }, + BookmarkColumns.BOOKMARK + " = ?", new String[] { "1" }, null); + assertEquals("public API", 1, c.getCount()); + assertTrue(c.moveToFirst()); + assertEquals("http://slashdot.org/", c.getString(0)); + assertEquals(123456, c.getInt(1)); + c.close(); + } + + public void testEmptyUpgrade() { + mBp1.delete(Browser.BOOKMARKS_URI, null, null); + Cursor c = getMockContentResolver().query(Bookmarks.CONTENT_URI, + null, null, null, null); + assertEquals(0, c.getCount()); + c.close(); + } + +} diff --git a/tests/src/com/android/browser/tests/utils/ProviderTestCase3.java b/tests/src/com/android/browser/tests/utils/ProviderTestCase3.java index c374292..536163a 100644 --- a/tests/src/com/android/browser/tests/utils/ProviderTestCase3.java +++ b/tests/src/com/android/browser/tests/utils/ProviderTestCase3.java @@ -69,6 +69,11 @@ public abstract class ProviderTestCase3<T extends ContentProvider> extends Andro public Context getApplicationContext() { return this; } + + @Override + public Object getSystemService(String name) { + return null; + } } /** * Constructor. @@ -114,7 +119,15 @@ public abstract class ProviderTestCase3<T extends ContentProvider> extends Andro //delegated to getContext(), // The context that file methods are delegated to filenamePrefix); - mProviderContext = new IsolatedContext(mResolver, targetContextWrapper); + // The default IsolatedContext has a mock AccountManager that doesn't + // work for us, so override getSystemService to always return null + mProviderContext = new IsolatedContext(mResolver, targetContextWrapper) { + + @Override + public Object getSystemService(String name) { + return null; + } + }; mProvider = mProviderClass.newInstance(); mProvider.attachInfo(mProviderContext, null); |