GlifStyleTest.java revision ceea5ff728985c6a43c7c6de61ed2b7f530db483
14ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam/* 24ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * Copyright (C) 2017 The Android Open Source Project 34ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * 44ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * Licensed under the Apache License, Version 2.0 (the "License"); 54ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * you may not use this file except in compliance with the License. 64ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * You may obtain a copy of the License at 74ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * 84ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * http://www.apache.org/licenses/LICENSE-2.0 94ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * 104ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * Unless required by applicable law or agreed to in writing, software 114ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * distributed under the License is distributed on an "AS IS" BASIS, 124ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * See the License for the specific language governing permissions and 144ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam * limitations under the License. 154ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam */ 164ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam 174ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lampackage com.android.setupwizardlib.util; 184ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam 194ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport static org.junit.Assert.assertEquals; 204ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport static org.junit.Assert.assertNull; 21ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lamimport static org.junit.Assert.assertTrue; 224ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport static org.robolectric.RuntimeEnvironment.application; 234ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam 24c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lamimport android.annotation.TargetApi; 25c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lamimport android.app.Activity; 264ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport android.content.Context; 274ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport android.os.Build.VERSION; 284ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport android.os.Build.VERSION_CODES; 29c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lamimport android.os.Bundle; 30c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lamimport android.support.annotation.Nullable; 314ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport android.view.ContextThemeWrapper; 324ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport android.widget.Button; 33ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lamimport android.widget.ProgressBar; 344ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam 354ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport com.android.setupwizardlib.BuildConfig; 364ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport com.android.setupwizardlib.R; 374ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; 384ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam 394ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport org.junit.Before; 404ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport org.junit.Test; 414ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport org.junit.runner.RunWith; 424ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport org.robolectric.Robolectric; 434ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport org.robolectric.annotation.Config; 444ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam 454ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam@RunWith(SuwLibRobolectricTestRunner.class) 464ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam@Config(constants = BuildConfig.class, sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) 474ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lampublic class GlifStyleTest { 484ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam 494ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam private Context mContext; 504ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam 514ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam @Before 524ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam public void setUp() { 534ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam mContext = new ContextThemeWrapper(application, R.style.SuwThemeGlif_Light); 544ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam } 554ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam 564ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam @Test 574ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam public void testSuwGlifButtonTertiary() { 584ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam Button button = new Button( 594ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam mContext, 604ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam Robolectric.buildAttributeSet() 614ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam .setStyleAttribute("@style/SuwGlifButton.Tertiary") 624ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam .build()); 634ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam assertNull("Background of tertiary button should be null", button.getBackground()); 644ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam assertNull("Tertiary button should have no transformation method", 654ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam button.getTransformationMethod()); 664ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam if (VERSION.SDK_INT < VERSION_CODES.M) { 674ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam // Robolectric resolved the wrong theme attribute on versions >= M 684ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam // https://github.com/robolectric/robolectric/issues/2940 694ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam assertEquals("ff4285f4", Integer.toHexString(button.getTextColors().getDefaultColor())); 704ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam } 714ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam } 72c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam 73c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam @TargetApi(VERSION_CODES.LOLLIPOP) 74c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam @Config(sdk = Config.NEWEST_SDK) 75c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam @Test 76c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam public void glifThemeLight_statusBarColorShouldBeTransparent() { 77c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam GlifThemeActivity activity = Robolectric.setupActivity(GlifThemeActivity.class); 78c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam assertEquals(0x00000000, activity.getWindow().getStatusBarColor()); 79c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam } 80c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam 81ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam @Test 82ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam public void glifLoadingScreen_shouldHaveProgressBar() { 83ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam GlifThemeActivity activity = Robolectric.setupActivity(GlifThemeActivity.class); 84ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam activity.setContentView(R.layout.suw_glif_loading_screen); 85ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam 86ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam assertTrue("Progress bar should exist", 87ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam activity.findViewById(R.id.suw_large_progress_bar) instanceof ProgressBar); 88ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam } 89ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam 90c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam private static class GlifThemeActivity extends Activity { 91c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam 92c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam @Override 93c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam protected void onCreate(@Nullable Bundle savedInstanceState) { 94c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam setTheme(R.style.SuwThemeGlif_Light); 95c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam super.onCreate(savedInstanceState); 96c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam } 97c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam } 984ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam} 99