/* * 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 android.widget.expandablelistview; import android.app.Instrumentation; import android.test.ActivityInstrumentationTestCase2; import android.util.ExpandableListScenario; import android.util.ListUtil; import android.view.KeyEvent; import android.view.View; import android.widget.ExpandableListAdapter; import android.widget.ExpandableListView; import junit.framework.Assert; public class ExpandableListTester { private final ExpandableListView mExpandableListView; private final ExpandableListAdapter mAdapter; private final ListUtil mListUtil; private final ActivityInstrumentationTestCase2 mActivityInstrumentation; Instrumentation mInstrumentation; public ExpandableListTester( ExpandableListView expandableListView, ActivityInstrumentationTestCase2 activityInstrumentation) { mExpandableListView = expandableListView; Instrumentation instrumentation = activityInstrumentation.getInstrumentation(); mListUtil = new ListUtil(mExpandableListView, instrumentation); mAdapter = mExpandableListView.getExpandableListAdapter(); mActivityInstrumentation = activityInstrumentation; mInstrumentation = mActivityInstrumentation.getInstrumentation(); } private void expandGroup(final int groupIndex, int flatPosition) { Assert.assertFalse("Group is already expanded", mExpandableListView .isGroupExpanded(groupIndex)); mListUtil.arrowScrollToSelectedPosition(flatPosition); mInstrumentation.waitForIdleSync(); mActivityInstrumentation.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER); mActivityInstrumentation.getInstrumentation().waitForIdleSync(); Assert.assertTrue("Group did not expand " + groupIndex, mExpandableListView.isGroupExpanded(groupIndex)); } void testContextMenus() { // Add a position tester ContextMenu listener to the ExpandableListView PositionTesterContextMenuListener menuListener = new PositionTesterContextMenuListener(); mExpandableListView.setOnCreateContextMenuListener(menuListener); int index = 0; // Scrolling on header elements should trigger an AdapterContextMenu for (int i=0; i