2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android
.widget
.gridview
.touch
;
19 import android
.widget
.gridview
.GridStackFromBottom
;
20 import android
.test
.TouchUtils
;
21 import android
.test
.suitebuilder
.annotation
.MediumTest
;
23 import android
.test
.ActivityInstrumentationTestCase
;
24 import android
.widget
.GridView
;
25 import android
.view
.View
;
27 public class GridTouchStackFromBottomTest
extends ActivityInstrumentationTestCase
<GridStackFromBottom
> {
28 private GridStackFromBottom mActivity
;
29 private GridView mGridView
;
31 public GridTouchStackFromBottomTest() {
32 super("com.android.frameworks.coretests", GridStackFromBottom
.class);
36 protected void setUp() throws Exception
{
39 mActivity
= getActivity();
40 mGridView
= getActivity().getGridView();
44 public void testPreconditions() {
45 assertNotNull(mActivity
);
46 assertNotNull(mGridView
);
48 // First item should be selected
49 assertEquals(mGridView
.getAdapter().getCount() - 1, mGridView
.getSelectedItemPosition());
53 public void testPushUp() {
54 TouchUtils
.scrollToBottom(this, mGridView
);
56 // Nothing should be selected
57 assertEquals("Selection still available after touch", -1,
58 mGridView
.getSelectedItemPosition());
60 View lastChild
= mGridView
.getChildAt(mGridView
.getChildCount() - 1);
62 assertEquals("Last item not the last child in the grid",
63 mGridView
.getAdapter().getCount() - 1, lastChild
.getId());
65 assertEquals("Last item not at the bottom of the grid",
66 mGridView
.getHeight() - mGridView
.getListPaddingBottom(), lastChild
.getBottom());
70 public void testPullDown() {
71 TouchUtils
.scrollToTop(this, mGridView
);
73 // Nothing should be selected
74 assertEquals("Selection still available after touch", -1,
75 mGridView
.getSelectedItemPosition());
77 View lastChild
= mGridView
.getChildAt(mGridView
.getChildCount() - 1);
79 assertEquals("Last item not the last child in the grid",
80 mGridView
.getAdapter().getCount() - 1, lastChild
.getId());
82 assertEquals("Last item not at the bottom of the grid",
83 mGridView
.getHeight() - mGridView
.getListPaddingBottom(), lastChild
.getBottom());
87 public void testPushUpFast() {
88 TouchUtils
.dragViewToTop(this, mGridView
.getChildAt(mGridView
.getChildCount() - 1), 2);
90 // Nothing should be selected
91 assertEquals("Selection still available after touch", -1,
92 mGridView
.getSelectedItemPosition());
94 View lastChild
= mGridView
.getChildAt(mGridView
.getChildCount() - 1);
96 assertEquals("Last item not the last child in the grid",
97 mGridView
.getAdapter().getCount() - 1, lastChild
.getId());
99 assertEquals("Last item not at the bottom of the grid",
100 mGridView
.getHeight() - mGridView
.getListPaddingBottom(), lastChild
.getBottom());
104 public void testPullDownFast() {
105 TouchUtils
.dragViewToBottom(this, mGridView
.getChildAt(0), 2);
107 // Nothing should be selected
108 assertEquals("Selection still available after touch", -1,
109 mGridView
.getSelectedItemPosition());
111 View lastChild
= mGridView
.getChildAt(mGridView
.getChildCount() - 1);
113 assertEquals("Last item not the last child in the grid",
114 mGridView
.getAdapter().getCount() - 1, lastChild
.getId());
116 assertEquals("Last item not at the bottom of the grid",
117 mGridView
.getHeight() - mGridView
.getListPaddingBottom(), lastChild
.getBottom());