1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.android_webview.test;
7 import android.os.Build;
8 import android.test.suitebuilder.annotation.SmallTest;
10 import org.chromium.android_webview.AwContents;
11 import org.chromium.base.test.util.Feature;
14 * TestSuite for EME key systems.
16 public class KeySystemTest extends AwTestBase {
18 private TestAwContentsClient mContentsClient = new TestAwContentsClient();
19 private AwContents mAwContents;
22 protected void setUp() throws Exception {
25 final AwTestContainerView testContainerView =
26 createAwTestContainerViewOnMainSync(mContentsClient);
27 mAwContents = testContainerView.getAwContents();
28 enableJavaScriptOnUiThread(mAwContents);
30 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
31 getKeySystemTestPage(), "text/html", false);
34 private String getKeySystemTestPage() {
35 return "<html> <script>" +
36 "function isKeySystemSupported(keySystem) {" +
37 "var video = document.createElement('video');" +
38 "return video.canPlayType('video/mp4', keySystem);" +
43 private String isKeySystemSupported(String keySystem) throws Exception {
44 return executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
45 "isKeySystemSupported('" + keySystem + "')");
48 @Feature({"AndroidWebView"})
50 public void testSupportClearKeySystem() throws Throwable {
51 assertEquals("\"maybe\"", isKeySystemSupported("webkit-org.w3.clearkey"));
54 @Feature({"AndroidWebView"})
56 public void testSupportWidevineKeySystem() throws Throwable {
57 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
58 return; // MediaDrm/Crypto is supported from KitKat.
60 assertEquals("\"maybe\"", isKeySystemSupported("com.widevine.alpha"));
63 @Feature({"AndroidWebView"})
65 public void testNotSupportFooKeySystem() throws Throwable {
66 assertEquals("\"\"", isKeySystemSupported("com.foo.keysystem"));
69 @Feature({"AndroidWebView"})
71 public void testSupportPlatformKeySystem() throws Throwable {
72 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
73 return; // MediaDrm/Crypto is supported from KitKat.
75 assertEquals("\"maybe\"", isKeySystemSupported("com.oem.test-keysystem"));