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

COVERAGE SUMMARY FOR SOURCE FILE [ShortcutHelperTest.java]

nameclass, %method, %block, %line, %
ShortcutHelperTest.java100% (4/4)100% (15/15)99%  (165/167)97%  (38/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ShortcutHelperTest$TestObserver100% (1/1)100% (3/3)88%  (15/17)80%  (4/5)
onSendBroadcast (Intent): boolean 100% (1/1)82%  (9/11)75%  (3/4)
ShortcutHelperTest$TestObserver (): void 100% (1/1)100% (3/3)100% (1/1)
ShortcutHelperTest$TestObserver (ShortcutHelperTest$1): void 100% (1/1)100% (3/3)100% (1/1)
     
class ShortcutHelperTest100% (1/1)100% (8/8)100% (123/123)100% (32/32)
<static initializer> 100% (1/1)100% (7/7)100% (2/2)
ShortcutHelperTest (): void 100% (1/1)100% (3/3)100% (2/2)
access$100 (ShortcutHelperTest): ChromiumTestShellActivity 100% (1/1)100% (3/3)100% (1/1)
access$200 (ShortcutHelperTest): ShortcutHelperTest$TestObserver 100% (1/1)100% (3/3)100% (1/1)
addShortcutToURL (String): void 100% (1/1)100% (20/20)100% (5/5)
setUp (): void 100% (1/1)100% (25/25)100% (7/7)
testAddBookmarkShortcut (): void 100% (1/1)100% (29/29)100% (8/8)
testAddWebappShortcut (): void 100% (1/1)100% (33/33)100% (8/8)
     
class ShortcutHelperTest$1100% (1/1)100% (2/2)100% (12/12)100% (3/3)
ShortcutHelperTest$1 (ShortcutHelperTest): void 100% (1/1)100% (6/6)100% (1/1)
run (): void 100% (1/1)100% (6/6)100% (2/2)
     
class ShortcutHelperTest$2100% (1/1)100% (2/2)100% (15/15)100% (2/2)
ShortcutHelperTest$2 (ShortcutHelperTest): void 100% (1/1)100% (6/6)100% (1/1)
isSatisfied (): boolean 100% (1/1)100% (9/9)100% (1/1)

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.chrome.browser;
6 
7import android.content.Intent;
8import android.os.Parcel;
9import android.test.suitebuilder.annotation.MediumTest;
10import android.util.Log;
11import org.chromium.base.test.util.Feature;
12import org.chromium.base.test.util.UrlUtils;
13import org.chromium.chrome.testshell.ChromiumTestShellActivity;
14import org.chromium.chrome.testshell.ChromiumTestShellApplication;
15import org.chromium.chrome.testshell.ChromiumTestShellApplicationObserver;
16import org.chromium.chrome.testshell.ChromiumTestShellTestBase;
17import org.chromium.chrome.testshell.TestShellTab;
18import org.chromium.content.browser.test.util.Criteria;
19import org.chromium.content.browser.test.util.CriteriaHelper;
20 
21public class ShortcutHelperTest extends ChromiumTestShellTestBase {
22    private static final String WEBAPP_PACKAGE_NAME = "packageName";
23    private static final String WEBAPP_CLASS_NAME = "className";
24 
25    private static final String WEBAPP_TITLE = "Webapp shortcut";
26    private static final String WEBAPP_HTML = UrlUtils.encodeHtmlDataUri(
27            "<html><head>"
28            + "<meta name=\"mobile-web-app-capable\" content=\"yes\" />"
29            + "<title>" + WEBAPP_TITLE + "</title>"
30            + "</head><body>Webapp capable</body></html>");
31 
32    private static final String NORMAL_TITLE = "Plain shortcut";
33    private static final String NORMAL_HTML = UrlUtils.encodeHtmlDataUri(
34            "<html>"
35            + "<head><title>" + NORMAL_TITLE + "</title></head>"
36            + "<body>Not Webapp capable</body></html>");
37 
38    private static class TestObserver implements ChromiumTestShellApplicationObserver {
39        Intent firedIntent;
40 
41        @Override
42        public boolean onSendBroadcast(Intent intent) {
43            if (intent.hasExtra(Intent.EXTRA_SHORTCUT_NAME)) {
44                // Stop a shortcut from really being added.
45                firedIntent = intent;
46                return false;
47            }
48 
49            return true;
50        }
51    }
52 
53    private ChromiumTestShellActivity mActivity;
54    private TestObserver mTestObserver;
55 
56    @Override
57    public void setUp() throws Exception {
58        ShortcutHelper.setWebappActivityInfo(WEBAPP_PACKAGE_NAME, WEBAPP_CLASS_NAME);
59        mActivity = launchChromiumTestShellWithBlankPage();
60 
61        // Set up the observer.
62        mTestObserver = new TestObserver();
63        ChromiumTestShellApplication application =
64                (ChromiumTestShellApplication) mActivity.getApplication();
65        application.addObserver(mTestObserver);
66 
67        super.setUp();
68    }
69 
70    @MediumTest
71    @Feature("{Webapp}")
72    public void testAddWebappShortcut() throws InterruptedException {
73        addShortcutToURL(WEBAPP_HTML);
74 
75        // Make sure the intent's parameters make sense.
76        Intent firedIntent = mTestObserver.firedIntent;
77        assertEquals(WEBAPP_TITLE, firedIntent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME));
78 
79        Intent launchIntent = firedIntent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
80        assertEquals(WEBAPP_HTML, launchIntent.getStringExtra(ShortcutHelper.EXTRA_URL));
81        assertEquals(WEBAPP_PACKAGE_NAME, launchIntent.getComponent().getPackageName());
82        assertEquals(WEBAPP_CLASS_NAME, launchIntent.getComponent().getClassName());
83    }
84 
85    @MediumTest
86    @Feature("{Webapp}")
87    public void testAddBookmarkShortcut() throws InterruptedException {
88        addShortcutToURL(NORMAL_HTML);
89 
90        // Make sure the intent's parameters make sense.
91        Intent firedIntent = mTestObserver.firedIntent;
92        assertEquals(NORMAL_TITLE, firedIntent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME));
93 
94        Intent launchIntent = firedIntent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
95        assertEquals(Intent.ACTION_VIEW, launchIntent.getAction());
96        assertEquals(NORMAL_HTML, launchIntent.getDataString());
97        assertNull(launchIntent.getComponent());
98    }
99 
100    private void addShortcutToURL(String url) throws InterruptedException {
101        loadUrlWithSanitization(url);
102        assertTrue(waitForActiveShellToBeDoneLoading());
103 
104        // Add the shortcut.
105        getInstrumentation().runOnMainSync(new Runnable() {
106            @Override
107            public void run() {
108                ShortcutHelper.addShortcut(mActivity.getActiveTab());
109            }
110        });
111 
112        // Make sure that the shortcut was added.
113        assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
114            @Override
115            public boolean isSatisfied() {
116                return mTestObserver.firedIntent != null;
117            }
118        }));
119    }
120}

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