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