Add Encrypted Media Extensions events and errors to HTMLMediaElement

https://bugs.webkit.org/show_bug.cgi?id=82974

Patch by David Dorwin <ddorwin@chromium.org> on 2012-04-12
Reviewed by Adam Barth.

The new events and errors are behind the ENABLE(ENCRYPTED_MEDIA) feature define.
Implementation is based on v0.1 of the draft proposal at
http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-media.html#events.

Source/WebCore:

Tests: fast/events/constructors/media-key-event-constructor.html
       media/encrypted-media/encrypted-media-constants.html
       media/encrypted-media/encrypted-media-events.html

* WebCore.gypi:
* bindings/v8/Dictionary.cpp:
(WebCore::Dictionary::get):
(WebCore):
* bindings/v8/Dictionary.h:
(WebCore):
(Dictionary):
* dom/EventNames.h:
(WebCore):
* dom/EventNames.in:
* html/HTMLAttributeNames.in:
* html/HTMLMediaElement.cpp:
(WebCore):
(WebCore::HTMLMediaElement::mediaPlayerKeyAdded):
(WebCore::HTMLMediaElement::mediaPlayerKeyError):
(WebCore::HTMLMediaElement::mediaPlayerKeyMessage):
(WebCore::HTMLMediaElement::mediaPlayerKeyNeeded):
* html/HTMLMediaElement.h:
(HTMLMediaElement):
* html/HTMLMediaElement.idl:
* html/MediaError.h:
* html/MediaError.idl:
* html/MediaKeyError.h: Added.
(WebCore):
(MediaKeyError):
(WebCore::MediaKeyError::create):
(WebCore::MediaKeyError::code):
(WebCore::MediaKeyError::MediaKeyError):
* html/MediaKeyError.idl: Added.
* html/MediaKeyEvent.cpp: Added.
(WebCore):
(WebCore::MediaKeyEventInit::MediaKeyEventInit):
(WebCore::MediaKeyEvent::MediaKeyEvent):
(WebCore::MediaKeyEvent::~MediaKeyEvent):
(WebCore::MediaKeyEvent::interfaceName):
* html/MediaKeyEvent.h: Added.
(WebCore):
(MediaKeyEventInit):
(MediaKeyEvent):
(WebCore::MediaKeyEvent::create):
(WebCore::MediaKeyEvent::keySystem):
(WebCore::MediaKeyEvent::sessionId):
(WebCore::MediaKeyEvent::initData):
(WebCore::MediaKeyEvent::message):
(WebCore::MediaKeyEvent::defaultURL):
(WebCore::MediaKeyEvent::errorCode):
(WebCore::MediaKeyEvent::systemCode):
* html/MediaKeyEvent.idl: Added.
* page/DOMWindow.idl:
* platform/graphics/MediaPlayer.cpp:
(WebCore):
(WebCore::MediaPlayer::keyAdded):
(WebCore::MediaPlayer::keyError):
(WebCore::MediaPlayer::keyMessage):
(WebCore::MediaPlayer::keyNeeded):
* platform/graphics/MediaPlayer.h:
(MediaPlayerClient):
(WebCore::MediaPlayerClient::mediaPlayerKeyAdded):
(WebCore::MediaPlayerClient::mediaPlayerKeyError):
(WebCore::MediaPlayerClient::mediaPlayerKeyMessage):
(WebCore::MediaPlayerClient::mediaPlayerKeyNeeded):
(MediaPlayer):

Source/WebKit/chromium:

* public/WebMediaPlayerClient.h:
* src/AssertMatchingEnums.cpp:
* src/WebMediaPlayerClientImpl.cpp:
(WebKit::WebMediaPlayerClientImpl::keyAdded):
(WebKit):
(WebKit::WebMediaPlayerClientImpl::keyError):
(WebKit::WebMediaPlayerClientImpl::keyMessage):
(WebKit::WebMediaPlayerClientImpl::keyNeeded):
* src/WebMediaPlayerClientImpl.h:
(WebMediaPlayerClientImpl):

LayoutTests:

* fast/events/constructors/media-key-event-constructor-expected.txt: Added.
* fast/events/constructors/media-key-event-constructor.html: Added.
* fast/js/resources/js-test-pre.js:
(shouldBeZero):
(shouldBeEmptyString):
* media/encrypted-media/encrypted-media-constants-expected.txt: Added.
* media/encrypted-media/encrypted-media-constants.html: Added.
* media/encrypted-media/encrypted-media-events-expected.txt: Added.
* media/encrypted-media/encrypted-media-events.html: Added.
* media/video-test.js:
(testExpected):
(testArraysEqual):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114067 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5bb1d5ee
2012-04-12 David Dorwin <ddorwin@chromium.org>
Add Encrypted Media Extensions events and errors to HTMLMediaElement
https://bugs.webkit.org/show_bug.cgi?id=82974
Reviewed by Adam Barth.
The new events and errors are behind the ENABLE(ENCRYPTED_MEDIA) feature define.
Implementation is based on v0.1 of the draft proposal at
http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-media.html#events.
* fast/events/constructors/media-key-event-constructor-expected.txt: Added.
* fast/events/constructors/media-key-event-constructor.html: Added.
* fast/js/resources/js-test-pre.js:
(shouldBeZero):
(shouldBeEmptyString):
* media/encrypted-media/encrypted-media-constants-expected.txt: Added.
* media/encrypted-media/encrypted-media-constants.html: Added.
* media/encrypted-media/encrypted-media-events-expected.txt: Added.
* media/encrypted-media/encrypted-media-events.html: Added.
* media/video-test.js:
(testExpected):
(testArraysEqual):
2012-04-12 Pablo Flouret <pablof@motorola.com>
Make layout tests not access apache on localhost:80
This tests the constructor for the MediaKeyEvent DOM class.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
*** No initializer passed ***
PASS new MediaKeyEvent('MediaKeyEvent').bubbles is false
PASS new MediaKeyEvent('MediaKeyEvent').cancelable is false
PASS new MediaKeyEvent('MediaKeyEvent').keySystem is ""
PASS new MediaKeyEvent('MediaKeyEvent').sessionId is ""
PASS new MediaKeyEvent('MediaKeyEvent').initData is null
PASS new MediaKeyEvent('MediaKeyEvent').message is null
PASS new MediaKeyEvent('MediaKeyEvent').defaultURL is ""
PASS new MediaKeyEvent('MediaKeyEvent').errorCode is null
PASS new MediaKeyEvent('MediaKeyEvent').systemCode is 0
*** Bubbles and cancelable true, other members are missing ***
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).bubbles is true
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).cancelable is true
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).keySystem is ""
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).sessionId is ""
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).initData is null
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).message is null
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).defaultURL is ""
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).errorCode is null
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).systemCode is 0
*** Bubbles and cancelable true, invalid other members ***
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).bubbles is true
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).cancelable is true
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).keySystem is "undefined"
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).sessionId is "undefined"
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).initData is null
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).message is null
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).defaultURL is "undefined"
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).errorCode is null
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).systemCode is 0
*** Initialize 'keySystem' with a invalid values ***
PASS new MediaKeyEvent('MediaKeyEvent', { keySystem: emptyObject }).keySystem is "[object Object]"
PASS new MediaKeyEvent('MediaKeyEvent', { keySystem: document }).keySystem is "[object HTMLDocument]"
*** Initialize 'sessionId' with a invalid values ***
PASS new MediaKeyEvent('MediaKeyEvent', { sessionId: emptyObject }).sessionId is "[object Object]"
PASS new MediaKeyEvent('MediaKeyEvent', { sessionId: document }).sessionId is "[object HTMLDocument]"
*** Initialize 'initData' with a invalid values ***
PASS new MediaKeyEvent('MediaKeyEvent', { initData: 10 }).initData is null
PASS new MediaKeyEvent('MediaKeyEvent', { initData: 'string' }).initData is null
PASS new MediaKeyEvent('MediaKeyEvent', { initData: emptyObject }).initData is null
PASS new MediaKeyEvent('MediaKeyEvent', { initData: document }).initData is null
*** Initialize 'message' with a invalid values ***
PASS new MediaKeyEvent('MediaKeyEvent', { message: 10 }).message is null
PASS new MediaKeyEvent('MediaKeyEvent', { message: 'string' }).message is null
PASS new MediaKeyEvent('MediaKeyEvent', { message: emptyObject }).message is null
PASS new MediaKeyEvent('MediaKeyEvent', { message: document }).message is null
*** Initialize 'defaultURL' with a invalid values ***
PASS new MediaKeyEvent('MediaKeyEvent', { defaultURL: emptyObject }).defaultURL is "[object Object]"
PASS new MediaKeyEvent('MediaKeyEvent', { defaultURL: document }).defaultURL is "[object HTMLDocument]"
*** Initialize 'errorCode' with a invalid values ***
PASS new MediaKeyEvent('MediaKeyEvent', { errorCode: 10 }).errorCode is null
PASS new MediaKeyEvent('MediaKeyEvent', { errorCode: 'string' }).errorCode is null
PASS new MediaKeyEvent('MediaKeyEvent', { errorCode: emptyObject }).errorCode is null
PASS new MediaKeyEvent('MediaKeyEvent', { errorCode: document }).errorCode is null
*** Initialize 'systemCode' with a invalid values ***
PASS new MediaKeyEvent('MediaKeyEvent', { systemCode: 'string' }).systemCode is 0
PASS new MediaKeyEvent('MediaKeyEvent', { systemCode: emptyObject }).systemCode is 0
PASS new MediaKeyEvent('MediaKeyEvent', { systemCode: document }).systemCode is 0
*** Bubbles and cancelable true, valid other members ***
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).bubbles is true
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).cancelable is true
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).keySystem is "keySystem"
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).sessionId is "sessionId"
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).initData is initDataArray
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).message is messageArray
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).defaultURL is "defaultURL"
FAIL new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).errorCode should be function MediaKeyError() { [native code] } (of type function). Was null (of type object).
FAIL new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).errorCode.code should be 1. Threw exception TypeError: Cannot read property 'code' of null
PASS new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).systemCode is 123
*** Initialize with valid members ***
FAIL new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).bubbles should be true. Was false.
FAIL new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).cancelable should be true. Was false.
PASS new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).keySystem is "keySystem"
PASS new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).sessionId is "sessionId"
PASS new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).initData is initDataArray
PASS new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).message is messageArray
PASS new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).defaultURL is "defaultURL"
FAIL new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).errorCode should be function MediaKeyError() { [native code] } (of type function). Was null (of type object).
FAIL new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).errorCode.code should be 1. Threw exception TypeError: Cannot read property 'code' of null
PASS new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).systemCode is 123
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<script>
window.jsTestIsAsync = true;
description("This tests the constructor for the MediaKeyEvent DOM class.");
function test()
{
debug("<br>*** No initializer passed ***");
shouldBe("new MediaKeyEvent('MediaKeyEvent').bubbles", "false");
shouldBe("new MediaKeyEvent('MediaKeyEvent').cancelable", "false");
shouldBeEmptyString("new MediaKeyEvent('MediaKeyEvent').keySystem");
shouldBeEmptyString("new MediaKeyEvent('MediaKeyEvent').sessionId");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent').initData");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent').message");
shouldBeEmptyString("new MediaKeyEvent('MediaKeyEvent').defaultURL");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent').errorCode");
shouldBeZero("new MediaKeyEvent('MediaKeyEvent').systemCode");
debug("<br>*** Bubbles and cancelable true, other members are missing ***");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).bubbles", "true");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).cancelable", "true");
shouldBeEmptyString("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).keySystem");
shouldBeEmptyString("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).sessionId");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).initData");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).message");
shouldBeEmptyString("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).defaultURL");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).errorCode");
shouldBeZero("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true }).systemCode");
debug("<br>*** Bubbles and cancelable true, invalid other members ***");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).bubbles", "true");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).cancelable", "true");
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).keySystem", "undefined");
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).sessionId", "undefined");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).initData");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).message");
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).defaultURL", "undefined");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).errorCode");
shouldBeZero("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: undefined, sessionId: undefined, initData: Uint8Array, message: Uint8Array, defaultURL: undefined, errorCode: MediaKeyError, systemCode: undefined }).systemCode");
debug("<br>*** Initialize 'keySystem' with a invalid values ***");
emptyObject = { };
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { keySystem: emptyObject }).keySystem", "[object Object]");
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { keySystem: document }).keySystem", "[object HTMLDocument]");
debug("<br>*** Initialize 'sessionId' with a invalid values ***");
emptyObject = { };
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { sessionId: emptyObject }).sessionId", "[object Object]");
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { sessionId: document }).sessionId", "[object HTMLDocument]");
debug("<br>*** Initialize 'initData' with a invalid values ***");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { initData: 10 }).initData");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { initData: \'string\' }).initData");
emptyObject = { };
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { initData: emptyObject }).initData");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { initData: document }).initData");
debug("<br>*** Initialize 'message' with a invalid values ***");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { message: 10 }).message");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { message: \'string\' }).message");
emptyObject = { };
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { message: emptyObject }).message");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { message: document }).message");
debug("<br>*** Initialize 'defaultURL' with a invalid values ***");
emptyObject = { };
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { defaultURL: emptyObject }).defaultURL", "[object Object]");
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { defaultURL: document }).defaultURL", "[object HTMLDocument]");
debug("<br>*** Initialize 'errorCode' with a invalid values ***");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { errorCode: 10 }).errorCode");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { errorCode: \'string\' }).errorCode");
emptyObject = { };
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { errorCode: emptyObject }).errorCode");
shouldBeNull("new MediaKeyEvent('MediaKeyEvent', { errorCode: document }).errorCode");
debug("<br>*** Initialize 'systemCode' with a invalid values ***");
shouldBeZero("new MediaKeyEvent('MediaKeyEvent', { systemCode: \'string\' }).systemCode");
emptyObject = { };
shouldBeZero("new MediaKeyEvent('MediaKeyEvent', { systemCode: emptyObject }).systemCode");
shouldBeZero("new MediaKeyEvent('MediaKeyEvent', { systemCode: document }).systemCode");
debug("<br>*** Bubbles and cancelable true, valid other members ***");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).bubbles", "true");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).cancelable", "true");
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).keySystem", "keySystem");
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).sessionId", "sessionId");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).initData", "initDataArray");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).message", "messageArray");
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).defaultURL", "defaultURL");
// FIXME(82988): These two fail.
shouldBe("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).errorCode", "errorObject");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).errorCode.code", "MediaKeyError.MEDIA_KEYERR_UNKNOWN");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { bubbles: true, cancelable: true, keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).systemCode", "123");
debug("<br>*** Initialize with valid members ***");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).bubbles", "true");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).cancelable", "true");
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).keySystem", "keySystem");
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).sessionId", "sessionId");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).initData", "initDataArray");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).message", "messageArray");
shouldBeEqualToString("new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).defaultURL", "defaultURL");
// FIXME(82988): These two fail.
shouldBe("new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).errorCode", "errorObject");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).errorCode.code", "MediaKeyError.MEDIA_KEYERR_UNKNOWN");
shouldBe("new MediaKeyEvent('MediaKeyEvent', { keySystem: 'keySystem', sessionId: 'sessionId', initData: initDataArray, message: messageArray, defaultURL: 'defaultURL', errorCode: errorObject, systemCode: 123 }).systemCode", "123");
debug("");
finishJSTest();
}
var initDataArray = new Uint8Array([0x41, 0x42, 0x43]);
var messageArray = new Uint8Array([0x51, 0x52, 0x53]);
// FIXME(82988): This does not create an error like we want.
var errorObject = window.MediaKeyError;
// shouldBe("typeof errorObject", TBD);
video = document.createElement('video');
document.body.appendChild(video);
test()
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>
......@@ -254,6 +254,7 @@ function shouldBeTrueQuiet(_a) { shouldBe(_a, "true", true); }
function shouldBeFalse(_a) { shouldBe(_a, "false"); }
function shouldBeNaN(_a) { shouldBe(_a, "NaN"); }
function shouldBeNull(_a) { shouldBe(_a, "null"); }
function shouldBeZero(_a) { shouldBe(_a, "0"); }
function shouldBeEqualToString(a, b)
{
......@@ -261,6 +262,8 @@ function shouldBeEqualToString(a, b)
shouldBe(a, unevaledString);
}
function shouldBeEmptyString(_a) { shouldBeEqualToString(_a, ""); }
function shouldEvaluateTo(actual, expected) {
// A general-purpose comparator. 'actual' should be a string to be
// evaluated, as for shouldBe(). 'expected' may be any type and will be
......
Test MediaKeyError constants and additional MediaError constant.
EXPECTED (MediaKeyError.MEDIA_KEYERR_UNKNOWN == '1') OK
EXPECTED (MediaKeyError.MEDIA_KEYERR_CLIENT == '2') OK
EXPECTED (MediaKeyError.MEDIA_KEYERR_SERVICE == '3') OK
EXPECTED (MediaKeyError.MEDIA_KEYERR_OUTPUT == '4') OK
EXPECTED (MediaKeyError.MEDIA_KEYERR_HARDWARECHANGE == '5') OK
EXPECTED (MediaKeyError.MEDIA_KEYERR_DOMAIN == '6') OK
EXPECTED (MediaError.MEDIA_ERR_ENCRYPTED == '5') OK
END OF TEST
<!DOCTYPE html>
<html>
<head>
<script src=../video-test.js></script>
<script type="text/javascript">
function doTest ()
{
testExpected("MediaKeyError.MEDIA_KEYERR_UNKNOWN", 1);
testExpected("MediaKeyError.MEDIA_KEYERR_CLIENT", 2);
testExpected("MediaKeyError.MEDIA_KEYERR_SERVICE", 3);
testExpected("MediaKeyError.MEDIA_KEYERR_OUTPUT", 4);
testExpected("MediaKeyError.MEDIA_KEYERR_HARDWARECHANGE", 5);
testExpected("MediaKeyError.MEDIA_KEYERR_DOMAIN", 6);
consoleWrite("");
testExpected("MediaError.MEDIA_ERR_ENCRYPTED", 5);
endTest();
}
</script>
</head>
<body onload="doTest()">
<p>Test MediaKeyError constants and additional MediaError constant.</p>
</body>
</html>
Test all the key-related events.
*** Verify the presence of on* attributes. These would return undefined if they are not present. ***
EXPECTED (video.onwebkitkeyadded === 'null') OK
EXPECTED (video.onwebkitkeyerror === 'null') OK
EXPECTED (video.onwebkitkeymessage === 'null') OK
EXPECTED (video.onwebkitneedkey === 'null') OK
*** Test events using on* attributes. ***
EVENT(loadstart)
RUN(video.webkitGenerateKeyRequest('webkit-org.w3.clearkey', initData))
keymessage event occurred
EXPECTED (event.target == '[object HTMLVideoElement]') OK
EXPECTED (event instanceof window.MediaKeyEvent == 'true') OK
EXPECTED (event.keySystem == 'webkit-org.w3.clearkey') OK
The sessionId should be a non-empty string containing an integer.
EXPECTED (event.sessionId != '') OK
EXPECTED (event.sessionId != 'null') OK
EXPECTED (event.sessionId != 'undefined') OK
EXPECTED (isNaN(event.sessionId) == 'false') OK
EXPECTED (String(event.sessionId) == String(parseInt(event.sessionId)) == 'true') OK
Implementations should avoid sessionIds of 0.
EXPECTED (event.sessionId > '0') OK
EXPECTED (event.initData === 'null') OK
EXPECTED (event.message.length == '3') OK
EXPECTED (event.message[0] == '65') OK
EXPECTED (event.message[1] == '66') OK
EXPECTED (event.message[2] == '67') OK
EXPECTED (event.defaultURL == '') OK
EXPECTED (event.errorCode === 'null') OK
EXPECTED (event.systemCode == '0') OK
RUN(video.webkitAddKey('webkit-org.w3.clearkey', key, event.initData, event.sessionId))
keyadded event occurred
EXPECTED (event.target == '[object HTMLVideoElement]') OK
EXPECTED (event instanceof window.MediaKeyEvent == 'true') OK
EXPECTED (event.keySystem == 'webkit-org.w3.clearkey') OK
EXPECTED (event.sessionId == keyMessageSessionId == 'true') OK
EXPECTED (event.initData === 'null') OK
EXPECTED (event.message === 'null') OK
EXPECTED (event.defaultURL == '') OK
EXPECTED (event.errorCode === 'null') OK
EXPECTED (event.systemCode == '0') OK
RUN(video.webkitAddKey('webkit-org.w3.clearkey', invalidKey, null, event.sessionId))
keyerror event occurred
EXPECTED (event.target == '[object HTMLVideoElement]') OK
EXPECTED (event instanceof window.MediaKeyEvent == 'true') OK
EXPECTED (event.keySystem == 'webkit-org.w3.clearkey') OK
EXPECTED (event.sessionId == keyMessageSessionId == 'true') OK
EXPECTED (event.initData === 'null') OK
EXPECTED (event.message === 'null') OK
EXPECTED (event.defaultURL == '') OK
EXPECTED (event.errorCode.code == '1') OK
EXPECTED (event.systemCode == '0') OK
*** Test events using addEventListener(). ***
EVENT(loadstart)
RUN(video.webkitGenerateKeyRequest('webkit-org.w3.clearkey', initData))
EVENT(webkitkeymessage)
keymessage event occurred
EXPECTED (event.target == '[object HTMLVideoElement]') OK
EXPECTED (event instanceof window.MediaKeyEvent == 'true') OK
EXPECTED (event.keySystem == 'webkit-org.w3.clearkey') OK
The sessionId should be a non-empty string containing an integer.
EXPECTED (event.sessionId != '') OK
EXPECTED (event.sessionId != 'null') OK
EXPECTED (event.sessionId != 'undefined') OK
EXPECTED (isNaN(event.sessionId) == 'false') OK
EXPECTED (String(event.sessionId) == String(parseInt(event.sessionId)) == 'true') OK
Implementations should avoid sessionIds of 0.
EXPECTED (event.sessionId > '0') OK
The sessionsId should be different from the first run.
EXPECTED (event.sessionId != '1') OK
EXPECTED (event.initData === 'null') OK
EXPECTED (event.message.length == '3') OK
EXPECTED (event.message[0] == '65') OK
EXPECTED (event.message[1] == '66') OK
EXPECTED (event.message[2] == '67') OK
EXPECTED (event.defaultURL == '') OK
EXPECTED (event.errorCode === 'null') OK
EXPECTED (event.systemCode == '0') OK
RUN(video.webkitAddKey('webkit-org.w3.clearkey', key, event.initData, event.sessionId))
EVENT(webkitkeyadded)
keyadded event occurred
EXPECTED (event.target == '[object HTMLVideoElement]') OK
EXPECTED (event instanceof window.MediaKeyEvent == 'true') OK
EXPECTED (event.keySystem == 'webkit-org.w3.clearkey') OK
EXPECTED (event.sessionId == keyMessageSessionId == 'true') OK
EXPECTED (event.initData === 'null') OK
EXPECTED (event.message === 'null') OK
EXPECTED (event.defaultURL == '') OK
EXPECTED (event.errorCode === 'null') OK
EXPECTED (event.systemCode == '0') OK
RUN(video.webkitAddKey('webkit-org.w3.clearkey', invalidKey, null, event.sessionId))
EVENT(webkitkeyerror)
keyerror event occurred
EXPECTED (event.target == '[object HTMLVideoElement]') OK
EXPECTED (event instanceof window.MediaKeyEvent == 'true') OK
EXPECTED (event.keySystem == 'webkit-org.w3.clearkey') OK
EXPECTED (event.sessionId == keyMessageSessionId == 'true') OK
EXPECTED (event.initData === 'null') OK
EXPECTED (event.message === 'null') OK
EXPECTED (event.defaultURL == '') OK
EXPECTED (event.errorCode.code == '1') OK
EXPECTED (event.systemCode == '0') OK
Attributes are read-only.
RUN(event.keySystem = 'blah')
RUN(event.sessionId = 'blah')
RUN(event.initData = new Uint8Array([0x12]))
RUN(event.message = new Uint8Array([0x12]))
RUN(event.defaultURL = 'example.com')
RUN(event.errorCode.code = MediaKeyError.MEDIA_KEYERR_CLIENT)
RUN(event.systemCode = 123)
EXPECTED (event.keySystem == 'webkit-org.w3.clearkey') OK
EXPECTED (event.sessionId == keyMessageSessionId == 'true') OK
EXPECTED (event.initData === 'null') OK
EXPECTED (event.message === 'null') OK
EXPECTED (event.defaultURL == '') OK
EXPECTED (event.errorCode.code == '1') OK
EXPECTED (event.systemCode == '0') OK
END OF TEST
<!doctype html>
<html lang="en">
<head>
</head>
<body>
<video></video>
<p>Test all the key-related events.</p>
<script src=../media-file.js></script>
<script src=../video-test.js></script>
<script>
// The test runs twice, once using on* and then using addEventListener().
var isFirstRun = true;
var initData = new Uint8Array([0x41, 0x42, 0x43]);
// 128 bit key.
var key = new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70]);
// This key will cause an asynchronous error because it is too short.
var invalidKey = new Uint8Array([0x61]);
// After the first keyMessage event, the sessionId should always be the same.
// Initialize it to an invalid value until then.
var keyMessageSessionId = -1;
// Remember the first ID to make sure the second one is different.
var firstRunKeyMessageSessionId = -1;
function keyAdded(event)
{
consoleWrite("keyadded event occurred");
testExpected("event.target", video);
testExpected("event instanceof window.MediaKeyEvent", true);
testExpected("event.keySystem", "webkit-org.w3.clearkey");
testExpected("event.sessionId == keyMessageSessionId", true);
// The other attributes are not used for this event.
testExpected("event.initData", null, "===");
testExpected("event.message", null, "===");
testExpected("event.defaultURL", "");
testExpected("event.errorCode", null, "===");
testExpected("event.systemCode", 0);
consoleWrite("");
// Cause a keyerror by passing an invalid key.
run("video.webkitAddKey('webkit-org.w3.clearkey', invalidKey, null, event.sessionId)");
}
function keyError(event)
{
consoleWrite("keyerror event occurred");
testExpected("event.target", video);
testExpected("event instanceof window.MediaKeyEvent", true);
testExpected("event.keySystem", "webkit-org.w3.clearkey");
testExpected("event.sessionId == keyMessageSessionId", true);
// The next three attributes are not used for this event.
testExpected("event.initData", null, "===");
testExpected("event.message", null, "===");
testExpected("event.defaultURL", "");
testExpected("event.errorCode.code", MediaKeyError.MEDIA_KEYERR_UNKNOWN);
// systemCode is not supported by the Clear Key key system.
testExpected("event.systemCode", 0);
if (isFirstRun) {
isFirstRun = false;
runTest();
} else {
consoleWrite("");
consoleWrite("Attributes are read-only.");
run("event.keySystem = 'blah'");
run("event.sessionId = 'blah'");
run("event.initData = new Uint8Array([0x12])");
run("event.message = new Uint8Array([0x12])");
run("event.defaultURL = 'example.com'");
run("event.errorCode.code = MediaKeyError.MEDIA_KEYERR_CLIENT");
run("event.systemCode = 123");
testExpected("event.keySystem", "webkit-org.w3.clearkey");
testExpected("event.sessionId == keyMessageSessionId", true);
testExpected("event.initData", null, "===");
testExpected("event.message", null, "===");
testExpected("event.defaultURL", "");
testExpected("event.errorCode.code", MediaKeyError.MEDIA_KEYERR_UNKNOWN);
testExpected("event.systemCode", 0);
endTest();
}
}
function keyMessage(event)
{
consoleWrite("keymessage event occurred");
testExpected("event.target", video);
testExpected("event instanceof window.MediaKeyEvent", true);
testExpected("event.keySystem", "webkit-org.w3.clearkey");
consoleWrite("The sessionId should be a non-empty string containing an integer.");
testExpected("event.sessionId", "", "!=");
testExpected("event.sessionId", null, "!=");
testExpected("event.sessionId", undefined, "!=");
testExpected("isNaN(event.sessionId)", false);
// Make sure the number is not a float.
testExpected("String(event.sessionId) == String(parseInt(event.sessionId))", true);
consoleWrite("Implementations should avoid sessionIds of 0.");
testExpected("event.sessionId", 0, ">");
// All other events should have this same sessionId.
keyMessageSessionId = event.sessionId;
if (isFirstRun)
firstRunKeyMessageSessionId = keyMessageSessionId;
else {
consoleWrite("The sessionsId should be different from the first run.");
testExpected("event.sessionId", firstRunKeyMessageSessionId, "!=");
}
// initData is not used for this event.
testExpected("event.initData", null, "===");
// At least for now, the Clear Key message is the initData.
testArraysEqual("event.message", initData);
// Not supported by the test file.
testExpected("event.defaultURL", "");
// The error attributes are not used for this event.
testExpected("event.errorCode", null, "===");
testExpected("event.systemCode", 0);
consoleWrite("");
run("video.webkitAddKey('webkit-org.w3.clearkey', key, event.initData, event.sessionId)");
}
function needKey(event)
{
consoleWrite("needKey event occurred");
testExpected(