From 9266c558bf1d21ff647525ff99f7dadbca417309 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Thu, 15 Jan 2009 16:12:10 -0800 Subject: auto import from //branches/cupcake/...@126645 --- .../location/LocationManagerProximityTest.java | 15 +- .../src/com/android/dumprendertree/FileFilter.java | 5 +- .../android/content/AbstractTableMergerTest.java | 578 +++++++++++++++++++++ .../android/widget/AutoCompleteTextViewPopup.java | 119 +++++ .../listview/ListSetSelectionTest.java | 74 +++ 5 files changed, 789 insertions(+), 2 deletions(-) create mode 100644 tests/FrameworkTest/tests/src/android/content/AbstractTableMergerTest.java create mode 100644 tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewPopup.java create mode 100644 tests/FrameworkTest/tests/src/com/android/frameworktest/listview/ListSetSelectionTest.java (limited to 'tests') diff --git a/tests/CoreTests/android/location/LocationManagerProximityTest.java b/tests/CoreTests/android/location/LocationManagerProximityTest.java index f2bff4d..5f62983 100644 --- a/tests/CoreTests/android/location/LocationManagerProximityTest.java +++ b/tests/CoreTests/android/location/LocationManagerProximityTest.java @@ -47,6 +47,7 @@ public class LocationManagerProximityTest extends AndroidTestCase { private PendingIntent mPendingIntent; private TestIntentReceiver mIntentReceiver; private String mOriginalAllowedProviders; + private int mOriginalMocksAllowed; private static final String LOG_TAG = "LocationProximityTest"; @@ -59,6 +60,15 @@ public class LocationManagerProximityTest extends AndroidTestCase { @Override protected void setUp() throws Exception { super.setUp(); + + // allow mock locations + mOriginalMocksAllowed = + android.provider.Settings.Secure.getInt(getContext().getContentResolver(), + android.provider.Settings.Secure.ALLOW_MOCK_LOCATION, 0); + + android.provider.Settings.Secure.putInt(getContext().getContentResolver(), + android.provider.Settings.Secure.ALLOW_MOCK_LOCATION, 1); + mOriginalAllowedProviders = android.provider.Settings.Secure.getString( getContext().getContentResolver(), @@ -100,6 +110,9 @@ public class LocationManagerProximityTest extends AndroidTestCase { getContext().unregisterReceiver(mIntentReceiver); } + android.provider.Settings.Secure.putInt(getContext().getContentResolver(), + android.provider.Settings.Secure.ALLOW_MOCK_LOCATION, mOriginalMocksAllowed); + if (mOriginalAllowedProviders != null) { // restore original settings android.provider.Settings.Secure.putString( @@ -107,7 +120,7 @@ public class LocationManagerProximityTest extends AndroidTestCase { android.provider.Settings.Secure.LOCATION_PROVIDERS_ALLOWED, mOriginalAllowedProviders); mLocationManager.updateProviders(); - } + } } /** diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/FileFilter.java b/tests/DumpRenderTree/src/com/android/dumprendertree/FileFilter.java index 5a73759..91597d5 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/FileFilter.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/FileFilter.java @@ -87,7 +87,10 @@ public class FileFilter { "font-face-implicit-local-font.html", "font-face-locally-installed.html", "beforeSelectorOnCodeElement.html", - "cssTarget-crash.html" + "cssTarget-crash.html", + "searchfield-heights.html", // Bug 1570692 + "tabindex-focus-blur-all.html", + "search-rtl.html" // fast/forms/search-rtl.html }; static void fillIgnoreResultSet() { diff --git a/tests/FrameworkTest/tests/src/android/content/AbstractTableMergerTest.java b/tests/FrameworkTest/tests/src/android/content/AbstractTableMergerTest.java new file mode 100644 index 0000000..aa3d186 --- /dev/null +++ b/tests/FrameworkTest/tests/src/android/content/AbstractTableMergerTest.java @@ -0,0 +1,578 @@ +package android.content; + +import com.google.android.collect.Lists; +import com.google.android.collect.Sets; + +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.net.Uri; +import android.test.AndroidTestCase; +import android.text.TextUtils; + +import java.util.ArrayList; +import java.util.Map; +import java.util.SortedSet; + +/** Unit test for {@link android.content.AbstractTableMerger}. */ +public class AbstractTableMergerTest extends AndroidTestCase { + MockSyncableContentProvider mRealProvider; + MockSyncableContentProvider mTempProvider; + MockTableMerger mMerger; + MockSyncContext mSyncContext; + + static final String TABLE_NAME = "items"; + static final String DELETED_TABLE_NAME = "deleted_items"; + static final Uri CONTENT_URI = Uri.parse("content://testdata"); + static final Uri TABLE_URI = Uri.withAppendedPath(CONTENT_URI, TABLE_NAME); + static final Uri DELETED_TABLE_URI = Uri.withAppendedPath(CONTENT_URI, DELETED_TABLE_NAME); + + private final String ACCOUNT = "account@goo.com"; + + private final ArrayList mExpectations = Lists.newArrayList(); + + static class Expectation { + enum Type { + UPDATE, + INSERT, + DELETE, + RESOLVE + } + + Type mType; + ContentValues mValues; + Long mLocalRowId; + + Expectation(Type type, Long localRowId, ContentValues values) { + mType = type; + mValues = values; + mLocalRowId = localRowId; + if (type == Type.DELETE) { + assertNull(values); + } else { + assertFalse(values.containsKey("_id")); + } + } + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mSyncContext = new MockSyncContext(); + mRealProvider = new MockSyncableContentProvider(); + mTempProvider = mRealProvider.getTemporaryInstance(); + mMerger = new MockTableMerger(mRealProvider.getDatabase(), + TABLE_NAME, TABLE_URI, DELETED_TABLE_NAME, DELETED_TABLE_URI); + mExpectations.clear(); + } + + ContentValues newValues(String data, String syncId, String syncAccount, + String syncTime, String syncVersion, Long syncLocalId) { + ContentValues values = new ContentValues(); + if (data != null) values.put("data", data); + if (syncTime != null) values.put("_sync_time", syncTime); + if (syncVersion != null) values.put("_sync_version", syncVersion); + if (syncId != null) values.put("_sync_id", syncId); + if (syncAccount != null) values.put("_sync_account", syncAccount); + values.put("_sync_local_id", syncLocalId); + values.put("_sync_dirty", 0); + return values; + } + + ContentValues newDeletedValues(String syncId, String syncAccount, String syncVersion, + Long syncLocalId) { + ContentValues values = new ContentValues(); + if (syncVersion != null) values.put("_sync_version", syncVersion); + if (syncId != null) values.put("_sync_id", syncId); + if (syncAccount != null) values.put("_sync_account", syncAccount); + if (syncLocalId != null) values.put("_sync_local_id", syncLocalId); + return values; + } + + ContentValues newModifyData(String data) { + ContentValues values = new ContentValues(); + values.put("data", data); + values.put("_sync_dirty", 1); + return values; + } + + // Want to test adding, changing, deleting entries to a provider that has extra entries + // before and after the entries being changed. + public void testInsert() { + // add rows to the real provider + // add new row to the temp provider + final ContentValues row1 = newValues("d1", "si1", ACCOUNT, "st1", "sv1", null); + mTempProvider.insert(TABLE_URI, row1); + + // add expected callbacks to merger + mExpectations.add(new Expectation(Expectation.Type.INSERT, null /* syncLocalId */, row1)); + + // run merger + SyncResult syncResult = new SyncResult(); + mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult); + + // check that all expectations were met + assertEquals("not all expectations were met", 0, mExpectations.size()); + } + + public void testUpdateWithLocalId() { + // add rows to the real provider + // add new row to the temp provider that matches an unsynced row in the real provider + final ContentValues row1 = newValues("d1", "si1", ACCOUNT, "st1", "sv1", 11L); + mTempProvider.insert(TABLE_URI, row1); + + // add expected callbacks to merger + mExpectations.add(new Expectation(Expectation.Type.UPDATE, 11L, row1)); + + // run merger + SyncResult syncResult = new SyncResult(); + mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult); + + // check that all expectations were met + assertEquals("not all expectations were met", 0, mExpectations.size()); + } + + public void testUpdateWithoutLocalId() { + // add rows to the real provider + Uri i1 = mRealProvider.insert(TABLE_URI, + newValues("d1", "si1", ACCOUNT, "st1", "sv1", null)); + + // add new row to the temp provider that matches an unsynced row in the real provider + final ContentValues row1 = newValues("d2", "si1", ACCOUNT, "st2", "sv2", null); + mTempProvider.insert(TABLE_URI, row1); + + // add expected callbacks to merger + mExpectations.add(new Expectation(Expectation.Type.UPDATE, ContentUris.parseId(i1), row1)); + + // run merger + SyncResult syncResult = new SyncResult(); + mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult); + + // check that all expectations were met + assertEquals("not all expectations were met", 0, mExpectations.size()); + } + + public void testResolve() { + // add rows to the real provider + Uri i1 = mRealProvider.insert(TABLE_URI, + newValues("d1", "si1", ACCOUNT, "st1", "sv1", null)); + mRealProvider.update(TABLE_URI, newModifyData("d2"), null, null); + + // add row to the temp provider that matches a dirty, synced row in the real provider + final ContentValues row1 = newValues("d3", "si1", ACCOUNT, "st2", "sv2", null); + mTempProvider.insert(TABLE_URI, row1); + + // add expected callbacks to merger + mExpectations.add(new Expectation(Expectation.Type.RESOLVE, ContentUris.parseId(i1), row1)); + + // run merger + SyncResult syncResult = new SyncResult(); + mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult); + + // check that all expectations were met + assertEquals("not all expectations were met", 0, mExpectations.size()); + } + + public void testResolveWithLocalId() { + // add rows to the real provider + Uri i1 = mRealProvider.insert(TABLE_URI, + newValues("d1", "si1", ACCOUNT, "st1", "sv1", null)); + mRealProvider.update(TABLE_URI, newModifyData("d2"), null, null); + + // add row to the temp provider that matches a dirty, synced row in the real provider + ContentValues row1 = newValues("d2", "si1", ACCOUNT, "st2", "sv2", ContentUris.parseId(i1)); + mTempProvider.insert(TABLE_URI, row1); + + // add expected callbacks to merger + mExpectations.add(new Expectation(Expectation.Type.UPDATE, ContentUris.parseId(i1), row1)); + + // run merger + SyncResult syncResult = new SyncResult(); + mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult); + + // check that all expectations were met + assertEquals("not all expectations were met", 0, mExpectations.size()); + } + + public void testDeleteRowAfterDelete() { + // add rows to the real provider + Uri i1 = mRealProvider.insert(TABLE_URI, + newValues("d1", "si1", ACCOUNT, "st1", "sv1", null)); + + // add a deleted record to the temp provider + ContentValues row1 = newDeletedValues(null, null, null, ContentUris.parseId(i1)); + mTempProvider.insert(DELETED_TABLE_URI, row1); + + // add expected callbacks to merger + mExpectations.add(new Expectation(Expectation.Type.DELETE, ContentUris.parseId(i1), null)); + + // run merger + SyncResult syncResult = new SyncResult(); + mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult); + + // check that all expectations were met + assertEquals("not all expectations were met", 0, mExpectations.size()); + } + + public void testDeleteRowAfterInsert() { + // add rows to the real provider + Uri i1 = mRealProvider.insert(TABLE_URI, newModifyData("d1")); + + // add a deleted record to the temp provider + ContentValues row1 = newDeletedValues(null, null, null, ContentUris.parseId(i1)); + mTempProvider.insert(DELETED_TABLE_URI, row1); + + // add expected callbacks to merger + mExpectations.add(new Expectation(Expectation.Type.DELETE, ContentUris.parseId(i1), null)); + + // run merger + SyncResult syncResult = new SyncResult(); + mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult); + + // check that all expectations were met + assertEquals("not all expectations were met", 0, mExpectations.size()); + } + + public void testDeleteRowAfterUpdate() { + // add rows to the real provider + Uri i1 = mRealProvider.insert(TABLE_URI, + newValues("d1", "si1", ACCOUNT, "st1", "sv1", null)); + + // add a deleted record to the temp provider + ContentValues row1 = newDeletedValues("si1", ACCOUNT, "sv1", ContentUris.parseId(i1)); + mTempProvider.insert(DELETED_TABLE_URI, row1); + + // add expected callbacks to merger + mExpectations.add(new Expectation(Expectation.Type.DELETE, ContentUris.parseId(i1), null)); + + // run merger + SyncResult syncResult = new SyncResult(); + mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult); + + // check that all expectations were met + assertEquals("not all expectations were met", 0, mExpectations.size()); + } + + public void testDeleteRowFromServer() { + // add rows to the real provider + Uri i1 = mRealProvider.insert(TABLE_URI, + newValues("d1", "si1", ACCOUNT, "st1", "sv1", null)); + + // add a deleted record to the temp provider + ContentValues row1 = newDeletedValues("si1", ACCOUNT, "sv1", null); + mTempProvider.insert(DELETED_TABLE_URI, row1); + + // add expected callbacks to merger + mExpectations.add(new Expectation(Expectation.Type.DELETE, ContentUris.parseId(i1), null)); + + // run merger + SyncResult syncResult = new SyncResult(); + mMerger.mergeServerDiffs(mSyncContext, ACCOUNT, mTempProvider, syncResult); + + // check that all expectations were met + assertEquals("not all expectations were met", 0, mExpectations.size()); + } + + class MockTableMerger extends AbstractTableMerger { + public MockTableMerger(SQLiteDatabase database, String table, Uri tableURL, + String deletedTable, Uri deletedTableURL) { + super(database, table, tableURL, deletedTable, deletedTableURL); + } + + public void insertRow(ContentProvider diffs, Cursor diffsCursor) { + Expectation expectation = mExpectations.remove(0); + checkExpectation(expectation, + Expectation.Type.INSERT, null /* syncLocalId */, diffsCursor); + } + + public void updateRow(long localPersonID, ContentProvider diffs, Cursor diffsCursor) { + Expectation expectation = mExpectations.remove(0); + checkExpectation(expectation, Expectation.Type.UPDATE, localPersonID, diffsCursor); + } + + public void resolveRow(long localPersonID, String syncID, ContentProvider diffs, + Cursor diffsCursor) { + Expectation expectation = mExpectations.remove(0); + checkExpectation(expectation, Expectation.Type.RESOLVE, localPersonID, diffsCursor); + } + + @Override + public void deleteRow(Cursor cursor) { + Expectation expectation = mExpectations.remove(0); + assertEquals(expectation.mType, Expectation.Type.DELETE); + assertNotNull(expectation.mLocalRowId); + final long localRowId = cursor.getLong(cursor.getColumnIndexOrThrow("_id")); + assertEquals((long)expectation.mLocalRowId, localRowId); + cursor.moveToNext(); + mDb.delete(TABLE_NAME, "_id=" + localRowId, null); + } + + protected void notifyChanges() { + throw new UnsupportedOperationException(); + } + + void checkExpectation(Expectation expectation, + Expectation.Type actualType, Long localRowId, + Cursor cursor) { + assertEquals(expectation.mType, actualType); + assertEquals(expectation.mLocalRowId, localRowId); + + final SortedSet actualKeys = Sets.newSortedSet(cursor.getColumnNames()); + final SortedSet expectedKeys = Sets.newSortedSet(); + for (Map.Entry entry : expectation.mValues.valueSet()) { + expectedKeys.add(entry.getKey()); + } + actualKeys.remove("_id"); + actualKeys.remove("_sync_mark"); + actualKeys.remove("_sync_local_id"); + expectedKeys.remove("_sync_local_id"); + expectedKeys.remove("_id"); + assertEquals("column mismatch", + TextUtils.join(",", expectedKeys), TextUtils.join(",", actualKeys)); + +// if (localRowId != null) { +// assertEquals((long) localRowId, +// cursor.getLong(cursor.getColumnIndexOrThrow("_sync_local_id"))); +// } else { +// assertTrue("unexpected _sync_local_id, " +// + cursor.getLong(cursor.getColumnIndexOrThrow("_sync_local_id")), +// cursor.isNull(cursor.getColumnIndexOrThrow("_sync_local_id"))); +// } + + for (String name : cursor.getColumnNames()) { + if ("_id".equals(name)) { + continue; + } + if (cursor.isNull(cursor.getColumnIndexOrThrow(name))) { + assertNull(expectation.mValues.getAsString(name)); + } else { + String actualValue = + cursor.getString(cursor.getColumnIndexOrThrow(name)); + assertEquals("mismatch on column " + name, + expectation.mValues.getAsString(name), actualValue); + } + } + } + } + + class MockSyncableContentProvider extends SyncableContentProvider { + SQLiteDatabase mDb; + boolean mIsTemporary; + boolean mContainsDiffs; + + private final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH); + + private static final int MATCHER_ITEMS = 0; + private static final int MATCHER_DELETED_ITEMS = 1; + + public MockSyncableContentProvider() { + mIsTemporary = false; + setContainsDiffs(false); + sURIMatcher.addURI(CONTENT_URI.getAuthority(), "items", MATCHER_ITEMS); + sURIMatcher.addURI(CONTENT_URI.getAuthority(), "deleted_items", MATCHER_DELETED_ITEMS); + + mDb = SQLiteDatabase.create(null); + mDb.execSQL("CREATE TABLE items (" + + "_id INTEGER PRIMARY KEY AUTOINCREMENT, " + + "data TEXT, " + + "_sync_time TEXT, " + + "_sync_version TEXT, " + + "_sync_id TEXT, " + + "_sync_local_id INTEGER, " + + "_sync_dirty INTEGER NOT NULL DEFAULT 0, " + + "_sync_account TEXT, " + + "_sync_mark INTEGER)"); + + mDb.execSQL("CREATE TABLE deleted_items (" + + "_id INTEGER PRIMARY KEY AUTOINCREMENT, " + + "_sync_version TEXT, " + + "_sync_id TEXT, " + + "_sync_local_id INTEGER, " + + "_sync_account TEXT, " + + "_sync_mark INTEGER)"); + } + + public boolean onCreate() { + throw new UnsupportedOperationException(); + } + + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, + String sortOrder) { + int match = sURIMatcher.match(uri); + switch (match) { + case MATCHER_ITEMS: + return mDb.query(TABLE_NAME, projection, selection, selectionArgs, + null, null, sortOrder); + case MATCHER_DELETED_ITEMS: + return mDb.query(DELETED_TABLE_NAME, projection, selection, selectionArgs, + null, null, sortOrder); + default: + throw new UnsupportedOperationException("Cannot query URL: " + uri); + } + } + + public String getType(Uri uri) { + throw new UnsupportedOperationException(); + } + + public Uri insert(Uri uri, ContentValues values) { + int match = sURIMatcher.match(uri); + switch (match) { + case MATCHER_ITEMS: { + long id = mDb.insert(TABLE_NAME, "_id", values); + return CONTENT_URI.buildUpon().appendPath(String.valueOf(id)).build(); + } + case MATCHER_DELETED_ITEMS: { + long id = mDb.insert(DELETED_TABLE_NAME, "_id", values); + return CONTENT_URI.buildUpon().appendPath(String.valueOf(id)).build(); + } + default: + throw new UnsupportedOperationException("Cannot query URL: " + uri); + } + } + + public int delete(Uri uri, String selection, String[] selectionArgs) { + int match = sURIMatcher.match(uri); + switch (match) { + case MATCHER_ITEMS: + return mDb.delete(TABLE_NAME, selection, selectionArgs); + case MATCHER_DELETED_ITEMS: + return mDb.delete(DELETED_TABLE_NAME, selection, selectionArgs); + default: + throw new UnsupportedOperationException("Cannot query URL: " + uri); + } + } + + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + int match = sURIMatcher.match(uri); + switch (match) { + case MATCHER_ITEMS: + return mDb.update(TABLE_NAME, values, selection, selectionArgs); + case MATCHER_DELETED_ITEMS: + return mDb.update(DELETED_TABLE_NAME, values, selection, selectionArgs); + default: + throw new UnsupportedOperationException("Cannot query URL: " + uri); + } + } + + protected boolean isTemporary() { + return mIsTemporary; + } + + public void close() { + throw new UnsupportedOperationException(); + } + + protected void bootstrapDatabase(SQLiteDatabase db) { + throw new UnsupportedOperationException(); + } + + protected boolean upgradeDatabase(SQLiteDatabase db, int oldVersion, int newVersion) { + throw new UnsupportedOperationException(); + } + + protected void onDatabaseOpened(SQLiteDatabase db) { + throw new UnsupportedOperationException(); + } + + public MockSyncableContentProvider getTemporaryInstance() { + MockSyncableContentProvider temp = new MockSyncableContentProvider(); + temp.mIsTemporary = true; + temp.setContainsDiffs(true); + return temp; + } + + public SQLiteDatabase getDatabase() { + return mDb; + } + + public boolean getContainsDiffs() { + return mContainsDiffs; + } + + public void setContainsDiffs(boolean containsDiffs) { + mContainsDiffs = containsDiffs; + } + + protected Iterable getMergers() { + throw new UnsupportedOperationException(); + } + + public boolean changeRequiresLocalSync(Uri uri) { + throw new UnsupportedOperationException(); + } + + public void onSyncStart(SyncContext context, String account) { + throw new UnsupportedOperationException(); + } + + public void onSyncStop(SyncContext context, boolean success) { + throw new UnsupportedOperationException(); + } + + public String getSyncingAccount() { + throw new UnsupportedOperationException(); + } + + public void merge(SyncContext context, SyncableContentProvider diffs, + TempProviderSyncResult result, SyncResult syncResult) { + throw new UnsupportedOperationException(); + } + + public void onSyncCanceled() { + throw new UnsupportedOperationException(); + } + + public boolean isMergeCancelled() { + return false; + } + + protected int updateInternal(Uri url, ContentValues values, String selection, + String[] selectionArgs) { + throw new UnsupportedOperationException(); + } + + protected int deleteInternal(Uri url, String selection, String[] selectionArgs) { + throw new UnsupportedOperationException(); + } + + protected Uri insertInternal(Uri url, ContentValues values) { + throw new UnsupportedOperationException(); + } + + protected Cursor queryInternal(Uri url, String[] projection, String selection, + String[] selectionArgs, String sortOrder) { + throw new UnsupportedOperationException(); + } + + protected void onAccountsChanged(String[] accountsArray) { + throw new UnsupportedOperationException(); + } + + protected void deleteRowsForRemovedAccounts(Map accounts, String table, + String accountColumnName) { + throw new UnsupportedOperationException(); + } + + public void wipeAccount(String account) { + throw new UnsupportedOperationException(); + } + + public byte[] readSyncDataBytes(String account) { + throw new UnsupportedOperationException(); + } + + public void writeSyncDataBytes(String account, byte[] data) { + throw new UnsupportedOperationException(); + } + } + + class MockSyncContext extends SyncContext { + public MockSyncContext() { + super(null); + } + + @Override + public void setStatusText(String message) { + } + } +} diff --git a/tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewPopup.java b/tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewPopup.java new file mode 100644 index 0000000..7a4c78f --- /dev/null +++ b/tests/FrameworkTest/tests/src/android/widget/AutoCompleteTextViewPopup.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2008 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 android.widget; + +import android.app.Instrumentation; +import android.test.ActivityInstrumentationTestCase2; +import android.test.suitebuilder.annotation.MediumTest; + +/** + * A collection of tests on aspects of the AutoCompleteTextView's popup + */ +public class AutoCompleteTextViewPopup + extends ActivityInstrumentationTestCase2 { + + public AutoCompleteTextViewPopup() { + super("com.android.frameworktest", AutoCompleteTextViewSimple.class); + } + + /** Test that we can move the selection and it responds as expected */ + @MediumTest + public void testPopupSetListSelection() throws Throwable { + AutoCompleteTextViewSimple theActivity = getActivity(); + final AutoCompleteTextView textView = theActivity.getTextView(); + final Instrumentation instrumentation = getInstrumentation(); + + // focus and type + textView.requestFocus(); + instrumentation.waitForIdleSync(); + sendKeys("A"); + + // No initial selection + assertEquals("getListSelection(-1)", + ListView.INVALID_POSITION, textView.getListSelection()); + + // set and check + runTestOnUiThread(new Runnable() { + public void run() { + textView.setListSelection(0); + } + }); + instrumentation.waitForIdleSync(); + assertEquals("set selection to (0)", 0, textView.getListSelection()); + + // Use movement to cross-check the movement + sendKeys("DPAD_DOWN"); + assertEquals("move selection to (1)", 1, textView.getListSelection()); + } + + /** Test that we can look at the selection as we move around */ + @MediumTest + public void testPopupGetListSelection() { + AutoCompleteTextViewSimple theActivity = getActivity(); + AutoCompleteTextView textView = theActivity.getTextView(); + final Instrumentation instrumentation = getInstrumentation(); + + // focus and type + textView.requestFocus(); + instrumentation.waitForIdleSync(); + sendKeys("A"); + + // No initial selection + assertEquals("getListSelection(-1)", + ListView.INVALID_POSITION, textView.getListSelection()); + + // check for selection position as expected + sendKeys("DPAD_DOWN"); + assertEquals("move selection to (0)", 0, textView.getListSelection()); + + // Repeat for one more movement + sendKeys("DPAD_DOWN"); + assertEquals("move selection to (1)", 1, textView.getListSelection()); + } + + /** Test that we can clear the selection */ + @MediumTest + public void testPopupClearListSelection() throws Throwable { + AutoCompleteTextViewSimple theActivity = getActivity(); + final AutoCompleteTextView textView = theActivity.getTextView(); + final Instrumentation instrumentation = getInstrumentation(); + + // focus and type + textView.requestFocus(); + instrumentation.waitForIdleSync(); + sendKeys("A"); + + // No initial selection + assertEquals("getListSelection(-1)", + ListView.INVALID_POSITION, textView.getListSelection()); + + // check for selection position as expected + sendKeys("DPAD_DOWN"); + assertEquals("getListSelection(0)", 0, textView.getListSelection()); + + // clear it + runTestOnUiThread(new Runnable() { + public void run() { + textView.clearListSelection(); + } + }); + instrumentation.waitForIdleSync(); + assertEquals("setListSelection(ListView.INVALID_POSITION)", + ListView.INVALID_POSITION, textView.getListSelection()); + } + +} diff --git a/tests/FrameworkTest/tests/src/com/android/frameworktest/listview/ListSetSelectionTest.java b/tests/FrameworkTest/tests/src/com/android/frameworktest/listview/ListSetSelectionTest.java new file mode 100644 index 0000000..18b6199 --- /dev/null +++ b/tests/FrameworkTest/tests/src/com/android/frameworktest/listview/ListSetSelectionTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2007 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.frameworktest.listview; + +import android.test.ActivityInstrumentationTestCase2; +import android.test.UiThreadTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.widget.ListView; + +/** + * Basic tests of setting & clearing the selection + */ +public class ListSetSelectionTest extends ActivityInstrumentationTestCase2 { + private ListSimple mActivity; + private ListView mListView; + + public ListSetSelectionTest() { + super("com.android.frameworktest", ListSimple.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mActivity = getActivity(); + mListView = getActivity().getListView(); + } + + @MediumTest + public void testPreconditions() { + assertNotNull(mActivity); + assertNotNull(mListView); + } + + /** Confirm that we can set the selection to each specific position */ + @MediumTest + @UiThreadTest + public void testSetSelection() { + // Set the selection to each position + int childCount = mListView.getChildCount(); + for (int i=0; i