Home | History | Annotate | Download | only in touchmode
      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.widget.touchmode;
     18 
     19 import android.widget.layout.linear.LLOfButtons1;
     20 import android.widget.layout.linear.LLOfButtons2;
     21 import static android.util.TouchModeFlexibleAsserts.assertInTouchModeAfterClick;
     22 import static android.util.TouchModeFlexibleAsserts.assertNotInTouchModeAfterKey;
     23 import static android.util.TouchModeFlexibleAsserts.assertInTouchModeAfterTap;
     24 
     25 import android.test.ActivityInstrumentationTestCase;
     26 import android.test.suitebuilder.annotation.LargeTest;
     27 import android.test.suitebuilder.annotation.MediumTest;
     28 import android.view.KeyEvent;
     29 
     30 /**
     31  * Tests that the touch mode changes from various events, and that the state
     32  * persists across activities.
     33  */
     34 public class ChangeTouchModeTest extends ActivityInstrumentationTestCase<LLOfButtons1> {
     35 
     36     public ChangeTouchModeTest() {
     37         super("com.android.frameworks.coretests", LLOfButtons1.class);
     38     }
     39 
     40     @Override
     41     protected void setUp() throws Exception {
     42         super.setUp();
     43     }
     44 
     45     @MediumTest
     46     public void testPreconditions() throws Exception {
     47         assertFalse("touch mode", getActivity().isInTouchMode());
     48     }
     49 
     50     @MediumTest
     51     public void testTouchingScreenEntersTouchMode() throws Exception {
     52         assertInTouchModeAfterTap(this, getActivity().getFirstButton());
     53         assertTrue("touch mode", getActivity().isInTouchMode());
     54     }
     55 
     56     // TODO: reenable when more reliable
     57     public void DISABLE_testDpadDirectionLeavesTouchMode() throws Exception {
     58         assertInTouchModeAfterClick(this, getActivity().getFirstButton());
     59         sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
     60         assertNotInTouchModeAfterKey(this, KeyEvent.KEYCODE_DPAD_RIGHT, getActivity().getFirstButton());
     61         assertFalse("touch mode", getActivity().isInTouchMode());
     62     }
     63 
     64     public void TODO_touchTrackBallMovementLeavesTouchMode() throws Exception {
     65 
     66     }
     67 
     68     @MediumTest
     69     public void testTouchModeFalseAcrossActivites() throws Exception {
     70 
     71         getInstrumentation().waitForIdleSync();
     72 
     73         LLOfButtons2 otherActivity = null;
     74         try {
     75             otherActivity =
     76                     launchActivity("com.android.frameworks.coretests", LLOfButtons2.class, null);
     77             assertNotNull(otherActivity);
     78             assertFalse(otherActivity.isInTouchMode());
     79         } finally {
     80             if (otherActivity != null) {
     81                 otherActivity.finish();
     82             }
     83         }
     84     }
     85 
     86     @LargeTest
     87     public void testTouchModeTrueAcrossActivites() throws Exception {
     88         assertInTouchModeAfterClick(this, getActivity().getFirstButton());
     89         LLOfButtons2 otherActivity = null;
     90         try {
     91             otherActivity =
     92                     launchActivity("com.android.frameworks.coretests", LLOfButtons2.class, null);
     93             assertNotNull(otherActivity);
     94             assertTrue(otherActivity.isInTouchMode());
     95         } finally {
     96             if (otherActivity != null) {
     97                 otherActivity.finish();
     98             }
     99         }
    100     }
    101 
    102     @LargeTest
    103     public void testTouchModeChangedInOtherActivity() throws Exception {
    104 
    105         assertFalse("touch mode", getActivity().isInTouchMode());
    106 
    107         LLOfButtons2 otherActivity = null;
    108         try {
    109             otherActivity =
    110                     launchActivity("com.android.frameworks.coretests", LLOfButtons2.class, null);
    111             assertNotNull(otherActivity);
    112             assertFalse(otherActivity.isInTouchMode());
    113             assertInTouchModeAfterClick(this, otherActivity.getFirstButton());
    114             assertTrue(otherActivity.isInTouchMode());
    115         } finally {
    116             if (otherActivity != null) {
    117                 otherActivity.finish();
    118             }
    119         }
    120 
    121         // need to wait for async update back to window to occur
    122         Thread.sleep(200);
    123 
    124         assertTrue("touch mode", getActivity().isInTouchMode());
    125     }
    126 
    127 }
    128