Home | History | Annotate | Download | only in widget
      1 /*
      2  * Copyright 2018 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 androidx.core.widget;
     18 
     19 import static org.junit.Assert.assertEquals;
     20 
     21 import android.support.test.filters.LargeTest;
     22 import android.support.test.rule.ActivityTestRule;
     23 import android.support.test.runner.AndroidJUnit4;
     24 import android.view.View;
     25 
     26 import androidx.core.test.R;
     27 import androidx.testutils.PollingCheck;
     28 
     29 import org.junit.Before;
     30 import org.junit.Rule;
     31 import org.junit.Test;
     32 import org.junit.runner.RunWith;
     33 
     34 /**
     35  * Tests for {@link ContentLoadingProgressBar}
     36  */
     37 @RunWith(AndroidJUnit4.class)
     38 public class ContentLoadingProgressBarTest {
     39     @Rule
     40     public final ActivityTestRule<ContentLoadingProgressBarActivity> mActivityTestRule;
     41 
     42     public ContentLoadingProgressBarTest() {
     43         mActivityTestRule = new ActivityTestRule<>(ContentLoadingProgressBarActivity.class);
     44     }
     45 
     46     private ContentLoadingProgressBar mContentLoadingProgressBar;
     47 
     48     @Before
     49     public void setUp() {
     50         mContentLoadingProgressBar = mActivityTestRule.getActivity().findViewById(R.id.progressBar);
     51     }
     52 
     53     @Test
     54     @LargeTest
     55     public void showAndThenLaterHide() {
     56         mContentLoadingProgressBar.show();
     57 
     58         PollingCheck.waitFor(new PollingCheck.PollingCheckCondition() {
     59             @Override
     60             public boolean canProceed() {
     61                 return mContentLoadingProgressBar.getVisibility() == View.VISIBLE;
     62             }
     63         });
     64 
     65         mContentLoadingProgressBar.hide();
     66 
     67         PollingCheck.waitFor(new PollingCheck.PollingCheckCondition() {
     68             @Override
     69             public boolean canProceed() {
     70                 return mContentLoadingProgressBar.getVisibility() == View.GONE;
     71             }
     72         });
     73     }
     74 
     75     @Test
     76     @LargeTest
     77     public void showAndImmediatelyHide() {
     78         mContentLoadingProgressBar.show();
     79         mContentLoadingProgressBar.hide();
     80 
     81         // show() followed immediately by hide() should leave the progress bar in GONE state
     82         assertEquals(mContentLoadingProgressBar.getVisibility(), View.GONE);
     83 
     84         // The next show() should eventually show the progress bar
     85         mContentLoadingProgressBar.show();
     86         PollingCheck.waitFor(new PollingCheck.PollingCheckCondition() {
     87             @Override
     88             public boolean canProceed() {
     89                 return mContentLoadingProgressBar.getVisibility() == View.VISIBLE;
     90             }
     91         });
     92 
     93 
     94         // The next hide() should eventually hide the progress bar
     95         mContentLoadingProgressBar.hide();
     96         PollingCheck.waitFor(new PollingCheck.PollingCheckCondition() {
     97             @Override
     98             public boolean canProceed() {
     99                 return mContentLoadingProgressBar.getVisibility() == View.GONE;
    100             }
    101         });
    102     }
    103 }
    104