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: base/test/android/java/src/org/chromium/base/TestUiThread.java

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 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 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.base; 5 package org.chromium.base;
6 6
7 import android.os.Looper; 7 import android.os.Looper;
8 8
9 import java.util.concurrent.CountDownLatch; 9 import java.util.concurrent.CountDownLatch;
10 import java.util.concurrent.atomic.AtomicBoolean; 10 import java.util.concurrent.atomic.AtomicBoolean;
11 11
12 import javax.annotation.concurrent.ThreadSafe; 12 import javax.annotation.concurrent.ThreadSafe;
13 13
14 /** 14 /**
15 * Set up a thread as the Chromium UI Thread, and run its looper. This is is int ended for C++ unit 15 * Set up a thread as the Chromium UI Thread, and run its looper. This is is int ended for C++ unit
16 * tests (e.g. the net unit tests) that don't run with the UI thread as their ma in looper, but test 16 * tests (e.g. the net unit tests) that don't run with the UI thread as their ma in looper, but test
17 * code that, on Android, uses UI thread events, so need a running UI thread. 17 * code that, on Android, uses UI thread events, so need a running UI thread.
18 */ 18 */
19 @ThreadSafe 19 @ThreadSafe
20 public class TestUiThread { 20 public class TestUiThread {
21 private static final AtomicBoolean sStarted = new AtomicBoolean(false); 21 private static final AtomicBoolean sStarted = new AtomicBoolean(false);
22 private static final String TAG = Log.makeTag("TestUiThread"); 22 private static final String TAG = "cr.TestUiThread";
23 23
24 @CalledByNative 24 @CalledByNative
25 private static void loop() { 25 private static void loop() {
26 // @{link ThreadUtils#setUiThread(Looper)} can only be called once in a test run, so do this 26 // @{link ThreadUtils#setUiThread(Looper)} can only be called once in a test run, so do this
27 // once, and leave it running. 27 // once, and leave it running.
28 if (sStarted.getAndSet(true)) return; 28 if (sStarted.getAndSet(true)) return;
29 29
30 final CountDownLatch startLatch = new CountDownLatch(1); 30 final CountDownLatch startLatch = new CountDownLatch(1);
31 new Thread(new Runnable() { 31 new Thread(new Runnable() {
32 32
33 @Override 33 @Override
34 public void run() { 34 public void run() {
35 Looper.prepare(); 35 Looper.prepare();
36 ThreadUtils.setUiThread(Looper.myLooper()); 36 ThreadUtils.setUiThread(Looper.myLooper());
37 startLatch.countDown(); 37 startLatch.countDown();
38 Looper.loop(); 38 Looper.loop();
39 } 39 }
40 40
41 }).start(); 41 }).start();
42 42
43 try { 43 try {
44 startLatch.await(); 44 startLatch.await();
45 } catch (InterruptedException e) { 45 } catch (InterruptedException e) {
46 Log.e(TAG, "Failed to set UI Thread"); 46 Log.e(TAG, "Failed to set UI Thread");
47 } 47 }
48 } 48 }
49 } 49 }
OLDNEW
« no previous file with comments | « base/test/BUILD.gn ('k') | base/test/android/javatests/src/org/chromium/base/test/BaseActivityInstrumentationTestCase.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698