blob: 05973fd1440c44a338caffbcddb47a0ade3896bc [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', 'function');
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");
testException('mediaKeys.createSession("unsupported/type")', "'TypeError: Not enough arguments'");
testDOMException('mediaKeys.createSession("unsupported/type", new Uint8Array(1))', "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);
testException('mediaKeySession.update(null)', "'TypeError: Argument 1 (\\'key\\') to WebKitMediaKeySession.update must be an instance of Uint8Array'");
endTest();
}
</script>
</head>
<body onload="runTest()">
<p>This tests the basic API of WebKitMediaKeys and WebKitMediaKeySession.</p>
</body>
</html>