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

COVERAGE SUMMARY FOR SOURCE FILE [BookmarkUtils.java]

nameclass, %method, %block, %line, %
BookmarkUtils.java100% (1/1)33%  (1/3)35%  (25/71)43%  (6/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BookmarkUtils100% (1/1)33%  (1/3)35%  (25/71)43%  (6/14)
BookmarkUtils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
byteArrayEqual (byte [], byte []): boolean 0%   (0/1)0%   (0/26)0%   (0/5)
getIcon (String): byte [] 100% (1/1)60%  (25/42)75%  (6/8)

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.chrome.browser.test.util;
6 
7import android.graphics.Bitmap;
8import android.graphics.Bitmap.CompressFormat;
9import android.graphics.BitmapFactory;
10import android.util.Log;
11 
12import org.chromium.base.test.util.UrlUtils;
13 
14import java.io.ByteArrayOutputStream;
15import java.io.InputStream;
16import java.io.IOException;
17import java.net.URL;
18import java.util.Arrays;
19 
20/**
21 * Set of utility functions shared between tests managing bookmarks.
22 */
23public class BookmarkUtils {
24    private static final String TAG = "BookmarkUtils";
25 
26    /**
27     * Checks if two byte arrays are equal. Used to compare icons.
28     * @return True if equal, false otherwise.
29     */
30    public static boolean byteArrayEqual(byte[] byte1, byte[] byte2) {
31        if (byte1 == null && byte2 != null) {
32            return byte2.length == 0;
33        }
34        if (byte2 == null && byte1 != null) {
35            return byte1.length == 0;
36        }
37        return Arrays.equals(byte1, byte2);
38    }
39 
40    /**
41     * Retrieves a byte array with the decoded image data of an icon.
42     * @return Data of the icon.
43     */
44    public static byte[] getIcon(String testPath) {
45        ByteArrayOutputStream bos = new ByteArrayOutputStream();
46        try {
47            InputStream faviconStream = (InputStream) (new URL(
48                    UrlUtils.getTestFileUrl(testPath))).getContent();
49            Bitmap faviconBitmap = BitmapFactory.decodeStream(faviconStream);
50            faviconBitmap.compress(CompressFormat.PNG, 0, bos);
51        } catch (IOException e) {
52            Log.e(TAG, "Error trying to get the icon '" + testPath + "': " + e.getMessage());
53        }
54        return bos.toByteArray();
55    }
56}

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