OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.test.util; |
| 6 |
| 7 import android.app.Instrumentation; |
| 8 |
| 9 import junit.framework.Assert; |
| 10 |
| 11 import org.chromium.chrome.browser.ChromeActivity; |
| 12 |
| 13 /** |
| 14 * Collection of menu utilities. |
| 15 */ |
| 16 public class MenuUtils { |
| 17 /** |
| 18 * Trigger for a new activity based on a menu being pressed. |
| 19 */ |
| 20 public static class MenuActivityTrigger implements Runnable { |
| 21 |
| 22 private final Instrumentation mInstrumentation; |
| 23 private final ChromeActivity mActivity; |
| 24 private final int mMenuId; |
| 25 |
| 26 public MenuActivityTrigger(Instrumentation instrumentation, ChromeActivi
ty activity, |
| 27 int menuId) { |
| 28 mInstrumentation = instrumentation; |
| 29 mActivity = activity; |
| 30 mMenuId = menuId; |
| 31 } |
| 32 |
| 33 @Override |
| 34 public void run() { |
| 35 mInstrumentation.runOnMainSync(new Runnable() { |
| 36 @Override |
| 37 public void run() { |
| 38 Assert.assertTrue("Could not execute menu item.", |
| 39 mActivity.onMenuOrKeyboardAction(mMenuId, true)); |
| 40 } |
| 41 }); |
| 42 } |
| 43 } |
| 44 |
| 45 /** |
| 46 * Execute a particular menu item from the custom menu. |
| 47 * The item is executed even if it is disabled or not visible. |
| 48 */ |
| 49 public static void invokeCustomMenuActionSync(Instrumentation instrumentatio
n, |
| 50 final ChromeActivity activity, final int id) { |
| 51 instrumentation.runOnMainSync(new Runnable() { |
| 52 @Override |
| 53 public void run() { |
| 54 Assert.assertTrue("Could not execute menu item.", |
| 55 activity.onMenuOrKeyboardAction(id, true)); |
| 56 } |
| 57 }); |
| 58 } |
| 59 } |
OLD | NEW |