EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.base.test.util]

COVERAGE SUMMARY FOR SOURCE FILE [UrlUtils.java]

nameclass, %method, %block, %line, %
UrlUtils.java100% (1/1)67%  (2/3)66%  (31/47)50%  (4/8)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class UrlUtils100% (1/1)67%  (2/3)66%  (31/47)50%  (4/8)
UrlUtils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
encodeHtmlDataUri (String): String 100% (1/1)58%  (18/31)50%  (3/6)
getTestFileUrl (String): String 100% (1/1)100% (13/13)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.base.test.util;
6 
7import org.chromium.base.PathUtils;
8 
9import junit.framework.Assert;
10 
11/**
12 * Collection of URL utilities.
13 */
14public class UrlUtils {
15    private final static String DATA_DIR = "/chrome/test/data/";
16 
17    /**
18     * Construct a suitable URL for loading a test data file.
19     * @param path Pathname relative to external/chrome/testing/data
20     */
21    public static String getTestFileUrl(String path) {
22        return "file://" + PathUtils.getExternalStorageDirectory() + DATA_DIR + path;
23    }
24 
25    /**
26     * Construct a data:text/html URI for loading from an inline HTML.
27     * @param html An unencoded HTML
28     * @return String An URI that contains the given HTML
29     */
30    public static String encodeHtmlDataUri(String html) {
31        try {
32            // URLEncoder encodes into application/x-www-form-encoded, so
33            // ' '->'+' needs to be undone and replaced with ' '->'%20'
34            // to match the Data URI requirements.
35            String encoded =
36                    "data:text/html;utf-8," +
37                    java.net.URLEncoder.encode(html, "UTF-8");
38            encoded = encoded.replace("+", "%20");
39            return encoded;
40        } catch (java.io.UnsupportedEncodingException e) {
41            Assert.fail("Unsupported encoding: " + e.getMessage());
42            return null;
43        }
44    }
45}

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