Home | History | Annotate | Download | only in test
      1 /*
      2  * Copyright (C) 2015 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.setupwizardlib.test;
     18 
     19 import static org.junit.Assert.assertSame;
     20 import static org.junit.Assert.assertTrue;
     21 
     22 import android.content.Context;
     23 import android.graphics.drawable.ShapeDrawable;
     24 import android.support.test.InstrumentationRegistry;
     25 import android.support.test.filters.SmallTest;
     26 import android.support.test.runner.AndroidJUnit4;
     27 
     28 import com.android.setupwizardlib.view.StatusBarBackgroundLayout;
     29 
     30 import org.junit.Test;
     31 import org.junit.runner.RunWith;
     32 
     33 @RunWith(AndroidJUnit4.class)
     34 @SmallTest
     35 public class StatusBarBackgroundLayoutTest {
     36 
     37     @Test
     38     public void testSetStatusBarBackground() {
     39         final StatusBarBackgroundLayout layout = new StatusBarBackgroundLayout(
     40                 InstrumentationRegistry.getContext());
     41         final ShapeDrawable drawable = new ShapeDrawable();
     42         layout.setStatusBarBackground(drawable);
     43         assertSame("Status bar background drawable should be same as set",
     44                 drawable, layout.getStatusBarBackground());
     45     }
     46 
     47     @Test
     48     public void testAttachedToWindow() {
     49         // Attaching to window should request apply window inset
     50         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
     51             final TestStatusBarBackgroundLayout layout =
     52                     new TestStatusBarBackgroundLayout(InstrumentationRegistry.getContext());
     53             layout.mRequestApplyInsets = false;
     54             layout.onAttachedToWindow();
     55 
     56             assertTrue("Attaching to window should apply window inset", layout.mRequestApplyInsets);
     57         }
     58     }
     59 
     60     private static class TestStatusBarBackgroundLayout extends StatusBarBackgroundLayout {
     61 
     62         boolean mRequestApplyInsets = false;
     63 
     64         TestStatusBarBackgroundLayout(Context context) {
     65             super(context);
     66         }
     67 
     68         @Override
     69         public void onAttachedToWindow() {
     70             super.onAttachedToWindow();
     71         }
     72 
     73         @Override
     74         public void requestApplyInsets() {
     75             super.requestApplyInsets();
     76             mRequestApplyInsets = true;
     77         }
     78     }
     79 }
     80