OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.android_webview.test; | 5 package org.chromium.android_webview.test; |
6 | 6 |
7 import android.os.Build; | 7 import android.os.Build; |
8 import android.support.test.filters.SmallTest; | 8 import android.support.test.filters.SmallTest; |
9 | 9 |
10 import org.chromium.android_webview.AwContents; | 10 import org.chromium.android_webview.AwContents; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 @Override | 44 @Override |
45 protected void setUp() throws Exception { | 45 protected void setUp() throws Exception { |
46 super.setUp(); | 46 super.setUp(); |
47 | 47 |
48 final AwTestContainerView testContainerView = | 48 final AwTestContainerView testContainerView = |
49 createAwTestContainerViewOnMainSync(mContentsClient); | 49 createAwTestContainerViewOnMainSync(mContentsClient); |
50 mAwContents = testContainerView.getAwContents(); | 50 mAwContents = testContainerView.getAwContents(); |
51 enableJavaScriptOnUiThread(mAwContents); | 51 enableJavaScriptOnUiThread(mAwContents); |
52 | 52 |
53 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 53 // Treat file:/// as secure context, which is required by EME APIs. |
54 getKeySystemTestPage(), "text/html", false); | 54 allowFileAccessFromFileURLs(mAwContents); |
55 } | |
56 | 55 |
57 private String getKeySystemTestPage() { | 56 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
58 return "<html> <script>" | 57 "file:///android_asset/key-system-test.html"); |
59 + "var result;" | |
60 + "function success(keySystemAccess) {" | |
61 + " result = 'supported';" | |
62 + "}" | |
63 + "function failure(error){" | |
64 + " result = error.name;" | |
65 + "}" | |
66 + "function isKeySystemSupported(keySystem) {" | |
67 + " navigator.requestMediaKeySystemAccess(keySystem, [{}]).then
(" | |
68 + " success, failure);" | |
69 + "}" | |
70 + "function areProprietaryCodecsSupported() {" | |
71 + " var video = document.createElement('video');" | |
72 + " return video.canPlayType('video/mp4; codecs=\"avc1\"');" | |
73 + "}" | |
74 + "</script> </html>"; | |
75 } | 58 } |
76 | 59 |
77 private String isKeySystemSupported(String keySystem) throws Exception { | 60 private String isKeySystemSupported(String keySystem) throws Exception { |
78 executeJavaScriptAndWaitForResult( | 61 executeJavaScriptAndWaitForResult( |
79 mAwContents, mContentsClient, "isKeySystemSupported('" + keySyst
em + "')"); | 62 mAwContents, mContentsClient, "isKeySystemSupported('" + keySyst
em + "')"); |
80 | 63 |
81 pollInstrumentationThread(new Callable<Boolean>() { | 64 pollInstrumentationThread(new Callable<Boolean>() { |
82 @Override | 65 @Override |
83 public Boolean call() throws Exception { | 66 public Boolean call() throws Exception { |
84 return !getResultFromJS().equals("null"); | 67 return !getResultFromJS().equals("null"); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 assertEquals(getPlatformKeySystemExpectations(), | 125 assertEquals(getPlatformKeySystemExpectations(), |
143 isKeySystemSupported("x-com.oem.test-keysystem")); | 126 isKeySystemSupported("x-com.oem.test-keysystem")); |
144 } | 127 } |
145 | 128 |
146 @Feature({"AndroidWebView"}) | 129 @Feature({"AndroidWebView"}) |
147 @SmallTest | 130 @SmallTest |
148 public void testSupportPlatformKeySystemNoPrefix() throws Throwable { | 131 public void testSupportPlatformKeySystemNoPrefix() throws Throwable { |
149 assertEquals("\"NotSupportedError\"", isKeySystemSupported("com.oem.test
-keysystem")); | 132 assertEquals("\"NotSupportedError\"", isKeySystemSupported("com.oem.test
-keysystem")); |
150 } | 133 } |
151 } | 134 } |
OLD | NEW |