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 import com.android.setupwizardlib.view.StatusBarBackgroundLayout; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 @RunWith(AndroidJUnit4.class) 32 @SmallTest 33 public class StatusBarBackgroundLayoutTest { 34 35 @Test testSetStatusBarBackground()36 public void testSetStatusBarBackground() { 37 final StatusBarBackgroundLayout layout = 38 new StatusBarBackgroundLayout(InstrumentationRegistry.getContext()); 39 final ShapeDrawable drawable = new ShapeDrawable(); 40 layout.setStatusBarBackground(drawable); 41 assertSame( 42 "Status bar background drawable should be same as set", 43 drawable, 44 layout.getStatusBarBackground()); 45 } 46 47 @Test testAttachedToWindow()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 TestStatusBarBackgroundLayout(Context context)64 TestStatusBarBackgroundLayout(Context context) { 65 super(context); 66 } 67 68 @Override onAttachedToWindow()69 public void onAttachedToWindow() { 70 super.onAttachedToWindow(); 71 } 72 73 @Override requestApplyInsets()74 public void requestApplyInsets() { 75 super.requestApplyInsets(); 76 mRequestApplyInsets = true; 77 } 78 } 79 } 80