Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / android_webview / javatests / src / org / chromium / android_webview / test / KeySystemTest.java
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.
4
5 package org.chromium.android_webview.test;
6
7 import android.os.Build;
8 import android.test.suitebuilder.annotation.SmallTest;
9
10 import org.chromium.android_webview.AwContents;
11 import org.chromium.base.test.util.Feature;
12
13 /**
14  * TestSuite for EME key systems.
15  */
16 public class KeySystemTest extends AwTestBase {
17
18     private TestAwContentsClient mContentsClient = new TestAwContentsClient();
19     private AwContents mAwContents;
20
21     @Override
22     protected void setUp() throws Exception {
23         super.setUp();
24
25         final AwTestContainerView testContainerView =
26                 createAwTestContainerViewOnMainSync(mContentsClient);
27         mAwContents = testContainerView.getAwContents();
28         enableJavaScriptOnUiThread(mAwContents);
29
30         loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
31             getKeySystemTestPage(), "text/html", false);
32     }
33
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);" +
39                 "}" +
40                 "</script> </html>";
41     }
42
43     private String isKeySystemSupported(String keySystem) throws Exception {
44         return executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
45                   "isKeySystemSupported('" + keySystem + "')");
46     }
47
48     @Feature({"AndroidWebView"})
49     @SmallTest
50     public void testSupportClearKeySystem() throws Throwable {
51         assertEquals("\"maybe\"", isKeySystemSupported("webkit-org.w3.clearkey"));
52     }
53
54     @Feature({"AndroidWebView"})
55     @SmallTest
56     public void testSupportWidevineKeySystem() throws Throwable {
57         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
58             return;  // MediaDrm/Crypto is supported from KitKat.
59         }
60         assertEquals("\"maybe\"", isKeySystemSupported("com.widevine.alpha"));
61     }
62
63     @Feature({"AndroidWebView"})
64     @SmallTest
65     public void testNotSupportFooKeySystem() throws Throwable {
66         assertEquals("\"\"", isKeySystemSupported("com.foo.keysystem"));
67     }
68
69     @Feature({"AndroidWebView"})
70     @SmallTest
71     public void testSupportPlatformKeySystem() throws Throwable {
72         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
73             return;  // MediaDrm/Crypto is supported from KitKat.
74         }
75         assertEquals("\"maybe\"", isKeySystemSupported("com.oem.test-keysystem"));
76     }
77 }