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.view.Longpress; 20import com.android.frameworks.coretests.R; 21import android.util.KeyUtils; 22import android.test.TouchUtils; 23import android.test.suitebuilder.annotation.LargeTest; 24import android.test.suitebuilder.annotation.MediumTest; 25 26import android.test.ActivityInstrumentationTestCase; 27import android.view.View; 28import android.view.View.OnLongClickListener; 29 30/** 31 * Exercises {@link android.view.View}'s longpress plumbing by testing the 32 * disabled case. 33 */ 34public class DisabledLongpressTest extends ActivityInstrumentationTestCase<Longpress> { 35 private View mSimpleView; 36 private boolean mLongClicked; 37 38 public DisabledLongpressTest() { 39 super("com.android.frameworks.coretests", Longpress.class); 40 } 41 42 @Override 43 public void setUp() throws Exception { 44 super.setUp(); 45 46 final Longpress a = getActivity(); 47 mSimpleView = a.findViewById(R.id.simple_view); 48 mSimpleView.setOnLongClickListener(new OnLongClickListener() { 49 public boolean onLongClick(View v) { 50 mLongClicked = true; 51 return true; 52 } 53 }); 54 // The View#setOnLongClickListener will ensure the View is long 55 // clickable, we reverse that here 56 mSimpleView.setLongClickable(false); 57 } 58 59 @Override 60 protected void tearDown() throws Exception { 61 super.tearDown(); 62 63 mLongClicked = false; 64 } 65 66 @MediumTest 67 public void testSetUpConditions() throws Exception { 68 assertNotNull(mSimpleView); 69 assertTrue(mSimpleView.hasFocus()); 70 assertFalse(mLongClicked); 71 } 72 73 @LargeTest 74 public void testKeypadLongClick() throws Exception { 75 mSimpleView.requestFocus(); 76 getInstrumentation().waitForIdleSync(); 77 KeyUtils.longClick(this); 78 79 getInstrumentation().waitForIdleSync(); 80 assertFalse(mLongClicked); 81 } 82 83 @LargeTest 84 public void testTouchLongClick() throws Exception { 85 TouchUtils.longClickView(this, mSimpleView); 86 getInstrumentation().waitForIdleSync(); 87 assertFalse(mLongClicked); 88 } 89} 90