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.menu;
18
19import android.view.menu.MenuWith1Item;
20import android.util.KeyUtils;
21import 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() {
35        super("com.android.frameworks.coretests", MenuWith1Item.class);
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        /* TODO These need to be rewritten to account for presenters that an activity
65         * does not have access to.
66
67        // open menu, move around to give it focus
68        sendKeys(KeyEvent.KEYCODE_MENU, KeyEvent.KEYCODE_DPAD_LEFT);
69        final View menuItem = mActivity.getItemView(MenuBuilder.TYPE_ICON, 0);
70        assertTrue("menuItem.isFocused()", menuItem.isFocused());
71
72        // close the menu
73        sendKeys(KeyEvent.KEYCODE_MENU);
74        Thread.sleep(500);
75
76        // touch the screen
77        TouchUtils.clickView(this, mActivity.getButton());
78        assertTrue("should be in touch mode after touching button",
79                mActivity.getButton().isInTouchMode());
80
81        // open the menu, menu item shouldn't be focused, because we are not
82        // in touch mode
83        sendKeys(KeyEvent.KEYCODE_MENU);
84        assertTrue("menuItem.isInTouchMode()", menuItem.isInTouchMode());
85        assertFalse("menuItem.isFocused()", menuItem.isFocused());
86         */
87    }
88}
89