1 /* 2 * Copyright (C) 2017 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.google.common.truth.Truth.assertThat; 20 21 import static org.robolectric.RuntimeEnvironment.application; 22 23 import android.app.Activity; 24 import android.content.ComponentName; 25 import android.content.pm.PackageManager; 26 import android.os.UserHandle; 27 28 import com.android.settings.ChooseLockPattern.ChooseLockPatternFragment; 29 import com.android.settings.testutils.shadow.SettingsShadowResources; 30 import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor; 31 import com.android.settings.testutils.shadow.ShadowEventLogWriter; 32 import com.android.settings.testutils.shadow.ShadowUtils; 33 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 import org.robolectric.Robolectric; 38 import org.robolectric.RuntimeEnvironment; 39 import org.robolectric.annotation.Config; 40 import org.robolectric.res.builder.RobolectricPackageManager.ComponentState; 41 42 @RunWith(SettingsRobolectricTestRunner.class) 43 @Config( 44 manifest = TestConfig.MANIFEST_PATH, 45 sdk = TestConfig.SDK_VERSION, 46 shadows = { 47 SettingsShadowResources.class, 48 SettingsShadowResources.SettingsShadowTheme.class, 49 ShadowDynamicIndexableContentMonitor.class, 50 ShadowEventLogWriter.class, 51 ShadowUtils.class 52 }) 53 public class SetupChooseLockPatternTest { 54 55 private SetupChooseLockPattern mActivity; 56 57 @Before setUp()58 public void setUp() { 59 RuntimeEnvironment.getRobolectricPackageManager().setComponentEnabledSetting( 60 new ComponentName(application, SetupRedactionInterstitial.class), 61 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 62 PackageManager.DONT_KILL_APP); 63 64 mActivity = Robolectric.buildActivity( 65 SetupChooseLockPattern.class, 66 SetupChooseLockPattern.createIntent( 67 application, 68 false, /* requirePassword */ 69 false, /* confirmCredentials */ 70 UserHandle.myUserId())) 71 .setup().get(); 72 } 73 74 @Test chooseLockSaved_shouldEnableRedactionInterstitial()75 public void chooseLockSaved_shouldEnableRedactionInterstitial() { 76 findFragment(mActivity).onChosenLockSaveFinished(false, null); 77 78 ComponentState redactionComponentState = 79 RuntimeEnvironment.getRobolectricPackageManager().getComponentState( 80 new ComponentName(application, SetupRedactionInterstitial.class)); 81 assertThat(redactionComponentState.newState).named("Redaction component state") 82 .isEqualTo(PackageManager.COMPONENT_ENABLED_STATE_ENABLED); 83 } 84 findFragment(Activity activity)85 private ChooseLockPatternFragment findFragment(Activity activity) { 86 return (ChooseLockPatternFragment) 87 activity.getFragmentManager().findFragmentById(R.id.main_content); 88 } 89 } 90