1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.widget.listview;
18
19import android.app.Instrumentation;
20import android.test.ActivityInstrumentationTestCase;
21import android.test.suitebuilder.annotation.LargeTest;
22import android.test.suitebuilder.annotation.MediumTest;
23import android.view.KeyEvent;
24import android.widget.ListView;
25
26import android.widget.listview.ListHeterogeneous;
27
28public class ListHeterogeneousTest extends ActivityInstrumentationTestCase<ListHeterogeneous> {
29    private ListHeterogeneous mActivity;
30    private ListView mListView;
31
32
33    public ListHeterogeneousTest() {
34        super("com.android.frameworks.coretests", ListHeterogeneous.class);
35    }
36
37    @Override
38    protected void setUp() throws Exception {
39        super.setUp();
40
41        mActivity = getActivity();
42        mListView = getActivity().getListView();
43    }
44
45    @MediumTest
46    public void testPreconditions() {
47        assertNotNull(mActivity);
48        assertNotNull(mListView);
49    }
50
51    @LargeTest
52    public void testKeyScrolling() {
53        Instrumentation inst = getInstrumentation();
54
55        int count = mListView.getAdapter().getCount();
56
57
58        for (int i = 0; i < count - 1; i++) {
59            inst.sendCharacterSync(KeyEvent.KEYCODE_DPAD_DOWN);
60        }
61        inst.waitForIdleSync();
62        int convertMissesBefore = mActivity.getConvertMisses();
63
64        assertEquals("Unexpected convert misses", 0, convertMissesBefore);
65
66        for (int i = 0; i < count - 1; i++) {
67            inst.sendCharacterSync(KeyEvent.KEYCODE_DPAD_UP);
68        }
69        inst.waitForIdleSync();
70        int convertMissesAfter = mActivity.getConvertMisses();
71
72        assertEquals("Unexpected convert misses", 0, convertMissesAfter);
73    }
74}
75