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 17 package android.widget.focus; 18 19 import android.test.ActivityInstrumentationTestCase; 20 import android.test.suitebuilder.annotation.MediumTest; 21 import android.view.KeyEvent; 22 import android.view.View; 23 import 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 */ 29 public 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