• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.frameworktest.listview;
18 
19 import android.app.Instrumentation;
20 import android.test.ActivityInstrumentationTestCase;
21 import android.test.suitebuilder.annotation.MediumTest;
22 import android.widget.Button;
23 import android.widget.ListView;
24 
25 import com.android.frameworktest.R;
26 import com.android.frameworktest.listview.ListViewHeight;
27 
28 public class ListViewHeightTest extends ActivityInstrumentationTestCase<ListViewHeight> {
29     private ListViewHeight mActivity;
30 
31 
ListViewHeightTest()32     public ListViewHeightTest() {
33         super("com.android.frameworktest", ListViewHeight.class);
34     }
35 
36     @Override
setUp()37     protected void setUp() throws Exception {
38         super.setUp();
39 
40         mActivity = getActivity();
41     }
42 
43     @MediumTest
testPreconditions()44     public void testPreconditions() {
45         assertNotNull(mActivity);
46     }
47 
48     @MediumTest
testButtons()49     public void testButtons() {
50         Instrumentation inst = getInstrumentation();
51         final Button button1 = (Button) mActivity.findViewById(R.id.button1);
52         final Button button2 = (Button) mActivity.findViewById(R.id.button2);
53         final Button button3 = (Button) mActivity.findViewById(R.id.button3);
54 
55 
56         ListView list = (ListView) mActivity.findViewById(R.id.inner_list);
57         assertEquals("Unexpected items in adapter", 0, list.getCount());
58         assertEquals("Unexpected children in list view", 0, list.getChildCount());
59 
60         mActivity.runOnUiThread(new Runnable() {
61             public void run() {
62                 button1.performClick();
63             }
64         });
65         inst.waitForIdleSync();
66         assertTrue("List not be visible after clicking button1", list.isShown());
67         assertTrue("List incorrect height", list.getHeight() == 200);
68 
69         mActivity.runOnUiThread(new Runnable() {
70             public void run() {
71                 button2.performClick();
72             }
73         });
74         inst.waitForIdleSync();
75         assertTrue("List not be visible after clicking button2", list.isShown());
76 
77         mActivity.runOnUiThread(new Runnable() {
78             public void run() {
79                 button3.performClick();
80             }
81         });
82         inst.waitForIdleSync();
83         assertFalse("List should not be visible clicking button3", list.isShown());
84     }
85 
86 }
87