GoneParentFocusedChildTest.java revision 1d3165f10b12165f02b7015ac1a817c5f60e6399
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.focus;
18
19import android.test.ActivityInstrumentationTestCase;
20import android.test.suitebuilder.annotation.MediumTest;
21import android.view.KeyEvent;
22import android.view.View;
23import android.widget.focus.GoneParentFocusedChild;
24
25/**
26 * When a parent is GONE, key events shouldn't go to its children, even if they
27 * have focus. (part of investigation into issue 945150).
28 */
29public class GoneParentFocusedChildTest
30        extends ActivityInstrumentationTestCase<GoneParentFocusedChild> {
31
32
33    public GoneParentFocusedChildTest() {
34        super("com.android.frameworks.coretests", GoneParentFocusedChild.class);
35    }
36
37    @MediumTest
38    public void testPreconditinos() {
39        assertNotNull(getActivity().getLayout());
40        assertNotNull(getActivity().getGoneGroup());
41        assertNotNull(getActivity().getButton());
42        assertTrue("button should have focus",
43                getActivity().getButton().hasFocus());
44        assertEquals("gone group should be, well, gone!",
45                View.GONE,
46                getActivity().getGoneGroup().getVisibility());
47        assertFalse("the activity should have received no key events",
48                getActivity().isUnhandledKeyEvent());
49    }
50
51    @MediumTest
52    public void testKeyEventGoesToActivity() {
53        sendKeys(KeyEvent.KEYCODE_J);
54        assertTrue(getActivity().isUnhandledKeyEvent());
55    }
56}
57