mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-26 12:44:38 +00:00
Add support for inline video playback of gifs in Conversation.
This commit is contained in:
committed by
Greyson Parrelli
parent
32d79ead15
commit
281630e751
@@ -0,0 +1,19 @@
|
||||
package org.thoughtcrime.securesms.giph.mp4
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class GiphyMp4PlaybackControllerRangeComparatorTest {
|
||||
@Test
|
||||
fun `Given a range of numbers, when I sort with comparator, then I expect an array sorted from the center out`() {
|
||||
val testSubject = createComparator(0, 10)
|
||||
|
||||
val sorted = (0..10).sortedWith(testSubject).toIntArray()
|
||||
val expected = intArrayOf(5, 4, 6, 3, 7, 2, 8, 1, 9, 0, 10)
|
||||
|
||||
Assert.assertArrayEquals(expected, sorted)
|
||||
}
|
||||
|
||||
private fun createComparator(start: Int, end: Int): GiphyMp4PlaybackController.RangeComparator =
|
||||
GiphyMp4PlaybackController.RangeComparator(start, end)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.thoughtcrime.securesms.giph.mp4
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class GiphyMp4PlaybackPolicyEnforcerTest {
|
||||
|
||||
@Test
|
||||
fun `Given a 1s video, when I have a max time of 8s and max repeats of 4, then I expect 4 loops`() {
|
||||
val mediaDuration = TimeUnit.SECONDS.toMillis(1)
|
||||
val maxDuration = TimeUnit.SECONDS.toMillis(8)
|
||||
val maxRepeats = 4L
|
||||
var ended = false
|
||||
val testSubject = GiphyMp4PlaybackPolicyEnforcer({ ended = true }, maxDuration, maxRepeats)
|
||||
|
||||
testSubject.setMediaDuration(mediaDuration)
|
||||
|
||||
Assert.assertTrue((0..2).map { testSubject.endPlayback() }.all { !it })
|
||||
Assert.assertFalse(ended)
|
||||
Assert.assertTrue(testSubject.endPlayback())
|
||||
Assert.assertTrue(ended)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given a 3s video, when I have a max time of 8s and max repeats of 4, then I expect 2 loops`() {
|
||||
val mediaDuration = TimeUnit.SECONDS.toMillis(3)
|
||||
val maxDuration = TimeUnit.SECONDS.toMillis(8)
|
||||
val maxRepeats = 4L
|
||||
var ended = false
|
||||
val testSubject = GiphyMp4PlaybackPolicyEnforcer({ ended = true }, maxDuration, maxRepeats)
|
||||
|
||||
testSubject.setMediaDuration(mediaDuration)
|
||||
|
||||
Assert.assertFalse(testSubject.endPlayback())
|
||||
Assert.assertFalse(ended)
|
||||
Assert.assertTrue(testSubject.endPlayback())
|
||||
Assert.assertTrue(ended)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given a 10s video, when I have a max time of 8s and max repeats of 4, then I expect 1 loop`() {
|
||||
val mediaDuration = TimeUnit.SECONDS.toMillis(10)
|
||||
val maxDuration = TimeUnit.SECONDS.toMillis(8)
|
||||
val maxRepeats = 4L
|
||||
var ended = false
|
||||
val testSubject = GiphyMp4PlaybackPolicyEnforcer({ ended = true }, maxDuration, maxRepeats)
|
||||
|
||||
testSubject.setMediaDuration(mediaDuration)
|
||||
|
||||
Assert.assertTrue(testSubject.endPlayback())
|
||||
Assert.assertTrue(ended)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user