summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
author Max Spencer <maxspencer@google.com> 2023-04-21 09:12:34 +0000
committer Max Spencer <maxspencer@google.com> 2023-04-24 10:02:00 +0000
commit43584c24d0e65f721595bf61b0da336da30eee56 (patch)
tree69e5d403eea04d10e97dfd1e43dc4cee7d85fab6 /tests
parent28c3d83a23076913176f368b0cd73f3ad682822b (diff)
Track dataChanged in SC refresh atoms
Bug: 268328334 Test: atest SafetyCenterSystemEventReportedLoggingHostTest Change-Id: Ie46adda7e10916a1c3ea7cd6000c5c376c24e571
Diffstat (limited to 'tests')
-rw-r--r--tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetySourceStateCollectedLoggingHelperTests.kt17
-rw-r--r--tests/hostside/safetycenter/src/android/safetycenter/hostside/SafetyCenterSystemEventReportedLoggingHostTest.kt36
2 files changed, 49 insertions, 4 deletions
diff --git a/tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetySourceStateCollectedLoggingHelperTests.kt b/tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetySourceStateCollectedLoggingHelperTests.kt
index 9c90142e7..1010930c2 100644
--- a/tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetySourceStateCollectedLoggingHelperTests.kt
+++ b/tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetySourceStateCollectedLoggingHelperTests.kt
@@ -76,6 +76,17 @@ class SafetySourceStateCollectedLoggingHelperTests {
}
@Test
+ fun refreshAllSources_twiceSameData_allSuccessful() {
+ repeat(2) {
+ simulateRefresh(
+ Response.SetData(safetySourceTestData.information),
+ Response.SetData(safetySourceTestData.recommendationWithAccountIssue),
+ Response.SetData(safetySourceTestData.criticalWithResolvingDeviceIssue)
+ )
+ }
+ }
+
+ @Test
fun refreshAllSources_reasonPageOpen_oneError() {
simulateRefresh(
Response.SetData(safetySourceTestData.information),
@@ -88,8 +99,6 @@ class SafetySourceStateCollectedLoggingHelperTests {
fun refreshAllSources_reasonPageOpen_oneSuccessOneErrorOneTimeout() {
SafetyCenterFlags.setAllRefreshTimeoutsTo(Coroutines.TIMEOUT_SHORT)
simulateRefresh(Response.SetData(safetySourceTestData.information), Response.Error, null)
- // Give time for responses to all sources
- Thread.sleep(Coroutines.TIMEOUT_SHORT.toMillis() * 2)
}
@Test
@@ -101,8 +110,6 @@ class SafetySourceStateCollectedLoggingHelperTests {
null,
refreshReason = SafetyCenterManager.REFRESH_REASON_RESCAN_BUTTON_CLICK
)
- // Give time for responses to all sources
- Thread.sleep(Coroutines.TIMEOUT_SHORT.toMillis() * 2)
}
private fun simulateRefresh(
@@ -121,5 +128,7 @@ class SafetySourceStateCollectedLoggingHelperTests {
SafetySourceReceiver.setResponse(Request.Refresh(SOURCE_ID_3), source3Response)
}
safetyCenterManager.refreshSafetySourcesWithReceiverPermissionAndWait(refreshReason)
+ // Give time for responses to all sources
+ Thread.sleep(Coroutines.TIMEOUT_SHORT.toMillis())
}
}
diff --git a/tests/hostside/safetycenter/src/android/safetycenter/hostside/SafetyCenterSystemEventReportedLoggingHostTest.kt b/tests/hostside/safetycenter/src/android/safetycenter/hostside/SafetyCenterSystemEventReportedLoggingHostTest.kt
index a01dce43d..922ffb885 100644
--- a/tests/hostside/safetycenter/src/android/safetycenter/hostside/SafetyCenterSystemEventReportedLoggingHostTest.kt
+++ b/tests/hostside/safetycenter/src/android/safetycenter/hostside/SafetyCenterSystemEventReportedLoggingHostTest.kt
@@ -141,9 +141,45 @@ class SafetyCenterSystemEventReportedLoggingHostTest : BaseHostJUnit4Test() {
assertWithMessage("the system event atoms").that(systemEventAtoms).hasSize(4)
assertWithMessage("the number of atoms with the button-click refresh reason")
.that(systemEventAtoms.count { it.refreshReason == REFRESH_REASON_BUTTON_CLICK })
+ }
+
+ fun refreshAllSources_firstTime_allSourcesSuccessful_dataChangedTrueForAll() {
+ helperAppRule.runTest(
+ ".SafetySourceStateCollectedLoggingHelperTests",
+ "refreshAllSources_reasonPageOpen_allSuccessful"
+ )
+
+ val systemEventAtoms =
+ ReportUtils.getEventMetricDataList(device).mapNotNull {
+ it.atom.safetyCenterSystemEventReported
+ }
+
+ assertWithMessage("the number of atoms with dataChanged=true")
+ .that(systemEventAtoms.count { it.dataChanged })
.isEqualTo(4)
}
+ @Test
+ fun refreshAllSources_secondTime_allSourcesUnchanged_dataChangedFalseForAll() {
+ helperAppRule.runTest(
+ ".SafetySourceStateCollectedLoggingHelperTests",
+ "refreshAllSources_twiceSameData_allSuccessful"
+ )
+
+ val systemEventAtoms =
+ ReportUtils.getEventMetricDataList(device).mapNotNull {
+ it.atom.safetyCenterSystemEventReported
+ }
+
+ // There are three sources in the multiple sources config, of which one is not allowed to
+ // refresh on page open, except when there is no data. Plus, for each refresh there is an
+ // overall refresh atom making seven atoms in total.
+ assertWithMessage("the number of atoms").that(systemEventAtoms).hasSize(7)
+ assertWithMessage("the number of atoms with dataChanged=false")
+ .that(systemEventAtoms.count { !it.dataChanged })
+ .isEqualTo(3)
+ }
+
companion object {
private const val REFRESH_REASON_PAGE_OPEN = 100L
private const val REFRESH_REASON_BUTTON_CLICK = 200L