Home | History | Annotate | Download | only in listview
      1 /*
      2  * Copyright (C) 2008 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 android.widget.listview;
     18 
     19 import android.app.Instrumentation;
     20 import android.content.Intent;
     21 import android.test.ActivityInstrumentationTestCase;
     22 import android.test.suitebuilder.annotation.LargeTest;
     23 import android.test.suitebuilder.annotation.MediumTest;
     24 import android.view.KeyEvent;
     25 import android.view.View;
     26 import android.widget.ListView;
     27 
     28 public class ListEmptyViewTest extends ActivityInstrumentationTestCase<ListWithEmptyView> {
     29     private ListWithEmptyView mActivity;
     30     private ListView mListView;
     31 
     32 
     33     public ListEmptyViewTest() {
     34         super("com.android.frameworks.coretests", ListWithEmptyView.class);
     35     }
     36 
     37     @Override
     38     protected void setUp() throws Exception {
     39         super.setUp();
     40 
     41         mActivity = getActivity();
     42         mListView = getActivity().getListView();
     43     }
     44 
     45     @MediumTest
     46     public void testPreconditions() {
     47         assertNotNull(mActivity);
     48         assertNotNull(mListView);
     49 
     50         assertTrue("Empty view not shown", mListView.getVisibility() == View.GONE);
     51     }
     52 
     53     @MediumTest
     54     public void testZeroToOne() {
     55         Instrumentation inst = getInstrumentation();
     56 
     57         inst.invokeMenuActionSync(mActivity, mActivity.MENU_ADD, 0);
     58         inst.waitForIdleSync();
     59         assertTrue("Empty view still shown", mActivity.getEmptyView().getVisibility() == View.GONE);
     60         assertTrue("List not shown", mActivity.getListView().getVisibility() == View.VISIBLE);
     61     }
     62 
     63     @MediumTest
     64     public void testZeroToOneForwardBack() {
     65         Instrumentation inst = getInstrumentation();
     66 
     67         inst.invokeMenuActionSync(mActivity, mActivity.MENU_ADD, 0);
     68         inst.waitForIdleSync();
     69         assertTrue("Empty view still shown", mActivity.getEmptyView().getVisibility() == View.GONE);
     70         assertTrue("List not shown", mActivity.getListView().getVisibility() == View.VISIBLE);
     71 
     72         // Navigate forward
     73         Intent intent = new Intent();
     74         intent.setClass(mActivity, ListWithEmptyView.class);
     75         mActivity.startActivity(intent);
     76 
     77         // Navigate backward
     78         inst.sendCharacterSync(KeyEvent.KEYCODE_BACK);
     79         inst.waitForIdleSync();
     80         assertTrue("Empty view still shown", mActivity.getEmptyView().getVisibility() == View.GONE);
     81         assertTrue("List not shown", mActivity.getListView().getVisibility() == View.VISIBLE);
     82 
     83     }
     84 
     85     @LargeTest
     86     public void testZeroToManyToZero() {
     87         Instrumentation inst = getInstrumentation();
     88 
     89         int i;
     90 
     91         for (i = 0; i < 10; i++) {
     92             inst.invokeMenuActionSync(mActivity, mActivity.MENU_ADD, 0);
     93             inst.waitForIdleSync();
     94             assertTrue("Empty view still shown",
     95                     mActivity.getEmptyView().getVisibility() == View.GONE);
     96             assertTrue("List not shown", mActivity.getListView().getVisibility() == View.VISIBLE);
     97         }
     98 
     99         for (i = 0; i < 10; i++) {
    100             inst.invokeMenuActionSync(mActivity, mActivity.MENU_REMOVE, 0);
    101             inst.waitForIdleSync();
    102             if (i < 9) {
    103                 assertTrue("Empty view still shown",
    104                         mActivity.getEmptyView().getVisibility() == View.GONE);
    105                 assertTrue("List not shown",
    106                         mActivity.getListView().getVisibility() == View.VISIBLE);
    107             } else {
    108                 assertTrue("Empty view not shown",
    109                         mActivity.getEmptyView().getVisibility() == View.VISIBLE);
    110                 assertTrue("List still shown",
    111                         mActivity.getListView().getVisibility() == View.GONE);
    112             }
    113         }
    114 
    115         // Navigate forward
    116         Intent intent = new Intent();
    117         intent.setClass(mActivity, ListWithEmptyView.class);
    118         mActivity.startActivity(intent);
    119 
    120         // Navigate backward
    121         inst.sendCharacterSync(KeyEvent.KEYCODE_BACK);
    122         inst.waitForIdleSync();
    123         assertTrue("Empty view not shown", mActivity.getEmptyView().getVisibility() == View.VISIBLE);
    124         assertTrue("List still shown", mActivity.getListView().getVisibility() == View.GONE);
    125     }
    126 
    127 
    128 }
    129