EMMA Coverage Report (generated Tue Aug 20 10:07:21 PDT 2013)
[all classes][org.chromium.android_webview.test]

COVERAGE SUMMARY FOR SOURCE FILE [WebViewFindApisTestBase.java]

nameclass, %method, %block, %line, %
WebViewFindApisTestBase.java100% (8/8)100% (26/26)95%  (225/236)93%  (40.8/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class WebViewFindApisTestBase$IntegerFuture100% (1/1)100% (4/4)88%  (28/32)88%  (7/8)
get (long, TimeUnit): int 100% (1/1)69%  (9/13)67%  (2/3)
WebViewFindApisTestBase$IntegerFuture (): void 100% (1/1)100% (9/9)100% (2/2)
WebViewFindApisTestBase$IntegerFuture (WebViewFindApisTestBase$1): void 100% (1/1)100% (3/3)100% (1/1)
set (int): void 100% (1/1)100% (7/7)100% (3/3)
     
class WebViewFindApisTestBase100% (1/1)100% (10/10)94%  (92/98)91%  (20/22)
setUp (): void 100% (1/1)60%  (9/15)67%  (4/6)
WebViewFindApisTestBase (): void 100% (1/1)100% (3/3)100% (2/2)
access$000 (WebViewFindApisTestBase): WebViewFindApisTestBase$FindResultListener 100% (1/1)100% (3/3)100% (1/1)
access$002 (WebViewFindApisTestBase, WebViewFindApisTestBase$FindResultListen... 100% (1/1)100% (5/5)100% (1/1)
access$200 (WebViewFindApisTestBase): AwContents 100% (1/1)100% (3/3)100% (1/1)
clearMatchesOnUiThread (): void 100% (1/1)100% (7/7)100% (2/2)
contents (): AwContents 100% (1/1)100% (3/3)100% (1/1)
findAllAsyncOnUiThread (String): int 100% (1/1)100% (14/14)100% (3/3)
findNextOnUiThread (boolean): int 100% (1/1)100% (14/14)100% (3/3)
loadContentsFromStringSync (String): AwContents 100% (1/1)100% (31/31)100% (5/5)
     
class WebViewFindApisTestBase$1100% (1/1)100% (2/2)95%  (18/19)95%  (3.8/4)
onFindResultReceived (int, int, boolean): void 100% (1/1)92%  (12/13)93%  (2.8/3)
WebViewFindApisTestBase$1 (WebViewFindApisTestBase): void 100% (1/1)100% (6/6)100% (1/1)
     
class WebViewFindApisTestBase$2100% (1/1)100% (2/2)100% (25/25)100% (4/4)
WebViewFindApisTestBase$2 (WebViewFindApisTestBase, String): void 100% (1/1)100% (10/10)100% (1/1)
run (): void 100% (1/1)100% (15/15)100% (3/3)
     
class WebViewFindApisTestBase$2$1100% (1/1)100% (2/2)100% (13/13)100% (3/3)
WebViewFindApisTestBase$2$1 (WebViewFindApisTestBase$2): void 100% (1/1)100% (6/6)100% (1/1)
onFindResultReceived (int, int, boolean): void 100% (1/1)100% (7/7)100% (2/2)
     
class WebViewFindApisTestBase$3100% (1/1)100% (2/2)100% (25/25)100% (4/4)
WebViewFindApisTestBase$3 (WebViewFindApisTestBase, boolean): void 100% (1/1)100% (10/10)100% (1/1)
run (): void 100% (1/1)100% (15/15)100% (3/3)
     
class WebViewFindApisTestBase$3$1100% (1/1)100% (2/2)100% (13/13)100% (3/3)
WebViewFindApisTestBase$3$1 (WebViewFindApisTestBase$3): void 100% (1/1)100% (6/6)100% (1/1)
onFindResultReceived (int, int, boolean): void 100% (1/1)100% (7/7)100% (2/2)
     
class WebViewFindApisTestBase$4100% (1/1)100% (2/2)100% (11/11)100% (3/3)
WebViewFindApisTestBase$4 (WebViewFindApisTestBase): void 100% (1/1)100% (6/6)100% (1/1)
run (): void 100% (1/1)100% (5/5)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.android_webview.test;
6 
7import java.util.concurrent.Callable;
8import java.util.concurrent.CountDownLatch;
9import java.util.concurrent.TimeUnit;
10import java.util.concurrent.TimeoutException;
11 
12import org.chromium.android_webview.AwContents;
13 
14/**
15 * Base class for WebView find-in-page API tests.
16 */
17public class WebViewFindApisTestBase extends AwTestBase {
18 
19    private static final String WOODCHUCK =
20            "How much WOOD would a woodchuck chuck if a woodchuck could chuck wOoD?";
21 
22    private FindResultListener mFindResultListener;
23    private AwContents mContents;
24 
25    @Override
26    protected void setUp() throws Exception {
27        super.setUp();
28        try {
29            mContents = loadContentsFromStringSync(WOODCHUCK);
30        } catch (Throwable t) {
31            throw new Exception(t);
32        }
33    }
34 
35    protected AwContents contents() {
36        return mContents;
37    }
38 
39    // Internal interface to intercept find results from AwContentsClient.
40    private interface FindResultListener {
41        public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
42                boolean isDoneCounting);
43    };
44 
45    private AwContents loadContentsFromStringSync(final String html) throws Throwable {
46        final TestAwContentsClient contentsClient = new TestAwContentsClient() {
47            @Override
48            public void onFindResultReceived(int activeMatchOrdinal,
49                    int numberOfMatches, boolean isDoneCounting) {
50                if (mFindResultListener == null) return;
51                mFindResultListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
52                        isDoneCounting);
53            }
54        };
55 
56        final AwContents contents =
57                createAwTestContainerViewOnMainSync(contentsClient).getAwContents();
58        final String data = "<html><head></head><body>" + html + "</body></html>";
59        loadDataSync(contents, contentsClient.getOnPageFinishedHelper(),
60                data, "text/html", false);
61        return contents;
62    }
63 
64    /**
65     * Invokes findAllAsync on the UI thread, blocks until find results are
66     * received, and returns the number of matches.
67     *
68     * @param searchString A string to search for.
69     * @return The number of instances of the string that were found.
70     * @throws Throwable
71     */
72    protected int findAllAsyncOnUiThread(final String searchString)
73            throws Throwable {
74        final IntegerFuture future = new IntegerFuture() {
75            @Override
76            public void run() {
77                mFindResultListener = new FindResultListener() {
78                    @Override
79                    public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
80                            boolean isDoneCounting) {
81                        if (isDoneCounting) set(numberOfMatches);
82                    }
83                };
84                mContents.findAllAsync(searchString);
85            }
86        };
87        runTestOnUiThread(future);
88        return future.get(10, TimeUnit.SECONDS);
89    }
90 
91    /**
92     * Invokes findNext on the UI thread, blocks until find results are
93     * received, and returns the ordinal of the highlighted match.
94     *
95     * @param forwards The direction to search as a boolean, with forwards
96     *                 represented as true and backwards as false.
97     * @return The ordinal of the highlighted match.
98     * @throws Throwable
99     */
100    protected int findNextOnUiThread(final boolean forwards)
101            throws Throwable {
102        final IntegerFuture future = new IntegerFuture() {
103            @Override
104            public void run() {
105                mFindResultListener = new FindResultListener() {
106                    @Override
107                    public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
108                            boolean isDoneCounting) {
109                        if (isDoneCounting) set(activeMatchOrdinal);
110                    }
111                };
112                mContents.findNext(forwards);
113            }
114        };
115        runTestOnUiThread(future);
116        return future.get(10, TimeUnit.SECONDS);
117    }
118 
119    /**
120     * Invokes clearMatches on the UI thread.
121     *
122     * @throws Throwable
123     */
124    protected void clearMatchesOnUiThread() throws Throwable {
125        runTestOnUiThread(new Runnable() {
126            @Override
127            public void run() {
128                mContents.clearMatches();
129            }
130        });
131    }
132 
133    // Similar to java.util.concurrent.Future, but without the ability to cancel.
134    private static abstract class IntegerFuture implements Runnable {
135        private CountDownLatch mLatch = new CountDownLatch(1);
136        private int mValue;
137 
138        @Override
139        public abstract void run();
140 
141        /**
142         * Gets the value of this Future, blocking for up to the specified
143         * timeout for it become available. Throws a TimeoutException if the
144         * timeout expires.
145         */
146        public int get(long timeout, TimeUnit unit) throws Throwable {
147            if (!mLatch.await(timeout, unit)) {
148                throw new TimeoutException();
149            }
150            return mValue;
151        }
152 
153        /**
154         * Sets the value of this Future.
155         */
156        protected void set(int value) {
157            mValue = value;
158            mLatch.countDown();
159        }
160    }
161}

[all classes][org.chromium.android_webview.test]
EMMA 2.0.5312 (C) Vladimir Roubtsov