1/* 2 * Copyright (C) 2018 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; 23 24import android.app.Activity; 25import android.graphics.Color; 26import android.graphics.Typeface; 27import android.os.Build.VERSION; 28import android.os.Build.VERSION_CODES; 29import android.os.Bundle; 30import android.support.annotation.Nullable; 31import android.view.View; 32import android.widget.Button; 33 34import com.android.setupwizardlib.R; 35import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; 36 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(minSdk = Config.OLDEST_SDK, maxSdk = Config.NEWEST_SDK) 44public class GlifV3StyleTest { 45 46 @Test 47 public void activityWithGlifV3Theme_shouldUseLightNavBarOnV27OrAbove() { 48 GlifThemeActivity activity = Robolectric.setupActivity(GlifThemeActivity.class); 49 if (VERSION.SDK_INT >= VERSION_CODES.O_MR1) { 50 assertEquals( 51 activity.getWindow().getNavigationBarColor(), 52 Color.WHITE); 53 int vis = activity.getWindow().getDecorView().getSystemUiVisibility(); 54 assertTrue((vis & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) != 0); 55 } else if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { 56 assertEquals( 57 activity.getWindow().getNavigationBarColor(), 58 Color.BLACK); 59 } 60 // Nav bar color is not customizable pre-L 61 } 62 63 @Test 64 public void buttonWithGlifV3_shouldBeGoogleSans() { 65 GlifThemeActivity activity = Robolectric.setupActivity(GlifThemeActivity.class); 66 Button button = new Button( 67 activity, 68 Robolectric.buildAttributeSet() 69 .setStyleAttribute("@style/SuwGlifButton.Primary") 70 .build()); 71 assertThat(button.getTypeface()).isEqualTo(Typeface.create("google-sans", 0)); 72 // Button should not be all caps 73 assertThat(button.getTransformationMethod()).isNull(); 74 } 75 76 private static class GlifThemeActivity extends Activity { 77 78 @Override 79 protected void onCreate(@Nullable Bundle savedInstanceState) { 80 setTheme(R.style.SuwThemeGlifV3_Light); 81 super.onCreate(savedInstanceState); 82 } 83 } 84} 85