The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Neal Nguyen | 1d3165f | 2010-01-12 13:26:10 -0800 | [diff] [blame] | 17 | package android.view.menu; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Neal Nguyen | 1d3165f | 2010-01-12 13:26:10 -0800 | [diff] [blame] | 19 | import android.view.menu.MenuWith1Item; |
| 20 | import android.util.KeyUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import com.android.internal.view.menu.MenuBuilder; |
| 22 | |
| 23 | import android.test.suitebuilder.annotation.LargeTest; |
| 24 | import android.test.suitebuilder.annotation.MediumTest; |
| 25 | import android.test.TouchUtils; |
| 26 | |
| 27 | import android.test.ActivityInstrumentationTestCase; |
| 28 | import android.view.KeyEvent; |
| 29 | import android.view.View; |
| 30 | |
| 31 | public class MenuWith1ItemTest extends ActivityInstrumentationTestCase<MenuWith1Item> { |
| 32 | private MenuWith1Item mActivity; |
| 33 | |
| 34 | public MenuWith1ItemTest() { |
Neal Nguyen | 1d3165f | 2010-01-12 13:26:10 -0800 | [diff] [blame] | 35 | super("com.android.frameworks.coretests", MenuWith1Item.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | @Override |
| 39 | protected void setUp() throws Exception { |
| 40 | super.setUp(); |
| 41 | mActivity = getActivity(); |
| 42 | } |
| 43 | |
| 44 | @MediumTest |
| 45 | public void testPreconditions() { |
| 46 | assertNotNull(mActivity); |
| 47 | assertFalse(mActivity.getButton().isInTouchMode()); |
| 48 | } |
| 49 | |
| 50 | @MediumTest |
| 51 | public void testItemClick() { |
| 52 | |
| 53 | // Open menu, click on an item |
| 54 | KeyUtils.tapMenuKey(this); |
| 55 | getInstrumentation().waitForIdleSync(); |
| 56 | assertFalse("Item seems to have been clicked before we clicked on it", mActivity |
| 57 | .wasItemClicked(0)); |
| 58 | sendKeys(KeyEvent.KEYCODE_DPAD_CENTER); |
| 59 | assertTrue("Item doesn't seem to have registered our click", mActivity.wasItemClicked(0)); |
| 60 | } |
| 61 | |
| 62 | @LargeTest |
| 63 | public void testTouchModeTransfersRemovesFocus() throws Exception { |
| 64 | // open menu, move around to give it focus |
| 65 | sendKeys(KeyEvent.KEYCODE_MENU, KeyEvent.KEYCODE_DPAD_LEFT); |
| 66 | final View menuItem = mActivity.getItemView(MenuBuilder.TYPE_ICON, 0); |
| 67 | assertTrue("menuItem.isFocused()", menuItem.isFocused()); |
| 68 | |
| 69 | // close the menu |
| 70 | sendKeys(KeyEvent.KEYCODE_MENU); |
| 71 | Thread.sleep(500); |
| 72 | |
| 73 | // touch the screen |
| 74 | TouchUtils.clickView(this, mActivity.getButton()); |
| 75 | assertTrue("should be in touch mode after touching button", |
| 76 | mActivity.getButton().isInTouchMode()); |
| 77 | |
| 78 | // open the menu, menu item shouldn't be focused, because we are not |
| 79 | // in touch mode |
| 80 | sendKeys(KeyEvent.KEYCODE_MENU); |
| 81 | assertTrue("menuItem.isInTouchMode()", menuItem.isInTouchMode()); |
| 82 | assertFalse("menuItem.isFocused()", menuItem.isFocused()); |
| 83 | } |
| 84 | } |