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 1915d9037e89d502c7deb9cbf81c0407d433a5706bMaurice Lamimport static com.google.common.truth.Truth.assertThat; 2015d9037e89d502c7deb9cbf81c0407d433a5706bMaurice Lam 214ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport static org.junit.Assert.assertEquals; 22ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lamimport static org.junit.Assert.assertTrue; 234ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport static org.robolectric.RuntimeEnvironment.application; 244ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam 25c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lamimport android.annotation.TargetApi; 26c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lamimport android.app.Activity; 274ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport android.content.Context; 284ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport android.os.Build.VERSION; 294ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport android.os.Build.VERSION_CODES; 30c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lamimport android.os.Bundle; 31c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lamimport android.support.annotation.Nullable; 324ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport android.view.ContextThemeWrapper; 334ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lamimport android.widget.Button; 34ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lamimport android.widget.ProgressBar; 354ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam 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) 4666815fe66392bcbb12e2fc93bbf326a5c2d8782fMaurice Lam@Config(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()); 6315d9037e89d502c7deb9cbf81c0407d433a5706bMaurice Lam assertThat(button.getBackground()).named("background").isNotNull(); 6415d9037e89d502c7deb9cbf81c0407d433a5706bMaurice Lam assertThat(button.getTransformationMethod()).named("transformation method").isNull(); 654ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam if (VERSION.SDK_INT < VERSION_CODES.M) { 664ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam // Robolectric resolved the wrong theme attribute on versions >= M 674ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam // https://github.com/robolectric/robolectric/issues/2940 684ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam assertEquals("ff4285f4", Integer.toHexString(button.getTextColors().getDefaultColor())); 694ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam } 704ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam } 71c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam 72c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam @TargetApi(VERSION_CODES.LOLLIPOP) 73c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam @Config(sdk = Config.NEWEST_SDK) 74c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam @Test 75c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam public void glifThemeLight_statusBarColorShouldBeTransparent() { 76c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam GlifThemeActivity activity = Robolectric.setupActivity(GlifThemeActivity.class); 77c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam assertEquals(0x00000000, activity.getWindow().getStatusBarColor()); 78c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam } 79c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam 80ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam @Test 81ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam public void glifLoadingScreen_shouldHaveProgressBar() { 82ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam GlifThemeActivity activity = Robolectric.setupActivity(GlifThemeActivity.class); 83ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam activity.setContentView(R.layout.suw_glif_loading_screen); 84ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam 85ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam assertTrue("Progress bar should exist", 86ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam activity.findViewById(R.id.suw_large_progress_bar) instanceof ProgressBar); 87ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam } 88ceea5ff728985c6a43c7c6de61ed2b7f530db483Maurice Lam 89c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam private static class GlifThemeActivity extends Activity { 90c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam 91c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam @Override 92c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam protected void onCreate(@Nullable Bundle savedInstanceState) { 93c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam setTheme(R.style.SuwThemeGlif_Light); 94c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam super.onCreate(savedInstanceState); 95c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam } 96c072bc26cd2709a2cfcdeb36e3c45c35fdaaf01bMaurice Lam } 974ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dcMaurice Lam} 98