1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.widget.gridview.touch;
18
19import android.widget.gridview.GridStackFromBottom;
20import android.test.TouchUtils;
21import android.test.suitebuilder.annotation.MediumTest;
22
23import android.test.ActivityInstrumentationTestCase;
24import android.widget.GridView;
25import android.view.View;
26
27public class GridTouchStackFromBottomTest extends ActivityInstrumentationTestCase<GridStackFromBottom> {
28    private GridStackFromBottom mActivity;
29    private GridView mGridView;
30
31    public GridTouchStackFromBottomTest() {
32        super("com.android.frameworks.coretests", GridStackFromBottom.class);
33    }
34
35    @Override
36    protected void setUp() throws Exception {
37        super.setUp();
38
39        mActivity = getActivity();
40        mGridView = getActivity().getGridView();
41    }
42
43    @MediumTest
44    public void testPreconditions() {
45        assertNotNull(mActivity);
46        assertNotNull(mGridView);
47
48        // First item should be selected
49        assertEquals(mGridView.getAdapter().getCount() - 1, mGridView.getSelectedItemPosition());
50    }
51
52    @MediumTest
53    public void testPushUp() {
54        TouchUtils.scrollToBottom(this, mGridView);
55
56        // Nothing should be selected
57        assertEquals("Selection still available after touch", -1,
58                mGridView.getSelectedItemPosition());
59
60        View lastChild = mGridView.getChildAt(mGridView.getChildCount() - 1);
61
62        assertEquals("Last item not the last child in the grid",
63                mGridView.getAdapter().getCount() - 1, lastChild.getId());
64
65        assertEquals("Last item not at the bottom of the grid",
66                mGridView.getHeight() - mGridView.getListPaddingBottom(), lastChild.getBottom());
67    }
68
69    @MediumTest
70    public void testPullDown() {
71        TouchUtils.scrollToTop(this, mGridView);
72
73        // Nothing should be selected
74        assertEquals("Selection still available after touch", -1,
75                mGridView.getSelectedItemPosition());
76
77        View lastChild = mGridView.getChildAt(mGridView.getChildCount() - 1);
78
79        assertEquals("Last item not the last child in the grid",
80                mGridView.getAdapter().getCount() - 1, lastChild.getId());
81
82        assertEquals("Last item not at the bottom of the grid",
83                mGridView.getHeight() - mGridView.getListPaddingBottom(), lastChild.getBottom());
84    }
85
86    @MediumTest
87    public void testPushUpFast() {
88        TouchUtils.dragViewToTop(this, mGridView.getChildAt(mGridView.getChildCount() - 1), 2);
89
90        // Nothing should be selected
91        assertEquals("Selection still available after touch", -1,
92                mGridView.getSelectedItemPosition());
93
94        View lastChild = mGridView.getChildAt(mGridView.getChildCount() - 1);
95
96        assertEquals("Last item not the last child in the grid",
97                mGridView.getAdapter().getCount() - 1, lastChild.getId());
98
99        assertEquals("Last item not at the bottom of the grid",
100                mGridView.getHeight() - mGridView.getListPaddingBottom(), lastChild.getBottom());
101    }
102
103    @MediumTest
104    public void testPullDownFast() {
105        TouchUtils.dragViewToBottom(this, mGridView.getChildAt(0), 2);
106
107        // Nothing should be selected
108        assertEquals("Selection still available after touch", -1,
109                mGridView.getSelectedItemPosition());
110
111        View lastChild = mGridView.getChildAt(mGridView.getChildCount() - 1);
112
113        assertEquals("Last item not the last child in the grid",
114                mGridView.getAdapter().getCount() - 1, lastChild.getId());
115
116        assertEquals("Last item not at the bottom of the grid",
117                mGridView.getHeight() - mGridView.getListPaddingBottom(), lastChild.getBottom());
118    }
119}
120