1 /* 2 * Copyright (C) 2022 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 android.safetycenter.functional.ui 18 19 import android.content.Context 20 import android.os.Build 21 import android.os.Build.VERSION_CODES.TIRAMISU 22 import android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE 23 import android.os.Bundle 24 import android.safetycenter.SafetyCenterManager.EXTRA_SAFETY_SOURCE_ID 25 import android.safetycenter.SafetyCenterManager.EXTRA_SAFETY_SOURCE_ISSUE_ID 26 import android.safetycenter.SafetySourceData.SEVERITY_LEVEL_CRITICAL_WARNING 27 import android.safetycenter.SafetySourceData.SEVERITY_LEVEL_INFORMATION 28 import android.safetycenter.SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION 29 import androidx.test.core.app.ApplicationProvider.getApplicationContext 30 import androidx.test.ext.junit.runners.AndroidJUnit4 31 import androidx.test.filters.SdkSuppress 32 import androidx.test.uiautomator.By 33 import com.android.compatibility.common.util.DisableAnimationRule 34 import com.android.compatibility.common.util.FreezeRotationRule 35 import com.android.compatibility.common.util.UiAutomatorUtils2.getUiDevice 36 import com.android.safetycenter.testing.Coroutines.TIMEOUT_LONG 37 import com.android.safetycenter.testing.Coroutines.TIMEOUT_SHORT 38 import com.android.safetycenter.testing.SafetyCenterActivityLauncher.launchSafetyCenterActivity 39 import com.android.safetycenter.testing.SafetyCenterFlags 40 import com.android.safetycenter.testing.SafetyCenterTestConfigs 41 import com.android.safetycenter.testing.SafetyCenterTestConfigs.Companion.ISSUE_ONLY_ALL_OPTIONAL_ID 42 import com.android.safetycenter.testing.SafetyCenterTestConfigs.Companion.SINGLE_SOURCE_ID 43 import com.android.safetycenter.testing.SafetyCenterTestConfigs.Companion.SOURCE_ID_1 44 import com.android.safetycenter.testing.SafetyCenterTestConfigs.Companion.SOURCE_ID_2 45 import com.android.safetycenter.testing.SafetyCenterTestConfigs.Companion.SOURCE_ID_3 46 import com.android.safetycenter.testing.SafetyCenterTestConfigs.Companion.SOURCE_ID_4 47 import com.android.safetycenter.testing.SafetyCenterTestConfigs.Companion.SOURCE_ID_5 48 import com.android.safetycenter.testing.SafetyCenterTestHelper 49 import com.android.safetycenter.testing.SafetyCenterTestRule 50 import com.android.safetycenter.testing.SafetySourceIntentHandler.Request 51 import com.android.safetycenter.testing.SafetySourceIntentHandler.Response 52 import com.android.safetycenter.testing.SafetySourceReceiver 53 import com.android.safetycenter.testing.SafetySourceTestData 54 import com.android.safetycenter.testing.SafetySourceTestData.Companion.CRITICAL_ISSUE_ID 55 import com.android.safetycenter.testing.SafetySourceTestData.Companion.RECOMMENDATION_ISSUE_ID 56 import com.android.safetycenter.testing.SettingsPackage.getSettingsPackageName 57 import com.android.safetycenter.testing.SupportsSafetyCenterRule 58 import com.android.safetycenter.testing.UiTestHelper.MORE_ISSUES_LABEL 59 import com.android.safetycenter.testing.UiTestHelper.RESCAN_BUTTON_LABEL 60 import com.android.safetycenter.testing.UiTestHelper.clickConfirmDismissal 61 import com.android.safetycenter.testing.UiTestHelper.clickDismissIssueCard 62 import com.android.safetycenter.testing.UiTestHelper.clickMoreIssuesCard 63 import com.android.safetycenter.testing.UiTestHelper.resetRotation 64 import com.android.safetycenter.testing.UiTestHelper.rotate 65 import com.android.safetycenter.testing.UiTestHelper.setAnimationsEnabled 66 import com.android.safetycenter.testing.UiTestHelper.waitAllTextDisplayed 67 import com.android.safetycenter.testing.UiTestHelper.waitAllTextNotDisplayed 68 import com.android.safetycenter.testing.UiTestHelper.waitButtonDisplayed 69 import com.android.safetycenter.testing.UiTestHelper.waitCollapsedIssuesDisplayed 70 import com.android.safetycenter.testing.UiTestHelper.waitDisplayed 71 import com.android.safetycenter.testing.UiTestHelper.waitExpandedIssuesDisplayed 72 import com.android.safetycenter.testing.UiTestHelper.waitPageTitleDisplayed 73 import com.android.safetycenter.testing.UiTestHelper.waitSourceDataDisplayed 74 import com.android.safetycenter.testing.UiTestHelper.waitSourceIssueDisplayed 75 import com.android.safetycenter.testing.UiTestHelper.waitSourceIssueNotDisplayed 76 import org.junit.After 77 import org.junit.Assume.assumeTrue 78 import org.junit.Rule 79 import org.junit.Test 80 import org.junit.runner.RunWith 81 82 /** Functional tests for the Safety Center Activity. */ 83 @RunWith(AndroidJUnit4::class) 84 class SafetyCenterActivityTest { 85 86 private val context: Context = getApplicationContext() 87 private val safetyCenterTestHelper = SafetyCenterTestHelper(context) 88 private val safetySourceTestData = SafetySourceTestData(context) 89 private val safetyCenterTestConfigs = SafetyCenterTestConfigs(context) 90 91 @get:Rule(order = 1) val supportsSafetyCenterRule = SupportsSafetyCenterRule(context) 92 @get:Rule(order = 2) val safetyCenterTestRule = SafetyCenterTestRule(safetyCenterTestHelper) 93 @get:Rule(order = 3) val disableAnimationRule = DisableAnimationRule() 94 @get:Rule(order = 4) val freezeRotationRule = FreezeRotationRule() 95 96 @After clearDataAfterTestnull97 fun clearDataAfterTest() { 98 getUiDevice().resetRotation() 99 } 100 101 @Test launchActivity_allowingSettingsTrampolinenull102 fun launchActivity_allowingSettingsTrampoline() { 103 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 104 val dataToDisplay = safetySourceTestData.criticalWithResolvingGeneralIssue 105 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, dataToDisplay) 106 107 context.launchSafetyCenterActivity(preventTrampolineToSettings = false) { 108 waitSourceDataDisplayed(dataToDisplay) 109 } 110 } 111 112 @Test launchActivity_displaysStaticSourcesnull113 fun launchActivity_displaysStaticSources() { 114 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.staticSourcesConfig) 115 116 context.launchSafetyCenterActivity { 117 waitAllTextDisplayed( 118 context.getString(safetyCenterTestConfigs.staticSourceGroup1.titleResId), 119 context.getString(safetyCenterTestConfigs.staticSource1.titleResId), 120 context.getString(safetyCenterTestConfigs.staticSource1.summaryResId), 121 context.getString(safetyCenterTestConfigs.staticSourceGroup2.titleResId), 122 context.getString(safetyCenterTestConfigs.staticSource2.titleResId), 123 context.getString(safetyCenterTestConfigs.staticSource2.summaryResId) 124 ) 125 } 126 } 127 128 @Test launchActivity_displaysSafetyDatanull129 fun launchActivity_displaysSafetyData() { 130 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 131 val dataToDisplay = safetySourceTestData.criticalWithResolvingGeneralIssue 132 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, dataToDisplay) 133 134 context.launchSafetyCenterActivity { waitSourceDataDisplayed(dataToDisplay) } 135 } 136 137 @Test launchActivity_displaysCollapsedGroupsOfMultipleSourcenull138 fun launchActivity_displaysCollapsedGroupsOfMultipleSource() { 139 with(safetyCenterTestHelper) { 140 setConfig(safetyCenterTestConfigs.multipleSourceGroupsConfig) 141 setData( 142 SOURCE_ID_1, 143 safetySourceTestData.buildSafetySourceDataWithSummary( 144 severityLevel = SEVERITY_LEVEL_INFORMATION, 145 entryTitle = SAFETY_SOURCE_1_TITLE, 146 entrySummary = SAFETY_SOURCE_1_SUMMARY, 147 withIssue = false 148 ) 149 ) 150 setData( 151 SOURCE_ID_2, 152 safetySourceTestData.buildSafetySourceDataWithSummary( 153 severityLevel = SEVERITY_LEVEL_INFORMATION, 154 entryTitle = SAFETY_SOURCE_2_TITLE, 155 entrySummary = SAFETY_SOURCE_2_SUMMARY, 156 withIssue = false 157 ) 158 ) 159 setData( 160 SOURCE_ID_3, 161 safetySourceTestData.buildSafetySourceDataWithSummary( 162 severityLevel = SEVERITY_LEVEL_INFORMATION, 163 entryTitle = SAFETY_SOURCE_3_TITLE, 164 entrySummary = SAFETY_SOURCE_3_SUMMARY, 165 withIssue = false 166 ) 167 ) 168 setData( 169 SOURCE_ID_4, 170 safetySourceTestData.buildSafetySourceDataWithSummary( 171 severityLevel = SEVERITY_LEVEL_INFORMATION, 172 entryTitle = SAFETY_SOURCE_4_TITLE, 173 entrySummary = SAFETY_SOURCE_4_SUMMARY, 174 withIssue = false 175 ) 176 ) 177 setData( 178 SOURCE_ID_5, 179 safetySourceTestData.buildSafetySourceDataWithSummary( 180 severityLevel = SEVERITY_LEVEL_INFORMATION, 181 entryTitle = SAFETY_SOURCE_5_TITLE, 182 entrySummary = SAFETY_SOURCE_5_SUMMARY, 183 withIssue = false 184 ) 185 ) 186 } 187 188 context.launchSafetyCenterActivity { 189 waitAllTextDisplayed( 190 context.getString(safetyCenterTestConfigs.dynamicSourceGroup1.titleResId), 191 context.getString(safetyCenterTestConfigs.dynamicSourceGroup1.summaryResId), 192 context.getString(safetyCenterTestConfigs.dynamicSourceGroup3.titleResId), 193 context.getString(safetyCenterTestConfigs.dynamicSourceGroup3.summaryResId) 194 ) 195 waitAllTextNotDisplayed( 196 SAFETY_SOURCE_1_TITLE, 197 SAFETY_SOURCE_1_SUMMARY, 198 SAFETY_SOURCE_2_TITLE, 199 SAFETY_SOURCE_2_SUMMARY, 200 SAFETY_SOURCE_4_TITLE, 201 SAFETY_SOURCE_4_SUMMARY, 202 SAFETY_SOURCE_5_TITLE, 203 SAFETY_SOURCE_5_SUMMARY 204 ) 205 } 206 } 207 208 @Test launchActivity_displaysPrioritizedGroupSummarynull209 fun launchActivity_displaysPrioritizedGroupSummary() { 210 with(safetyCenterTestHelper) { 211 setConfig(safetyCenterTestConfigs.multipleSourceGroupsConfig) 212 setData( 213 SOURCE_ID_1, 214 safetySourceTestData.buildSafetySourceDataWithSummary( 215 severityLevel = SEVERITY_LEVEL_INFORMATION, 216 entryTitle = SAFETY_SOURCE_1_TITLE, 217 entrySummary = SAFETY_SOURCE_1_SUMMARY, 218 withIssue = false 219 ) 220 ) 221 setData( 222 SOURCE_ID_2, 223 safetySourceTestData.buildSafetySourceDataWithSummary( 224 severityLevel = SEVERITY_LEVEL_RECOMMENDATION, 225 entryTitle = SAFETY_SOURCE_2_TITLE, 226 entrySummary = SAFETY_SOURCE_2_SUMMARY, 227 withIssue = true 228 ) 229 ) 230 setData( 231 SOURCE_ID_3, 232 safetySourceTestData.buildSafetySourceDataWithSummary( 233 severityLevel = SEVERITY_LEVEL_INFORMATION, 234 entryTitle = SAFETY_SOURCE_3_TITLE, 235 entrySummary = SAFETY_SOURCE_3_SUMMARY, 236 withIssue = false 237 ) 238 ) 239 setData( 240 SOURCE_ID_4, 241 safetySourceTestData.buildSafetySourceDataWithSummary( 242 severityLevel = SEVERITY_LEVEL_RECOMMENDATION, 243 entryTitle = SAFETY_SOURCE_4_TITLE, 244 entrySummary = SAFETY_SOURCE_4_SUMMARY, 245 withIssue = true 246 ) 247 ) 248 setData( 249 SOURCE_ID_5, 250 safetySourceTestData.buildSafetySourceDataWithSummary( 251 severityLevel = SEVERITY_LEVEL_CRITICAL_WARNING, 252 entryTitle = SAFETY_SOURCE_5_TITLE, 253 entrySummary = SAFETY_SOURCE_5_SUMMARY, 254 withIssue = true 255 ) 256 ) 257 } 258 259 context.launchSafetyCenterActivity { 260 waitAllTextDisplayed( 261 context.getString(safetyCenterTestConfigs.dynamicSourceGroup1.titleResId), 262 SAFETY_SOURCE_2_SUMMARY, 263 context.getString(safetyCenterTestConfigs.dynamicSourceGroup3.titleResId), 264 SAFETY_SOURCE_5_SUMMARY 265 ) 266 waitAllTextNotDisplayed( 267 SAFETY_SOURCE_1_TITLE, 268 SAFETY_SOURCE_2_TITLE, 269 SAFETY_SOURCE_1_SUMMARY, 270 SAFETY_SOURCE_4_TITLE, 271 SAFETY_SOURCE_5_TITLE, 272 SAFETY_SOURCE_4_SUMMARY 273 ) 274 } 275 } 276 277 @Test launchActivity_displaysGroupsOfSingleSourceAsEntitynull278 fun launchActivity_displaysGroupsOfSingleSourceAsEntity() { 279 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourceGroupsConfig) 280 281 context.launchSafetyCenterActivity { 282 waitAllTextDisplayed( 283 context.getString(safetyCenterTestConfigs.dynamicSource3.titleResId) 284 ) 285 waitAllTextNotDisplayed( 286 context.getString(safetyCenterTestConfigs.dynamicSourceGroup2.titleResId) 287 ) 288 } 289 } 290 291 @Test updatingSafetySourceData_updatesDisplayedSafetyDatanull292 fun updatingSafetySourceData_updatesDisplayedSafetyData() { 293 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 294 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, safetySourceTestData.information) 295 296 context.launchSafetyCenterActivity { 297 val dataToDisplay = safetySourceTestData.recommendationWithGeneralIssue 298 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, dataToDisplay) 299 300 waitSourceDataDisplayed(dataToDisplay) 301 } 302 } 303 304 @Test updatingSafetySourceData_withoutSubtitle_newIssueWithSubtitlenull305 fun updatingSafetySourceData_withoutSubtitle_newIssueWithSubtitle() { 306 val initialDataToDisplay = safetySourceTestData.informationWithIssue 307 val updatedDataToDisplay = safetySourceTestData.informationWithSubtitleIssue 308 309 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 310 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, initialDataToDisplay) 311 312 context.launchSafetyCenterActivity { 313 waitSourceIssueDisplayed(safetySourceTestData.informationIssue) 314 315 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, updatedDataToDisplay) 316 317 waitSourceIssueDisplayed(safetySourceTestData.informationIssueWithSubtitle) 318 } 319 } 320 321 @Test updatingSafetySourceData_withSubtitle_newIssueWithoutSubtitlenull322 fun updatingSafetySourceData_withSubtitle_newIssueWithoutSubtitle() { 323 val initialDataToDisplay = safetySourceTestData.informationWithSubtitleIssue 324 val updatedDataToDisplay = safetySourceTestData.informationWithIssue 325 326 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 327 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, initialDataToDisplay) 328 329 context.launchSafetyCenterActivity { 330 waitSourceIssueDisplayed(safetySourceTestData.informationIssueWithSubtitle) 331 332 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, updatedDataToDisplay) 333 334 waitAllTextNotDisplayed(safetySourceTestData.informationIssueWithSubtitle.subtitle) 335 waitSourceIssueDisplayed(safetySourceTestData.informationIssue) 336 } 337 } 338 339 @Test entryListWithEntryGroup_informationState_hasContentDescriptionnull340 fun entryListWithEntryGroup_informationState_hasContentDescription() { 341 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 342 safetyCenterTestHelper.setData(SOURCE_ID_1, safetySourceTestData.information) 343 safetyCenterTestHelper.setData(SOURCE_ID_2, safetySourceTestData.information) 344 safetyCenterTestHelper.setData(SOURCE_ID_3, safetySourceTestData.information) 345 346 context.launchSafetyCenterActivity { 347 // Verify content description for the collapsed entry group, and click on it to expand 348 waitDisplayed(By.desc("List. OK. OK")) { it.click() } 349 350 // Verify content descriptions for the expanded group header and entry list item 351 waitAllTextDisplayed("OK") 352 waitDisplayed(By.desc("List item. Ok title. Ok summary")) 353 } 354 } 355 356 @Test entryListWithEntryGroup_recommendationState_hasActionsNeededContentDescriptionnull357 fun entryListWithEntryGroup_recommendationState_hasActionsNeededContentDescription() { 358 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 359 safetyCenterTestHelper.setData( 360 SOURCE_ID_1, 361 safetySourceTestData.recommendationWithGeneralIssue 362 ) 363 safetyCenterTestHelper.setData(SOURCE_ID_2, safetySourceTestData.information) 364 safetyCenterTestHelper.setData(SOURCE_ID_3, safetySourceTestData.information) 365 366 context.launchSafetyCenterActivity { 367 // Verify content description for the collapsed entry group, and click on it to expand. 368 waitDisplayed(By.desc("List. OK. Actions needed. Recommendation summary")) { 369 it.click() 370 } 371 372 // Verify content descriptions for the expanded group header and entry list items. 373 waitAllTextDisplayed("OK") 374 waitDisplayed(By.desc("List item. Recommendation title. Recommendation summary")) 375 waitDisplayed(By.desc("List item. Ok title. Ok summary")) 376 } 377 } 378 379 @Test entryListWithEntryGroup_clickingAnUnclickableDisabledEntry_doesNothingnull380 fun entryListWithEntryGroup_clickingAnUnclickableDisabledEntry_doesNothing() { 381 safetyCenterTestHelper.setConfig( 382 safetyCenterTestConfigs.multipleSourcesConfigWithSourceWithInvalidIntent 383 ) 384 safetyCenterTestHelper.setData(SOURCE_ID_1, safetySourceTestData.unspecified) 385 386 context.launchSafetyCenterActivity { 387 waitDisplayed(By.text("OK")) { it.click() } 388 waitDisplayed(By.text("Unspecified title")) { it.click() } 389 // Confirm that clicking on the entry neither redirects to any other screen nor 390 // collapses the group. 391 waitAllTextDisplayed("Unspecified title") 392 } 393 } 394 395 @Test entryListWithEntryGroup_unclickableDisabledEntry_hasContentDescriptionnull396 fun entryListWithEntryGroup_unclickableDisabledEntry_hasContentDescription() { 397 safetyCenterTestHelper.setConfig( 398 safetyCenterTestConfigs.multipleSourcesConfigWithSourceWithInvalidIntent 399 ) 400 safetyCenterTestHelper.setData(SOURCE_ID_1, safetySourceTestData.unspecified) 401 402 context.launchSafetyCenterActivity { 403 waitDisplayed(By.desc("List. OK. No info yet")) { it.click() } 404 // Make sure that the content description is correctly set for the unclickable disabled 405 // entries so that the talkback to works properly. 406 waitDisplayed(By.desc("List item. Unspecified title. Unspecified summary")) 407 } 408 } 409 410 @Test entryListWithEntryGroup_clickingAClickableDisabledEntry_redirectsToDifferentScreennull411 fun entryListWithEntryGroup_clickingAClickableDisabledEntry_redirectsToDifferentScreen() { 412 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 413 safetyCenterTestHelper.setData( 414 SOURCE_ID_1, 415 safetySourceTestData.unspecifiedDisabledWithTestActivityRedirect 416 ) 417 418 context.launchSafetyCenterActivity { 419 waitDisplayed(By.text("OK")) { it.click() } 420 waitDisplayed(By.text("Clickable disabled title")) { it.click() } 421 waitButtonDisplayed("Exit test activity") { it.click() } 422 } 423 } 424 425 @Test entryListWithEntryGroup_clickableDisabledEntry_hasContentDescriptionnull426 fun entryListWithEntryGroup_clickableDisabledEntry_hasContentDescription() { 427 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 428 safetyCenterTestHelper.setData( 429 SOURCE_ID_1, 430 safetySourceTestData.unspecifiedDisabledWithTestActivityRedirect 431 ) 432 433 context.launchSafetyCenterActivity { 434 waitDisplayed(By.desc("List. OK. No info yet")) { it.click() } 435 // Make sure that the content description is correctly set for the clickable disabled 436 // entry so that the talkback to works properly. 437 waitDisplayed( 438 By.desc("List item. Clickable disabled title. Clickable disabled summary") 439 ) 440 } 441 } 442 443 @Test entryListWithSingleSource_informationState_hasContentDescriptionnull444 fun entryListWithSingleSource_informationState_hasContentDescription() { 445 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 446 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, safetySourceTestData.information) 447 448 context.launchSafetyCenterActivity { 449 // Verify content description for the individual entry 450 waitDisplayed(By.desc("Ok title. Ok summary")) 451 } 452 } 453 454 @Test entryListWithSingleSource_clickingTheDefaultEntry_redirectsToDifferentScreennull455 fun entryListWithSingleSource_clickingTheDefaultEntry_redirectsToDifferentScreen() { 456 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 457 458 context.launchSafetyCenterActivity { 459 waitDisplayed(By.text("OK")) { it.click() } 460 waitButtonDisplayed("Exit test activity") { it.click() } 461 waitDisplayed(By.text("OK")) 462 } 463 } 464 465 @Test entryListWithSingleSource_clickingDefaultEntryImplicitIntent_redirectsToDifferentScreennull466 fun entryListWithSingleSource_clickingDefaultEntryImplicitIntent_redirectsToDifferentScreen() { 467 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.implicitIntentSingleSourceConfig) 468 469 context.launchSafetyCenterActivity { 470 waitDisplayed(By.text("OK")) { it.click() } 471 waitButtonDisplayed("Exit test activity") { it.click() } 472 } 473 } 474 475 @Test entryListWithSingleSource_clickingTheUpdatedEntry_redirectsToDifferentScreennull476 fun entryListWithSingleSource_clickingTheUpdatedEntry_redirectsToDifferentScreen() { 477 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 478 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, safetySourceTestData.information) 479 480 context.launchSafetyCenterActivity { 481 waitDisplayed(By.text("Ok title")) { it.click() } 482 waitButtonDisplayed("Exit test activity") { it.click() } 483 waitDisplayed(By.text("Ok title")) 484 } 485 } 486 487 @Test entryListWithSingleSource_clickingTheIconActionButton_redirectsToDifferentScreennull488 fun entryListWithSingleSource_clickingTheIconActionButton_redirectsToDifferentScreen() { 489 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 490 safetyCenterTestHelper.setData( 491 SINGLE_SOURCE_ID, 492 safetySourceTestData.informationWithIconAction 493 ) 494 495 context.launchSafetyCenterActivity { 496 waitDisplayed(By.desc("Information")) { it.click() } 497 waitButtonDisplayed("Exit test activity") { it.click() } 498 waitDisplayed(By.text("Ok title")) 499 } 500 } 501 502 @Test staticSource_clickingTheEntry_redirectsToDifferentScreennull503 fun staticSource_clickingTheEntry_redirectsToDifferentScreen() { 504 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.staticSourcesConfig) 505 506 context.launchSafetyCenterActivity { 507 waitDisplayed( 508 By.text(context.getString(safetyCenterTestConfigs.staticSource1.titleResId)) 509 ) { 510 it.click() 511 } 512 waitButtonDisplayed("Exit test activity") { it.click() } 513 waitAllTextDisplayed( 514 context.getString(safetyCenterTestConfigs.staticSource1.titleResId) 515 ) 516 } 517 } 518 519 @Test issueCard_noAttribution_hasProperContentDescriptionsnull520 fun issueCard_noAttribution_hasProperContentDescriptions() { 521 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.issueOnlySourceNoGroupTitleConfig) 522 523 val issue = safetySourceTestData.recommendationGeneralIssue 524 safetyCenterTestHelper.setData( 525 ISSUE_ONLY_ALL_OPTIONAL_ID, 526 SafetySourceTestData.issuesOnly(issue) 527 ) 528 529 context.launchSafetyCenterActivity { waitDisplayed(By.desc("Alert. ${issue.title}")) } 530 } 531 532 @Test 533 @SdkSuppress(minSdkVersion = UPSIDE_DOWN_CAKE) issueCard_withAttribution_hasProperContentDescriptionsnull534 fun issueCard_withAttribution_hasProperContentDescriptions() { 535 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 536 537 val data = safetySourceTestData.informationWithIssueWithAttributionTitle 538 val issue = data.issues[0] 539 540 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, data) 541 542 context.launchSafetyCenterActivity { 543 waitDisplayed(By.desc("Alert. ${issue.attributionTitle}")) 544 } 545 } 546 547 @Test issueCard_greenIssue_noDismissalConfirmationAndDismissesnull548 fun issueCard_greenIssue_noDismissalConfirmationAndDismisses() { 549 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 550 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, safetySourceTestData.informationWithIssue) 551 552 context.launchSafetyCenterActivity { 553 clickDismissIssueCard() 554 555 waitSourceIssueNotDisplayed(safetySourceTestData.informationIssue) 556 waitSourceDataDisplayed(safetySourceTestData.information) 557 waitButtonDisplayed(RESCAN_BUTTON_LABEL) 558 } 559 } 560 561 @Test issueCard_confirmsDismissal_dismissesnull562 fun issueCard_confirmsDismissal_dismisses() { 563 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 564 safetyCenterTestHelper.setData( 565 SINGLE_SOURCE_ID, 566 safetySourceTestData.criticalWithResolvingGeneralIssue 567 ) 568 569 context.launchSafetyCenterActivity { 570 clickDismissIssueCard() 571 waitAllTextDisplayed("Dismiss this alert?") 572 clickConfirmDismissal() 573 574 waitSourceIssueNotDisplayed(safetySourceTestData.criticalResolvingGeneralIssue) 575 waitButtonDisplayed(RESCAN_BUTTON_LABEL) 576 } 577 } 578 579 @Test issueCard_confirmsDismissal_afterRotation_dismissesnull580 fun issueCard_confirmsDismissal_afterRotation_dismisses() { 581 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 582 safetyCenterTestHelper.setData( 583 SINGLE_SOURCE_ID, 584 safetySourceTestData.criticalWithResolvingGeneralIssue 585 ) 586 587 context.launchSafetyCenterActivity { 588 clickDismissIssueCard() 589 waitAllTextDisplayed( 590 "Dismiss this alert?", 591 "Review your security and privacy settings any time to add more protection" 592 ) 593 594 getUiDevice().rotate() 595 596 waitAllTextDisplayed( 597 "Dismiss this alert?", 598 "Review your security and privacy settings any time to add more protection" 599 ) 600 clickConfirmDismissal() 601 602 waitSourceIssueNotDisplayed(safetySourceTestData.criticalResolvingGeneralIssue) 603 waitButtonDisplayed(RESCAN_BUTTON_LABEL) 604 } 605 } 606 607 @Test issueCard_confirmsDismissal_cancelsnull608 fun issueCard_confirmsDismissal_cancels() { 609 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 610 safetyCenterTestHelper.setData( 611 SINGLE_SOURCE_ID, 612 safetySourceTestData.criticalWithResolvingGeneralIssue 613 ) 614 615 context.launchSafetyCenterActivity { 616 clickDismissIssueCard() 617 waitAllTextDisplayed("Dismiss this alert?") 618 waitButtonDisplayed("Cancel") { it.click() } 619 620 waitSourceIssueDisplayed(safetySourceTestData.criticalResolvingGeneralIssue) 621 } 622 } 623 624 @Test issueCard_confirmsDismissal_afterRotation_cancelsnull625 fun issueCard_confirmsDismissal_afterRotation_cancels() { 626 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 627 safetyCenterTestHelper.setData( 628 SINGLE_SOURCE_ID, 629 safetySourceTestData.criticalWithResolvingGeneralIssue 630 ) 631 632 context.launchSafetyCenterActivity { 633 clickDismissIssueCard() 634 waitAllTextDisplayed("Dismiss this alert?") 635 636 getUiDevice().rotate() 637 638 waitAllTextDisplayed("Dismiss this alert?") 639 waitButtonDisplayed("Cancel") { it.click() } 640 641 waitSourceIssueDisplayed(safetySourceTestData.criticalResolvingGeneralIssue) 642 } 643 } 644 645 @Test issueCard_resolveIssue_successConfirmationShownnull646 fun issueCard_resolveIssue_successConfirmationShown() { 647 SafetyCenterFlags.hideResolvedIssueUiTransitionDelay = TIMEOUT_LONG 648 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 649 650 // Set the initial data for the source 651 safetyCenterTestHelper.setData( 652 SINGLE_SOURCE_ID, 653 safetySourceTestData.criticalWithResolvingIssueWithSuccessMessage 654 ) 655 656 // Clear the data when action is triggered to simulate resolution. 657 SafetySourceReceiver.setResponse( 658 Request.ResolveAction(SINGLE_SOURCE_ID), 659 Response.ClearData 660 ) 661 662 context.launchSafetyCenterActivity(withReceiverPermission = true) { 663 val action = safetySourceTestData.criticalResolvingActionWithSuccessMessage 664 waitButtonDisplayed(action.label) { 665 // Re-enable animations for this test as this is needed to show the success message. 666 setAnimationsEnabled(true) 667 it.click() 668 } 669 670 // Success message should show up if issue marked as resolved 671 val successMessage = action.successMessage 672 waitAllTextDisplayed(successMessage) 673 } 674 } 675 676 @Test issueCard_resolveIssue_issueDismissesnull677 fun issueCard_resolveIssue_issueDismisses() { 678 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 679 680 // Set the initial data for the source 681 safetyCenterTestHelper.setData( 682 SINGLE_SOURCE_ID, 683 safetySourceTestData.criticalWithResolvingIssueWithSuccessMessage 684 ) 685 686 // Clear the data when action is triggered to simulate resolution. 687 SafetySourceReceiver.setResponse( 688 Request.ResolveAction(SINGLE_SOURCE_ID), 689 Response.ClearData 690 ) 691 692 context.launchSafetyCenterActivity(withReceiverPermission = true) { 693 val action = safetySourceTestData.criticalResolvingActionWithSuccessMessage 694 waitButtonDisplayed(action.label) { it.click() } 695 696 // Wait for success message to go away, verify issue no longer displayed 697 val successMessage = action.successMessage 698 waitAllTextNotDisplayed(successMessage) 699 waitSourceIssueNotDisplayed( 700 safetySourceTestData.criticalResolvingIssueWithSuccessMessage 701 ) 702 } 703 } 704 705 @Test 706 @SdkSuppress(minSdkVersion = UPSIDE_DOWN_CAKE) issueCard_resolveIssue_withDialogClickYes_resolvesnull707 fun issueCard_resolveIssue_withDialogClickYes_resolves() { 708 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 709 safetyCenterTestHelper.setData( 710 SINGLE_SOURCE_ID, 711 safetySourceTestData.criticalWithResolvingGeneralIssueWithConfirmation 712 ) 713 714 // Clear the data when action is triggered to simulate resolution. 715 SafetySourceReceiver.setResponse( 716 Request.ResolveAction(SINGLE_SOURCE_ID), 717 Response.ClearData 718 ) 719 720 context.launchSafetyCenterActivity(withReceiverPermission = true) { 721 val action = safetySourceTestData.criticalResolvingActionWithConfirmation 722 waitButtonDisplayed(action.label) { it.click() } 723 724 waitAllTextDisplayed(SafetySourceTestData.CONFIRMATION_TITLE) 725 waitButtonDisplayed(SafetySourceTestData.CONFIRMATION_YES) { it.click() } 726 727 waitSourceIssueNotDisplayed(safetySourceTestData.criticalResolvingIssueWithConfirmation) 728 } 729 } 730 731 @Test 732 @SdkSuppress(minSdkVersion = UPSIDE_DOWN_CAKE) issueCard_resolveIssue_withDialog_rotates_clickYes_resolvesnull733 fun issueCard_resolveIssue_withDialog_rotates_clickYes_resolves() { 734 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 735 safetyCenterTestHelper.setData( 736 SINGLE_SOURCE_ID, 737 safetySourceTestData.criticalWithResolvingGeneralIssueWithConfirmation 738 ) 739 740 // Clear the data when action is triggered to simulate resolution. 741 SafetySourceReceiver.setResponse( 742 Request.ResolveAction(SINGLE_SOURCE_ID), 743 Response.ClearData 744 ) 745 746 context.launchSafetyCenterActivity(withReceiverPermission = true) { 747 val action = safetySourceTestData.criticalResolvingActionWithConfirmation 748 waitButtonDisplayed(action.label) { it.click() } 749 750 waitAllTextDisplayed(SafetySourceTestData.CONFIRMATION_TITLE) 751 752 getUiDevice().rotate() 753 754 waitAllTextDisplayed(SafetySourceTestData.CONFIRMATION_TITLE) 755 waitButtonDisplayed(SafetySourceTestData.CONFIRMATION_YES) { it.click() } 756 757 waitSourceIssueNotDisplayed(safetySourceTestData.criticalResolvingIssueWithConfirmation) 758 } 759 } 760 761 @Test 762 @SdkSuppress(minSdkVersion = UPSIDE_DOWN_CAKE) issueCard_resolveIssue_withDialogClicksNo_cancelsnull763 fun issueCard_resolveIssue_withDialogClicksNo_cancels() { 764 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 765 safetyCenterTestHelper.setData( 766 SINGLE_SOURCE_ID, 767 safetySourceTestData.criticalWithResolvingGeneralIssueWithConfirmation 768 ) 769 770 context.launchSafetyCenterActivity(withReceiverPermission = true) { 771 val action = safetySourceTestData.criticalResolvingActionWithConfirmation 772 waitButtonDisplayed(action.label) { it.click() } 773 774 waitAllTextDisplayed(SafetySourceTestData.CONFIRMATION_TITLE) 775 waitButtonDisplayed(SafetySourceTestData.CONFIRMATION_NO) { it.click() } 776 777 waitSourceIssueDisplayed(safetySourceTestData.criticalResolvingIssueWithConfirmation) 778 } 779 } 780 781 @Test issueCard_resolveIssue_noSuccessMessage_noResolutionUiShown_issueDismissesnull782 fun issueCard_resolveIssue_noSuccessMessage_noResolutionUiShown_issueDismisses() { 783 SafetyCenterFlags.hideResolvedIssueUiTransitionDelay = TIMEOUT_LONG 784 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 785 786 // Set the initial data for the source 787 safetyCenterTestHelper.setData( 788 SINGLE_SOURCE_ID, 789 safetySourceTestData.criticalWithResolvingGeneralIssue 790 ) 791 792 // Clear the data when action is triggered to simulate resolution. 793 SafetySourceReceiver.setResponse( 794 Request.ResolveAction(SINGLE_SOURCE_ID), 795 Response.ClearData 796 ) 797 798 context.launchSafetyCenterActivity(withReceiverPermission = true) { 799 val action = safetySourceTestData.criticalResolvingAction 800 waitButtonDisplayed(action.label) { 801 // Re-enable animations for this test as this is needed to show the success message. 802 setAnimationsEnabled(true) 803 it.click() 804 } 805 806 waitSourceIssueNotDisplayed(safetySourceTestData.criticalResolvingGeneralIssue) 807 } 808 } 809 810 @Test issueCard_resolvingInflightIssueFailed_issueRemainsnull811 fun issueCard_resolvingInflightIssueFailed_issueRemains() { 812 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 813 814 // Set the initial data for the source 815 val data = safetySourceTestData.criticalWithResolvingGeneralIssue 816 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, data) 817 818 // Respond with an error when the action is triggered 819 SafetySourceReceiver.setResponse(Request.ResolveAction(SINGLE_SOURCE_ID), Response.Error) 820 821 context.launchSafetyCenterActivity(withReceiverPermission = true) { 822 val action = safetySourceTestData.criticalResolvingAction 823 waitButtonDisplayed(action.label) { it.click() } 824 825 waitSourceIssueDisplayed(safetySourceTestData.criticalResolvingGeneralIssue) 826 } 827 } 828 829 @Test issueCard_resolvingInFlightIssueTimesOut_issueRemainsnull830 fun issueCard_resolvingInFlightIssueTimesOut_issueRemains() { 831 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 832 833 // Set the initial data for the source 834 val data = safetySourceTestData.criticalWithResolvingGeneralIssue 835 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, data) 836 837 SafetyCenterFlags.resolveActionTimeout = TIMEOUT_SHORT 838 839 // Set no data at all on the receiver, will ignore incoming call. 840 841 context.launchSafetyCenterActivity(withReceiverPermission = true) { 842 val action = safetySourceTestData.criticalResolvingAction 843 waitButtonDisplayed(action.label) { it.click() } 844 845 waitSourceIssueDisplayed(safetySourceTestData.criticalResolvingGeneralIssue) 846 } 847 } 848 849 @Test issueCard_clickingNonResolvingActionButton_redirectsToDifferentScreennull850 fun issueCard_clickingNonResolvingActionButton_redirectsToDifferentScreen() { 851 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 852 853 val data = safetySourceTestData.criticalWithTestActivityRedirectIssue 854 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, data) 855 856 context.launchSafetyCenterActivity { 857 val action = safetySourceTestData.testActivityRedirectAction 858 waitButtonDisplayed(action.label) { it.click() } 859 waitButtonDisplayed("Exit test activity") { it.click() } 860 } 861 } 862 863 @Test 864 @SdkSuppress(minSdkVersion = UPSIDE_DOWN_CAKE) issueCard_withAttributionTitleSetBySource_displaysAttributionTitlenull865 fun issueCard_withAttributionTitleSetBySource_displaysAttributionTitle() { 866 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 867 868 val data = safetySourceTestData.informationWithIssueWithAttributionTitle 869 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, data) 870 871 context.launchSafetyCenterActivity { waitAllTextDisplayed("Attribution Title") } 872 } 873 874 @Test 875 @SdkSuppress(minSdkVersion = UPSIDE_DOWN_CAKE) issueCard_attributionNotSetBySource_displaysGroupTitleAsAttributionnull876 fun issueCard_attributionNotSetBySource_displaysGroupTitleAsAttribution() { 877 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 878 879 val data = safetySourceTestData.recommendationWithGeneralIssue 880 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, data) 881 882 context.launchSafetyCenterActivity { waitAllTextDisplayed("OK") } 883 } 884 885 @Test 886 @SdkSuppress(minSdkVersion = UPSIDE_DOWN_CAKE) issueCard_attributionNotSetBySourceAndGroupTitleNull_doesNotDisplayAttributionTitlenull887 fun issueCard_attributionNotSetBySourceAndGroupTitleNull_doesNotDisplayAttributionTitle() { 888 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.issueOnlySourceNoGroupTitleConfig) 889 890 val data = SafetySourceTestData.issuesOnly(safetySourceTestData.recommendationGeneralIssue) 891 safetyCenterTestHelper.setData(ISSUE_ONLY_ALL_OPTIONAL_ID, data) 892 893 context.launchSafetyCenterActivity { waitAllTextNotDisplayed("Attribution Title", "OK") } 894 } 895 896 @Test 897 @SdkSuppress(maxSdkVersion = TIRAMISU) issueCard_attributionNotSetBySourceOnTiramisu_doesNotDisplayAttributionTitlenull898 fun issueCard_attributionNotSetBySourceOnTiramisu_doesNotDisplayAttributionTitle() { 899 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 900 901 val data = safetySourceTestData.recommendationWithGeneralIssue 902 safetyCenterTestHelper.setData(SINGLE_SOURCE_ID, data) 903 904 context.launchSafetyCenterActivity { waitAllTextNotDisplayed("Attribution title", "OK") } 905 } 906 907 @Test launchActivity_fromQuickSettings_issuesExpandednull908 fun launchActivity_fromQuickSettings_issuesExpanded() { 909 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 910 safetyCenterTestHelper.setData( 911 SOURCE_ID_1, 912 safetySourceTestData.criticalWithResolvingGeneralIssue 913 ) 914 safetyCenterTestHelper.setData( 915 SOURCE_ID_2, 916 safetySourceTestData.recommendationWithGeneralIssue 917 ) 918 safetyCenterTestHelper.setData(SOURCE_ID_3, safetySourceTestData.informationWithIssue) 919 920 val bundle = Bundle() 921 bundle.putBoolean(EXPAND_ISSUE_GROUP_QS_FRAGMENT_KEY, true) 922 context.launchSafetyCenterActivity(bundle) { 923 waitExpandedIssuesDisplayed( 924 safetySourceTestData.criticalResolvingGeneralIssue, 925 safetySourceTestData.recommendationGeneralIssue, 926 safetySourceTestData.informationIssue 927 ) 928 } 929 } 930 931 @Test launchActivity_fromNotification_targetIssueAlreadyFirstIssuenull932 fun launchActivity_fromNotification_targetIssueAlreadyFirstIssue() { 933 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 934 safetyCenterTestHelper.setData( 935 SOURCE_ID_1, 936 safetySourceTestData.criticalWithResolvingGeneralIssue 937 ) 938 safetyCenterTestHelper.setData( 939 SOURCE_ID_2, 940 safetySourceTestData.recommendationWithGeneralIssue 941 ) 942 safetyCenterTestHelper.setData(SOURCE_ID_3, safetySourceTestData.informationWithIssue) 943 944 val bundle = Bundle() 945 bundle.putString(EXTRA_SAFETY_SOURCE_ID, SOURCE_ID_1) 946 bundle.putString(EXTRA_SAFETY_SOURCE_ISSUE_ID, CRITICAL_ISSUE_ID) 947 context.launchSafetyCenterActivity(bundle) { 948 waitCollapsedIssuesDisplayed( 949 safetySourceTestData.criticalResolvingGeneralIssue, 950 safetySourceTestData.recommendationGeneralIssue, 951 safetySourceTestData.informationIssue 952 ) 953 } 954 } 955 956 @Test launchActivity_fromNotification_targetIssueSamePriorityAsFirstIssue_reorderedFirstIssuenull957 fun launchActivity_fromNotification_targetIssueSamePriorityAsFirstIssue_reorderedFirstIssue() { 958 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 959 safetyCenterTestHelper.setData( 960 SOURCE_ID_1, 961 safetySourceTestData.criticalWithResolvingGeneralIssue 962 ) 963 safetyCenterTestHelper.setData( 964 SOURCE_ID_2, 965 safetySourceTestData.criticalWithRedirectingIssue 966 ) 967 safetyCenterTestHelper.setData(SOURCE_ID_3, safetySourceTestData.informationWithIssue) 968 969 val bundle = Bundle() 970 bundle.putString(EXTRA_SAFETY_SOURCE_ID, SOURCE_ID_2) 971 bundle.putString(EXTRA_SAFETY_SOURCE_ISSUE_ID, CRITICAL_ISSUE_ID) 972 context.launchSafetyCenterActivity(bundle) { 973 waitCollapsedIssuesDisplayed( 974 safetySourceTestData.criticalRedirectingIssue, 975 safetySourceTestData.criticalResolvingGeneralIssue, 976 safetySourceTestData.informationIssue 977 ) 978 } 979 } 980 981 @Test launchActivity_fromNotification_targetLowerPriorityAsFirstIssue_reorderedSecondIssuenull982 fun launchActivity_fromNotification_targetLowerPriorityAsFirstIssue_reorderedSecondIssue() { 983 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 984 safetyCenterTestHelper.setData( 985 SOURCE_ID_1, 986 safetySourceTestData.criticalWithResolvingGeneralIssue 987 ) 988 safetyCenterTestHelper.setData( 989 SOURCE_ID_2, 990 safetySourceTestData.recommendationWithGeneralIssue 991 ) 992 safetyCenterTestHelper.setData(SOURCE_ID_3, safetySourceTestData.informationWithIssue) 993 994 val bundle = Bundle() 995 bundle.putString(EXTRA_SAFETY_SOURCE_ID, SOURCE_ID_2) 996 bundle.putString(EXTRA_SAFETY_SOURCE_ISSUE_ID, RECOMMENDATION_ISSUE_ID) 997 context.launchSafetyCenterActivity(bundle) { 998 waitSourceIssueDisplayed(safetySourceTestData.criticalResolvingGeneralIssue) 999 waitSourceIssueDisplayed(safetySourceTestData.recommendationGeneralIssue) 1000 waitAllTextDisplayed(MORE_ISSUES_LABEL) 1001 waitSourceIssueNotDisplayed(safetySourceTestData.informationIssue) 1002 } 1003 } 1004 1005 @Test launchActivity_fromNotification_targetIssueNotFoundnull1006 fun launchActivity_fromNotification_targetIssueNotFound() { 1007 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 1008 safetyCenterTestHelper.setData( 1009 SOURCE_ID_1, 1010 safetySourceTestData.criticalWithResolvingGeneralIssue 1011 ) 1012 safetyCenterTestHelper.setData( 1013 SOURCE_ID_2, 1014 safetySourceTestData.recommendationWithGeneralIssue 1015 ) 1016 safetyCenterTestHelper.setData(SOURCE_ID_3, safetySourceTestData.informationWithIssue) 1017 1018 val bundle = Bundle() 1019 bundle.putString(EXTRA_SAFETY_SOURCE_ID, SOURCE_ID_2) 1020 bundle.putString(EXTRA_SAFETY_SOURCE_ISSUE_ID, CRITICAL_ISSUE_ID) 1021 context.launchSafetyCenterActivity(bundle) { 1022 waitCollapsedIssuesDisplayed( 1023 safetySourceTestData.criticalResolvingGeneralIssue, 1024 safetySourceTestData.recommendationGeneralIssue, 1025 safetySourceTestData.informationIssue 1026 ) 1027 } 1028 } 1029 1030 @Test moreIssuesCard_underMaxShownIssues_noMoreIssuesCardnull1031 fun moreIssuesCard_underMaxShownIssues_noMoreIssuesCard() { 1032 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleSourceConfig) 1033 safetyCenterTestHelper.setData( 1034 SINGLE_SOURCE_ID, 1035 safetySourceTestData.criticalWithResolvingGeneralIssue 1036 ) 1037 1038 context.launchSafetyCenterActivity { 1039 waitSourceIssueDisplayed(safetySourceTestData.criticalResolvingGeneralIssue) 1040 waitAllTextNotDisplayed(MORE_ISSUES_LABEL) 1041 } 1042 } 1043 1044 @Test moreIssuesCard_moreIssuesCardShown_additionalIssueCardsCollapsednull1045 fun moreIssuesCard_moreIssuesCardShown_additionalIssueCardsCollapsed() { 1046 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 1047 safetyCenterTestHelper.setData( 1048 SOURCE_ID_1, 1049 safetySourceTestData.criticalWithResolvingGeneralIssue 1050 ) 1051 safetyCenterTestHelper.setData( 1052 SOURCE_ID_2, 1053 safetySourceTestData.recommendationWithGeneralIssue 1054 ) 1055 safetyCenterTestHelper.setData(SOURCE_ID_3, safetySourceTestData.informationWithIssue) 1056 1057 context.launchSafetyCenterActivity { 1058 waitCollapsedIssuesDisplayed( 1059 safetySourceTestData.criticalResolvingGeneralIssue, 1060 safetySourceTestData.recommendationGeneralIssue, 1061 safetySourceTestData.informationIssue 1062 ) 1063 } 1064 } 1065 1066 @Test moreIssuesCard_expandAdditionalIssueCardsnull1067 fun moreIssuesCard_expandAdditionalIssueCards() { 1068 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 1069 safetyCenterTestHelper.setData( 1070 SOURCE_ID_1, 1071 safetySourceTestData.criticalWithResolvingGeneralIssue 1072 ) 1073 safetyCenterTestHelper.setData( 1074 SOURCE_ID_2, 1075 safetySourceTestData.recommendationWithGeneralIssue 1076 ) 1077 safetyCenterTestHelper.setData(SOURCE_ID_3, safetySourceTestData.informationWithIssue) 1078 1079 context.launchSafetyCenterActivity { 1080 waitSourceIssueDisplayed(safetySourceTestData.criticalResolvingGeneralIssue) 1081 1082 clickMoreIssuesCard() 1083 1084 waitExpandedIssuesDisplayed( 1085 safetySourceTestData.criticalResolvingGeneralIssue, 1086 safetySourceTestData.recommendationGeneralIssue, 1087 safetySourceTestData.informationIssue 1088 ) 1089 } 1090 } 1091 1092 @Test moreIssuesCard_rotation_cardsStillExpandednull1093 fun moreIssuesCard_rotation_cardsStillExpanded() { 1094 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 1095 safetyCenterTestHelper.setData( 1096 SOURCE_ID_1, 1097 safetySourceTestData.criticalWithResolvingGeneralIssue 1098 ) 1099 safetyCenterTestHelper.setData( 1100 SOURCE_ID_2, 1101 safetySourceTestData.recommendationWithGeneralIssue 1102 ) 1103 safetyCenterTestHelper.setData(SOURCE_ID_3, safetySourceTestData.informationWithIssue) 1104 1105 context.launchSafetyCenterActivity { 1106 clickMoreIssuesCard() 1107 1108 // Not checking that all the cards are correctly expanded here, as it is already covered 1109 // by other tests and makes this tests too slow otherwise. See b/288381777. 1110 // We still check that the middle card title is displayed though, as this helps ensure 1111 // the expansion did go through. 1112 waitAllTextDisplayed(safetySourceTestData.recommendationGeneralIssue.title) 1113 1114 // Device rotation to trigger usage of savedinstancestate via config update 1115 getUiDevice().rotate() 1116 1117 // Verify cards remain expanded 1118 waitExpandedIssuesDisplayed( 1119 safetySourceTestData.criticalResolvingGeneralIssue, 1120 safetySourceTestData.recommendationGeneralIssue, 1121 safetySourceTestData.informationIssue 1122 ) 1123 } 1124 } 1125 1126 @Test moreIssuesCard_withThreeIssues_showsTopIssuesAndMoreIssuesCardnull1127 fun moreIssuesCard_withThreeIssues_showsTopIssuesAndMoreIssuesCard() { 1128 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 1129 safetyCenterTestHelper.setData( 1130 SOURCE_ID_1, 1131 safetySourceTestData.criticalWithResolvingGeneralIssue 1132 ) 1133 safetyCenterTestHelper.setData( 1134 SOURCE_ID_2, 1135 safetySourceTestData.recommendationWithGeneralIssue 1136 ) 1137 safetyCenterTestHelper.setData(SOURCE_ID_3, safetySourceTestData.informationWithIssue) 1138 1139 val bundle = Bundle() 1140 bundle.putString(EXTRA_SAFETY_SOURCE_ID, SOURCE_ID_2) 1141 bundle.putString(EXTRA_SAFETY_SOURCE_ISSUE_ID, RECOMMENDATION_ISSUE_ID) 1142 context.launchSafetyCenterActivity(bundle) { 1143 waitSourceIssueDisplayed(safetySourceTestData.criticalResolvingGeneralIssue) 1144 waitSourceIssueDisplayed(safetySourceTestData.recommendationGeneralIssue) 1145 waitAllTextDisplayed(MORE_ISSUES_LABEL) 1146 waitSourceIssueNotDisplayed(safetySourceTestData.informationIssue) 1147 } 1148 } 1149 1150 @Test moreIssuesCard_twoIssuesAlreadyShown_expandAdditionalIssueCardsnull1151 fun moreIssuesCard_twoIssuesAlreadyShown_expandAdditionalIssueCards() { 1152 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourcesConfig) 1153 safetyCenterTestHelper.setData( 1154 SOURCE_ID_1, 1155 safetySourceTestData.criticalWithResolvingGeneralIssue 1156 ) 1157 safetyCenterTestHelper.setData( 1158 SOURCE_ID_2, 1159 safetySourceTestData.recommendationWithGeneralIssue 1160 ) 1161 safetyCenterTestHelper.setData(SOURCE_ID_3, safetySourceTestData.informationWithIssue) 1162 1163 val bundle = Bundle() 1164 bundle.putString(EXTRA_SAFETY_SOURCE_ID, SOURCE_ID_2) 1165 bundle.putString(EXTRA_SAFETY_SOURCE_ISSUE_ID, RECOMMENDATION_ISSUE_ID) 1166 context.launchSafetyCenterActivity(bundle) { 1167 waitSourceIssueNotDisplayed(safetySourceTestData.informationIssue) 1168 1169 clickMoreIssuesCard() 1170 1171 waitSourceIssueDisplayed(safetySourceTestData.informationIssue) 1172 } 1173 } 1174 1175 @Test collapsedEntryGroup_expandsWhenClickednull1176 fun collapsedEntryGroup_expandsWhenClicked() { 1177 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourceGroupsConfig) 1178 with(safetyCenterTestHelper) { 1179 setConfig(safetyCenterTestConfigs.multipleSourceGroupsConfig) 1180 setData( 1181 SOURCE_ID_1, 1182 safetySourceTestData.buildSafetySourceDataWithSummary( 1183 severityLevel = SEVERITY_LEVEL_INFORMATION, 1184 entryTitle = SAFETY_SOURCE_1_TITLE, 1185 entrySummary = SAFETY_SOURCE_1_SUMMARY, 1186 withIssue = false 1187 ) 1188 ) 1189 setData( 1190 SOURCE_ID_2, 1191 safetySourceTestData.buildSafetySourceDataWithSummary( 1192 severityLevel = SEVERITY_LEVEL_INFORMATION, 1193 entryTitle = SAFETY_SOURCE_2_TITLE, 1194 entrySummary = SAFETY_SOURCE_2_SUMMARY, 1195 withIssue = false 1196 ) 1197 ) 1198 setData( 1199 SOURCE_ID_3, 1200 safetySourceTestData.buildSafetySourceDataWithSummary( 1201 severityLevel = SEVERITY_LEVEL_INFORMATION, 1202 entryTitle = SAFETY_SOURCE_3_TITLE, 1203 entrySummary = SAFETY_SOURCE_3_SUMMARY, 1204 withIssue = false 1205 ) 1206 ) 1207 setData( 1208 SOURCE_ID_4, 1209 safetySourceTestData.buildSafetySourceDataWithSummary( 1210 severityLevel = SEVERITY_LEVEL_INFORMATION, 1211 entryTitle = SAFETY_SOURCE_4_TITLE, 1212 entrySummary = SAFETY_SOURCE_4_SUMMARY, 1213 withIssue = false 1214 ) 1215 ) 1216 setData( 1217 SOURCE_ID_5, 1218 safetySourceTestData.buildSafetySourceDataWithSummary( 1219 severityLevel = SEVERITY_LEVEL_INFORMATION, 1220 entryTitle = SAFETY_SOURCE_5_TITLE, 1221 entrySummary = SAFETY_SOURCE_5_SUMMARY, 1222 withIssue = false 1223 ) 1224 ) 1225 } 1226 1227 context.launchSafetyCenterActivity { 1228 waitDisplayed( 1229 By.text(context.getString(safetyCenterTestConfigs.dynamicSourceGroup1.titleResId)) 1230 ) { 1231 it.click() 1232 } 1233 1234 waitAllTextNotDisplayed( 1235 context.getString(safetyCenterTestConfigs.dynamicSourceGroup1.summaryResId) 1236 ) 1237 waitAllTextDisplayed( 1238 SAFETY_SOURCE_1_TITLE, 1239 SAFETY_SOURCE_1_SUMMARY, 1240 SAFETY_SOURCE_2_TITLE, 1241 SAFETY_SOURCE_2_SUMMARY 1242 ) 1243 } 1244 } 1245 1246 @Test expandedEntryGroup_collapsesWhenClickednull1247 fun expandedEntryGroup_collapsesWhenClicked() { 1248 with(safetyCenterTestHelper) { 1249 setConfig(safetyCenterTestConfigs.multipleSourceGroupsConfig) 1250 setData( 1251 SOURCE_ID_1, 1252 safetySourceTestData.buildSafetySourceDataWithSummary( 1253 severityLevel = SEVERITY_LEVEL_INFORMATION, 1254 entryTitle = SAFETY_SOURCE_1_TITLE, 1255 entrySummary = SAFETY_SOURCE_1_SUMMARY, 1256 withIssue = false 1257 ) 1258 ) 1259 setData( 1260 SOURCE_ID_2, 1261 safetySourceTestData.buildSafetySourceDataWithSummary( 1262 severityLevel = SEVERITY_LEVEL_INFORMATION, 1263 entryTitle = SAFETY_SOURCE_2_TITLE, 1264 entrySummary = SAFETY_SOURCE_2_SUMMARY, 1265 withIssue = false 1266 ) 1267 ) 1268 setData( 1269 SOURCE_ID_3, 1270 safetySourceTestData.buildSafetySourceDataWithSummary( 1271 severityLevel = SEVERITY_LEVEL_INFORMATION, 1272 entryTitle = SAFETY_SOURCE_3_TITLE, 1273 entrySummary = SAFETY_SOURCE_3_SUMMARY, 1274 withIssue = false 1275 ) 1276 ) 1277 setData( 1278 SOURCE_ID_4, 1279 safetySourceTestData.buildSafetySourceDataWithSummary( 1280 severityLevel = SEVERITY_LEVEL_INFORMATION, 1281 entryTitle = SAFETY_SOURCE_4_TITLE, 1282 entrySummary = SAFETY_SOURCE_4_SUMMARY, 1283 withIssue = false 1284 ) 1285 ) 1286 setData( 1287 SOURCE_ID_5, 1288 safetySourceTestData.buildSafetySourceDataWithSummary( 1289 severityLevel = SEVERITY_LEVEL_INFORMATION, 1290 entryTitle = SAFETY_SOURCE_5_TITLE, 1291 entrySummary = SAFETY_SOURCE_5_SUMMARY, 1292 withIssue = false 1293 ) 1294 ) 1295 } 1296 1297 context.launchSafetyCenterActivity { 1298 waitDisplayed( 1299 By.text(context.getString(safetyCenterTestConfigs.dynamicSourceGroup1.titleResId)) 1300 ) { 1301 it.click() 1302 } 1303 1304 waitDisplayed( 1305 By.text(context.getString(safetyCenterTestConfigs.dynamicSourceGroup1.titleResId)) 1306 ) { 1307 it.click() 1308 } 1309 1310 waitAllTextDisplayed( 1311 context.getString(safetyCenterTestConfigs.dynamicSourceGroup1.titleResId) 1312 ) 1313 waitAllTextNotDisplayed(SAFETY_SOURCE_1_TITLE, SAFETY_SOURCE_2_TITLE) 1314 } 1315 } 1316 1317 @Test expandedEntryGroup_rotation_remainsExpandednull1318 fun expandedEntryGroup_rotation_remainsExpanded() { 1319 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourceGroupsConfig) 1320 1321 context.launchSafetyCenterActivity { 1322 waitDisplayed( 1323 By.text(context.getString(safetyCenterTestConfigs.dynamicSourceGroup1.titleResId)) 1324 ) { 1325 it.click() 1326 } 1327 1328 getUiDevice().rotate() 1329 1330 waitAllTextNotDisplayed( 1331 context.getString(safetyCenterTestConfigs.dynamicSourceGroup1.summaryResId) 1332 ) 1333 waitAllTextDisplayed( 1334 context.getString(safetyCenterTestConfigs.dynamicSource1.titleResId), 1335 context.getString(safetyCenterTestConfigs.dynamicSource2.titleResId) 1336 ) 1337 } 1338 } 1339 1340 @Test expandedEntryGroup_otherGroupRemainsCollapsednull1341 fun expandedEntryGroup_otherGroupRemainsCollapsed() { 1342 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.multipleSourceGroupsConfig) 1343 with(safetyCenterTestHelper) { 1344 setConfig(safetyCenterTestConfigs.multipleSourceGroupsConfig) 1345 setData( 1346 SOURCE_ID_1, 1347 safetySourceTestData.buildSafetySourceDataWithSummary( 1348 severityLevel = SEVERITY_LEVEL_INFORMATION, 1349 entryTitle = SAFETY_SOURCE_1_TITLE, 1350 entrySummary = SAFETY_SOURCE_1_SUMMARY, 1351 withIssue = false 1352 ) 1353 ) 1354 setData( 1355 SOURCE_ID_2, 1356 safetySourceTestData.buildSafetySourceDataWithSummary( 1357 severityLevel = SEVERITY_LEVEL_INFORMATION, 1358 entryTitle = SAFETY_SOURCE_2_TITLE, 1359 entrySummary = SAFETY_SOURCE_2_SUMMARY, 1360 withIssue = false 1361 ) 1362 ) 1363 setData( 1364 SOURCE_ID_3, 1365 safetySourceTestData.buildSafetySourceDataWithSummary( 1366 severityLevel = SEVERITY_LEVEL_INFORMATION, 1367 entryTitle = SAFETY_SOURCE_3_TITLE, 1368 entrySummary = SAFETY_SOURCE_3_SUMMARY, 1369 withIssue = false 1370 ) 1371 ) 1372 setData( 1373 SOURCE_ID_4, 1374 safetySourceTestData.buildSafetySourceDataWithSummary( 1375 severityLevel = SEVERITY_LEVEL_INFORMATION, 1376 entryTitle = SAFETY_SOURCE_4_TITLE, 1377 entrySummary = SAFETY_SOURCE_4_SUMMARY, 1378 withIssue = false 1379 ) 1380 ) 1381 setData( 1382 SOURCE_ID_5, 1383 safetySourceTestData.buildSafetySourceDataWithSummary( 1384 severityLevel = SEVERITY_LEVEL_INFORMATION, 1385 entryTitle = SAFETY_SOURCE_5_TITLE, 1386 entrySummary = SAFETY_SOURCE_5_SUMMARY, 1387 withIssue = false 1388 ) 1389 ) 1390 } 1391 1392 context.launchSafetyCenterActivity { 1393 waitDisplayed( 1394 By.text(context.getString(safetyCenterTestConfigs.dynamicSourceGroup1.titleResId)) 1395 ) { 1396 it.click() 1397 } 1398 1399 waitAllTextNotDisplayed( 1400 context.getString(safetyCenterTestConfigs.dynamicSourceGroup1.summaryResId) 1401 ) 1402 waitAllTextDisplayed( 1403 context.getString(safetyCenterTestConfigs.dynamicSourceGroup3.summaryResId) 1404 ) 1405 } 1406 } 1407 1408 @Test 1409 @SdkSuppress(maxSdkVersion = TIRAMISU) launchSafetyCenter_enableSubpagesFlagOnT_stillShowsExpandAndCollapseEntriesnull1410 fun launchSafetyCenter_enableSubpagesFlagOnT_stillShowsExpandAndCollapseEntries() { 1411 SafetyCenterFlags.showSubpages = true 1412 val sourceTestData = safetySourceTestData.information 1413 val config = safetyCenterTestConfigs.multipleSourceGroupsConfig 1414 with(safetyCenterTestHelper) { 1415 setConfig(config) 1416 setData(SOURCE_ID_1, sourceTestData) 1417 setData(SOURCE_ID_2, sourceTestData) 1418 setData(SOURCE_ID_3, sourceTestData) 1419 setData(SOURCE_ID_4, sourceTestData) 1420 setData(SOURCE_ID_5, sourceTestData) 1421 } 1422 val firstGroup = config.safetySourcesGroups.first() 1423 val lastGroup = config.safetySourcesGroups.last() 1424 1425 context.launchSafetyCenterActivity { 1426 waitAllTextDisplayed( 1427 context.getString(lastGroup.titleResId), 1428 context.getString(lastGroup.summaryResId) 1429 ) 1430 1431 waitDisplayed(By.text(context.getString(firstGroup.titleResId))) { it.click() } 1432 1433 waitAllTextDisplayed( 1434 sourceTestData.status!!.title, 1435 sourceTestData.status!!.summary, 1436 context.getString(lastGroup.titleResId), 1437 context.getString(lastGroup.summaryResId), 1438 ) 1439 } 1440 } 1441 1442 @Test startStaticEntryActivity_noConfigToBeSettingsActivity_noExtraInBundlenull1443 fun startStaticEntryActivity_noConfigToBeSettingsActivity_noExtraInBundle() { 1444 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.implicitIntentSingleSourceConfig) 1445 1446 context.launchSafetyCenterActivity { 1447 waitDisplayed(By.text("OK")) { it.click() } 1448 waitDisplayed(By.text("is_from_settings_homepage false")) 1449 waitButtonDisplayed("Exit test activity") { it.click() } 1450 } 1451 } 1452 1453 @Test startStaticEntryActivity_withConfigToBeSettingsActivity_trueExtraInBundlenull1454 fun startStaticEntryActivity_withConfigToBeSettingsActivity_trueExtraInBundle() { 1455 safetyCenterTestHelper.setConfig(safetyCenterTestConfigs.singleStaticSettingsSourceConfig) 1456 1457 context.launchSafetyCenterActivity { 1458 waitDisplayed(By.text("OK")) { it.click() } 1459 waitDisplayed(By.text("is_from_settings_homepage true")) 1460 waitButtonDisplayed("Exit test activity") { it.click() } 1461 } 1462 } 1463 1464 @Test launchActivity_openWithPrivacyControlsIntent_showsPrivacyControlsnull1465 fun launchActivity_openWithPrivacyControlsIntent_showsPrivacyControls() { 1466 context.launchSafetyCenterActivity(intentAction = PRIVACY_CONTROLS_ACTION) { 1467 waitPageTitleDisplayed("Privacy controls") 1468 } 1469 } 1470 1471 @Test launchActivity_openWithPrivacyControlsIntentWithScDisabled_showsLegacyPrivacyPagenull1472 fun launchActivity_openWithPrivacyControlsIntentWithScDisabled_showsLegacyPrivacyPage() { 1473 // This test should technically run on T+ but we have to restrict it to V+ as b/286690307 is 1474 // causing a flake which was only fixed on master. 1475 assumeTrue( 1476 Build.VERSION.SDK_INT > UPSIDE_DOWN_CAKE || Build.VERSION.CODENAME == "VanillaIceCream" 1477 ) 1478 safetyCenterTestHelper.setEnabled(false) 1479 1480 context.launchSafetyCenterActivity(intentAction = PRIVACY_CONTROLS_ACTION) { 1481 waitDisplayed(By.pkg(context.getSettingsPackageName())) 1482 waitPageTitleDisplayed("Privacy") 1483 } 1484 } 1485 1486 private companion object { 1487 const val EXPAND_ISSUE_GROUP_QS_FRAGMENT_KEY = "expand_issue_group_qs_fragment_key" 1488 const val SAFETY_SOURCE_1_TITLE = "Safety Source 1 Title" 1489 const val SAFETY_SOURCE_1_SUMMARY = "Safety Source 1 Summary" 1490 const val SAFETY_SOURCE_2_TITLE = "Safety Source 2 Title" 1491 const val SAFETY_SOURCE_2_SUMMARY = "Safety Source 2 Summary" 1492 const val SAFETY_SOURCE_3_TITLE = "Safety Source 3 Title" 1493 const val SAFETY_SOURCE_3_SUMMARY = "Safety Source 3 Summary" 1494 const val SAFETY_SOURCE_4_TITLE = "Safety Source 4 Title" 1495 const val SAFETY_SOURCE_4_SUMMARY = "Safety Source 4 Summary" 1496 const val SAFETY_SOURCE_5_TITLE = "Safety Source 5 Title" 1497 const val SAFETY_SOURCE_5_SUMMARY = "Safety Source 5 Summary" 1498 const val PRIVACY_CONTROLS_ACTION = "android.settings.PRIVACY_CONTROLS" 1499 } 1500 } 1501