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

COVERAGE SUMMARY FOR SOURCE FILE [AutofillTest.java]

nameclass, %method, %block, %line, %
AutofillTest.java100% (6/6)100% (25/25)100% (315/315)100% (43/43)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AutofillTest100% (1/1)100% (11/11)100% (195/195)100% (28/28)
AutofillTest (): void 100% (1/1)100% (3/3)100% (2/2)
access$100 (AutofillTest): AutofillPopup 100% (1/1)100% (3/3)100% (1/1)
access$102 (AutofillTest, AutofillPopup): AutofillPopup 100% (1/1)100% (5/5)100% (1/1)
access$200 (AutofillTest): WindowAndroid 100% (1/1)100% (3/3)100% (1/1)
access$300 (AutofillTest): AutofillTest$MockAutofillCallback 100% (1/1)100% (3/3)100% (1/1)
createFiveAutofillSuggestionArray (): AutofillSuggestion [] 100% (1/1)100% (48/48)100% (1/1)
createTwoAutofillSuggestionArray (): AutofillSuggestion [] 100% (1/1)100% (21/21)100% (1/1)
openAutofillPopupAndWaitUntilReady (AutofillSuggestion []): boolean 100% (1/1)100% (14/14)100% (2/2)
setUp (): void 100% (1/1)100% (37/37)100% (9/9)
testAutofillClickFirstSuggestion (): void 100% (1/1)100% (35/35)100% (8/8)
testAutofillWithDifferentNumberSuggestions (): void 100% (1/1)100% (23/23)100% (5/5)
     
class AutofillTest$1100% (1/1)100% (2/2)100% (34/34)100% (4/4)
AutofillTest$1 (AutofillTest, ViewAndroidDelegate): void 100% (1/1)100% (9/9)100% (1/1)
run (): void 100% (1/1)100% (25/25)100% (3/3)
     
class AutofillTest$2100% (1/1)100% (2/2)100% (16/16)100% (3/3)
AutofillTest$2 (AutofillTest, AutofillSuggestion []): void 100% (1/1)100% (9/9)100% (1/1)
run (): void 100% (1/1)100% (7/7)100% (2/2)
     
class AutofillTest$3100% (1/1)100% (2/2)100% (16/16)100% (2/2)
AutofillTest$3 (AutofillTest): void 100% (1/1)100% (6/6)100% (1/1)
isSatisfied (): boolean 100% (1/1)100% (10/10)100% (1/1)
     
class AutofillTest$MockAutofillCallback100% (1/1)100% (6/6)100% (43/43)100% (9/9)
AutofillTest$MockAutofillCallback (AutofillTest): void 100% (1/1)100% (15/15)100% (3/3)
AutofillTest$MockAutofillCallback (AutofillTest, AutofillTest$1): void 100% (1/1)100% (4/4)100% (1/1)
access$400 (AutofillTest$MockAutofillCallback): AtomicBoolean 100% (1/1)100% (3/3)100% (1/1)
requestHide (): void 100% (1/1)100% (1/1)100% (1/1)
suggestionSelected (int): void 100% (1/1)100% (12/12)100% (4/4)
waitForCallback (): boolean 100% (1/1)100% (8/8)100% (1/1)
     
class AutofillTest$MockAutofillCallback$1100% (1/1)100% (2/2)100% (11/11)100% (2/2)
AutofillTest$MockAutofillCallback$1 (AutofillTest$MockAutofillCallback): void 100% (1/1)100% (6/6)100% (1/1)
isSatisfied (): boolean 100% (1/1)100% (5/5)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.chrome.browser.autofill;
6 
7import android.test.suitebuilder.annotation.SmallTest;
8 
9import org.chromium.base.test.util.Feature;
10import org.chromium.chrome.testshell.ChromiumTestShellActivity;
11import org.chromium.chrome.testshell.ChromiumTestShellTestBase;
12import org.chromium.content.browser.test.util.TouchCommon;
13import org.chromium.content.browser.test.util.UiUtils;
14import org.chromium.content.browser.test.util.Criteria;
15import org.chromium.content.browser.test.util.CriteriaHelper;
16import org.chromium.ui.ViewAndroidDelegate;
17import org.chromium.ui.WindowAndroid;
18import org.chromium.ui.autofill.AutofillPopup;
19import org.chromium.ui.autofill.AutofillPopup.AutofillPopupDelegate;
20import org.chromium.ui.autofill.AutofillSuggestion;
21 
22import java.util.concurrent.atomic.AtomicBoolean;
23 
24/**
25 * Tests the Autofill's java code for creating the AutofillPopup object, opening and selecting
26 * popups.
27 */
28public class AutofillTest extends ChromiumTestShellTestBase {
29 
30    private AutofillPopup mAutofillPopup;
31    private WindowAndroid mWindowAndroid;
32    private MockAutofillCallback mMockAutofillCallback;
33 
34    @Override
35    public void setUp() throws Exception {
36        super.setUp();
37        ChromiumTestShellActivity activity = launchChromiumTestShellWithBlankPage();
38        assertNotNull(activity);
39        waitForActiveShellToBeDoneLoading();
40 
41        mMockAutofillCallback = new MockAutofillCallback();
42        mWindowAndroid = new WindowAndroid(activity);
43        final ViewAndroidDelegate viewDelegate =
44                activity.getActiveContentView().getContentViewCore().getViewAndroidDelegate();
45 
46        UiUtils.runOnUiThread(getActivity(), new Runnable() {
47            @Override
48            public void run() {
49                mAutofillPopup = new AutofillPopup(mWindowAndroid.getContext(),
50                        viewDelegate,
51                        mMockAutofillCallback);
52                mAutofillPopup.setAnchorRect(50, 500, 500, 50);
53            }
54        });
55 
56    }
57 
58    private class MockAutofillCallback implements AutofillPopupDelegate{
59        private static final int CALLBACK_TIMEOUT_MS = 4000;
60        private static final int CHECK_INTERVAL_MS = 100;
61        private final AtomicBoolean mGotPopupSelection = new AtomicBoolean(false);
62        public int mListIndex = -1;
63 
64        @Override
65        public void suggestionSelected(int listIndex) {
66            mListIndex = listIndex;
67            mAutofillPopup.dismiss();
68            mGotPopupSelection.set(true);
69        }
70 
71        public boolean waitForCallback() throws InterruptedException {
72            return CriteriaHelper.pollForCriteria(new Criteria() {
73                @Override
74                public boolean isSatisfied() {
75                    return mGotPopupSelection.get();
76                }
77            }, CALLBACK_TIMEOUT_MS, CHECK_INTERVAL_MS);
78        }
79 
80        @Override
81        public void requestHide() {
82        }
83    }
84 
85    private AutofillSuggestion[] createTwoAutofillSuggestionArray() {
86        return new AutofillSuggestion[] {
87            new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", 42),
88            new AutofillSuggestion("Arthur Dent", "West Country", 43),
89        };
90    }
91 
92    private AutofillSuggestion[] createFiveAutofillSuggestionArray() {
93        return new AutofillSuggestion[] {
94            new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", 42),
95            new AutofillSuggestion("Arthur Dent", "West Country", 43),
96            new AutofillSuggestion("Arthos", "France", 44),
97            new AutofillSuggestion("Porthos", "France", 45),
98            new AutofillSuggestion("Aramis", "France", 46),
99        };
100    }
101 
102    public boolean openAutofillPopupAndWaitUntilReady(final AutofillSuggestion[] suggestions)
103            throws InterruptedException {
104        UiUtils.runOnUiThread(getActivity(), new Runnable() {
105            @Override
106            public void run() {
107                mAutofillPopup.show(suggestions);
108            }
109        });
110        return CriteriaHelper.pollForCriteria(new Criteria() {
111            @Override
112            public boolean isSatisfied() {
113                return mAutofillPopup.getListView().getChildCount() > 0;
114            }
115        });
116    }
117 
118    @SmallTest
119    @Feature({"autofill"})
120    public void testAutofillWithDifferentNumberSuggestions() throws Exception {
121        assertTrue(openAutofillPopupAndWaitUntilReady(createTwoAutofillSuggestionArray()));
122        assertEquals(2, mAutofillPopup.getListView().getCount());
123 
124        assertTrue(openAutofillPopupAndWaitUntilReady(createFiveAutofillSuggestionArray()));
125        assertEquals(5, mAutofillPopup.getListView().getCount());
126    }
127 
128    @SmallTest
129    @Feature({"autofill"})
130    public void testAutofillClickFirstSuggestion() throws Exception {
131        AutofillSuggestion[] suggestions = createTwoAutofillSuggestionArray();
132        assertTrue(openAutofillPopupAndWaitUntilReady(suggestions));
133        assertEquals(2, mAutofillPopup.getListView().getCount());
134 
135        TouchCommon touchCommon = new TouchCommon(this);
136        touchCommon.singleClickViewRelative(mAutofillPopup.getListView(), 10, 10);
137        assertTrue(mMockAutofillCallback.waitForCallback());
138 
139        assertEquals(0, mMockAutofillCallback.mListIndex);
140    }
141}

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