• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.gestures;
18 
19 import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_LAUNCH_CAMERA_MODE;
20 import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_MULTI_TARGET_MODE;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 
24 import android.platform.test.annotations.DisableFlags;
25 import android.platform.test.annotations.EnableFlags;
26 import android.platform.test.flag.junit.SetFlagsRule;
27 import android.provider.SearchIndexableResource;
28 import android.service.quickaccesswallet.Flags;
29 
30 import com.android.settings.R;
31 import com.android.settings.testutils.shadow.SettingsShadowResources;
32 
33 import org.junit.Before;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.robolectric.RobolectricTestRunner;
38 import org.robolectric.RuntimeEnvironment;
39 import org.robolectric.annotation.Config;
40 
41 import java.util.List;
42 
43 @Config(shadows = SettingsShadowResources.class)
44 @RunWith(RobolectricTestRunner.class)
45 public class DoubleTapPowerSettingsTest {
46 
47     @Rule
48     public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
49     private DoubleTapPowerSettings mSettings;
50 
51     @Before
setUp()52     public void setUp() {
53         mSettings = new DoubleTapPowerSettings();
54     }
55 
56     @Test
57     @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
58     public void
getPreferenceScreenResId_flagEnabled_configIsMultiTargetMode_returnsMultiTargetResId()59             getPreferenceScreenResId_flagEnabled_configIsMultiTargetMode_returnsMultiTargetResId() {
60         SettingsShadowResources.overrideResource(
61                 com.android.internal.R.integer.config_doubleTapPowerGestureMode,
62                 DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
63         mSettings.onAttach(RuntimeEnvironment.getApplication());
64 
65         assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.double_tap_power_settings);
66     }
67 
68     @Test
69     @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
70     public void
getPreferenceScreenResId_flagEnabled_configIsCameraMode_returnsCameraLaunchResId()71             getPreferenceScreenResId_flagEnabled_configIsCameraMode_returnsCameraLaunchResId() {
72         SettingsShadowResources.overrideResource(
73                 com.android.internal.R.integer.config_doubleTapPowerGestureMode,
74                 DOUBLE_TAP_POWER_LAUNCH_CAMERA_MODE);
75         mSettings.onAttach(RuntimeEnvironment.getApplication());
76 
77         assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(
78                 R.xml.double_tap_power_to_open_camera_settings);
79     }
80 
81     @Test
82     @DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
getPreferenceScreenResId_flagDisabled_returnsFlagDisabledResId()83     public void getPreferenceScreenResId_flagDisabled_returnsFlagDisabledResId() {
84         assertThat(mSettings.getPreferenceScreenResId())
85                 .isEqualTo(R.xml.double_tap_power_to_open_camera_settings);
86     }
87 
88     @Test
89     @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
90     public void
testSearchIndexProvider_flagEnabled_configIsMultiTargetMode_indexMultiTargetResId()91             testSearchIndexProvider_flagEnabled_configIsMultiTargetMode_indexMultiTargetResId() {
92         SettingsShadowResources.overrideResource(
93                 com.android.internal.R.integer.config_doubleTapPowerGestureMode,
94                 DOUBLE_TAP_POWER_MULTI_TARGET_MODE);
95 
96         final List<SearchIndexableResource> indexRes =
97                 DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
98                         RuntimeEnvironment.getApplication(), true /* enabled */);
99 
100         assertThat(indexRes).isNotNull();
101         assertThat(indexRes.get(0).xmlResId).isEqualTo(R.xml.double_tap_power_settings);
102     }
103 
104     @Test
105     @EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
106     public void
testSearchIndexProvider_flagEnabled_configIsCameraLaunchMode_indexCameraLaunchResId()107             testSearchIndexProvider_flagEnabled_configIsCameraLaunchMode_indexCameraLaunchResId() {
108         SettingsShadowResources.overrideResource(
109                 com.android.internal.R.integer.config_doubleTapPowerGestureMode,
110                 DOUBLE_TAP_POWER_LAUNCH_CAMERA_MODE);
111 
112         final List<SearchIndexableResource> indexRes =
113                 DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
114                         RuntimeEnvironment.getApplication(), true /* enabled */);
115 
116         assertThat(indexRes).isNotNull();
117         assertThat(indexRes.get(0).xmlResId).isEqualTo(
118                 R.xml.double_tap_power_to_open_camera_settings);
119     }
120 
121     @Test
122     @DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
testSearchIndexProvider_flagDisabled_indexFlagDisabledResource()123     public void testSearchIndexProvider_flagDisabled_indexFlagDisabledResource() {
124         final List<SearchIndexableResource> indexRes =
125                 DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
126                         RuntimeEnvironment.getApplication(), true /* enabled */);
127 
128         assertThat(indexRes).isNotNull();
129         assertThat(indexRes.get(0).xmlResId)
130                 .isEqualTo(R.xml.double_tap_power_to_open_camera_settings);
131     }
132 }
133