blob: 4e7105349ca5f59bf860cf9b0ce37849e2203cbf [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Nguyen1d3165f2010-01-12 13:26:10 -080017package android.view.menu;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Neal Nguyen1d3165f2010-01-12 13:26:10 -080019import android.view.menu.MenuWith1Item;
20import android.util.KeyUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import com.android.internal.view.menu.MenuBuilder;
22
23import android.test.suitebuilder.annotation.LargeTest;
24import android.test.suitebuilder.annotation.MediumTest;
25import android.test.TouchUtils;
26
27import android.test.ActivityInstrumentationTestCase;
28import android.view.KeyEvent;
29import android.view.View;
30
31public class MenuWith1ItemTest extends ActivityInstrumentationTestCase<MenuWith1Item> {
32 private MenuWith1Item mActivity;
33
34 public MenuWith1ItemTest() {
Neal Nguyen1d3165f2010-01-12 13:26:10 -080035 super("com.android.frameworks.coretests", MenuWith1Item.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036 }
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}