1 /*
2  * Copyright (C) 2023 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.ui.privatespace
18 
19 
20 import android.os.Flags
21 import android.platform.test.annotations.RequiresFlagsDisabled
22 import android.platform.test.annotations.RequiresFlagsEnabled
23 import android.platform.test.flag.junit.DeviceFlagsValueProvider
24 import android.provider.Settings
25 import android.util.Log
26 import androidx.test.ext.junit.runners.AndroidJUnit4
27 import androidx.test.platform.app.InstrumentationRegistry
28 import androidx.test.uiautomator.By
29 import androidx.test.uiautomator.UiDevice
30 import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts
31 import com.android.settings.ui.testutils.SettingsTestUtils.clickObject
32 import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
33 import com.android.settings.ui.testutils.SettingsTestUtils.waitObject
34 import org.junit.Before
35 import org.junit.Rule
36 import org.junit.Test
37 import org.junit.runner.RunWith
38 
39 
40 @RunWith(AndroidJUnit4::class)
41 @RequiresFlagsEnabled(Flags.FLAG_ALLOW_PRIVATE_PROFILE,
42         android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES)
43 class PrivateSpaceAuthenticationActivityTest {
44     private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
45 
46     @get:Rule
47     public val mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule()
48 
49     @Before
setUpnull50     fun setUp() {
51         device.startMainActivityFromHomeScreen(Settings.ACTION_SECURITY_SETTINGS)
52         device.assertHasTexts(listOf(PRIVATE_SPACE_SETTING))
53     }
54 
55     @Test
showAuthenticationScreennull56     fun showAuthenticationScreen() {
57         Thread.sleep(1000)
58         device.clickObject(By.text(PRIVATE_SPACE_SETTING))
59         device.waitObject(By.text(DIALOG_TITLE))
60         Thread.sleep(1000)
61         device.assertHasTexts(listOf("Set a screen lock","Cancel"))
62     }
63 
64     @Test
onCancelLockExitSetupnull65     fun onCancelLockExitSetup() {
66         Thread.sleep(1000)
67         device.clickObject(By.text(PRIVATE_SPACE_SETTING))
68         device.waitObject(By.text(DIALOG_TITLE))
69         Thread.sleep(1000)
70         device.assertHasTexts(listOf(SET_LOCK_BUTTON, CANCEL_TEXT))
71         device.clickObject(By.text(CANCEL_TEXT))
72         device.assertHasTexts(listOf(PRIVATE_SPACE_SETTING))
73     }
74 
75     @Test
onSetupSetLocknull76     fun onSetupSetLock() {
77         Thread.sleep(1000)
78         device.clickObject(By.text(PRIVATE_SPACE_SETTING))
79         device.waitObject(By.text(DIALOG_TITLE))
80         Thread.sleep(1000)
81         device.assertHasTexts(listOf(SET_LOCK_BUTTON,CANCEL_TEXT))
82         device.clickObject(By.text(SET_LOCK_BUTTON))
83         Thread.sleep(1000)
84         device.assertHasTexts(listOf(PATTERN_TEXT, PIN_TEXT, PASSWORD_TEXT))
85     }
86 
87     private companion object {
88         // Items we really want to always show
89         val PRIVATE_SPACE_SETTING = "Private space"
90         const val SET_LOCK_BUTTON = "Set screen lock"
91         val CANCEL_TEXT = "Cancel"
92         val DIALOG_TITLE = "Set a screen lock"
93         val PATTERN_TEXT = "Pattern"
94         val PIN_TEXT = "PIN"
95         val PASSWORD_TEXT = "Password"
96     }
97 }
98