| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.test.util.browser.contextmenu; | 5 package org.chromium.chrome.test.util.browser.contextmenu; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.app.Instrumentation; | 8 import android.app.Instrumentation; |
| 9 import android.text.TextUtils; | 9 import android.text.TextUtils; |
| 10 import android.view.ContextMenu; | 10 import android.view.ContextMenu; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 helper.waitForCallback(callCount); | 81 helper.waitForCallback(callCount); |
| 82 return helper.getContextMenu(); | 82 return helper.getContextMenu(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 /** | 85 /** |
| 86 * Opens and selects an item from a context menu. | 86 * Opens and selects an item from a context menu. |
| 87 * @param tab The tab to open a context menu for. | 87 * @param tab The tab to open a context menu for. |
| 88 * @param openerDOMNodeId The DOM node to long press to open the conte
xt menu for. | 88 * @param openerDOMNodeId The DOM node to long press to open the conte
xt menu for. |
| 89 * @param itemId The context menu item ID to select. | 89 * @param itemId The context menu item ID to select. |
| 90 * @param activity The activity to assert for gaining focus aft
er click or null. | |
| 91 * @throws InterruptedException | 90 * @throws InterruptedException |
| 92 * @throws TimeoutException | 91 * @throws TimeoutException |
| 93 */ | 92 */ |
| 94 public static void selectContextMenuItem(Instrumentation instrumentation, Ac
tivity activity, | 93 public static void selectContextMenuItem(Instrumentation instrumentation, Ac
tivity activity, |
| 95 Tab tab, String openerDOMNodeId, final int itemId) | 94 Tab tab, String openerDOMNodeId, final int itemId) |
| 96 throws InterruptedException, TimeoutException { | 95 throws InterruptedException, TimeoutException { |
| 97 String jsCode = "document.getElementById('" + openerDOMNodeId + "')"; | 96 String jsCode = "document.getElementById('" + openerDOMNodeId + "')"; |
| 98 selectContextMenuItemByJs(instrumentation, activity, tab, jsCode, itemId
); | 97 selectContextMenuItemByJs(instrumentation, activity, tab, jsCode, itemId
); |
| 99 } | 98 } |
| 100 | 99 |
| 101 /** | 100 /** |
| 102 * Long presses to open and selects an item from a context menu. | 101 * Long presses to open and selects an item from a context menu. |
| 103 * @param tab The tab to open a context menu for. | 102 * @param tab The tab to open a context menu for. |
| 104 * @param jsCode The javascript to get the DOM node to long p
ress | 103 * @param jsCode The javascript to get the DOM node to long p
ress |
| 105 * to open the context menu for. | 104 * to open the context menu for. |
| 106 * @param itemId The context menu item ID to select. | 105 * @param itemId The context menu item ID to select. |
| 107 * @param activity The activity to assert for gaining focus aft
er click or null. | |
| 108 * @throws InterruptedException | 106 * @throws InterruptedException |
| 109 * @throws TimeoutException | 107 * @throws TimeoutException |
| 110 */ | 108 */ |
| 111 public static void selectContextMenuItemByJs(Instrumentation instrumentation
, Activity activity, | 109 public static void selectContextMenuItemByJs(Instrumentation instrumentation
, Activity activity, |
| 112 Tab tab, String jsCode, final int itemId) | 110 Tab tab, String jsCode, final int itemId) |
| 113 throws InterruptedException, TimeoutException { | 111 throws InterruptedException, TimeoutException { |
| 114 ContextMenu menu = openContextMenuByJs(tab, jsCode); | 112 ContextMenu menu = openContextMenuByJs(tab, jsCode); |
| 115 Assert.assertNotNull("Failed to open context menu", menu); | 113 Assert.assertNotNull("Failed to open context menu", menu); |
| 116 | 114 |
| 117 selectOpenContextMenuItem(instrumentation, activity, menu, itemId); | 115 selectOpenContextMenuItem(instrumentation, activity, menu, itemId); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 Assert.assertTrue("'" + itemId + "' is not enabled", item.isEnabled()); | 150 Assert.assertTrue("'" + itemId + "' is not enabled", item.isEnabled()); |
| 153 | 151 |
| 154 instrumentation.runOnMainSync(new Runnable() { | 152 instrumentation.runOnMainSync(new Runnable() { |
| 155 @Override | 153 @Override |
| 156 public void run() { | 154 public void run() { |
| 157 boolean activated = menu.performIdentifierAction(itemId, 0); | 155 boolean activated = menu.performIdentifierAction(itemId, 0); |
| 158 Assert.assertTrue("Failed to activate '" + itemId + "' in menu",
activated); | 156 Assert.assertTrue("Failed to activate '" + itemId + "' in menu",
activated); |
| 159 } | 157 } |
| 160 }); | 158 }); |
| 161 | 159 |
| 162 if (activity != null) { | 160 CriteriaHelper.pollInstrumentationThread(new Criteria("Activity did not
regain focus.") { |
| 163 CriteriaHelper.pollInstrumentationThread( | 161 @Override |
| 164 new Criteria("Activity did not regain focus.") { | 162 public boolean isSatisfied() { |
| 165 @Override | 163 return activity.hasWindowFocus(); |
| 166 public boolean isSatisfied() { | 164 } |
| 167 return activity.hasWindowFocus(); | 165 }); |
| 168 } | |
| 169 }); | |
| 170 } | |
| 171 } | 166 } |
| 172 } | 167 } |
| OLD | NEW |