Index: content/test/data/media/encrypted_media_utils.js |
diff --git a/content/test/data/media/encrypted_media_utils.js b/content/test/data/media/encrypted_media_utils.js |
index 16ab4b7ef687b6f9a74a492879936ad5469d6056..773fa9bb71e49c67cec519ab24918b42f7c34af3 100644 |
--- a/content/test/data/media/encrypted_media_utils.js |
+++ b/content/test/data/media/encrypted_media_utils.js |
@@ -31,7 +31,12 @@ var failMessage = ''; |
// Heart beat message header. |
var HEART_BEAT_HEADER = 'HEARTBEAT'; |
-function isHeartBeatMessage(msg) { |
+var EXTERNAL_CLEAR_KEY_KEY_SYSTEM = "org.chromium.externalclearkey"; |
+// Note that his URL has been normalized from the one in clear_key_cdm.cc. |
+var EXTERNAL_CLEAR_KEY_HEARTBEAT_URL = |
+ 'http://test.externalclearkey.chromium.org/'; |
scherkus (not reviewing)
2012/12/14 21:45:26
indent 2 more spaces
ddorwin
2012/12/14 21:55:16
Done.
|
+ |
+function isHeartbeatMessage(msg) { |
if (msg.length < HEART_BEAT_HEADER.length) |
return false; |
@@ -44,6 +49,7 @@ function isHeartBeatMessage(msg) { |
} |
function failTest(msg) { |
+ console.log("failTest('" + msg + "')"); |
if (msg instanceof Event) |
failMessage = msg.target + '.' + msg.type; |
else |
@@ -68,8 +74,10 @@ function loadEncryptedMediaFromURL(video) { |
function loadEncryptedMedia(video, mediaFile, keySystem, key) { |
var keyRequested = false; |
var sourceOpened = false; |
- // Add a property to video to check key was added. |
- video.hasKeyAdded = false; |
+ // Add properties to enable verification that events occurred. |
+ video.receivedKeyAdded = false; |
+ video.receivedHeartbeat = false; |
+ video.isHeartbeatExpected = keySystem === EXTERNAL_CLEAR_KEY_KEY_SYSTEM; |
if (!(video && mediaFile && keySystem && key)) |
failTest('Missing parameters in loadEncryptedMedia().'); |
@@ -104,20 +112,52 @@ function loadEncryptedMedia(video, mediaFile, keySystem, key) { |
} |
} |
- function onKeyAdded() { |
- video.hasKeyAdded = true; |
+ function onKeyAdded(e) { |
+ e.target.receivedKeyAdded = true; |
} |
function onKeyMessage(e) { |
- if (isHeartBeatMessage(e.message)) { |
- console.log('onKeyMessage - heart beat', e); |
+ // TODO(ddorwin): Enable after fixing http://crbug.com/166204. |
+ if (!e.keySystem && false) { |
+ failTest('keymessage without a keySystem: ' + e.keySystem); |
return; |
} |
+ if (!e.sessionId) { |
+ failTest('keymessage without a sessionId: ' + e.sessionId); |
+ return; |
+ } |
+ |
+ if (!e.message) { |
+ failTest('keymessage without a sessionId: ' + e.message); |
+ return; |
+ } |
+ |
+ if (isHeartbeatMessage(e.message)) { |
+ console.log('onKeyMessage - heartbeat', e); |
+ e.target.receivedHeartbeat = true; |
+ verifyHeartbeatMessage(e); |
+ return; |
+ } |
+ |
+ // keymessage in response to generateKeyRequest. Reply with key. |
console.log('onKeyMessage - key request', e); |
video.webkitAddKey(keySystem, key, e.message); |
} |
+ function verifyHeartbeatMessage(e) { |
+ // Only External Clear Key sends a HEARTBEAT message. |
+ if (EXTERNAL_CLEAR_KEY_KEY_SYSTEM != e.keySystem) { |
scherkus (not reviewing)
2012/12/14 21:45:26
what's up with the yoda condition
ddorwin
2012/12/14 21:55:16
Done.
|
+ failTest('Unexpected heartbeat from ' + e.keySystem); |
+ return; |
+ } |
+ |
+ if (e.defaultURL != EXTERNAL_CLEAR_KEY_HEARTBEAT_URL) { |
+ failTest('Heartbeat message with unexpected defaultURL: ' + e.defaultURL); |
+ return; |
+ } |
+ } |
+ |
var mediaSource = new WebKitMediaSource(); |
mediaSource.addEventListener('webkitsourceopen', onSourceOpen); |