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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java

Issue 1786243003: Rename pollForCriteria to pollForTestThreadCriteria. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and update MediaRouterIntegrationTest.java Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.browser.appmenu; 5 package org.chromium.chrome.browser.appmenu;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.content.pm.ActivityInfo; 8 import android.content.pm.ActivityInfo;
9 import android.test.suitebuilder.annotation.SmallTest; 9 import android.test.suitebuilder.annotation.SmallTest;
10 import android.view.KeyEvent; 10 import android.view.KeyEvent;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 super.setUp(); 87 super.setUp();
88 88
89 showAppMenuAndAssertMenuShown(); 89 showAppMenuAndAssertMenuShown();
90 mAppMenu = getActivity().getAppMenuHandler().getAppMenu(); 90 mAppMenu = getActivity().getAppMenuHandler().getAppMenu();
91 ThreadUtils.runOnUiThread(new Runnable() { 91 ThreadUtils.runOnUiThread(new Runnable() {
92 @Override 92 @Override
93 public void run() { 93 public void run() {
94 mAppMenu.getPopup().getListView().setSelection(0); 94 mAppMenu.getPopup().getListView().setSelection(0);
95 } 95 }
96 }); 96 });
97 CriteriaHelper.pollForCriteria(Criteria.equals(0, new Callable<Integer>( ) { 97 CriteriaHelper.pollInstrumentationThread(Criteria.equals(0, new Callable <Integer>() {
98 @Override 98 @Override
99 public Integer call() { 99 public Integer call() {
100 return getCurrentFocusedRow(); 100 return getCurrentFocusedRow();
101 } 101 }
102 })); 102 }));
103 getInstrumentation().waitForIdleSync(); 103 getInstrumentation().waitForIdleSync();
104 } 104 }
105 105
106 /** 106 /**
107 * Verify opening a new tab from the menu. 107 * Verify opening a new tab from the menu.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 /* 197 /*
198 @SmallTest 198 @SmallTest
199 @Feature({"Browser", "Main"}) 199 @Feature({"Browser", "Main"})
200 crbug.com/458193 200 crbug.com/458193
201 */ 201 */
202 @DisabledTest 202 @DisabledTest
203 public void testChangingOrientationHidesMenu() throws InterruptedException { 203 public void testChangingOrientationHidesMenu() throws InterruptedException {
204 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LA NDSCAPE); 204 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LA NDSCAPE);
205 showAppMenuAndAssertMenuShown(); 205 showAppMenuAndAssertMenuShown();
206 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PO RTRAIT); 206 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PO RTRAIT);
207 CriteriaHelper.pollForCriteria(new Criteria("AppMenu did not dismiss") { 207 CriteriaHelper.pollInstrumentationThread(new Criteria("AppMenu did not d ismiss") {
208 @Override 208 @Override
209 public boolean isSatisfied() { 209 public boolean isSatisfied() {
210 return !mAppMenuHandler.isAppMenuShowing(); 210 return !mAppMenuHandler.isAppMenuShowing();
211 } 211 }
212 }); 212 });
213 } 213 }
214 214
215 private void showAppMenuAndAssertMenuShown() throws InterruptedException { 215 private void showAppMenuAndAssertMenuShown() throws InterruptedException {
216 ThreadUtils.runOnUiThread(new Runnable() { 216 ThreadUtils.runOnUiThread(new Runnable() {
217 @Override 217 @Override
218 public void run() { 218 public void run() {
219 mAppMenuHandler.showAppMenu(null, false); 219 mAppMenuHandler.showAppMenu(null, false);
220 } 220 }
221 }); 221 });
222 CriteriaHelper.pollForCriteria(new Criteria("AppMenu did not show") { 222 CriteriaHelper.pollInstrumentationThread(new Criteria("AppMenu did not s how") {
223 @Override 223 @Override
224 public boolean isSatisfied() { 224 public boolean isSatisfied() {
225 return mAppMenuHandler.isAppMenuShowing(); 225 return mAppMenuHandler.isAppMenuShowing();
226 } 226 }
227 }); 227 });
228 } 228 }
229 229
230 private void hitEnterAndAssertAppMenuDismissed() throws InterruptedException { 230 private void hitEnterAndAssertAppMenuDismissed() throws InterruptedException {
231 getInstrumentation().waitForIdleSync(); 231 getInstrumentation().waitForIdleSync();
232 pressKey(KeyEvent.KEYCODE_ENTER); 232 pressKey(KeyEvent.KEYCODE_ENTER);
233 CriteriaHelper.pollForCriteria(new Criteria("AppMenu did not dismiss") { 233 CriteriaHelper.pollInstrumentationThread(new Criteria("AppMenu did not d ismiss") {
234 @Override 234 @Override
235 public boolean isSatisfied() { 235 public boolean isSatisfied() {
236 return !mAppMenuHandler.isAppMenuShowing(); 236 return !mAppMenuHandler.isAppMenuShowing();
237 } 237 }
238 }); 238 });
239 } 239 }
240 240
241 private void moveToBoundary(boolean towardsTop, boolean movePast) throws Int erruptedException { 241 private void moveToBoundary(boolean towardsTop, boolean movePast) throws Int erruptedException {
242 // Move to the boundary. 242 // Move to the boundary.
243 final int end = towardsTop ? 0 : getCount() - 1; 243 final int end = towardsTop ? 0 : getCount() - 1;
244 int increment = towardsTop ? -1 : 1; 244 int increment = towardsTop ? -1 : 1;
245 for (int index = getCurrentFocusedRow(); index != end; index += incremen t) { 245 for (int index = getCurrentFocusedRow(); index != end; index += incremen t) {
246 pressKey(towardsTop ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DP AD_DOWN); 246 pressKey(towardsTop ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DP AD_DOWN);
247 final int expectedPosition = index + increment; 247 final int expectedPosition = index + increment;
248 CriteriaHelper.pollForCriteria( 248 CriteriaHelper.pollInstrumentationThread(
249 Criteria.equals(expectedPosition, new Callable<Integer>() { 249 Criteria.equals(expectedPosition, new Callable<Integer>() {
250 @Override 250 @Override
251 public Integer call() { 251 public Integer call() {
252 return getCurrentFocusedRow(); 252 return getCurrentFocusedRow();
253 } 253 }
254 })); 254 }));
255 } 255 }
256 256
257 // Try moving past it by one. 257 // Try moving past it by one.
258 if (movePast) { 258 if (movePast) {
259 pressKey(towardsTop ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DP AD_DOWN); 259 pressKey(towardsTop ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DP AD_DOWN);
260 CriteriaHelper.pollForCriteria(Criteria.equals(end, new Callable<Int eger>() { 260 CriteriaHelper.pollInstrumentationThread(Criteria.equals(end, new Ca llable<Integer>() {
261 @Override 261 @Override
262 public Integer call() { 262 public Integer call() {
263 return getCurrentFocusedRow(); 263 return getCurrentFocusedRow();
264 } 264 }
265 })); 265 }));
266 } 266 }
267 267
268 // The menu should stay open. 268 // The menu should stay open.
269 assertTrue(mAppMenu.isShowing()); 269 assertTrue(mAppMenu.isShowing());
270 } 270 }
(...skipping 16 matching lines...) Expand all
287 ListView listView = popup.getListView(); 287 ListView listView = popup.getListView();
288 return listView.getSelectedItemPosition(); 288 return listView.getSelectedItemPosition();
289 } 289 }
290 290
291 private int getCount() { 291 private int getCount() {
292 ListPopupWindow popup = mAppMenu.getPopup(); 292 ListPopupWindow popup = mAppMenu.getPopup();
293 if (popup == null || popup.getListView() == null) return 0; 293 if (popup == null || popup.getListView() == null) return 0;
294 return popup.getListView().getCount(); 294 return popup.getListView().getCount();
295 } 295 }
296 } 296 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698