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 [JavaScriptUtils.java]

nameclass, %method, %block, %line, %
JavaScriptUtils.java67%  (2/3)56%  (5/9)68%  (53/78)62%  (8/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JavaScriptUtils$20%   (0/1)0%   (0/2)0%   (0/15)0%   (0/3)
JavaScriptUtils$2 (ContentView, String): void 0%   (0/1)0%   (0/9)0%   (0/1)
run (): void 0%   (0/1)0%   (0/6)0%   (0/2)
     
class JavaScriptUtils100% (1/1)60%  (3/5)77%  (33/43)67%  (6/9)
JavaScriptUtils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
executeJavaScript (ContentView, String): void 0%   (0/1)0%   (0/7)0%   (0/2)
executeJavaScriptAndWaitForResult (ContentView, TestCallbackHelperContainer, ... 100% (1/1)100% (7/7)100% (1/1)
executeJavaScriptAndWaitForResult (ContentViewCore, TestCallbackHelperContain... 100% (1/1)100% (7/7)100% (1/1)
executeJavaScriptAndWaitForResult (ContentViewCore, TestCallbackHelperContain... 100% (1/1)100% (19/19)100% (4/4)
     
class JavaScriptUtils$1100% (1/1)100% (2/2)100% (20/20)100% (3/3)
JavaScriptUtils$1 (TestCallbackHelperContainer$OnEvaluateJavaScriptResultHelp... 100% (1/1)100% (12/12)100% (1/1)
run (): void 100% (1/1)100% (8/8)100% (2/2)

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 junit.framework.Assert;
8 
9import org.chromium.base.ThreadUtils;
10import org.chromium.content.browser.ContentView;
11import org.chromium.content.browser.ContentViewCore;
12 
13import java.util.concurrent.TimeUnit;
14import java.util.concurrent.TimeoutException;
15 
16/**
17 * Collection of JavaScript utilities.
18 */
19public class JavaScriptUtils {
20    private static final long EVALUATION_TIMEOUT_SECONDS = 5;
21 
22    /**
23     * Executes the given snippet of JavaScript code within the given ContentView.
24     * Returns the result of its execution in JSON format.
25     */
26    public static String executeJavaScriptAndWaitForResult(
27            final ContentView view, TestCallbackHelperContainer viewClient,
28            final String code) throws InterruptedException, TimeoutException {
29        return executeJavaScriptAndWaitForResult(
30                view.getContentViewCore(),
31                viewClient.getOnEvaluateJavaScriptResultHelper(),
32                code);
33    }
34 
35    /**
36     * Executes the given snippet of JavaScript code within the given ContentViewCore.
37     * Does not depend on ContentView and TestCallbackHelperContainer.
38     * Returns the result of its execution in JSON format.
39     */
40    public static String executeJavaScriptAndWaitForResult(
41            final ContentViewCore viewCore,
42            final TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper helper,
43            final String code) throws InterruptedException, TimeoutException {
44        return executeJavaScriptAndWaitForResult(
45                viewCore, helper, code, EVALUATION_TIMEOUT_SECONDS, TimeUnit.SECONDS);
46    }
47 
48    /**
49     * Executes the given snippet of JavaScript code within the given ContentViewCore.
50     * Does not depend on ContentView and TestCallbackHelperContainer.
51     * Returns the result of its execution in JSON format.
52     */
53    public static String executeJavaScriptAndWaitForResult(
54            final ContentViewCore viewCore,
55            final TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper helper,
56            final String code,
57            final long timeout, final TimeUnit timeoutUnits)
58                    throws InterruptedException, TimeoutException {
59        ThreadUtils.runOnUiThread(new Runnable() {
60            @Override
61            public void run() {
62                helper.evaluateJavaScript(viewCore, code);
63            }
64        });
65        helper.waitUntilHasValue(timeout, timeoutUnits);
66        Assert.assertTrue("Failed to retrieve JavaScript evaluation results.", helper.hasValue());
67        return helper.getJsonResultAndClear();
68    }
69 
70    /**
71     * Executes the given snippet of JavaScript code but does not wait for the result.
72     */
73    public static void executeJavaScript(final ContentView view, final String code) {
74        ThreadUtils.runOnUiThread(new Runnable() {
75            @Override
76            public void run() {
77                view.evaluateJavaScript(code);
78            }
79        });
80    }
81}

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