GlifStyleTest.java revision 66815fe66392bcbb12e2fc93bbf326a5c2d8782f
1/* 2 * Copyright (C) 2017 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.util; 18 19import static org.junit.Assert.assertEquals; 20import static org.junit.Assert.assertNull; 21import static org.robolectric.RuntimeEnvironment.application; 22 23import android.annotation.TargetApi; 24import android.app.Activity; 25import android.content.Context; 26import android.os.Build.VERSION; 27import android.os.Build.VERSION_CODES; 28import android.os.Bundle; 29import android.support.annotation.Nullable; 30import android.view.ContextThemeWrapper; 31import android.widget.Button; 32 33import com.android.setupwizardlib.R; 34import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; 35 36import org.junit.Before; 37import org.junit.Test; 38import org.junit.runner.RunWith; 39import org.robolectric.Robolectric; 40import org.robolectric.annotation.Config; 41 42@RunWith(SuwLibRobolectricTestRunner.class) 43@Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) 44public class GlifStyleTest { 45 46 private Context mContext; 47 48 @Before 49 public void setUp() { 50 mContext = new ContextThemeWrapper(application, R.style.SuwThemeGlif_Light); 51 } 52 53 @Test 54 public void testSuwGlifButtonTertiary() { 55 Button button = new Button( 56 mContext, 57 Robolectric.buildAttributeSet() 58 .setStyleAttribute("@style/SuwGlifButton.Tertiary") 59 .build()); 60 assertNull("Background of tertiary button should be null", button.getBackground()); 61 assertNull("Tertiary button should have no transformation method", 62 button.getTransformationMethod()); 63 if (VERSION.SDK_INT < VERSION_CODES.M) { 64 // Robolectric resolved the wrong theme attribute on versions >= M 65 // https://github.com/robolectric/robolectric/issues/2940 66 assertEquals("ff4285f4", Integer.toHexString(button.getTextColors().getDefaultColor())); 67 } 68 } 69 70 @TargetApi(VERSION_CODES.LOLLIPOP) 71 @Config(sdk = Config.NEWEST_SDK) 72 @Test 73 public void glifThemeLight_statusBarColorShouldBeTransparent() { 74 GlifThemeActivity activity = Robolectric.setupActivity(GlifThemeActivity.class); 75 assertEquals(0x00000000, activity.getWindow().getStatusBarColor()); 76 } 77 78 private static class GlifThemeActivity extends Activity { 79 80 @Override 81 protected void onCreate(@Nullable Bundle savedInstanceState) { 82 setTheme(R.style.SuwThemeGlif_Light); 83 super.onCreate(savedInstanceState); 84 } 85 } 86} 87