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

nameclass, %method, %block, %line, %
TestCallbackHelperContainer.java100% (8/8)95%  (36/38)83%  (250/300)90%  (60.4/67)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TestCallbackHelperContainer$OnReceivedErrorHelper100% (1/1)100% (6/6)76%  (45/59)87%  (10.5/12)
getDescription (): String 100% (1/1)67%  (8/12)78%  (1.6/2)
getErrorCode (): int 100% (1/1)67%  (8/12)78%  (1.6/2)
getFailingUrl (): String 100% (1/1)67%  (8/12)78%  (1.6/2)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
TestCallbackHelperContainer$OnReceivedErrorHelper (): void 100% (1/1)100% (3/3)100% (1/1)
notifyCalled (int, String, String): void 100% (1/1)100% (12/12)100% (5/5)
     
class TestCallbackHelperContainer$OnPageFinishedHelper100% (1/1)100% (4/4)79%  (23/29)89%  (5.4/6)
getUrl (): String 100% (1/1)67%  (8/12)78%  (1.6/2)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
TestCallbackHelperContainer$OnPageFinishedHelper (): void 100% (1/1)100% (3/3)100% (1/1)
notifyCalled (String): void 100% (1/1)100% (6/6)100% (3/3)
     
class TestCallbackHelperContainer$OnPageStartedHelper100% (1/1)100% (4/4)79%  (23/29)89%  (5.4/6)
getUrl (): String 100% (1/1)67%  (8/12)78%  (1.6/2)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
TestCallbackHelperContainer$OnPageStartedHelper (): void 100% (1/1)100% (3/3)100% (1/1)
notifyCalled (String): void 100% (1/1)100% (6/6)100% (3/3)
     
class TestCallbackHelperContainer$OnStartContentIntentHelper100% (1/1)100% (4/4)79%  (23/29)89%  (5.4/6)
getIntentUrl (): String 100% (1/1)67%  (8/12)78%  (1.6/2)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
TestCallbackHelperContainer$OnStartContentIntentHelper (): void 100% (1/1)100% (3/3)100% (1/1)
notifyCalled (String): void 100% (1/1)100% (6/6)100% (3/3)
     
class TestCallbackHelperContainer100% (1/1)71%  (5/7)84%  (41/49)86%  (12/14)
getOnPageStartedHelper (): TestCallbackHelperContainer$OnPageStartedHelper 0%   (0/1)0%   (0/4)0%   (0/1)
getOnReceivedErrorHelper (): TestCallbackHelperContainer$OnReceivedErrorHelper 0%   (0/1)0%   (0/4)0%   (0/1)
TestCallbackHelperContainer (ContentView): void 100% (1/1)100% (20/20)100% (5/5)
TestCallbackHelperContainer (TestContentViewClient, TestWebContentsObserver):... 100% (1/1)100% (9/9)100% (4/4)
getOnEvaluateJavaScriptResultHelper (): TestCallbackHelperContainer$OnEvaluat... 100% (1/1)100% (4/4)100% (1/1)
getOnPageFinishedHelper (): TestCallbackHelperContainer$OnPageFinishedHelper 100% (1/1)100% (4/4)100% (1/1)
getOnStartContentIntentHelper (): TestCallbackHelperContainer$OnStartContentI... 100% (1/1)100% (4/4)100% (1/1)
     
class TestCallbackHelperContainer$OnEvaluateJavaScriptResultHelper100% (1/1)100% (9/9)88%  (74/84)94%  (17.9/19)
notifyCalled (String): void 100% (1/1)73%  (11/15)89%  (3.6/4)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
getJsonResultAndClear (): String 100% (1/1)76%  (13/17)89%  (3.6/4)
TestCallbackHelperContainer$OnEvaluateJavaScriptResultHelper (): void 100% (1/1)100% (3/3)100% (1/1)
evaluateJavaScript (ContentViewCore, String): void 100% (1/1)100% (13/13)100% (4/4)
getHasValueCriteria (): Criteria 100% (1/1)100% (5/5)100% (1/1)
hasValue (): boolean 100% (1/1)100% (7/7)100% (1/1)
waitUntilHasValue (): boolean 100% (1/1)100% (7/7)100% (2/2)
waitUntilHasValue (long, TimeUnit): boolean 100% (1/1)100% (9/9)100% (2/2)
     
class TestCallbackHelperContainer$OnEvaluateJavaScriptResultHelper$1100% (1/1)100% (2/2)100% (11/11)100% (3/3)
TestCallbackHelperContainer$OnEvaluateJavaScriptResultHelper$1 (TestCallbackH... 100% (1/1)100% (6/6)100% (1/1)
handleJavaScriptResult (String): void 100% (1/1)100% (5/5)100% (2/2)
     
class TestCallbackHelperContainer$OnEvaluateJavaScriptResultHelper$2100% (1/1)100% (2/2)100% (10/10)100% (2/2)
TestCallbackHelperContainer$OnEvaluateJavaScriptResultHelper$2 (TestCallbackH... 100% (1/1)100% (6/6)100% (1/1)
isSatisfied (): boolean 100% (1/1)100% (4/4)100% (1/1)

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 
7 
8import android.util.Log;
9 
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 * This class is used to provide callback hooks for tests and related classes.
18 */
19public class TestCallbackHelperContainer {
20    private TestContentViewClient mTestContentViewClient;
21    private TestWebContentsObserver mTestWebContentsObserver;
22 
23    public TestCallbackHelperContainer(ContentView contentView) {
24        mTestContentViewClient = new TestContentViewClient();
25        contentView.getContentViewCore().setContentViewClient(mTestContentViewClient);
26        mTestWebContentsObserver = new TestWebContentsObserver(contentView.getContentViewCore());
27    }
28 
29    protected TestCallbackHelperContainer(
30            TestContentViewClient viewClient, TestWebContentsObserver contentsObserver) {
31        mTestContentViewClient = viewClient;
32        mTestWebContentsObserver = contentsObserver;
33    }
34 
35    public static class OnPageFinishedHelper extends CallbackHelper {
36        private String mUrl;
37        public void notifyCalled(String url) {
38            mUrl = url;
39            notifyCalled();
40        }
41        public String getUrl() {
42            assert getCallCount() > 0;
43            return mUrl;
44        }
45    }
46 
47    public static class OnPageStartedHelper extends CallbackHelper {
48        private String mUrl;
49        public void notifyCalled(String url) {
50            mUrl = url;
51            notifyCalled();
52        }
53        public String getUrl() {
54            assert getCallCount() > 0;
55            return mUrl;
56        }
57    }
58 
59    public static class OnReceivedErrorHelper extends CallbackHelper {
60        private int mErrorCode;
61        private String mDescription;
62        private String mFailingUrl;
63        public void notifyCalled(int errorCode, String description, String failingUrl) {
64            mErrorCode = errorCode;
65            mDescription = description;
66            mFailingUrl = failingUrl;
67            notifyCalled();
68        }
69        public int getErrorCode() {
70            assert getCallCount() > 0;
71            return mErrorCode;
72        }
73        public String getDescription() {
74            assert getCallCount() > 0;
75            return mDescription;
76        }
77        public String getFailingUrl() {
78            assert getCallCount() > 0;
79            return mFailingUrl;
80        }
81    }
82 
83    public static class OnEvaluateJavaScriptResultHelper extends CallbackHelper {
84        private String mJsonResult;
85 
86        /**
87         * Starts evaluation of a given JavaScript code on a given contentViewCore.
88         * @param contentViewCore A ContentViewCore instance to be used.
89         * @param code A JavaScript code to be evaluated.
90         */
91        public void evaluateJavaScript(ContentViewCore contentViewCore, String code) {
92            ContentViewCore.JavaScriptCallback callback =
93                new ContentViewCore.JavaScriptCallback() {
94                    @Override
95                    public void handleJavaScriptResult(String jsonResult) {
96                        notifyCalled(jsonResult);
97                    }
98                };
99            contentViewCore.evaluateJavaScript(code, callback);
100            mJsonResult = null;
101        }
102 
103        /**
104         * Returns true if the evaluation started by evaluateJavaScript() has completed.
105         */
106        public boolean hasValue() {
107            return mJsonResult != null;
108        }
109 
110        /**
111         * Returns the JSON result of a previously completed JavaScript evaluation and
112         * resets the helper to accept new evaluations.
113         * @return String JSON result of a previously completed JavaScript evaluation.
114         */
115        public String getJsonResultAndClear() {
116            assert hasValue();
117            String result = mJsonResult;
118            mJsonResult = null;
119            return result;
120        }
121 
122 
123        /**
124         * Returns a criteria that checks that the evaluation has finished.
125         */
126        public Criteria getHasValueCriteria() {
127            return new Criteria() {
128                @Override
129                public boolean isSatisfied() {
130                    return hasValue();
131                }
132            };
133        }
134 
135        /**
136         * Waits till the JavaScript evaluation finishes and returns true if a value was returned,
137         * false if it timed-out.
138         */
139        public boolean waitUntilHasValue(long timeout, TimeUnit timeoutUnits)
140                throws InterruptedException, TimeoutException {
141            waitUntilCriteria(getHasValueCriteria(), timeout, timeoutUnits);
142            return hasValue();
143        }
144 
145        public boolean waitUntilHasValue() throws InterruptedException, TimeoutException {
146            waitUntilCriteria(getHasValueCriteria());
147            return hasValue();
148        }
149 
150        public void notifyCalled(String jsonResult) {
151            assert !hasValue();
152            mJsonResult = jsonResult;
153            notifyCalled();
154        }
155    }
156 
157    public static class OnStartContentIntentHelper extends CallbackHelper {
158        private String mIntentUrl;
159        public void notifyCalled(String intentUrl) {
160            mIntentUrl = intentUrl;
161            notifyCalled();
162        }
163        public String getIntentUrl() {
164            assert getCallCount() > 0;
165            return mIntentUrl;
166        }
167    }
168 
169    public OnPageStartedHelper getOnPageStartedHelper() {
170        return mTestWebContentsObserver.getOnPageStartedHelper();
171    }
172 
173    public OnPageFinishedHelper getOnPageFinishedHelper() {
174        return mTestWebContentsObserver.getOnPageFinishedHelper();
175    }
176 
177    public OnReceivedErrorHelper getOnReceivedErrorHelper() {
178        return mTestWebContentsObserver.getOnReceivedErrorHelper();
179    }
180 
181    public OnEvaluateJavaScriptResultHelper getOnEvaluateJavaScriptResultHelper() {
182        return mTestContentViewClient.getOnEvaluateJavaScriptResultHelper();
183    }
184 
185    public OnStartContentIntentHelper getOnStartContentIntentHelper() {
186        return mTestContentViewClient.getOnStartContentIntentHelper();
187    }
188}

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