1/* 2 * Copyright (C) 2015 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.test; 18 19import android.app.Activity; 20import android.content.Intent; 21import android.test.AndroidTestCase; 22import android.test.suitebuilder.annotation.SmallTest; 23 24import com.android.setupwizardlib.util.WizardManagerHelper; 25 26public class WizardManagerHelperTest extends AndroidTestCase { 27 28 @SmallTest 29 public void testGetNextIntent() { 30 final Intent intent = new Intent("test.intent.ACTION"); 31 intent.putExtra("scriptUri", "android-resource://test-script"); 32 intent.putExtra("actionId", "test_action_id"); 33 intent.putExtra("theme", "test_theme"); 34 intent.putExtra("ignoreExtra", "poof"); // extra is ignored because it's not known 35 36 final Intent data = new Intent(); 37 data.putExtra("extraData", "shazam"); 38 39 final Intent nextIntent = 40 WizardManagerHelper.getNextIntent(intent, Activity.RESULT_OK, data); 41 assertEquals("Next intent action should be NEXT", "com.android.wizard.NEXT", 42 nextIntent.getAction()); 43 assertEquals("Script URI should be the same as original intent", 44 "android-resource://test-script", nextIntent.getStringExtra("scriptUri")); 45 assertEquals("Action ID should be the same as original intent", "test_action_id", 46 nextIntent.getStringExtra("actionId")); 47 assertEquals("Theme extra should be the same as original intent", "test_theme", 48 nextIntent.getStringExtra("theme")); 49 assertFalse("ignoreExtra should not be in nextIntent", nextIntent.hasExtra("ignoreExtra")); 50 assertEquals("Result code extra should be RESULT_OK", Activity.RESULT_OK, 51 nextIntent.getIntExtra("com.android.setupwizard.ResultCode", 0)); 52 assertEquals("Extra data should surface as extra in nextIntent", "shazam", 53 nextIntent.getStringExtra("extraData")); 54 } 55 56 @SmallTest 57 public void testIsSetupWizardTrue() { 58 final Intent intent = new Intent(); 59 intent.putExtra("firstRun", true); 60 assertTrue("Is setup wizard should be true", 61 WizardManagerHelper.isSetupWizardIntent(intent)); 62 } 63 64 @SmallTest 65 public void testIsSetupWizardFalse() { 66 final Intent intent = new Intent(); 67 intent.putExtra("firstRun", false); 68 assertFalse("Is setup wizard should be true", 69 WizardManagerHelper.isSetupWizardIntent(intent)); 70 } 71 72 @SmallTest 73 public void testHoloIsNotLightTheme() { 74 final Intent intent = new Intent(); 75 intent.putExtra("theme", "holo"); 76 assertFalse("Theme holo should not be light theme", 77 WizardManagerHelper.isLightTheme(intent, true)); 78 } 79 80 @SmallTest 81 public void testHoloLightIsLightTheme() { 82 final Intent intent = new Intent(); 83 intent.putExtra("theme", "holo_light"); 84 assertTrue("Theme holo_light should be light theme", 85 WizardManagerHelper.isLightTheme(intent, false)); 86 } 87 88 @SmallTest 89 public void testMaterialIsNotLightTheme() { 90 final Intent intent = new Intent(); 91 intent.putExtra("theme", "material"); 92 assertFalse("Theme material should not be light theme", 93 WizardManagerHelper.isLightTheme(intent, true)); 94 } 95 96 @SmallTest 97 public void testMaterialLightIsLightTheme() { 98 final Intent intent = new Intent(); 99 intent.putExtra("theme", "material_light"); 100 assertTrue("Theme material_light should be light theme", 101 WizardManagerHelper.isLightTheme(intent, false)); 102 } 103 104 @SmallTest 105 public void testMaterialBlueIsNotLightTheme() { 106 final Intent intent = new Intent(); 107 intent.putExtra("theme", "material_blue"); 108 assertFalse("Theme material_blue should not be light theme", 109 WizardManagerHelper.isLightTheme(intent, true)); 110 } 111 112 @SmallTest 113 public void testMaterialBlueLightIsLightTheme() { 114 final Intent intent = new Intent(); 115 intent.putExtra("theme", "material_blue_light"); 116 assertTrue("Theme material_blue_light should be light theme", 117 WizardManagerHelper.isLightTheme(intent, false)); 118 } 119 120 @SmallTest 121 public void testGlifIsDarkTheme() { 122 final Intent intent = new Intent(); 123 intent.putExtra("theme", "glif"); 124 assertFalse("Theme glif should be dark theme", 125 WizardManagerHelper.isLightTheme(intent, false)); 126 assertFalse("Theme glif should be dark theme", 127 WizardManagerHelper.isLightTheme(intent, true)); 128 } 129 130 @SmallTest 131 public void testGlifLightIsLightTheme() { 132 final Intent intent = new Intent(); 133 intent.putExtra("theme", "glif_light"); 134 assertTrue("Theme glif_light should be light theme", 135 WizardManagerHelper.isLightTheme(intent, false)); 136 assertTrue("Theme glif_light should be light theme", 137 WizardManagerHelper.isLightTheme(intent, true)); 138 } 139 140 @SmallTest 141 public void testIsLightThemeDefault() { 142 final Intent intent = new Intent(); 143 intent.putExtra("theme", "abracadabra"); 144 assertTrue("isLightTheme should return default value true", 145 WizardManagerHelper.isLightTheme(intent, true)); 146 assertFalse("isLightTheme should return default value false", 147 WizardManagerHelper.isLightTheme(intent, false)); 148 } 149 150 @SmallTest 151 public void testIsLightThemeUnspecified() { 152 final Intent intent = new Intent(); 153 assertTrue("isLightTheme should return default value true", 154 WizardManagerHelper.isLightTheme(intent, true)); 155 assertFalse("isLightTheme should return default value false", 156 WizardManagerHelper.isLightTheme(intent, false)); 157 } 158 159 @SmallTest 160 public void testIsLightThemeString() { 161 assertTrue("isLightTheme should return true for material_light", 162 WizardManagerHelper.isLightTheme("material_light", false)); 163 assertFalse("isLightTheme should return false for material", 164 WizardManagerHelper.isLightTheme("material", false)); 165 assertTrue("isLightTheme should return true for holo_light", 166 WizardManagerHelper.isLightTheme("holo_light", false)); 167 assertFalse("isLightTheme should return false for holo", 168 WizardManagerHelper.isLightTheme("holo", false)); 169 assertTrue("isLightTheme should return default value true", 170 WizardManagerHelper.isLightTheme("abracadabra", true)); 171 assertFalse("isLightTheme should return default value false", 172 WizardManagerHelper.isLightTheme("abracadabra", false)); 173 } 174} 175