From aed5aca3dde5c52f3649033655ae0901f811c082 Mon Sep 17 00:00:00 2001 From: christosts Date: Mon, 20 Jul 2020 18:01:37 +0100 Subject: [PATCH] ActionFileUpgradeUtil: add more tests action files Add test action files for DASH, HLS, SmoothStreaming and Progressive. PiperOrigin-RevId: 322166875 --- .../offline/ActionFileUpgradeUtilTest.java | 174 +++++++++++++++--- ...action_file_for_download_index_upgrade.exi | Bin 161 -> 0 bytes ...n_file_for_download_index_upgrade_dash.exi | Bin 0 -> 146 bytes ...on_file_for_download_index_upgrade_hls.exi | Bin 0 -> 146 bytes ...for_download_index_upgrade_progressive.exi | Bin 0 -> 140 bytes ...ion_file_for_download_index_upgrade_ss.exi | Bin 0 -> 154 bytes 6 files changed, 145 insertions(+), 29 deletions(-) delete mode 100644 testdata/src/test/assets/offline/action_file_for_download_index_upgrade.exi create mode 100644 testdata/src/test/assets/offline/action_file_for_download_index_upgrade_dash.exi create mode 100644 testdata/src/test/assets/offline/action_file_for_download_index_upgrade_hls.exi create mode 100644 testdata/src/test/assets/offline/action_file_for_download_index_upgrade_progressive.exi create mode 100644 testdata/src/test/assets/offline/action_file_for_download_index_upgrade_ss.exi diff --git a/library/core/src/test/java/com/google/android/exoplayer2/offline/ActionFileUpgradeUtilTest.java b/library/core/src/test/java/com/google/android/exoplayer2/offline/ActionFileUpgradeUtilTest.java index c77dca90ee..df45f88401 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/offline/ActionFileUpgradeUtilTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/offline/ActionFileUpgradeUtilTest.java @@ -24,11 +24,10 @@ import com.google.android.exoplayer2.database.ExoDatabaseProvider; import com.google.android.exoplayer2.testutil.TestUtil; import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.Util; +import com.google.common.collect.ImmutableList; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.util.Arrays; -import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -58,38 +57,32 @@ public class ActionFileUpgradeUtilTest { } @Test - public void upgradeAndDelete_createsDownloads() throws IOException { - // Copy the test asset to a file. + public void upgradeAndDelete_progressiveActionFile_createsDownloads() throws IOException { byte[] actionFileBytes = TestUtil.getByteArray( ApplicationProvider.getApplicationContext(), - "offline/action_file_for_download_index_upgrade.exi"); + "offline/action_file_for_download_index_upgrade_progressive.exi"); try (FileOutputStream output = new FileOutputStream(tempFile)) { output.write(actionFileBytes); } - - StreamKey expectedStreamKey1 = - new StreamKey(/* periodIndex= */ 3, /* groupIndex= */ 4, /* trackIndex= */ 5); - StreamKey expectedStreamKey2 = - new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 1, /* trackIndex= */ 2); DownloadRequest expectedRequest1 = new DownloadRequest( - /* id= */ "key123", - Uri.parse("https://www.test.com/download1"), + /* id= */ "http://www.test.com/1/video.mp4", + Uri.parse("http://www.test.com/1/video.mp4"), /* mimeType= */ MimeTypes.VIDEO_UNKNOWN, - asList(expectedStreamKey1), + /* streamKeys= */ ImmutableList.of(), /* keySetId= */ null, - /* customCacheKey= */ "key123", - /* data= */ new byte[] {1, 2, 3, 4}); + /* customCacheKey= */ null, + /* data= */ null); DownloadRequest expectedRequest2 = new DownloadRequest( - /* id= */ "key234", - Uri.parse("https://www.test.com/download2"), + /* id= */ "customCacheKey", + Uri.parse("http://www.test.com/2/video.mp4"), /* mimeType= */ MimeTypes.VIDEO_UNKNOWN, - asList(expectedStreamKey2), + /* streamKeys= */ ImmutableList.of(), /* keySetId= */ null, - /* customCacheKey= */ "key234", - new byte[] {5, 4, 3, 2, 1}); + /* customCacheKey= */ "customCacheKey", + /* data= */ new byte[] {0, 1, 2, 3}); ActionFileUpgradeUtil.upgradeAndDelete( tempFile, @@ -98,6 +91,133 @@ public class ActionFileUpgradeUtilTest { /* deleteOnFailure= */ true, /* addNewDownloadsAsCompleted= */ false); + assertThat(tempFile.exists()).isFalse(); + assertDownloadIndexContainsRequest(expectedRequest1, Download.STATE_QUEUED); + assertDownloadIndexContainsRequest(expectedRequest2, Download.STATE_QUEUED); + } + + @Test + public void upgradeAndDelete_dashActionFile_createsDownloads() throws IOException { + byte[] actionFileBytes = + TestUtil.getByteArray( + ApplicationProvider.getApplicationContext(), + "offline/action_file_for_download_index_upgrade_dash.exi"); + try (FileOutputStream output = new FileOutputStream(tempFile)) { + output.write(actionFileBytes); + } + DownloadRequest expectedRequest1 = + new DownloadRequest( + /* id= */ "http://www.test.com/1/manifest.mpd", + Uri.parse("http://www.test.com/1/manifest.mpd"), + MimeTypes.APPLICATION_MPD, + /* streamKeys= */ ImmutableList.of(), + /* keySetId= */ null, + /* customCacheKey= */ null, + /* data= */ null); + DownloadRequest expectedRequest2 = + new DownloadRequest( + /* id= */ "http://www.test.com/2/manifest.mpd", + Uri.parse("http://www.test.com/2/manifest.mpd"), + MimeTypes.APPLICATION_MPD, + ImmutableList.of( + new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0), + new StreamKey(/* groupIndex= */ 1, /* trackIndex= */ 1)), + /* keySetId= */ null, + /* customCacheKey= */ null, + /* data= */ new byte[] {0, 1, 2, 3}); + + ActionFileUpgradeUtil.upgradeAndDelete( + tempFile, + /* downloadIdProvider= */ null, + downloadIndex, + /* deleteOnFailure= */ true, + /* addNewDownloadsAsCompleted= */ false); + + assertThat(tempFile.exists()).isFalse(); + assertDownloadIndexContainsRequest(expectedRequest1, Download.STATE_QUEUED); + assertDownloadIndexContainsRequest(expectedRequest2, Download.STATE_QUEUED); + } + + @Test + public void upgradeAndDelete_hlsActionFile_createsDownloads() throws IOException { + byte[] actionFileBytes = + TestUtil.getByteArray( + ApplicationProvider.getApplicationContext(), + "offline/action_file_for_download_index_upgrade_hls.exi"); + try (FileOutputStream output = new FileOutputStream(tempFile)) { + output.write(actionFileBytes); + } + DownloadRequest expectedRequest1 = + new DownloadRequest( + /* id= */ "http://www.test.com/1/manifest.m3u8", + Uri.parse("http://www.test.com/1/manifest.m3u8"), + MimeTypes.APPLICATION_M3U8, + /* streamKeys= */ ImmutableList.of(), + /* keySetId= */ null, + /* customCacheKey= */ null, + /* data= */ null); + DownloadRequest expectedRequest2 = + new DownloadRequest( + /* id= */ "http://www.test.com/2/manifest.m3u8", + Uri.parse("http://www.test.com/2/manifest.m3u8"), + MimeTypes.APPLICATION_M3U8, + ImmutableList.of( + new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0), + new StreamKey(/* groupIndex= */ 1, /* trackIndex= */ 1)), + /* keySetId= */ null, + /* customCacheKey= */ null, + /* data= */ new byte[] {0, 1, 2, 3}); + + ActionFileUpgradeUtil.upgradeAndDelete( + tempFile, + /* downloadIdProvider= */ null, + downloadIndex, + /* deleteOnFailure= */ true, + /* addNewDownloadsAsCompleted= */ false); + + assertThat(tempFile.exists()).isFalse(); + assertDownloadIndexContainsRequest(expectedRequest1, Download.STATE_QUEUED); + assertDownloadIndexContainsRequest(expectedRequest2, Download.STATE_QUEUED); + } + + @Test + public void upgradeAndDelete_smoothStreamingActionFile_createsDownloads() throws IOException { + byte[] actionFileBytes = + TestUtil.getByteArray( + ApplicationProvider.getApplicationContext(), + "offline/action_file_for_download_index_upgrade_ss.exi"); + try (FileOutputStream output = new FileOutputStream(tempFile)) { + output.write(actionFileBytes); + } + DownloadRequest expectedRequest1 = + new DownloadRequest( + /* id= */ "http://www.test.com/1/video.ism/manifest", + Uri.parse("http://www.test.com/1/video.ism/manifest"), + MimeTypes.APPLICATION_SS, + /* streamKeys= */ ImmutableList.of(), + /* keySetId= */ null, + /* customCacheKey= */ null, + /* data= */ null); + DownloadRequest expectedRequest2 = + new DownloadRequest( + /* id= */ "http://www.test.com/2/video.ism/manifest", + Uri.parse("http://www.test.com/2/video.ism/manifest"), + MimeTypes.APPLICATION_SS, + ImmutableList.of( + new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0), + new StreamKey(/* groupIndex= */ 1, /* trackIndex= */ 1)), + /* keySetId= */ null, + /* customCacheKey= */ null, + /* data= */ new byte[] {0, 1, 2, 3}); + + ActionFileUpgradeUtil.upgradeAndDelete( + tempFile, + /* downloadIdProvider= */ null, + downloadIndex, + /* deleteOnFailure= */ true, + /* addNewDownloadsAsCompleted= */ false); + + assertThat(tempFile.exists()).isFalse(); assertDownloadIndexContainsRequest(expectedRequest1, Download.STATE_QUEUED); assertDownloadIndexContainsRequest(expectedRequest2, Download.STATE_QUEUED); } @@ -109,7 +229,7 @@ public class ActionFileUpgradeUtilTest { /* id= */ "id", Uri.parse("https://www.test.com/download"), /* mimeType= */ null, - asList( + ImmutableList.of( new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 1, /* trackIndex= */ 2), new StreamKey(/* periodIndex= */ 3, /* groupIndex= */ 4, /* trackIndex= */ 5)), /* keySetId= */ new byte[] {1, 2, 3, 4}, @@ -133,7 +253,7 @@ public class ActionFileUpgradeUtilTest { /* id= */ "id", Uri.parse("https://www.test.com/download1"), /* mimeType= */ null, - asList(streamKey1), + ImmutableList.of(streamKey1), /* keySetId= */ new byte[] {1, 2, 3, 4}, /* customCacheKey= */ "key123", /* data= */ new byte[] {1, 2, 3, 4}); @@ -142,7 +262,7 @@ public class ActionFileUpgradeUtilTest { /* id= */ "id", Uri.parse("https://www.test.com/download2"), /* mimeType= */ MimeTypes.APPLICATION_MP4, - asList(streamKey2), + ImmutableList.of(streamKey2), /* keySetId= */ new byte[] {5, 4, 3, 2, 1}, /* customCacheKey= */ "key345", /* data= */ new byte[] {5, 4, 3, 2, 1}); @@ -174,7 +294,7 @@ public class ActionFileUpgradeUtilTest { /* id= */ "id1", Uri.parse("https://www.test.com/download1"), /* mimeType= */ null, - asList(streamKey1), + ImmutableList.of(streamKey1), /* keySetId= */ new byte[] {1, 2, 3, 4}, /* customCacheKey= */ "key123", /* data= */ new byte[] {1, 2, 3, 4}); @@ -183,7 +303,7 @@ public class ActionFileUpgradeUtilTest { /* id= */ "id2", Uri.parse("https://www.test.com/download2"), /* mimeType= */ null, - asList(streamKey2), + ImmutableList.of(streamKey2), /* keySetId= */ new byte[] {5, 4, 3, 2, 1}, /* customCacheKey= */ "key123", /* data= */ new byte[] {5, 4, 3, 2, 1}); @@ -207,8 +327,4 @@ public class ActionFileUpgradeUtilTest { assertThat(download.request).isEqualTo(request); assertThat(download.state).isEqualTo(state); } - - private static List asList(StreamKey... streamKeys) { - return Arrays.asList(streamKeys); - } } diff --git a/testdata/src/test/assets/offline/action_file_for_download_index_upgrade.exi b/testdata/src/test/assets/offline/action_file_for_download_index_upgrade.exi deleted file mode 100644 index 0bf49b133a1c91e9542671bad37539141a8f953d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 161 zcmZQz00SllmXg%s5+Iw2K`x`Dq@dVJU%$M(Tn{9wmzt!pOwT w0;Cy%m>I+eVpc{5w(QhOLnC9N%`yUNV_;=vVP*mu1i~NyqJaV+!;Fkg03X{PQ~&?~ diff --git a/testdata/src/test/assets/offline/action_file_for_download_index_upgrade_dash.exi b/testdata/src/test/assets/offline/action_file_for_download_index_upgrade_dash.exi new file mode 100644 index 0000000000000000000000000000000000000000..9c249a377eb4efe157bc08906206ff9dcb081842 GIT binary patch literal 146 zcmZQz00SllmXyTe3@}?Mqokz3N?*Ucyj-s&wYWqtIX_q5P(L>@FEb6q%`HfQXabQ0 Yv>9P&V_{%qVg_ntLYM((F#=hP0B~O%cmMzZ literal 0 HcmV?d00001 diff --git a/testdata/src/test/assets/offline/action_file_for_download_index_upgrade_hls.exi b/testdata/src/test/assets/offline/action_file_for_download_index_upgrade_hls.exi new file mode 100644 index 0000000000000000000000000000000000000000..a6315a80ef4d4bfd0177ba698ca53e1caf07676e GIT binary patch literal 146 zcmZQz00Sll=8T+TAd`_nIisYcz)D}gyu4hmB(=CiFF8L~-%vj{F)uR>#LYD>wSZ^> ak@&S4VQOPxU}RzjYGgu~0cSA+S&RTibQ|CR literal 0 HcmV?d00001 diff --git a/testdata/src/test/assets/offline/action_file_for_download_index_upgrade_progressive.exi b/testdata/src/test/assets/offline/action_file_for_download_index_upgrade_progressive.exi new file mode 100644 index 0000000000000000000000000000000000000000..477bd0815a5c80d19c275ee2440eb9de4d667185 GIT binary patch literal 140 zcmZQz00Sll?t-HH^rF<_;>@yCu#kL4NlAf~zJ7Umxn4 kfeAz-k@}2K^|3H8GBGnU@FkZPm*nR