[go: nahoru, domu]

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.FlakyTest;
21import android.test.suitebuilder.annotation.LargeTest;
22import android.test.suitebuilder.annotation.MediumTest;
23import android.test.TouchUtils;
24import android.test.suitebuilder.annotation.Suppress;
25import android.view.View;
26import android.view.KeyEvent;
27import com.android.frameworks.coretests.R;
28
29@Suppress // Flaky
30public class GlobalFocusChangeTest extends ActivityInstrumentationTestCase<GlobalFocusChange> {
31    private GlobalFocusChange mActivity;
32    private View mLeft;
33    private View mRight;
34
35    public GlobalFocusChangeTest() {
36        super("com.android.frameworks.coretests", GlobalFocusChange.class);
37    }
38
39    @Override
40    public void setUp() throws Exception {
41        super.setUp();
42        mActivity = getActivity();
43        mLeft = mActivity.findViewById(R.id.left);
44        mRight = mActivity.findViewById(R.id.right);
45    }
46
47    @Override
48    protected void tearDown() throws Exception {
49        mActivity.reset();
50        super.tearDown();
51    }
52
53    @FlakyTest(tolerance = 4)
54    @LargeTest
55    public void testFocusChange() throws Exception {
56        sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
57
58        assertFalse(mLeft.isFocused());
59        assertTrue(mRight.isFocused());
60
61        assertSame(mLeft, mActivity.mOldFocus);
62        assertSame(mRight, mActivity.mNewFocus);
63    }
64
65    @FlakyTest(tolerance = 4)
66    @MediumTest
67    public void testEnterTouchMode() throws Exception {
68        assertTrue(mLeft.isFocused());
69
70        TouchUtils.tapView(this, mLeft);
71
72        assertSame(mLeft, mActivity.mOldFocus);
73        assertSame(null, mActivity.mNewFocus);
74    }
75
76    @FlakyTest(tolerance = 4)
77    @MediumTest
78    public void testLeaveTouchMode() throws Exception {
79        assertTrue(mLeft.isFocused());
80
81        TouchUtils.tapView(this, mLeft);
82        sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
83
84        assertTrue(mLeft.isFocused());
85
86        assertSame(null, mActivity.mOldFocus);
87        assertSame(mLeft, mActivity.mNewFocus);
88    }
89}
90