• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.password.ChooseLockPattern.ChooseLockPatternFragment;
29 import com.android.settings.password.ChooseLockPattern.IntentBuilder;
30 import com.android.settings.password.SetupChooseLockPattern;
31 import com.android.settings.testutils.SettingsRobolectricTestRunner;
32 import com.android.settings.testutils.shadow.SettingsShadowResources;
33 import com.android.settings.testutils.shadow.ShadowEventLogWriter;
34 import com.android.settings.testutils.shadow.ShadowUtils;
35 
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.robolectric.Robolectric;
40 import org.robolectric.RuntimeEnvironment;
41 import org.robolectric.annotation.Config;
42 import org.robolectric.res.builder.RobolectricPackageManager.ComponentState;
43 
44 @RunWith(SettingsRobolectricTestRunner.class)
45 @Config(
46         manifest = TestConfig.MANIFEST_PATH,
47         sdk = TestConfig.SDK_VERSION,
48         shadows = {
49                 SettingsShadowResources.class,
50                 SettingsShadowResources.SettingsShadowTheme.class,
51                 ShadowEventLogWriter.class,
52                 ShadowUtils.class
53         })
54 public class SetupChooseLockPatternTest {
55 
56     private SetupChooseLockPattern mActivity;
57 
58     @Before
setUp()59     public void setUp() {
60         RuntimeEnvironment.getRobolectricPackageManager().setComponentEnabledSetting(
61                 new ComponentName(application, SetupRedactionInterstitial.class),
62                 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
63                 PackageManager.DONT_KILL_APP);
64 
65         mActivity =  Robolectric.buildActivity(
66                 SetupChooseLockPattern.class,
67                 SetupChooseLockPattern.modifyIntentForSetup(
68                         application,
69                         new IntentBuilder(application)
70                                 .setUserId(UserHandle.myUserId())
71                                 .build()))
72                 .setup().get();
73     }
74 
75     @Test
chooseLockSaved_shouldEnableRedactionInterstitial()76     public void chooseLockSaved_shouldEnableRedactionInterstitial() {
77         findFragment(mActivity).onChosenLockSaveFinished(false, null);
78 
79         ComponentState redactionComponentState =
80                 RuntimeEnvironment.getRobolectricPackageManager().getComponentState(
81                         new ComponentName(application, SetupRedactionInterstitial.class));
82         assertThat(redactionComponentState.newState).named("Redaction component state")
83                 .isEqualTo(PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
84     }
85 
findFragment(Activity activity)86     private ChooseLockPatternFragment findFragment(Activity activity) {
87         return (ChooseLockPatternFragment)
88                 activity.getFragmentManager().findFragmentById(R.id.main_content);
89     }
90 }
91