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 17package com.android.setupwizardlib.test; 18 19import android.content.Context; 20import android.graphics.drawable.ShapeDrawable; 21import android.test.AndroidTestCase; 22import android.test.suitebuilder.annotation.SmallTest; 23 24import com.android.setupwizardlib.view.StatusBarBackgroundLayout; 25 26public class StatusBarBackgroundLayoutTest extends AndroidTestCase { 27 28 @SmallTest 29 public void testSetStatusBarBackground() { 30 final StatusBarBackgroundLayout layout = new StatusBarBackgroundLayout(getContext()); 31 final ShapeDrawable drawable = new ShapeDrawable(); 32 layout.setStatusBarBackground(drawable); 33 assertSame("Status bar background drawable should be same as set", 34 drawable, layout.getStatusBarBackground()); 35 } 36 37 @SmallTest 38 public void testAttachedToWindow() { 39 // Attaching to window should request apply window inset 40 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { 41 final TestStatusBarBackgroundLayout layout = 42 new TestStatusBarBackgroundLayout(getContext()); 43 layout.mRequestApplyInsets = false; 44 layout.onAttachedToWindow(); 45 46 assertTrue("Attaching to window should apply window inset", layout.mRequestApplyInsets); 47 } 48 } 49 50 private static class TestStatusBarBackgroundLayout extends StatusBarBackgroundLayout { 51 52 boolean mRequestApplyInsets = false; 53 54 TestStatusBarBackgroundLayout(Context context) { 55 super(context); 56 } 57 58 @Override 59 public void onAttachedToWindow() { 60 super.onAttachedToWindow(); 61 } 62 63 @Override 64 public void requestApplyInsets() { 65 super.requestApplyInsets(); 66 mRequestApplyInsets = true; 67 } 68 } 69} 70