EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.content.browser.test.util]

COVERAGE SUMMARY FOR SOURCE FILE [UiUtils.java]

nameclass, %method, %block, %line, %
UiUtils.java100% (2/2)60%  (3/5)75%  (36/48)57%  (8/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class UiUtils100% (1/1)33%  (1/3)62%  (20/32)45%  (5/11)
UiUtils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
settleDownUI (Instrumentation): void 0%   (0/1)0%   (0/5)0%   (0/3)
runOnUiThread (Activity, Runnable): void 100% (1/1)83%  (20/24)71%  (5/7)
     
class UiUtils$1100% (1/1)100% (2/2)100% (16/16)100% (4/4)
UiUtils$1 (Runnable, Semaphore): void 100% (1/1)100% (9/9)100% (1/1)
run (): void 100% (1/1)100% (7/7)100% (3/3)

1// Copyright (c) 2012 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 
5package org.chromium.content.browser.test.util;
6 
7import android.app.Activity;
8import android.app.Instrumentation;
9 
10import junit.framework.Assert;
11 
12import java.util.concurrent.Semaphore;
13import java.util.concurrent.TimeUnit;
14 
15/**
16 * Collection of UI utilities.
17 */
18public class UiUtils {
19    private static final int WAIT_FOR_RESPONSE_MS = 10000;  // timeout to wait for runOnUiThread()
20 
21    /**
22     * Runs the runnable on the UI thread.
23     *
24     * @param activity The activity on which the runnable must run.
25     * @param runnable The runnable to run.
26     */
27    public static void runOnUiThread(Activity activity, final Runnable runnable) {
28        final Semaphore finishedSemaphore = new Semaphore(0);
29        activity.runOnUiThread(new Runnable() {
30            @Override
31            public void run() {
32                runnable.run();
33                finishedSemaphore.release();
34            }});
35        try {
36            Assert.assertTrue(finishedSemaphore.tryAcquire(1, WAIT_FOR_RESPONSE_MS,
37                    TimeUnit.MILLISECONDS));
38        } catch (InterruptedException ignored) {
39            Assert.assertTrue("Interrupted while waiting for main thread Runnable", false);
40        }
41    }
42 
43    /**
44     * Waits for the UI thread to settle down.
45     * <p>
46     * Waits for an extra period of time after the UI loop is idle.
47     *
48     * @param instrumentation Instrumentation object used by the test.
49     */
50    public static void settleDownUI(Instrumentation instrumentation) throws InterruptedException {
51        instrumentation.waitForIdleSync();
52        Thread.sleep(1000);
53    }
54}

[all classes][org.chromium.content.browser.test.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov