1 /* 2 * Copyright (C) 2016 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 17 package com.android.settings; 18 19 import static com.android.settings.testutils.ResIdSubject.assertResId; 20 import static com.google.common.truth.Truth.assertThat; 21 22 import android.content.Intent; 23 import android.os.SystemProperties; 24 25 import com.android.settings.testutils.SettingsRobolectricTestRunner; 26 import com.android.setupwizardlib.util.WizardManagerHelper; 27 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 @RunWith(SettingsRobolectricTestRunner.class) 32 public class SetupWizardUtilsTest { 33 34 @Test testCopySetupExtras()35 public void testCopySetupExtras() throws Throwable { 36 Intent fromIntent = new Intent(); 37 final String theme = "TEST_THEME"; 38 fromIntent.putExtra(WizardManagerHelper.EXTRA_THEME, theme); 39 fromIntent.putExtra(WizardManagerHelper.EXTRA_USE_IMMERSIVE_MODE, true); 40 Intent toIntent = new Intent(); 41 SetupWizardUtils.copySetupExtras(fromIntent, toIntent); 42 43 assertThat(theme).isEqualTo(toIntent.getStringExtra(WizardManagerHelper.EXTRA_THEME)); 44 assertThat(toIntent.getBooleanExtra(WizardManagerHelper.EXTRA_USE_IMMERSIVE_MODE, false)) 45 .isTrue(); 46 } 47 48 @Test testGetTheme_withIntentExtra_shouldReturnExtraTheme()49 public void testGetTheme_withIntentExtra_shouldReturnExtraTheme() { 50 SystemProperties.set(SetupWizardUtils.SYSTEM_PROP_SETUPWIZARD_THEME, 51 WizardManagerHelper.THEME_GLIF); 52 Intent intent = new Intent(); 53 intent.putExtra(WizardManagerHelper.EXTRA_THEME, WizardManagerHelper.THEME_GLIF_V2); 54 55 assertResId(SetupWizardUtils.getTheme(intent)).isEqualTo(R.style.GlifV2Theme); 56 } 57 58 @Test testGetTheme_withEmptyIntent_shouldReturnSystemProperty()59 public void testGetTheme_withEmptyIntent_shouldReturnSystemProperty() { 60 SystemProperties.set(SetupWizardUtils.SYSTEM_PROP_SETUPWIZARD_THEME, 61 WizardManagerHelper.THEME_GLIF_V2_LIGHT); 62 Intent intent = new Intent(); 63 64 assertResId(SetupWizardUtils.getTheme(intent)).isEqualTo(R.style.GlifV2Theme_Light); 65 } 66 67 @Test testGetTheme_glifV3Light_shouldReturnThemeResource()68 public void testGetTheme_glifV3Light_shouldReturnThemeResource() { 69 SystemProperties.set(SetupWizardUtils.SYSTEM_PROP_SETUPWIZARD_THEME, 70 WizardManagerHelper.THEME_GLIF_V3_LIGHT); 71 Intent intent = new Intent(); 72 73 assertResId(SetupWizardUtils.getTheme(intent)).isEqualTo(R.style.GlifV3Theme_Light); 74 assertResId(SetupWizardUtils.getTransparentTheme(intent)) 75 .isEqualTo(R.style.GlifV3Theme_Light_Transparent); 76 } 77 } 78