diff options
author | Gilles Debunne <debunne@google.com> | 2010-02-24 15:50:40 -0800 |
---|---|---|
committer | Gilles Debunne <debunne@google.com> | 2010-02-25 13:46:50 -0800 |
commit | 192ab903887bbb8e7c7b6da5c581573850e30f46 (patch) | |
tree | 0c04c40ae694e8fd47bfc5f90f5de98ece14c3ca /core | |
parent | 27eb24148a935d10c2c490205174c59a47e76dc6 (diff) | |
download | frameworks_base-192ab903887bbb8e7c7b6da5c581573850e30f46.zip frameworks_base-192ab903887bbb8e7c7b6da5c581573850e30f46.tar.gz frameworks_base-192ab903887bbb8e7c7b6da5c581573850e30f46.tar.bz2 |
New test on ContextMenuInfo packed positions.
With and without headers.
Non regression test for bug
http://b/issue?id=1778239
Change-Id: I0235528ac6f8394292bac35f2350f3d5be1e4df7
Diffstat (limited to 'core')
7 files changed, 121 insertions, 31 deletions
diff --git a/core/java/android/test/InstrumentationTestCase.java b/core/java/android/test/InstrumentationTestCase.java index 22d95d1..cd33d8a 100644 --- a/core/java/android/test/InstrumentationTestCase.java +++ b/core/java/android/test/InstrumentationTestCase.java @@ -16,8 +16,6 @@ package android.test; -import junit.framework.TestCase; - import android.app.Activity; import android.app.Instrumentation; import android.content.Intent; @@ -26,9 +24,11 @@ import android.util.Log; import android.view.KeyEvent; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.lang.reflect.InvocationTargetException; + +import junit.framework.TestCase; /** * A test case that has access to {@link Instrumentation}. @@ -86,7 +86,6 @@ public class InstrumentationTestCase extends TestCase { * @param extras Optional extra stuff to pass to the activity. * @return The activity, or null if non launched. */ - @SuppressWarnings("unchecked") public final <T extends Activity> T launchActivity( String pkg, Class<T> activityCls, @@ -338,6 +337,7 @@ public class InstrumentationTestCase extends TestCase { * * @throws Exception */ + @Override protected void tearDown() throws Exception { Runtime.getRuntime().gc(); Runtime.getRuntime().runFinalization(); diff --git a/core/java/android/widget/ExpandableListConnector.java b/core/java/android/widget/ExpandableListConnector.java index ccce7c1..9c43e9b 100644 --- a/core/java/android/widget/ExpandableListConnector.java +++ b/core/java/android/widget/ExpandableListConnector.java @@ -25,7 +25,6 @@ import android.view.ViewGroup; import java.util.ArrayList; import java.util.Collections; -import java.util.List; /* * Implementation notes: @@ -637,7 +636,7 @@ class ExpandableListConnector extends BaseAdapter implements Filterable { // Check to see if it's already expanded if (posMetadata.groupMetadata != null) return false; - /* Restrict number of exp groups to mMaxExpGroupCount */ + /* Restrict number of expanded groups to mMaxExpGroupCount */ if (mExpGroupMetadataList.size() >= mMaxExpGroupCount) { /* Collapse a group */ // TODO: Collapse something not on the screen instead of the first one? diff --git a/core/tests/coretests/src/android/widget/expandablelistview/ExpandableListBasicTest.java b/core/tests/coretests/src/android/widget/expandablelistview/ExpandableListBasicTest.java index 23a4cde..22bbabc 100644 --- a/core/tests/coretests/src/android/widget/expandablelistview/ExpandableListBasicTest.java +++ b/core/tests/coretests/src/android/widget/expandablelistview/ExpandableListBasicTest.java @@ -16,29 +16,28 @@ package android.widget.expandablelistview; -import android.widget.expandablelistview.ExpandableListSimple; +import android.app.Instrumentation; +import android.test.ActivityInstrumentationTestCase2; +import android.test.suitebuilder.annotation.MediumTest; import android.util.ExpandableListScenario; import android.util.ListUtil; import android.util.ExpandableListScenario.MyGroup; - -import java.util.List; - -import android.test.ActivityInstrumentationTestCase; -import android.test.suitebuilder.annotation.MediumTest; import android.view.KeyEvent; +import android.view.View; import android.widget.BaseExpandableListAdapter; import android.widget.ExpandableListAdapter; import android.widget.ExpandableListView; -public class ExpandableListBasicTest extends ActivityInstrumentationTestCase<ExpandableListSimple> { +import java.util.List; + +public class ExpandableListBasicTest extends ActivityInstrumentationTestCase2<ExpandableListSimple> { private ExpandableListScenario mActivity; private ExpandableListView mListView; private ExpandableListAdapter mAdapter; private ListUtil mListUtil; public ExpandableListBasicTest() { - super("com.android.frameworks.coretests", - ExpandableListSimple.class); + super(ExpandableListSimple.class); } @Override @@ -87,7 +86,6 @@ public class ExpandableListBasicTest extends ActivityInstrumentationTestCase<Exp @MediumTest public void testExpandedGroupMovement() { - // Expand the first group mListUtil.arrowScrollToSelectedPosition(0); sendKeys(KeyEvent.KEYCODE_DPAD_CENTER); @@ -125,5 +123,55 @@ public class ExpandableListBasicTest extends ActivityInstrumentationTestCase<Exp assertFalse("The expanded state was given to the inserted group", mListView.isGroupExpanded(0)); } - + + // Static utility method, shared by different ExpandableListView scenario. + static void checkGroupAndChildPositions(ExpandableListView elv, + ActivityInstrumentationTestCase2<? extends ExpandableListScenario> activityInstrumentation) { + // Add a position tester ContextMenu listener to the ExpandableListView + PositionTesterContextMenuListener menuListener = new PositionTesterContextMenuListener(); + elv.setOnCreateContextMenuListener(menuListener); + + ListUtil listUtil = new ListUtil(elv, activityInstrumentation.getInstrumentation()); + ExpandableListAdapter adapter = elv.getExpandableListAdapter(); + Instrumentation instrumentation = activityInstrumentation.getInstrumentation(); + + int index = elv.getHeaderViewsCount(); + int groupCount = adapter.getGroupCount(); + for (int groupIndex = 0; groupIndex < groupCount; groupIndex++) { + + // Expand group + assertFalse("Group is already expanded", elv.isGroupExpanded(groupIndex)); + listUtil.arrowScrollToSelectedPosition(index); + instrumentation.waitForIdleSync(); + activityInstrumentation.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER); + activityInstrumentation.getInstrumentation().waitForIdleSync(); + assertTrue("Group did not expand " + groupIndex, elv.isGroupExpanded(groupIndex)); + + // Check group index in context menu + menuListener.expectGroupContextMenu(groupIndex); + // Make sure the group is visible so that getChild finds it + listUtil.arrowScrollToSelectedPosition(index); + View groupChild = elv.getChildAt(index - elv.getFirstVisiblePosition()); + elv.showContextMenuForChild(groupChild); + index++; + + final int childrenCount = adapter.getChildrenCount(groupIndex); + for (int childIndex = 0; childIndex < childrenCount; childIndex++) { + // Check child index in context menu + listUtil.arrowScrollToSelectedPosition(index); + menuListener.expectChildContextMenu(groupIndex, childIndex); + View child = elv.getChildAt(index - elv.getFirstVisiblePosition()); + elv.showContextMenuForChild(child); + index++; + } + } + + // Cleanup: remove the listener we added. + elv.setOnCreateContextMenuListener(null); + } + + @MediumTest + public void testGroupChildPositions() { + checkGroupAndChildPositions(mListView, this); + } } diff --git a/core/tests/coretests/src/android/widget/expandablelistview/ExpandableListWithHeaders.java b/core/tests/coretests/src/android/widget/expandablelistview/ExpandableListWithHeaders.java index 7965f9f..2251c1d 100644 --- a/core/tests/coretests/src/android/widget/expandablelistview/ExpandableListWithHeaders.java +++ b/core/tests/coretests/src/android/widget/expandablelistview/ExpandableListWithHeaders.java @@ -16,13 +16,10 @@ package android.widget.expandablelistview; -import android.util.ExpandableListScenario; - import android.os.Bundle; +import android.util.ExpandableListScenario; import android.widget.Button; import android.widget.ExpandableListView; -import android.widget.ListAdapter; -import android.widget.ListView; public class ExpandableListWithHeaders extends ExpandableListScenario { private static final int[] sNumChildren = {1, 4, 3, 2, 6}; @@ -46,13 +43,13 @@ public class ExpandableListWithHeaders extends ExpandableListScenario { for (int i = 0; i < sNumOfHeadersAndFooters; i++) { Button header = new Button(this); - header.setText("Header View"); + header.setText("Header View " + i); expandableListView.addHeaderView(header); } for (int i = 0; i < sNumOfHeadersAndFooters; i++) { Button footer = new Button(this); - footer.setText("Footer View"); + footer.setText("Footer View " + i); expandableListView.addFooterView(footer); } diff --git a/core/tests/coretests/src/android/widget/expandablelistview/ExpandableListWithHeadersTest.java b/core/tests/coretests/src/android/widget/expandablelistview/ExpandableListWithHeadersTest.java index 50d0929..ca07e6b 100644 --- a/core/tests/coretests/src/android/widget/expandablelistview/ExpandableListWithHeadersTest.java +++ b/core/tests/coretests/src/android/widget/expandablelistview/ExpandableListWithHeadersTest.java @@ -16,22 +16,20 @@ package android.widget.expandablelistview; -import android.test.ActivityInstrumentationTestCase; +import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.MediumTest; +import android.util.ListUtil; import android.view.KeyEvent; import android.widget.ExpandableListView; -import android.widget.expandablelistview.ExpandableListWithHeaders; -import android.util.ListUtil; - -public class ExpandableListWithHeadersTest extends ActivityInstrumentationTestCase<ExpandableListWithHeaders> { +public class ExpandableListWithHeadersTest extends + ActivityInstrumentationTestCase2<ExpandableListWithHeaders> { private ExpandableListView mExpandableListView; private ListUtil mListUtil; public ExpandableListWithHeadersTest() { - super("com.android.frameworks.coretests", - ExpandableListWithHeaders.class); + super(ExpandableListWithHeaders.class); } @Override @@ -63,4 +61,9 @@ public class ExpandableListWithHeadersTest extends ActivityInstrumentationTestCa getInstrumentation().waitForIdleSync(); assertTrue(mExpandableListView.isGroupExpanded(0)); } + + @MediumTest + public void testGroupChildPositions() { + ExpandableListBasicTest.checkGroupAndChildPositions(mExpandableListView, this); + } } diff --git a/core/tests/coretests/src/android/widget/expandablelistview/InflatedExpandableListView.java b/core/tests/coretests/src/android/widget/expandablelistview/InflatedExpandableListView.java index 08b0d31..f4c9d56 100644 --- a/core/tests/coretests/src/android/widget/expandablelistview/InflatedExpandableListView.java +++ b/core/tests/coretests/src/android/widget/expandablelistview/InflatedExpandableListView.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package android.view.widget.expandablelistview; +package android.widget.expandablelistview; import com.android.frameworks.coretests.R; diff --git a/core/tests/coretests/src/android/widget/expandablelistview/PositionTesterContextMenuListener.java b/core/tests/coretests/src/android/widget/expandablelistview/PositionTesterContextMenuListener.java new file mode 100644 index 0000000..b96bca1 --- /dev/null +++ b/core/tests/coretests/src/android/widget/expandablelistview/PositionTesterContextMenuListener.java @@ -0,0 +1,43 @@ +package android.widget.expandablelistview; + +import android.view.ContextMenu; +import android.view.View; +import android.view.ContextMenu.ContextMenuInfo; +import android.view.View.OnCreateContextMenuListener; +import android.widget.ExpandableListView; + +import junit.framework.Assert; + +public class PositionTesterContextMenuListener implements OnCreateContextMenuListener { + + private int groupPosition, childPosition; + + private int testType; // as returned by getPackedPositionType + + public void expectGroupContextMenu(int groupPosition) { + this.groupPosition = groupPosition; + testType = ExpandableListView.PACKED_POSITION_TYPE_GROUP; + } + + public void expectChildContextMenu(int groupPosition, int childPosition) { + this.groupPosition = groupPosition; + this.childPosition = childPosition; + testType = ExpandableListView.PACKED_POSITION_TYPE_CHILD; + } + + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { + ExpandableListView.ExpandableListContextMenuInfo elvMenuInfo = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; + long packedPosition = elvMenuInfo.packedPosition; + + int packedPositionType = ExpandableListView.getPackedPositionType(packedPosition); + Assert.assertEquals("Wrong packed position type", testType, packedPositionType); + + int packedPositionGroup = ExpandableListView.getPackedPositionGroup(packedPosition); + Assert.assertEquals("Wrong group position", groupPosition, packedPositionGroup); + + if (testType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { + int packedPositionChild = ExpandableListView.getPackedPositionChild(packedPosition); + Assert.assertEquals("Wrong child position", childPosition, packedPositionChild); + } + } +} |