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

COVERAGE SUMMARY FOR SOURCE FILE [AwContentsClientGetDefaultVideoPosterTest.java]

nameclass, %method, %block, %line, %
AwContentsClientGetDefaultVideoPosterTest.java100% (2/2)100% (8/8)100% (139/139)100% (38/38)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AwContentsClientGetDefaultVideoPosterTest100% (1/1)100% (4/4)100% (96/96)100% (24/24)
AwContentsClientGetDefaultVideoPosterTest (): void 100% (1/1)100% (3/3)100% (2/2)
testGetDefaultVideoPoster (): void 100% (1/1)100% (23/23)100% (6/6)
testInterceptDefaultVidoePosterURL (): void 100% (1/1)100% (42/42)100% (9/9)
testNoDefaultVideoPoster (): void 100% (1/1)100% (28/28)100% (7/7)
     
class AwContentsClientGetDefaultVideoPosterTest$DefaultVideoPosterClient100% (1/1)100% (4/4)100% (43/43)100% (14/14)
AwContentsClientGetDefaultVideoPosterTest$DefaultVideoPosterClient (Context):... 100% (1/1)100% (11/11)100% (4/4)
getDefaultVideoPoster (): Bitmap 100% (1/1)100% (6/6)100% (2/2)
getPoster (): Bitmap 100% (1/1)100% (21/21)100% (6/6)
waitForGetDefaultVideoPosterCalled (): void 100% (1/1)100% (5/5)100% (2/2)

1// Copyright 2013 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 android.content.Context;
8import android.graphics.Bitmap;
9import android.graphics.BitmapFactory;
10import android.test.suitebuilder.annotation.SmallTest;
11import android.util.Log;
12 
13import org.chromium.android_webview.DefaultVideoPosterRequestHandler;
14import org.chromium.android_webview.InterceptedRequestData;
15import org.chromium.base.test.util.Feature;
16import org.chromium.content.browser.test.util.CallbackHelper;
17 
18import java.io.IOException;
19import java.io.InputStream;
20import java.util.concurrent.TimeoutException;
21 
22/**
23 * Tests for AwContentClient.GetDefaultVideoPoster.
24 */
25public class AwContentsClientGetDefaultVideoPosterTest extends AwTestBase {
26    private static final String TAG = "AwContentsClientGetDefaultVideoPosterTest";
27 
28    private static class DefaultVideoPosterClient extends TestAwContentsClient {
29        private CallbackHelper mVideoPosterCallbackHelper = new CallbackHelper();
30        private Bitmap mPoster;
31        private Context mContext;
32 
33        public DefaultVideoPosterClient(Context context) {
34            mContext = context;
35        }
36 
37        @Override
38        public Bitmap getDefaultVideoPoster() {
39            mVideoPosterCallbackHelper.notifyCalled();
40            return getPoster();
41        }
42 
43        public void waitForGetDefaultVideoPosterCalled() throws InterruptedException,
44                TimeoutException {
45            mVideoPosterCallbackHelper.waitForCallback(0);
46        }
47 
48        public Bitmap getPoster() {
49            if (mPoster == null) {
50                try {
51                    mPoster = BitmapFactory.decodeStream(
52                            mContext.getAssets().open("asset_icon.png"));
53                } catch (IOException e) {
54                    Log.e(TAG, null, e);
55                }
56            }
57            return mPoster;
58        }
59    }
60 
61    @Feature({"AndroidWebView"})
62    @SmallTest
63    public void testGetDefaultVideoPoster() throws Throwable {
64        DefaultVideoPosterClient contentsClient =
65                new DefaultVideoPosterClient(getInstrumentation().getContext());
66        AwTestContainerView testContainerView =
67                createAwTestContainerViewOnMainSync(contentsClient);
68        String data = "<html><head><body><video id='video' control src='' /> </body></html>";
69        loadDataAsync(testContainerView.getAwContents(), data, "text/html", false);
70        contentsClient.waitForGetDefaultVideoPosterCalled();
71    }
72 
73    @Feature({"AndroidWebView"})
74    @SmallTest
75    public void testInterceptDefaultVidoePosterURL() throws Throwable {
76        DefaultVideoPosterClient contentsClient =
77                new DefaultVideoPosterClient(getInstrumentation().getTargetContext());
78        DefaultVideoPosterRequestHandler handler =
79                new DefaultVideoPosterRequestHandler(contentsClient);
80        InterceptedRequestData requestData =
81                handler.shouldInterceptRequest(handler.getDefaultVideoPosterURL());
82        assertTrue(requestData.getMimeType().equals("image/png"));
83        Bitmap bitmap = BitmapFactory.decodeStream(requestData.getData());
84        Bitmap poster = contentsClient.getPoster();
85        assertEquals("poster.getHeight() not equal to bitmap.getHeight()",
86                poster.getHeight(), bitmap.getHeight());
87        assertEquals("poster.getWidth() not equal to bitmap.getWidth()",
88                poster.getWidth(), bitmap.getWidth());
89    }
90 
91    @Feature({"AndroidWebView"})
92    @SmallTest
93    public void testNoDefaultVideoPoster() throws Throwable {
94        NullContentsClient contentsClient = new NullContentsClient();
95        DefaultVideoPosterRequestHandler handler =
96                new DefaultVideoPosterRequestHandler(contentsClient);
97        InterceptedRequestData requestData =
98                handler.shouldInterceptRequest(handler.getDefaultVideoPosterURL());
99        assertTrue(requestData.getMimeType().equals("image/png"));
100        InputStream in = requestData.getData();
101        assertEquals("Should get -1", in.read(), -1);
102    }
103}

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