OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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.content.browser.input; |
| 6 |
| 7 import android.os.Handler; |
| 8 import android.os.Looper; |
| 9 |
| 10 import java.util.concurrent.Callable; |
| 11 import java.util.concurrent.FutureTask; |
| 12 import java.util.concurrent.TimeUnit; |
| 13 |
| 14 /** |
| 15 * Utilities for testing IME (input method editor). |
| 16 */ |
| 17 public class ImeTestUtils { |
| 18 private static final long MAX_WAIT_TIME_MILLIS = 5000; |
| 19 |
| 20 public static <T> T runBlockingOnHandlerNoException(Handler handler, Callabl
e<T> callable) { |
| 21 try { |
| 22 return runBlockingOnHandler(handler, callable, MAX_WAIT_TIME_MILLIS)
; |
| 23 } catch (Exception e) { |
| 24 throw new RuntimeException("Error occured waiting for callable", e); |
| 25 } |
| 26 } |
| 27 |
| 28 public static <T> T runBlockingOnHandler(Handler handler, Callable<T> callab
le) |
| 29 throws Exception { |
| 30 return runBlockingOnHandler(handler, callable, MAX_WAIT_TIME_MILLIS); |
| 31 } |
| 32 |
| 33 public static <T> T runBlockingOnHandler( |
| 34 Handler handler, Callable<T> callable, long waitTimeMillis) throws E
xception { |
| 35 if (handler.getLooper() == Looper.myLooper()) { |
| 36 return callable.call(); |
| 37 } else { |
| 38 FutureTask<T> task = new FutureTask<T>(callable); |
| 39 handler.post(task); |
| 40 return task.get(waitTimeMillis, TimeUnit.MILLISECONDS); |
| 41 } |
| 42 } |
| 43 } |
OLD | NEW |