The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Neal Nguyen | 1d3165f | 2010-01-12 13:26:10 -0800 | [diff] [blame] | 17 | package android.view; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import android.test.ActivityInstrumentationTestCase; |
Aurimas Liutikas | 54e221a | 2017-05-09 11:08:34 -0700 | [diff] [blame] | 20 | import android.test.TouchUtils; |
| 21 | import android.test.suitebuilder.annotation.LargeTest; |
| 22 | import android.test.suitebuilder.annotation.MediumTest; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.view.KeyEvent; |
| 24 | import android.view.View; |
Aurimas Liutikas | 54e221a | 2017-05-09 11:08:34 -0700 | [diff] [blame] | 25 | import android.widget.Button; |
| 26 | |
| 27 | import com.android.frameworks.coretests.R; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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() { |
Neal Nguyen | 1d3165f | 2010-01-12 13:26:10 -0800 | [diff] [blame] | 39 | super("com.android.frameworks.coretests", Disabled.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | mDisabledParent = a.findViewById(R.id.clickableParent); |
Aurimas Liutikas | 54e221a | 2017-05-09 11:08:34 -0700 | [diff] [blame] | 49 | getInstrumentation().runOnMainSync( |
| 50 | new Runnable() { |
| 51 | @Override |
| 52 | public void run() { |
| 53 | mDisabled.setOnClickListener(new View.OnClickListener() { |
| 54 | public void onClick(View v) { |
| 55 | mClicked = true; |
| 56 | } |
| 57 | }); |
| 58 | mDisabledParent.setOnClickListener(new View.OnClickListener() { |
| 59 | public void onClick(View v) { |
| 60 | mParentClicked = true; |
| 61 | } |
| 62 | }); |
| 63 | } |
| 64 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
| 68 | protected void tearDown() throws Exception { |
| 69 | super.tearDown(); |
| 70 | |
| 71 | mClicked = false; |
| 72 | mParentClicked = false; |
| 73 | } |
| 74 | |
| 75 | @MediumTest |
| 76 | public void testSetUpConditions() throws Exception { |
| 77 | assertNotNull(mDisabled); |
| 78 | assertNotNull(mDisabledParent); |
| 79 | assertFalse(mDisabled.isEnabled()); |
| 80 | assertTrue(mDisabledParent.isEnabled()); |
| 81 | assertTrue(mDisabled.hasFocus()); |
| 82 | } |
| 83 | |
| 84 | @MediumTest |
| 85 | public void testKeypadClick() throws Exception { |
| 86 | sendKeys(KeyEvent.KEYCODE_DPAD_CENTER); |
| 87 | getInstrumentation().waitForIdleSync(); |
| 88 | assertFalse(mClicked); |
| 89 | assertFalse(mParentClicked); |
| 90 | } |
| 91 | |
| 92 | @LargeTest |
| 93 | public void testTouchClick() throws Exception { |
| 94 | TouchUtils.clickView(this, mDisabled); |
| 95 | getInstrumentation().waitForIdleSync(); |
| 96 | assertFalse(mClicked); |
| 97 | assertFalse(mParentClicked); |
| 98 | } |
| 99 | } |