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. 32 */ 33public class LongpressTest extends ActivityInstrumentationTestCase<Longpress> { 34 private View mSimpleView; 35 private boolean mLongClicked; 36 37 public LongpressTest() { 38 super("com.android.frameworks.coretests", Longpress.class); 39 } 40 41 @Override 42 public void setUp() throws Exception { 43 super.setUp(); 44 45 final Longpress a = getActivity(); 46 mSimpleView = a.findViewById(R.id.simple_view); 47 mSimpleView.setOnLongClickListener(new OnLongClickListener() { 48 public boolean onLongClick(View v) { 49 mLongClicked = true; 50 return true; 51 } 52 }); 53 } 54 55 @Override 56 protected void tearDown() throws Exception { 57 super.tearDown(); 58 59 mLongClicked = false; 60 } 61 62 @MediumTest 63 public void testSetUpConditions() throws Exception { 64 assertNotNull(mSimpleView); 65 assertTrue(mSimpleView.hasFocus()); 66 assertFalse(mLongClicked); 67 } 68 69 @LargeTest 70 public void testKeypadLongClick() throws Exception { 71 mSimpleView.requestFocus(); 72 getInstrumentation().waitForIdleSync(); 73 KeyUtils.longClick(this); 74 75 getInstrumentation().waitForIdleSync(); 76 assertTrue(mLongClicked); 77 } 78 79 @LargeTest 80 public void testTouchLongClick() throws Exception { 81 TouchUtils.longClickView(this, mSimpleView); 82 getInstrumentation().waitForIdleSync(); 83 assertTrue(mLongClicked); 84 } 85} 86