diff options
author | ddorwin <ddorwin@chromium.org> | 2015-09-15 13:40:41 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-15 20:41:15 +0000 |
commit | 05ed8af0a33ad820c45c3f026703ebf433711628 (patch) | |
tree | 92e8d91d3bc620d4a705025d15338dba684cfb58 /android_webview | |
parent | 2f0be931fd7358911a68b81a3fd6d0fcfb0c54ce (diff) | |
download | chromium_src-05ed8af0a33ad820c45c3f026703ebf433711628.zip chromium_src-05ed8af0a33ad820c45c3f026703ebf433711628.tar.gz chromium_src-05ed8af0a33ad820c45c3f026703ebf433711628.tar.bz2 |
Switch WebView KeySystemTest to unprefixed EME.
requestMediaKeySystemAccess() is used to determine key system support.
For platform-based key systems, it requires the ProtectedMediaId permission.
BUG=451117
TEST=Modified tests pass.
Review URL: https://codereview.chromium.org/1335893003
Cr-Commit-Position: refs/heads/master@{#348983}
Diffstat (limited to 'android_webview')
-rw-r--r-- | android_webview/javatests/src/org/chromium/android_webview/test/KeySystemTest.java | 79 | ||||
-rw-r--r-- | android_webview/test/shell/res/values/config.xml | 2 |
2 files changed, 67 insertions, 14 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/KeySystemTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/KeySystemTest.java index 5f67179..ccc036f 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/KeySystemTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/KeySystemTest.java @@ -8,16 +8,39 @@ import android.os.Build; import android.test.suitebuilder.annotation.SmallTest; import org.chromium.android_webview.AwContents; +import org.chromium.android_webview.permission.AwPermissionRequest; +import org.chromium.android_webview.permission.Resource; import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.MinAndroidSdkLevel; +import java.util.concurrent.Callable; + /** * TestSuite for EME key systems. + * + * MediaDrm support requires KitKat or later. + * Although, WebView requires Lollipop for the onPermissionRequest() API, + * this test intercepts this path and thus can run on KitKat. */ @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT) public class KeySystemTest extends AwTestBase { + /** + * AwContentsClient subclass that allows permissions requests for the + * protected media ID. This is required for all supported key systems other + * than Clear Key. + */ + private static class EmeAllowingAwContentsClient extends TestAwContentsClient { + @Override + public void onPermissionRequest(AwPermissionRequest awPermissionRequest) { + if (awPermissionRequest.getResources() == Resource.ProtectedMediaId) { + awPermissionRequest.grant(); + } else { + awPermissionRequest.deny(); + } + } + }; - private TestAwContentsClient mContentsClient = new TestAwContentsClient(); + private TestAwContentsClient mContentsClient = new EmeAllowingAwContentsClient(); private AwContents mAwContents; @Override @@ -35,45 +58,73 @@ public class KeySystemTest extends AwTestBase { private String getKeySystemTestPage() { return "<html> <script>" + + "var result;" + + "function success(keySystemAccess) {" + + " result = 'supported';" + + "}" + + "function failure(error){" + + " result = error.name;" + + "}" + "function isKeySystemSupported(keySystem) {" - + " var video = document.createElement('video');" - + " return video.canPlayType('video/mp4', keySystem);" + + " navigator.requestMediaKeySystemAccess(keySystem, [{}]).then(" + + " success, failure);" + "}" + "</script> </html>"; } private String isKeySystemSupported(String keySystem) throws Exception { - return executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, + executeJavaScriptAndWaitForResult(mAwContents, mContentsClient, "isKeySystemSupported('" + keySystem + "')"); + + poll(new Callable<Boolean>() { + @Override + public Boolean call() throws Exception { + return !getResultFromJS().equals("null"); + } + }); + + return getResultFromJS(); + } + + private String getResultFromJS() { + String result = "null"; + try { + result = executeJavaScriptAndWaitForResult( + mAwContents, mContentsClient, "result"); + } catch (Exception e) { + fail("Unable to get result"); + } + return result; } @Feature({"AndroidWebView"}) @SmallTest public void testSupportClearKeySystem() throws Throwable { - assertEquals("\"maybe\"", isKeySystemSupported("webkit-org.w3.clearkey")); + assertEquals("\"supported\"", isKeySystemSupported("org.w3.clearkey")); } @Feature({"AndroidWebView"}) @SmallTest public void testSupportWidevineKeySystem() throws Throwable { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - return; // MediaDrm/Crypto is supported from KitKat. - } - assertEquals("\"maybe\"", isKeySystemSupported("com.widevine.alpha")); + assertEquals("\"supported\"", isKeySystemSupported("com.widevine.alpha")); } @Feature({"AndroidWebView"}) @SmallTest public void testNotSupportFooKeySystem() throws Throwable { - assertEquals("\"\"", isKeySystemSupported("com.foo.keysystem")); + assertEquals("\"NotSupportedError\"", isKeySystemSupported("com.foo.keysystem")); } @Feature({"AndroidWebView"}) @SmallTest public void testSupportPlatformKeySystem() throws Throwable { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - return; // MediaDrm/Crypto is supported from KitKat. - } - assertEquals("\"maybe\"", isKeySystemSupported("com.oem.test-keysystem")); + assertEquals("\"supported\"", isKeySystemSupported("x-com.oem.test-keysystem")); + } + + // TODO(ddorwin): This should fail: http://crbug.com/531764. + @Feature({"AndroidWebView"}) + @SmallTest + public void testSupportPlatformKeySystemNoPrefix() throws Throwable { + assertEquals("\"supported\"", isKeySystemSupported("com.oem.test-keysystem")); } } diff --git a/android_webview/test/shell/res/values/config.xml b/android_webview/test/shell/res/values/config.xml index 4d2b7d8..9a3f2f5 100644 --- a/android_webview/test/shell/res/values/config.xml +++ b/android_webview/test/shell/res/values/config.xml @@ -9,6 +9,8 @@ <string-array name="config_key_system_uuid_mapping" translatable="false"> <!-- Use Widevine's UUID to pass the availability-test of MediaDRM plugin --> <!--suppress TypographyDashes --> + <item>"x-com.oem.test-keysystem,EDEF8BA9-79D6-4ACE-A3C8-27DCD51D21ED"</item> + <!--suppress TypographyDashes --> <item>"com.oem.test-keysystem,EDEF8BA9-79D6-4ACE-A3C8-27DCD51D21ED"</item> </string-array> </resources> |