blob: d78e5e9bcbbdb7df07fc429baab57f4ff5011a6c [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Nguyen1d3165f2010-01-12 13:26:10 -080017package android.view;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.test.ActivityInstrumentationTestCase;
Aurimas Liutikas54e221a2017-05-09 11:08:34 -070020import android.test.TouchUtils;
21import android.test.suitebuilder.annotation.LargeTest;
22import android.test.suitebuilder.annotation.MediumTest;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.view.KeyEvent;
24import android.view.View;
Aurimas Liutikas54e221a2017-05-09 11:08:34 -070025import android.widget.Button;
26
27import com.android.frameworks.coretests.R;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
29/**
30 * Exercises {@link android.view.View}'s disabled property.
31 */
32public 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 Nguyen1d3165f2010-01-12 13:26:10 -080039 super("com.android.frameworks.coretests", Disabled.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 }
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 Project9066cfe2009-03-03 19:31:44 -080048 mDisabledParent = a.findViewById(R.id.clickableParent);
Aurimas Liutikas54e221a2017-05-09 11:08:34 -070049 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 Project9066cfe2009-03-03 19:31:44 -080065 }
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}