WizardManagerHelperTest.java revision 56a19113d248d9ffdb462a0af6ba8a967635be66
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 = WizardManagerHelper.getNextIntent(intent, Activity.RESULT_OK, data); 40 assertEquals("Next intent action should be NEXT", "com.android.wizard.NEXT", 41 nextIntent.getAction()); 42 assertEquals("Script URI should be the same as original intent", 43 "android-resource://test-script", nextIntent.getStringExtra("scriptUri")); 44 assertEquals("Action ID should be the same as original intent", "test_action_id", 45 nextIntent.getStringExtra("actionId")); 46 assertEquals("Theme extra should be the same as original intent", "test_theme", 47 nextIntent.getStringExtra("theme")); 48 assertFalse("ignoreExtra should not be in nextIntent", nextIntent.hasExtra("ignoreExtra")); 49 assertEquals("Result code extra should be RESULT_OK", Activity.RESULT_OK, 50 nextIntent.getIntExtra("com.android.setupwizard.ResultCode", 0)); 51 assertEquals("Extra data should surface as extra in nextIntent", "shazam", 52 nextIntent.getStringExtra("extraData")); 53 } 54 55 @SmallTest 56 public void testIsSetupWizardTrue() { 57 final Intent intent = new Intent(); 58 intent.putExtra("firstRun", true); 59 assertTrue("Is setup wizard should be true", 60 WizardManagerHelper.isSetupWizardIntent(intent)); 61 } 62 63 @SmallTest 64 public void testIsSetupWizardFalse() { 65 final Intent intent = new Intent(); 66 intent.putExtra("firstRun", false); 67 assertFalse("Is setup wizard should be true", 68 WizardManagerHelper.isSetupWizardIntent(intent)); 69 } 70 71 @SmallTest 72 public void testHoloIsNotLightTheme() { 73 final Intent intent = new Intent(); 74 intent.putExtra("theme", "holo"); 75 assertFalse("Theme holo should not be light theme", 76 WizardManagerHelper.isLightTheme(intent, true)); 77 } 78 79 @SmallTest 80 public void testHoloLightIsLightTheme() { 81 final Intent intent = new Intent(); 82 intent.putExtra("theme", "holo_light"); 83 assertTrue("Theme holo_light should be light theme", 84 WizardManagerHelper.isLightTheme(intent, false)); 85 } 86 87 @SmallTest 88 public void testMaterialIsNotLightTheme() { 89 final Intent intent = new Intent(); 90 intent.putExtra("theme", "material"); 91 assertFalse("Theme material should not be light theme", 92 WizardManagerHelper.isLightTheme(intent, true)); 93 } 94 95 @SmallTest 96 public void testMaterialLightIsLightTheme() { 97 final Intent intent = new Intent(); 98 intent.putExtra("theme", "material_light"); 99 assertTrue("Theme material_light should be light theme", 100 WizardManagerHelper.isLightTheme(intent, false)); 101 } 102 103 @SmallTest 104 public void testMaterialBlueIsNotLightTheme() { 105 final Intent intent = new Intent(); 106 intent.putExtra("theme", "material_blue"); 107 assertFalse("Theme material_blue should not be light theme", 108 WizardManagerHelper.isLightTheme(intent, true)); 109 } 110 111 @SmallTest 112 public void testMaterialBlueLightIsLightTheme() { 113 final Intent intent = new Intent(); 114 intent.putExtra("theme", "material_blue_light"); 115 assertTrue("Theme material_blue_light should be light theme", 116 WizardManagerHelper.isLightTheme(intent, false)); 117 } 118 119 @SmallTest 120 public void testIsLightThemeDefault() { 121 final Intent intent = new Intent(); 122 intent.putExtra("theme", "abracadabra"); 123 assertTrue("isLightTheme should return default value true", 124 WizardManagerHelper.isLightTheme(intent, true)); 125 assertFalse("isLightTheme should return default value false", 126 WizardManagerHelper.isLightTheme(intent, false)); 127 } 128 129 @SmallTest 130 public void testIsLightThemeUnspecified() { 131 final Intent intent = new Intent(); 132 assertTrue("isLightTheme should return default value true", 133 WizardManagerHelper.isLightTheme(intent, true)); 134 assertFalse("isLightTheme should return default value false", 135 WizardManagerHelper.isLightTheme(intent, false)); 136 } 137} 138