1/*
2 * Copyright (C) 2008 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.focus;
18
19import android.test.ActivityInstrumentationTestCase;
20import android.test.suitebuilder.annotation.MediumTest;
21import android.view.KeyEvent;
22import android.widget.Button;
23import android.widget.ListView;
24import android.widget.listview.ListHorizontalFocusWithinItemWins;
25
26public class ListHorizontalFocusWithinItemWinsTest extends ActivityInstrumentationTestCase<ListHorizontalFocusWithinItemWins> {
27
28    private ListView mListView;
29    private Button mTopLeftButton;
30    private Button mTopRightButton;
31    private Button mBottomMiddleButton;
32
33    public ListHorizontalFocusWithinItemWinsTest() {
34        super("com.android.frameworks.coretests", ListHorizontalFocusWithinItemWins.class);
35    }
36
37    @Override
38    protected void setUp() throws Exception {
39        super.setUp();
40
41        mListView = getActivity().getListView();
42        mTopLeftButton = getActivity().getTopLeftButton();
43        mTopRightButton = getActivity().getTopRightButton();
44        mBottomMiddleButton = getActivity().getBottomMiddleButton();
45    }
46
47    @MediumTest
48    public void testPreconditions() {
49        assertEquals("list position", 0, mListView.getSelectedItemPosition());
50        assertTrue("mTopLeftButton.isFocused()", mTopLeftButton.isFocused());
51    }
52
53    @MediumTest
54    public void testOptionWithinItemTrumpsGlobal() {
55        sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
56
57        assertEquals("list position", 0, mListView.getSelectedItemPosition());
58        assertTrue("mTopRightButton.isFocused()", mTopRightButton.isFocused());
59
60        sendKeys(KeyEvent.KEYCODE_DPAD_LEFT);
61        assertEquals("list position", 0, mListView.getSelectedItemPosition());
62        assertTrue("mTopLeftButton.isFocused()", mTopLeftButton.isFocused());
63    }
64
65}
66