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.arrowscroll;
18
19import android.test.ActivityInstrumentationTestCase;
20import android.test.suitebuilder.annotation.MediumTest;
21import android.widget.ListView;
22import android.view.KeyEvent;
23import android.widget.listview.ListItemFocusableAboveUnfocusable;
24
25public class ListItemFocusableAboveUnfocusableTest extends ActivityInstrumentationTestCase<ListItemFocusableAboveUnfocusable> {
26    private ListView mListView;
27
28    public ListItemFocusableAboveUnfocusableTest() {
29        super("com.android.frameworks.coretests", ListItemFocusableAboveUnfocusable.class);
30    }
31
32    protected void setUp() throws Exception {
33        super.setUp();
34
35        mListView = getActivity().getListView();
36    }
37
38
39    @MediumTest
40    public void testPreconditions() {
41        assertEquals("selected position", 0, mListView.getSelectedItemPosition());
42        assertTrue(mListView.getChildAt(0).isFocused());
43        assertFalse(mListView.getChildAt(1).isFocusable());
44    }
45
46    @MediumTest
47    public void testMovingToUnFocusableTakesFocusAway() {
48        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
49
50        assertFalse("focused item should have lost focus",
51                mListView.getChildAt(0).isFocused());
52        assertEquals("selected position", 1, mListView.getSelectedItemPosition());
53    }
54
55}
56