Merge "New test on ContextMenuInfo packed positions."
This commit is contained in:
committed by
Android (Google) Code Review
commit
aa635db5c6
@@ -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();
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.view.widget.expandablelistview;
|
||||
package android.widget.expandablelistview;
|
||||
|
||||
import com.android.frameworks.coretests.R;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user