blob: 6bbd2b02865a39a85f52108a6788ca6c2a782a5f [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<title>WebKitMediaKeys</title>
<script src=../video-test.js></script>
<script>
function stringToUint8Array(str)
{
var arr=[];
for(var i=0,j=str.length;i<j;++i)
arr[i]=str.charCodeAt(i);
return new Uint8Array(arr);
}
var mediaKeys;
var mediaKeySession;
var initData = stringToUint8Array('mock');
function runTest()
{
// Initialize the MockCDM. It supports the key system 'com.apple.mock', the
// mime type 'video/mock'. It requires init data to begin with 'mock', and
// keys to begin with 'key'.
if (internals)
internals.initializeMockCDM();
consoleWrite("Test WebKitMediaKeys.");
testExpected('typeof window.WebKitMediaKeys', 'object');
testDOMException('new WebKitMediaKeys("")', "DOMException.INVALID_ACCESS_ERR");
testDOMException('new WebKitMediaKeys("unsupported")', "DOMException.NOT_SUPPORTED_ERR");
run('mediaKeys = new WebKitMediaKeys("com.webcore.mock")');
testExpected('mediaKeys.keySystem', 'com.webcore.mock');
testExpected('typeof mediaKeys.createSession', 'function');
testDOMException('mediaKeys.createSession("", new Uint8Array(1))', "DOMException.INVALID_ACCESS_ERR");
testDOMException('mediaKeys.createSession("unsupported/type")', "DOMException.NOT_SUPPORTED_ERR");
consoleWrite("");
consoleWrite("Test WebKitMediaKeySession.");
run('mediaKeySession = mediaKeys.createSession("video/mock", initData)');
testExpected('typeof mediaKeySession', 'object');
testExpected('typeof mediaKeySession.addEventListener', 'function');
testExpected('typeof mediaKeySession.update', 'function');
testExpected('mediaKeySession.error', null);
testExpected('mediaKeySession.keySystem', 'com.webcore.mock');
testExpected('mediaKeySession.sessionId', null, '!=');
testExpected('mediaKeySession.onwebkitkeyadded', null);
testExpected('mediaKeySession.onwebkitkeyerror', null);
testExpected('mediaKeySession.onwebkitkeymessage', null);
testDOMException('mediaKeySession.update(null)', "DOMException.INVALID_ACCESS_ERR");
endTest();
}
</script>
</head>
<body onload="runTest()">
<p>This tests the basic API of WebKitMediaKeys and WebKitMediaKeySession.</p>
</body>
</html>