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.view; 18 19 import com.android.frameworks.coretests.R; 20 import android.test.TouchUtils; 21 import android.test.suitebuilder.annotation.MediumTest; 22 import android.test.suitebuilder.annotation.LargeTest; 23 24 import android.test.ActivityInstrumentationTestCase; 25 import android.widget.Button; 26 import android.view.KeyEvent; 27 import android.view.View; 28 29 /** 30 * Exercises {@link android.view.View}'s disabled property. 31 */ 32 public class DisabledTest extends ActivityInstrumentationTestCase<Disabled> { 33 private Button mDisabled; 34 private View mDisabledParent; 35 private boolean mClicked; 36 private boolean mParentClicked; 37 38 public DisabledTest() { 39 super("com.android.frameworks.coretests", Disabled.class); 40 } 41 42 @Override 43 public void setUp() throws Exception { 44 super.setUp(); 45 46 final Disabled a = getActivity(); 47 mDisabled = (Button) a.findViewById(R.id.disabledButton); 48 mDisabled.setOnClickListener(new View.OnClickListener() { 49 public void onClick(View v) { 50 mClicked = true; 51 } 52 }); 53 54 mDisabledParent = a.findViewById(R.id.clickableParent); 55 mDisabledParent.setOnClickListener(new View.OnClickListener() { 56 public void onClick(View v) { 57 mParentClicked = true; 58 } 59 }); 60 } 61 62 @Override 63 protected void tearDown() throws Exception { 64 super.tearDown(); 65 66 mClicked = false; 67 mParentClicked = false; 68 } 69 70 @MediumTest 71 public void testSetUpConditions() throws Exception { 72 assertNotNull(mDisabled); 73 assertNotNull(mDisabledParent); 74 assertFalse(mDisabled.isEnabled()); 75 assertTrue(mDisabledParent.isEnabled()); 76 assertTrue(mDisabled.hasFocus()); 77 } 78 79 @MediumTest 80 public void testKeypadClick() throws Exception { 81 sendKeys(KeyEvent.KEYCODE_DPAD_CENTER); 82 getInstrumentation().waitForIdleSync(); 83 assertFalse(mClicked); 84 assertFalse(mParentClicked); 85 } 86 87 @LargeTest 88 public void testTouchClick() throws Exception { 89 TouchUtils.clickView(this, mDisabled); 90 getInstrumentation().waitForIdleSync(); 91 assertFalse(mClicked); 92 assertFalse(mParentClicked); 93 } 94 } 95