Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: content/test/data/media/encrypted_media_utils.js

Issue 11469040: EME v0.1: Report defaultURL in KeyMessage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: feedback Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 var QueryString = function() { 5 var QueryString = function() {
6 // Allows access to query parameters on the URL; e.g., given a URL like: 6 // Allows access to query parameters on the URL; e.g., given a URL like:
7 // http://<server>/my.html?test=123&bob=123 7 // http://<server>/my.html?test=123&bob=123
8 // Parameters can then be accessed via QueryString.test or QueryString.bob. 8 // Parameters can then be accessed via QueryString.test or QueryString.bob.
9 var params = {}; 9 var params = {};
10 // RegEx to split out values by &. 10 // RegEx to split out values by &.
(...skipping 13 matching lines...) Expand all
24 if (!mediaType) 24 if (!mediaType)
25 mediaType = 'video/webm; codecs="vorbis, vp8"' 25 mediaType = 'video/webm; codecs="vorbis, vp8"'
26 // Default key used to encrypt many media files used in browser tests. 26 // Default key used to encrypt many media files used in browser tests.
27 var KEY = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b, 27 var KEY = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
28 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]); 28 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]);
29 // Stores a failure message that is read by the browser test when it fails. 29 // Stores a failure message that is read by the browser test when it fails.
30 var failMessage = ''; 30 var failMessage = '';
31 // Heart beat message header. 31 // Heart beat message header.
32 var HEART_BEAT_HEADER = 'HEARTBEAT'; 32 var HEART_BEAT_HEADER = 'HEARTBEAT';
33 33
34 function isHeartBeatMessage(msg) { 34 var EXTERNAL_CLEAR_KEY_KEY_SYSTEM = "org.chromium.externalclearkey";
35 // Note that his URL has been normalized from the one in clear_key_cdm.cc.
36 var EXTERNAL_CLEAR_KEY_HEARTBEAT_URL =
37 'http://test.externalclearkey.chromium.org/';
38
39 function isHeartbeatMessage(msg) {
35 if (msg.length < HEART_BEAT_HEADER.length) 40 if (msg.length < HEART_BEAT_HEADER.length)
36 return false; 41 return false;
37 42
38 for (var i = 0; i < HEART_BEAT_HEADER.length; ++i) { 43 for (var i = 0; i < HEART_BEAT_HEADER.length; ++i) {
39 if (HEART_BEAT_HEADER[i] != String.fromCharCode(msg[i])) 44 if (String.fromCharCode(msg[i]) != HEART_BEAT_HEADER[i])
40 return false; 45 return false;
41 } 46 }
42 47
43 return true; 48 return true;
44 } 49 }
45 50
46 function failTest(msg) { 51 function failTest(msg) {
52 console.log("failTest('" + msg + "')");
47 if (msg instanceof Event) 53 if (msg instanceof Event)
48 failMessage = msg.target + '.' + msg.type; 54 failMessage = msg.target + '.' + msg.type;
49 else 55 else
50 failMessage = msg; 56 failMessage = msg;
51 setDocTitle('FAILED'); 57 setDocTitle('FAILED');
52 } 58 }
53 59
54 function setDocTitle(title) { 60 function setDocTitle(title) {
55 document.title = title.toUpperCase(); 61 document.title = title.toUpperCase();
56 } 62 }
57 63
58 function installTitleEventHandler(element, event) { 64 function installTitleEventHandler(element, event) {
59 element.addEventListener(event, function(e) { 65 element.addEventListener(event, function(e) {
60 setDocTitle(event.toString()); 66 setDocTitle(event.toString());
61 }, false); 67 }, false);
62 } 68 }
63 69
64 function loadEncryptedMediaFromURL(video) { 70 function loadEncryptedMediaFromURL(video) {
65 return loadEncryptedMedia(video, mediaFile, keySystem, KEY); 71 return loadEncryptedMedia(video, mediaFile, keySystem, KEY);
66 } 72 }
67 73
68 function loadEncryptedMedia(video, mediaFile, keySystem, key) { 74 function loadEncryptedMedia(video, mediaFile, keySystem, key) {
69 var keyRequested = false; 75 var keyRequested = false;
70 var sourceOpened = false; 76 var sourceOpened = false;
71 // Add a property to video to check key was added. 77 // Add properties to enable verification that events occurred.
72 video.hasKeyAdded = false; 78 video.receivedKeyAdded = false;
79 video.receivedHeartbeat = false;
80 video.isHeartbeatExpected = keySystem === EXTERNAL_CLEAR_KEY_KEY_SYSTEM;
73 81
74 if (!(video && mediaFile && keySystem && key)) 82 if (!(video && mediaFile && keySystem && key))
75 failTest('Missing parameters in loadEncryptedMedia().'); 83 failTest('Missing parameters in loadEncryptedMedia().');
76 84
77 function onSourceOpen(e) { 85 function onSourceOpen(e) {
78 if (sourceOpened) 86 if (sourceOpened)
79 return; 87 return;
80 sourceOpened = true; 88 sourceOpened = true;
81 console.log('onSourceOpen', e); 89 console.log('onSourceOpen', e);
82 var srcBuffer = 90 var srcBuffer =
(...skipping 14 matching lines...) Expand all
97 keyRequested = true; 105 keyRequested = true;
98 console.log('onNeedKey', e); 106 console.log('onNeedKey', e);
99 try { 107 try {
100 video.webkitGenerateKeyRequest(keySystem, e.initData); 108 video.webkitGenerateKeyRequest(keySystem, e.initData);
101 } 109 }
102 catch(error) { 110 catch(error) {
103 setDocTitle("GenerateKeyRequestException"); 111 setDocTitle("GenerateKeyRequestException");
104 } 112 }
105 } 113 }
106 114
107 function onKeyAdded() { 115 function onKeyAdded(e) {
108 video.hasKeyAdded = true; 116 e.target.receivedKeyAdded = true;
109 } 117 }
110 118
111 function onKeyMessage(e) { 119 function onKeyMessage(e) {
112 if (isHeartBeatMessage(e.message)) { 120 // TODO(ddorwin): Enable after fixing http://crbug.com/166204.
113 console.log('onKeyMessage - heart beat', e); 121 if (!e.keySystem && false) {
122 failTest('keymessage without a keySystem: ' + e.keySystem);
114 return; 123 return;
115 } 124 }
116 125
126 if (!e.sessionId) {
127 failTest('keymessage without a sessionId: ' + e.sessionId);
128 return;
129 }
130
131 if (!e.message) {
132 failTest('keymessage without a sessionId: ' + e.message);
shadi 2012/12/14 22:01:20 s/sessionId/message
ddorwin 2012/12/14 22:10:56 Done.
133 return;
134 }
135
136 if (isHeartbeatMessage(e.message)) {
137 console.log('onKeyMessage - heartbeat', e);
138 e.target.receivedHeartbeat = true;
139 verifyHeartbeatMessage(e);
140 return;
141 }
142
143 // keymessage in response to generateKeyRequest. Reply with key.
117 console.log('onKeyMessage - key request', e); 144 console.log('onKeyMessage - key request', e);
118 video.webkitAddKey(keySystem, key, e.message); 145 video.webkitAddKey(keySystem, key, e.message);
119 } 146 }
120 147
148 function verifyHeartbeatMessage(e) {
149 // Only External Clear Key sends a HEARTBEAT message.
150 if (e.keySystem != EXTERNAL_CLEAR_KEY_KEY_SYSTEM) {
151 failTest('Unexpected heartbeat from ' + e.keySystem);
152 return;
153 }
154
155 if (e.defaultURL != EXTERNAL_CLEAR_KEY_HEARTBEAT_URL) {
156 failTest('Heartbeat message with unexpected defaultURL: ' + e.defaultURL);
157 return;
158 }
159 }
160
121 var mediaSource = new WebKitMediaSource(); 161 var mediaSource = new WebKitMediaSource();
122 162
123 mediaSource.addEventListener('webkitsourceopen', onSourceOpen); 163 mediaSource.addEventListener('webkitsourceopen', onSourceOpen);
124 video.addEventListener('webkitneedkey', onNeedKey); 164 video.addEventListener('webkitneedkey', onNeedKey);
125 video.addEventListener('webkitkeymessage', onKeyMessage); 165 video.addEventListener('webkitkeymessage', onKeyMessage);
126 video.addEventListener('webkitkeyerror', failTest); 166 video.addEventListener('webkitkeyerror', failTest);
127 video.addEventListener('webkitkeyadded', onKeyAdded); 167 video.addEventListener('webkitkeyadded', onKeyAdded);
128 installTitleEventHandler(video, 'error'); 168 installTitleEventHandler(video, 'error');
129 169
130 video.src = window.URL.createObjectURL(mediaSource); 170 video.src = window.URL.createObjectURL(mediaSource);
131 return mediaSource; 171 return mediaSource;
132 } 172 }
OLDNEW
« no previous file with comments | « content/test/data/media/encrypted_media_player.html ('k') | webkit/media/crypto/ppapi/clear_key_cdm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698