Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/contextmenu/ContextMenuUtils.java

Issue 148523013: [Android] Rename TabBase to Tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2014_01_22_tabbase
Patch Set: sync Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/android/javatests/src/org/chromium/chrome/test/util/TabUtils.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.test.ActivityInstrumentationTestCase2; 7 import android.test.ActivityInstrumentationTestCase2;
8 import android.text.TextUtils; 8 import android.text.TextUtils;
9 import android.view.ContextMenu; 9 import android.view.ContextMenu;
10 import android.view.MenuItem; 10 import android.view.MenuItem;
11 11
12 import junit.framework.Assert; 12 import junit.framework.Assert;
13 13
14 import org.chromium.chrome.browser.TabBase; 14 import org.chromium.chrome.browser.Tab;
15 import org.chromium.chrome.test.util.TabBaseTabUtils; 15 import org.chromium.chrome.test.util.TabUtils;
16 import org.chromium.chrome.test.util.TabBaseTabUtils.TestCallbackHelperContainer ForTab; 16 import org.chromium.chrome.test.util.TabUtils.TestCallbackHelperContainerForTab;
17 import org.chromium.content.browser.test.util.Criteria; 17 import org.chromium.content.browser.test.util.Criteria;
18 import org.chromium.content.browser.test.util.CriteriaHelper; 18 import org.chromium.content.browser.test.util.CriteriaHelper;
19 import org.chromium.content.browser.test.util.DOMUtils; 19 import org.chromium.content.browser.test.util.DOMUtils;
20 20
21 import java.util.concurrent.TimeoutException; 21 import java.util.concurrent.TimeoutException;
22 22
23 /** 23 /**
24 * A utility class to help open and interact with context menus triggered by a W ebContents. 24 * A utility class to help open and interact with context menus triggered by a W ebContents.
25 */ 25 */
26 public class ContextMenuUtils { 26 public class ContextMenuUtils {
27 /** 27 /**
28 * Opens a context menu. 28 * Opens a context menu.
29 * @param testCase The test harness. 29 * @param testCase The test harness.
30 * @param tab The tab to open a context menu for. 30 * @param tab The tab to open a context menu for.
31 * @param client The helper client for {@code tab} that can w ait for events. If 31 * @param client The helper client for {@code tab} that can w ait for events. If
32 * this is {@code null} one will be built autom atically. 32 * this is {@code null} one will be built autom atically.
33 * @param openerDOMNodeId The DOM node to long press to open the conte xt menu for. 33 * @param openerDOMNodeId The DOM node to long press to open the conte xt menu for.
34 * @return The {@link ContextMenu} that was opened. 34 * @return The {@link ContextMenu} that was opened.
35 * @throws InterruptedException 35 * @throws InterruptedException
36 * @throws TimeoutException 36 * @throws TimeoutException
37 */ 37 */
38 public static ContextMenu openContextMenu(ActivityInstrumentationTestCase2 t estCase, 38 public static ContextMenu openContextMenu(ActivityInstrumentationTestCase2 t estCase,
39 TabBase tab, TestCallbackHelperContainerForTab client, String opener DOMNodeId) 39 Tab tab, TestCallbackHelperContainerForTab client, String openerDOMN odeId)
40 throws InterruptedException, TimeoutException { 40 throws InterruptedException, TimeoutException {
41 if (client == null) client = TabBaseTabUtils.getTestCallbackHelperContai ner(tab); 41 if (client == null) client = TabUtils.getTestCallbackHelperContainer(tab );
42 42
43 TestCallbackHelperContainerForTab.OnContextMenuShownHelper helper = 43 TestCallbackHelperContainerForTab.OnContextMenuShownHelper helper =
44 client.getOnContextMenuShownHelper(); 44 client.getOnContextMenuShownHelper();
45 45
46 int callCount = helper.getCallCount(); 46 int callCount = helper.getCallCount();
47 DOMUtils.longPressNode(testCase, tab.getContentView(), client, openerDOM NodeId); 47 DOMUtils.longPressNode(testCase, tab.getContentView(), client, openerDOM NodeId);
48 48
49 helper.waitForCallback(callCount); 49 helper.waitForCallback(callCount);
50 return helper.getContextMenu(); 50 return helper.getContextMenu();
51 } 51 }
52 52
53 /** 53 /**
54 * Opens and selects an item from a context menu. 54 * Opens and selects an item from a context menu.
55 * @param testCase The test harness. 55 * @param testCase The test harness.
56 * @param tab The tab to open a context menu for. 56 * @param tab The tab to open a context menu for.
57 * @param client The helper client for {@code tab} that can w ait for events. If 57 * @param client The helper client for {@code tab} that can w ait for events. If
58 * this is {@code null} one will be built autom atically. 58 * this is {@code null} one will be built autom atically.
59 * @param openerDOMNodeId The DOM node to long press to open the conte xt menu for. 59 * @param openerDOMNodeId The DOM node to long press to open the conte xt menu for.
60 * @param itemId The context menu item ID to select. 60 * @param itemId The context menu item ID to select.
61 * @throws InterruptedException 61 * @throws InterruptedException
62 * @throws TimeoutException 62 * @throws TimeoutException
63 */ 63 */
64 public static void selectContextMenuItem(ActivityInstrumentationTestCase2 te stCase, 64 public static void selectContextMenuItem(ActivityInstrumentationTestCase2 te stCase,
65 TabBase tab, TestCallbackHelperContainerForTab client, String opener DOMNodeId, 65 Tab tab, TestCallbackHelperContainerForTab client, String openerDOMN odeId,
66 final int itemId) throws InterruptedException, TimeoutException { 66 final int itemId) throws InterruptedException, TimeoutException {
67 ContextMenu menu = openContextMenu(testCase, tab, client, openerDOMNodeI d); 67 ContextMenu menu = openContextMenu(testCase, tab, client, openerDOMNodeI d);
68 Assert.assertNotNull("Failed to open context menu", menu); 68 Assert.assertNotNull("Failed to open context menu", menu);
69 69
70 selectOpenContextMenuItem(testCase, menu, itemId); 70 selectOpenContextMenuItem(testCase, menu, itemId);
71 } 71 }
72 72
73 /** 73 /**
74 * Opens and selects an item from a context menu. 74 * Opens and selects an item from a context menu.
75 * @param testCase The test harness. 75 * @param testCase The test harness.
76 * @param tab The tab to open a context menu for. 76 * @param tab The tab to open a context menu for.
77 * @param client The helper client for {@code tab} that can w ait for events. If 77 * @param client The helper client for {@code tab} that can w ait for events. If
78 * this is {@code null} one will be built autom atically. 78 * this is {@code null} one will be built autom atically.
79 * @param openerDOMNodeId The DOM node to long press to open the conte xt menu for. 79 * @param openerDOMNodeId The DOM node to long press to open the conte xt menu for.
80 * @param itemTitle The title of the context menu item to select . 80 * @param itemTitle The title of the context menu item to select .
81 * @throws InterruptedException 81 * @throws InterruptedException
82 * @throws TimeoutException 82 * @throws TimeoutException
83 */ 83 */
84 public static void selectContextMenuItemByTitle(ActivityInstrumentationTestC ase2 testCase, 84 public static void selectContextMenuItemByTitle(ActivityInstrumentationTestC ase2 testCase,
85 TabBase tab, TestCallbackHelperContainerForTab client, String opener DOMNodeId, 85 Tab tab, TestCallbackHelperContainerForTab client, String openerDOMN odeId,
86 String itemTitle) throws InterruptedException, TimeoutException { 86 String itemTitle) throws InterruptedException, TimeoutException {
87 87
88 ContextMenu menu = openContextMenu(testCase, tab, client, openerDOMNodeI d); 88 ContextMenu menu = openContextMenu(testCase, tab, client, openerDOMNodeI d);
89 Assert.assertNotNull("Failed to open context menu", menu); 89 Assert.assertNotNull("Failed to open context menu", menu);
90 90
91 Integer itemId = null; 91 Integer itemId = null;
92 for (int i = 0; i < menu.size(); i++) { 92 for (int i = 0; i < menu.size(); i++) {
93 MenuItem item = menu.getItem(i); 93 MenuItem item = menu.getItem(i);
94 if (TextUtils.equals(item.getTitle(), itemTitle)) { 94 if (TextUtils.equals(item.getTitle(), itemTitle)) {
95 itemId = item.getItemId(); 95 itemId = item.getItemId();
(...skipping 22 matching lines...) Expand all
118 118
119 Assert.assertTrue("Activity did not regain focus.", 119 Assert.assertTrue("Activity did not regain focus.",
120 CriteriaHelper.pollForCriteria(new Criteria() { 120 CriteriaHelper.pollForCriteria(new Criteria() {
121 @Override 121 @Override
122 public boolean isSatisfied() { 122 public boolean isSatisfied() {
123 return testCase.getActivity().hasWindowFocus(); 123 return testCase.getActivity().hasWindowFocus();
124 } 124 }
125 })); 125 }));
126 } 126 }
127 } 127 }
OLDNEW
« no previous file with comments | « chrome/test/android/javatests/src/org/chromium/chrome/test/util/TabUtils.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698