Fix Widevine offline test assertion for API29+.

The error type thrown when acquiring a license that has already
been released changed from MediaDrmStateException to IllegalStateException
from API 29.

Update the tests to assert the correct type of error based on API version.

PiperOrigin-RevId: 308239508
This commit is contained in:
tonihei 2020-04-24 13:49:09 +01:00 committed by Ian Baker
parent 30c55d117e
commit 13c668f9e0

View File

@ -17,7 +17,7 @@ package com.google.android.exoplayer2.playbacktests.gts;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.fail; import static org.junit.Assert.assertThrows;
import android.media.MediaDrm.MediaDrmStateException; import android.media.MediaDrm.MediaDrmStateException;
import android.net.Uri; import android.net.Uri;
@ -111,29 +111,47 @@ public final class DashWidevineOfflineTest {
@Test @Test
public void widevineOfflineReleasedLicenseV22() throws Throwable { public void widevineOfflineReleasedLicenseV22() throws Throwable {
if (Util.SDK_INT < 22) { if (Util.SDK_INT < 22 || Util.SDK_INT > 28) {
return; // Pass. return; // Pass.
} }
downloadLicense(); downloadLicense();
releaseLicense(); // keySetId no longer valid. releaseLicense(); // keySetId no longer valid.
try { Throwable error =
testRunner.run(); assertThrows(
fail("Playback should fail because the license has been released."); "Playback should fail because the license has been released.",
} catch (Throwable e) { Throwable.class,
() -> testRunner.run());
// Get the root cause // Get the root cause
while (true) { Throwable cause = error.getCause();
Throwable cause = e.getCause(); while (cause != null && cause != error) {
if (cause == null || cause == e) { error = cause;
break; cause = error.getCause();
} }
e = cause; assertThat(error).isInstanceOf(MediaDrmStateException.class);
} }
// It should be a MediaDrmStateException instance
if (!(e instanceof MediaDrmStateException)) { @Test
throw e; public void widevineOfflineReleasedLicenseV29() throws Throwable {
if (Util.SDK_INT < 29) {
return; // Pass.
} }
downloadLicense();
releaseLicense(); // keySetId no longer valid.
Throwable error =
assertThrows(
"Playback should fail because the license has been released.",
Throwable.class,
() -> testRunner.run());
// Get the root cause
Throwable cause = error.getCause();
while (cause != null && cause != error) {
error = cause;
cause = error.getCause();
} }
assertThat(error).isInstanceOf(IllegalArgumentException.class);
} }
@Test @Test