1 /* <lambda>null2 * 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 18 19 import android.platform.test.flag.junit.SetFlagsRule 20 import androidx.test.core.app.ActivityScenario 21 import androidx.test.espresso.Espresso.onView 22 import androidx.test.espresso.action.ViewActions.click 23 import androidx.test.espresso.assertion.ViewAssertions.doesNotExist 24 import androidx.test.espresso.assertion.ViewAssertions.matches 25 import androidx.test.espresso.matcher.ViewMatchers.isDisplayed 26 import androidx.test.espresso.matcher.ViewMatchers.withText 27 import androidx.test.ext.junit.runners.AndroidJUnit4 28 import com.android.settings.Settings.FactoryResetActivity 29 import com.android.settings.flags.Flags 30 import com.google.common.truth.Truth.assertThat 31 import org.junit.Ignore 32 import org.junit.Rule 33 import org.junit.Test 34 import org.junit.runner.RunWith 35 36 /** Test [MainClear]. */ 37 @Ignore 38 @RunWith(AndroidJUnit4::class) 39 class MainClearTest { 40 @get:Rule 41 val mSetFlagsRule = SetFlagsRule() 42 43 @Test 44 fun factoryResetCancelButton_flagDisabled_noCancelButton() { 45 mSetFlagsRule.disableFlags(Flags.FLAG_SHOW_FACTORY_RESET_CANCEL_BUTTON) 46 ActivityScenario.launch(FactoryResetActivity::class.java).use { 47 ensurePrimaryButton() 48 onView(withText(android.R.string.cancel)).check(doesNotExist()) 49 it.onActivity { activity -> assertThat(activity.isFinishing).isFalse() } 50 } 51 } 52 53 @Test 54 fun factoryResetCancelButton_flagEnabled_showCancelButton() { 55 mSetFlagsRule.enableFlags(Flags.FLAG_SHOW_FACTORY_RESET_CANCEL_BUTTON) 56 ActivityScenario.launch(FactoryResetActivity::class.java).use { 57 ensurePrimaryButton() 58 it.onActivity { activity -> assertThat(activity.isFinishing).isFalse() } 59 60 // Note: onView CANNOT be called within onActivity block, which runs in the main thread 61 onView(withText(android.R.string.cancel)).check(matches(isDisplayed())).perform(click()) 62 63 it.onActivity { activity -> assertThat(activity.isFinishing).isTrue() } 64 } 65 } 66 67 private fun ensurePrimaryButton() { 68 onView(withText(R.string.main_clear_button_text)).check(matches(isDisplayed())) 69 } 70 }