Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 192ab903 authored by Gilles Debunne's avatar Gilles Debunne
Browse files

New test on ContextMenuInfo packed positions.

With and without headers.
Non regression test for bug
http://b/issue?id=1778239

Change-Id: I0235528ac6f8394292bac35f2350f3d5be1e4df7
parent 27eb2414
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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();
+1 −2
Original line number Diff line number Diff line
@@ -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?
+59 −11
Original line number Diff line number Diff line
@@ -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);
@@ -126,4 +124,54 @@ public class ExpandableListBasicTest extends ActivityInstrumentationTestCase<Exp
                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);
    }
}
+3 −6
Original line number Diff line number Diff line
@@ -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);
        }
        
+10 −7
Original line number Diff line number Diff line
@@ -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);
    }
}
Loading