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 com.google.common.truth.Truth.assertThat; 20 21import static org.junit.Assert.assertEquals; 22import static org.junit.Assert.assertTrue; 23import static org.robolectric.RuntimeEnvironment.application; 24 25import android.annotation.TargetApi; 26import android.app.Activity; 27import android.content.Context; 28import android.os.Build.VERSION; 29import android.os.Build.VERSION_CODES; 30import android.os.Bundle; 31import android.support.annotation.Nullable; 32import android.view.ContextThemeWrapper; 33import android.widget.Button; 34import android.widget.ProgressBar; 35 36import com.android.setupwizardlib.R; 37import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; 38 39import org.junit.Before; 40import org.junit.Test; 41import org.junit.runner.RunWith; 42import org.robolectric.Robolectric; 43import org.robolectric.annotation.Config; 44 45@RunWith(SuwLibRobolectricTestRunner.class) 46@Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) 47public class GlifStyleTest { 48 49 private Context mContext; 50 51 @Before 52 public void setUp() { 53 mContext = new ContextThemeWrapper(application, R.style.SuwThemeGlif_Light); 54 } 55 56 @Test 57 public void testSuwGlifButtonTertiary() { 58 Button button = new Button( 59 mContext, 60 Robolectric.buildAttributeSet() 61 .setStyleAttribute("@style/SuwGlifButton.Tertiary") 62 .build()); 63 assertThat(button.getBackground()).named("background").isNotNull(); 64 assertThat(button.getTransformationMethod()).named("transformation method").isNull(); 65 if (VERSION.SDK_INT < VERSION_CODES.M) { 66 // Robolectric resolved the wrong theme attribute on versions >= M 67 // https://github.com/robolectric/robolectric/issues/2940 68 assertEquals("ff4285f4", Integer.toHexString(button.getTextColors().getDefaultColor())); 69 } 70 } 71 72 @TargetApi(VERSION_CODES.LOLLIPOP) 73 @Config(sdk = Config.NEWEST_SDK) 74 @Test 75 public void glifThemeLight_statusBarColorShouldBeTransparent() { 76 GlifThemeActivity activity = Robolectric.setupActivity(GlifThemeActivity.class); 77 assertEquals(0x00000000, activity.getWindow().getStatusBarColor()); 78 } 79 80 @Test 81 public void glifLoadingScreen_shouldHaveProgressBar() { 82 GlifThemeActivity activity = Robolectric.setupActivity(GlifThemeActivity.class); 83 activity.setContentView(R.layout.suw_glif_loading_screen); 84 85 assertTrue("Progress bar should exist", 86 activity.findViewById(R.id.suw_large_progress_bar) instanceof ProgressBar); 87 } 88 89 private static class GlifThemeActivity extends Activity { 90 91 @Override 92 protected void onCreate(@Nullable Bundle savedInstanceState) { 93 setTheme(R.style.SuwThemeGlif_Light); 94 super.onCreate(savedInstanceState); 95 } 96 } 97} 98