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.view;
18
19import android.test.ActivityInstrumentationTestCase;
20import android.test.TouchUtils;
21import android.test.suitebuilder.annotation.LargeTest;
22import android.test.suitebuilder.annotation.MediumTest;
23import android.view.KeyEvent;
24import android.view.View;
25import android.widget.Button;
26
27import com.android.frameworks.coretests.R;
28
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() {
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        mDisabledParent = a.findViewById(R.id.clickableParent);
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                });
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        assertFalse(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}
100