diff options
author | 2025-03-03 03:24:36 -0800 | |
---|---|---|
committer | 2025-03-03 03:24:36 -0800 | |
commit | 618c4babf98b8879d8ecedec5eb91ee466ed209a (patch) | |
tree | b7c828912eb074f5d3252755107bb9922cc5353a /tests | |
parent | 60885ba9eacda84822cd7d79fd937a6388ddabb6 (diff) | |
parent | 37a8ed07adff4b374d169613c2b471b56954a047 (diff) |
Merge "Hide cloud collections when a full sync is in progress" into main
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/providers/media/photopicker/PickerSyncControllerTest.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/src/com/android/providers/media/photopicker/PickerSyncControllerTest.java b/tests/src/com/android/providers/media/photopicker/PickerSyncControllerTest.java index ba98432fc..9dc227cc0 100644 --- a/tests/src/com/android/providers/media/photopicker/PickerSyncControllerTest.java +++ b/tests/src/com/android/providers/media/photopicker/PickerSyncControllerTest.java @@ -25,6 +25,7 @@ import static com.android.providers.media.util.BackgroundThreadUtils.waitForIdle import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; +import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; @@ -59,6 +60,7 @@ import com.android.providers.media.photopicker.data.CloudProviderInfo; import com.android.providers.media.photopicker.data.PickerDatabaseHelper; import com.android.providers.media.photopicker.data.PickerDbFacade; import com.android.providers.media.photopicker.sync.PickerSyncLockManager; +import com.android.providers.media.photopicker.util.exceptions.RequestObsoleteException; import com.android.providers.media.photopicker.util.exceptions.UnableToAcquireLockException; import com.android.providers.media.photopicker.v2.model.ProviderCollectionInfo; @@ -2101,6 +2103,70 @@ public class PickerSyncControllerTest { .that(mFacade.getCloudProvider()).isEqualTo(CLOUD_PRIMARY_PROVIDER_AUTHORITY); } + @Test + public void testIsFullSyncPending() throws RequestObsoleteException { + mController.setCloudProvider(/* authority */ CLOUD_PRIMARY_PROVIDER_AUTHORITY); + assertWithMessage("Full sync should be pending after setting the CMP.") + .that(mController.isFullSyncPending(CLOUD_PRIMARY_PROVIDER_AUTHORITY, false)) + .isTrue(); + + mController.syncAllMedia(); + assertWithMessage("Full sync should be completed after syncing with the CMP.") + .that(mController.isFullSyncPending(CLOUD_PRIMARY_PROVIDER_AUTHORITY, false)) + .isFalse(); + + // First Page of data + addMedia(mCloudFlakyMediaGenerator, CLOUD_ONLY_1); + addMedia(mCloudFlakyMediaGenerator, CLOUD_ONLY_2); + addMedia(mCloudFlakyMediaGenerator, CLOUD_ONLY_3); + addMedia(mCloudFlakyMediaGenerator, CLOUD_ONLY_4); + addMedia(mCloudFlakyMediaGenerator, CLOUD_ONLY_5); + // Second Page of data + addMedia(mCloudFlakyMediaGenerator, CLOUD_ONLY_6); + addMedia(mCloudFlakyMediaGenerator, CLOUD_ONLY_7); + addMedia(mCloudFlakyMediaGenerator, CLOUD_ONLY_8); + addMedia(mCloudFlakyMediaGenerator, CLOUD_ONLY_9); + addMedia(mCloudFlakyMediaGenerator, CLOUD_ONLY_10); + // Third Page of data + addMedia(mCloudFlakyMediaGenerator, CLOUD_ONLY_11); + + mController.setCloudProvider(/* authority */ FLAKY_CLOUD_PROVIDER_AUTHORITY); + assertWithMessage("Full sync should be pending after setting the CMP.") + .that(mController.isFullSyncPending(FLAKY_CLOUD_PROVIDER_AUTHORITY, false)) + .isTrue(); + + // FlakyCloudMediaProvider will throw errors on 2 out of 3 requests, if we sync once, it + // should not be able to complete the sync. + mController.syncAllMedia(); + assertWithMessage("Full sync should still be pending because it was stopped in between.") + .that(mController.isFullSyncPending(FLAKY_CLOUD_PROVIDER_AUTHORITY, false)) + .isTrue(); + + mController.syncAllMedia(); + mController.syncAllMedia(); + mController.syncAllMedia(); + assertWithMessage("Full sync should be complete now.") + .that(mController.isFullSyncPending(FLAKY_CLOUD_PROVIDER_AUTHORITY, false)) + .isFalse(); + } + + @Test + public void testIsFullSyncPendingForStaleCMP() throws RequestObsoleteException { + mController.setCloudProvider(/* authority */ CLOUD_PRIMARY_PROVIDER_AUTHORITY); + assertWithMessage("Full sync should be pending after setting the CMP.") + .that(mController.isFullSyncPending(CLOUD_PRIMARY_PROVIDER_AUTHORITY, false)) + .isTrue(); + + mController.syncAllMedia(); + assertWithMessage("Full sync should be completed after syncing with the CMP.") + .that(mController.isFullSyncPending(CLOUD_PRIMARY_PROVIDER_AUTHORITY, false)) + .isFalse(); + + assertThrows(RequestObsoleteException.class, + () -> mController.isFullSyncPending( + CLOUD_SECONDARY_PROVIDER_AUTHORITY, false)); + } + private static void addMedia(MediaGenerator generator, Pair<String, String> media) { generator.addMedia(media.first, media.second); } |