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
18 
19 import android.provider.Settings
20 import androidx.test.platform.app.InstrumentationRegistry
21 import androidx.test.uiautomator.By
22 import androidx.test.uiautomator.UiDevice
23 import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts
24 import com.android.settings.ui.testutils.SettingsTestUtils.assertObject
25 import com.android.settings.ui.testutils.SettingsTestUtils.clickObject
26 import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
27 import com.android.settings.ui.testutils.SettingsTestUtils.waitObject
28 import org.junit.Before
29 import org.junit.Test
30 
31 /** Verifies basic functionality of the About Phone screen  */
32 class AppsSettingsTests {
33     private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
34 
35     @Before
setUpnull36     fun setUp() {
37         device.startMainActivityFromHomeScreen(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS)
38         device.assertObject(By.text("All apps"))
39     }
40 
41     @Test
testAppSettingsListForCalculatornull42     fun testAppSettingsListForCalculator() {
43         device.clickObject(By.text("Calculator"))
44         device.waitObject(By.text("Open"))
45         device.assertHasTexts(ON_SCREEN_TEXTS)
46     }
47 
48     @Test
testDisablingAndEnablingSystemAppnull49     fun testDisablingAndEnablingSystemApp() {
50         device.clickObject(By.text("Calculator"))
51         device.clickObject(By.text("Disable"))
52         device.clickObject(By.text("Disable app"))  // Click on "Disable app" on dialog.
53         device.clickObject(By.text("Enable"))
54         device.assertObject(By.text("Disable"))
55     }
56 
57     private companion object {
58         val ON_SCREEN_TEXTS = listOf(
59             "Notifications",
60             "Permissions",
61             "Storage & cache",
62             "Mobile data & Wi‑Fi",
63             "Screen time",
64             "App battery usage",
65             "Language",
66             "Unused app settings",
67         )
68     }
69 }
70