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

COVERAGE SUMMARY FOR SOURCE FILE [AwContentsClientFaviconTest.java]

nameclass, %method, %block, %line, %
AwContentsClientFaviconTest.java83%  (5/6)100% (21/21)100% (251/251)100% (51/51)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AwContentsClientFaviconTest100% (1/1)100% (7/7)100% (181/181)100% (36/36)
<static initializer> 100% (1/1)100% (9/9)100% (2/2)
AwContentsClientFaviconTest (): void 100% (1/1)100% (3/3)100% (2/2)
init (AwContentsClientFaviconTest$TestAwContentsClientBase): void 100% (1/1)100% (13/13)100% (4/4)
setUp (): void 100% (1/1)100% (9/9)100% (3/3)
tearDown (): void 100% (1/1)100% (9/9)100% (3/3)
testReceiveBasicFavicon (): void 100% (1/1)100% (65/65)100% (12/12)
testReceiveBasicTouchIconLinkRel (): void 100% (1/1)100% (73/73)100% (10/10)
     
class AwContentsClientFaviconTest$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)
     
class AwContentsClientFaviconTest$FaviconHelper100% (1/1)100% (6/6)100% (33/33)100% (8/8)
AwContentsClientFaviconTest$FaviconHelper (): void 100% (1/1)100% (8/8)100% (2/2)
AwContentsClientFaviconTest$FaviconHelper (AwContentsClientFaviconTest$1): void 100% (1/1)100% (3/3)100% (1/1)
access$300 (AwContentsClientFaviconTest$FaviconHelper): Bitmap 100% (1/1)100% (3/3)100% (1/1)
access$500 (AwContentsClientFaviconTest$FaviconHelper): HashMap 100% (1/1)100% (3/3)100% (1/1)
notifyFavicon (Bitmap): void 100% (1/1)100% (6/6)100% (3/3)
notifyTouchIcon (String, boolean): void 100% (1/1)100% (10/10)100% (3/3)
     
class AwContentsClientFaviconTest$TestAwContentsClientBase100% (1/1)100% (2/2)100% (12/12)100% (2/2)
AwContentsClientFaviconTest$TestAwContentsClientBase (): void 100% (1/1)100% (9/9)100% (2/2)
AwContentsClientFaviconTest$TestAwContentsClientBase (AwContentsClientFavicon... 100% (1/1)100% (3/3)100% (1/1)
     
class AwContentsClientFaviconTest$TestAwContentsClientFavicon100% (1/1)100% (3/3)100% (12/12)100% (3/3)
AwContentsClientFaviconTest$TestAwContentsClientFavicon (): void 100% (1/1)100% (4/4)100% (1/1)
AwContentsClientFaviconTest$TestAwContentsClientFavicon (AwContentsClientFavi... 100% (1/1)100% (3/3)100% (1/1)
onReceivedIcon (Bitmap): void 100% (1/1)100% (5/5)100% (2/2)
     
class AwContentsClientFaviconTest$TestAwContentsClientTouchIcon100% (1/1)100% (3/3)100% (13/13)100% (3/3)
AwContentsClientFaviconTest$TestAwContentsClientTouchIcon (): void 100% (1/1)100% (4/4)100% (1/1)
AwContentsClientFaviconTest$TestAwContentsClientTouchIcon (AwContentsClientFa... 100% (1/1)100% (3/3)100% (1/1)
onReceivedTouchIconUrl (String, boolean): void 100% (1/1)100% (6/6)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 android.graphics.Bitmap;
8import android.graphics.BitmapFactory;
9import android.test.suitebuilder.annotation.SmallTest;
10 
11import org.chromium.android_webview.AwContents;
12import org.chromium.android_webview.test.util.CommonResources;
13import org.chromium.content.browser.test.util.CallbackHelper;
14import org.chromium.net.test.util.TestWebServer;
15 
16import java.io.InputStream;
17import java.net.URL;
18import java.util.HashMap;
19 
20/**
21 * Tests for the Favicon and TouchIcon related APIs.
22 */
23public class AwContentsClientFaviconTest extends AwTestBase {
24 
25    private static final String FAVICON1_URL = "/favicon1.png";
26    private static final String FAVICON1_PAGE_URL = "/favicon1.html";
27    private static final String FAVICON1_PAGE_HTML =
28      CommonResources.makeHtmlPageFrom(
29        "<link rel=\"icon\" href=\""+ FAVICON1_URL + "\" />",
30        "Body");
31 
32    private static final String TOUCHICON_REL_LINK = "touch.png";
33    private static final String TOUCHICON_REL_LINK_72 = "touch_72.png";
34    private static final String TOUCHICON_REL_URL = "/" + TOUCHICON_REL_LINK;
35    private static final String TOUCHICON_REL_URL_72 = "/" + TOUCHICON_REL_LINK_72;
36    private static final String TOUCHICON_REL_PAGE_HTML =
37      CommonResources.makeHtmlPageFrom(
38        "<link rel=\"apple-touch-icon\" href=\""+ TOUCHICON_REL_URL + "\" />" +
39        "<link rel=\"apple-touch-icon\" sizes=\"72x72\" href=\""+ TOUCHICON_REL_URL_72 + "\" />",
40        "Body");
41 
42    private static class FaviconHelper extends CallbackHelper {
43        private Bitmap mIcon;
44        private HashMap<String, Boolean> mTouchIcons = new HashMap<String, Boolean>();
45 
46        public void notifyFavicon(Bitmap icon) {
47            mIcon = icon;
48            super.notifyCalled();
49        }
50 
51        public void notifyTouchIcon(String url, boolean precomposed) {
52            mTouchIcons.put(url, precomposed);
53            super.notifyCalled();
54        }
55    }
56 
57    private static class TestAwContentsClientBase
58            extends org.chromium.android_webview.test.TestAwContentsClient {
59        FaviconHelper mFaviconHelper = new FaviconHelper();
60    }
61 
62    private static class TestAwContentsClientFavicon extends TestAwContentsClientBase {
63        @Override
64        public void onReceivedIcon(Bitmap bitmap) {
65            // We don't inform the API client about the URL of the icon.
66            mFaviconHelper.notifyFavicon(bitmap);
67        }
68    }
69 
70    private static class TestAwContentsClientTouchIcon extends TestAwContentsClientBase {
71        @Override
72        public void onReceivedTouchIconUrl(String url, boolean precomposed) {
73            mFaviconHelper.notifyTouchIcon(url, precomposed);
74        }
75    }
76 
77    private TestAwContentsClientBase mContentsClient;
78    private AwContents mAwContents;
79    private TestWebServer mWebServer;
80 
81    @Override
82    protected void setUp() throws Exception {
83        super.setUp();
84        mWebServer = new TestWebServer(false);
85    }
86 
87    private void init(TestAwContentsClientBase contentsClient) throws Exception {
88        mContentsClient = contentsClient;
89        AwTestContainerView testContainerView =
90                createAwTestContainerViewOnMainSync(mContentsClient);
91        mAwContents = testContainerView.getAwContents();
92    }
93 
94    @Override
95    protected void tearDown() throws Exception {
96        if (mWebServer != null) mWebServer.shutdown();
97        super.tearDown();
98    }
99 
100    @SmallTest
101    public void testReceiveBasicFavicon() throws Throwable {
102        init(new TestAwContentsClientFavicon());
103        int callCount = mContentsClient.mFaviconHelper.getCallCount();
104 
105        final String faviconUrl = mWebServer.setResponseBase64(FAVICON1_URL,
106          CommonResources.FAVICON_DATA_BASE64, CommonResources.getImagePngHeaders(true));
107        final String pageUrl = mWebServer.setResponse(FAVICON1_PAGE_URL, FAVICON1_PAGE_HTML,
108          CommonResources.getTextHtmlHeaders(true));
109 
110        loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
111 
112        mContentsClient.mFaviconHelper.waitForCallback(callCount);
113        Object originalFaviconSource = (new URL(faviconUrl)).getContent();
114        Bitmap originalFavicon = BitmapFactory.decodeStream((InputStream)originalFaviconSource);
115        assertNotNull(originalFavicon);
116        assertNotNull(mContentsClient.mFaviconHelper.mIcon);
117        assertTrue(mContentsClient.mFaviconHelper.mIcon.sameAs(originalFavicon));
118    }
119 
120    @SmallTest
121    public void testReceiveBasicTouchIconLinkRel() throws Throwable {
122        init(new TestAwContentsClientTouchIcon());
123        int callCount = mContentsClient.mFaviconHelper.getCallCount();
124 
125        final String pageUrl = mWebServer.setResponse(TOUCHICON_REL_URL, TOUCHICON_REL_PAGE_HTML,
126          CommonResources.getTextHtmlHeaders(true));
127 
128        loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
129 
130        mContentsClient.mFaviconHelper.waitForCallback(callCount,2);
131        HashMap<String, Boolean> touchIcons = mContentsClient.mFaviconHelper.mTouchIcons;
132        assertEquals(2, touchIcons.size());
133        assertFalse(touchIcons.get(mWebServer.getBaseUrl() + TOUCHICON_REL_LINK));
134        assertFalse(touchIcons.get(mWebServer.getBaseUrl() + TOUCHICON_REL_LINK_72));
135    }
136}

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