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

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

Issue 93243003: Add CDM FileIO tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: not to use base::MessageLoopProxy::current() Created 7 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
« no previous file with comments | « chrome/renderer/media/chrome_key_systems.cc ('k') | media/cdm/ppapi/cdm_file_io_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 keySystem = QueryString.keysystem; 5 var keySystem = QueryString.keysystem;
6 var mediaFile = QueryString.mediafile; 6 var mediaFile = QueryString.mediafile;
7 var mediaType = QueryString.mediatype || 'video/webm; codecs="vorbis, vp8"'; 7 var mediaType = QueryString.mediatype || 'video/webm; codecs="vorbis, vp8"';
8 var useMSE = QueryString.usemse == 1; 8 var useMSE = QueryString.usemse == 1;
9 9
10 // Default key used to encrypt many media files used in browser tests. 10 // Default key used to encrypt many media files used in browser tests.
11 var KEY = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b, 11 var KEY = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
12 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]); 12 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]);
13 // KEY_ID constant used as init data while encrypting test media files. 13 // KEY_ID constant used as init data while encrypting test media files.
14 var KEY_ID = getInitDataFromKeyId("0123456789012345"); 14 var KEY_ID = getInitDataFromKeyId("0123456789012345");
15 // Heart beat message header. 15 // Heart beat message header.
16 var HEART_BEAT_HEADER = 'HEARTBEAT'; 16 var HEART_BEAT_HEADER = 'HEARTBEAT';
17 var FILE_IO_TEST_RESULT_HEADER = 'FILEIOTESTRESULT';
17 var EXTERNAL_CLEAR_KEY_KEY_SYSTEM = "org.chromium.externalclearkey"; 18 var EXTERNAL_CLEAR_KEY_KEY_SYSTEM = "org.chromium.externalclearkey";
19 var EXTERNAL_CLEAR_KEY_FILE_IO_TEST_KEY_SYSTEM =
20 "org.chromium.externalclearkey.fileiotest";
18 // Note that his URL has been normalized from the one in clear_key_cdm.cc. 21 // Note that his URL has been normalized from the one in clear_key_cdm.cc.
19 var EXTERNAL_CLEAR_KEY_HEARTBEAT_URL = 22 var EXTERNAL_CLEAR_KEY_HEARTBEAT_URL =
20 'http://test.externalclearkey.chromium.org/'; 23 'http://test.externalclearkey.chromium.org/';
21 24
22 function isHeartbeatMessage(msg) { 25 function hasPrefix(msg, prefix) {
23 if (msg.length < HEART_BEAT_HEADER.length) 26 if (msg.length < prefix.length)
24 return false; 27 return false;
25 for (var i = 0; i < HEART_BEAT_HEADER.length; ++i) { 28 for (var i = 0; i < prefix.length; ++i) {
26 if (String.fromCharCode(msg[i]) != HEART_BEAT_HEADER[i]) 29 if (String.fromCharCode(msg[i]) != prefix[i])
27 return false; 30 return false;
28 } 31 }
29 return true; 32 return true;
30 } 33 }
31 34
35 function isHeartbeatMessage(msg) {
36 return hasPrefix(msg, HEART_BEAT_HEADER);
37 }
38
39 function isFileIOTestMessage(msg) {
40 return hasPrefix(msg, FILE_IO_TEST_RESULT_HEADER);
41 }
42
32 function loadEncryptedMediaFromURL(video) { 43 function loadEncryptedMediaFromURL(video) {
33 return loadEncryptedMedia(video, mediaFile, keySystem, KEY, useMSE); 44 return loadEncryptedMedia(video, mediaFile, keySystem, KEY, useMSE);
34 } 45 }
35 46
36 function loadEncryptedMedia(video, mediaFile, keySystem, key, useMSE, 47 function loadEncryptedMedia(video, mediaFile, keySystem, key, useMSE,
37 appendSourceCallbackFn) { 48 appendSourceCallbackFn) {
38 var keyRequested = false; 49 var keyRequested = false;
39 var sourceOpened = false; 50 var sourceOpened = false;
40 // Add properties to enable verification that events occurred. 51 // Add properties to enable verification that events occurred.
41 video.receivedKeyAdded = false; 52 video.receivedKeyAdded = false;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return; 93 return;
83 } 94 }
84 95
85 if (isHeartbeatMessage(e.message)) { 96 if (isHeartbeatMessage(e.message)) {
86 console.log('onKeyMessage - heartbeat', e); 97 console.log('onKeyMessage - heartbeat', e);
87 e.target.receivedHeartbeat = true; 98 e.target.receivedHeartbeat = true;
88 verifyHeartbeatMessage(e); 99 verifyHeartbeatMessage(e);
89 return; 100 return;
90 } 101 }
91 102
103 if (isFileIOTestMessage(e.message)) {
104 var success = getFileIOTestResult(e);
105 console.log('onKeyMessage - CDM file IO test: ' +
106 (success ? 'Success' : 'Fail'));
107 if (success)
108 setResultInTitle("FILEIOTESTSUCCESS");
109 else
110 setResultInTitle("FAILED");
111 return;
112 }
113
114 // For FileIOTest key system, no need to start playback.
115 if (e.keySystem == EXTERNAL_CLEAR_KEY_FILE_IO_TEST_KEY_SYSTEM)
116 return;
117
92 // No tested key system returns defaultURL in for key request messages. 118 // No tested key system returns defaultURL in for key request messages.
93 if (e.defaultURL) { 119 if (e.defaultURL) {
94 failTest('keymessage unexpectedly has defaultURL: ' + e.defaultURL); 120 failTest('keymessage unexpectedly has defaultURL: ' + e.defaultURL);
95 return; 121 return;
96 } 122 }
97 123
98 // keymessage in response to generateKeyRequest. Reply with key. 124 // keymessage in response to generateKeyRequest. Reply with key.
99 console.log('onKeyMessage - key request', e); 125 console.log('onKeyMessage - key request', e);
100 var initData = e.message; 126 var initData = e.message;
101 if (mediaType.indexOf('mp4') != -1) 127 if (mediaType.indexOf('mp4') != -1)
(...skipping 16 matching lines...) Expand all
118 failTest('Unexpected heartbeat from ' + e.keySystem); 144 failTest('Unexpected heartbeat from ' + e.keySystem);
119 return; 145 return;
120 } 146 }
121 147
122 if (e.defaultURL != EXTERNAL_CLEAR_KEY_HEARTBEAT_URL) { 148 if (e.defaultURL != EXTERNAL_CLEAR_KEY_HEARTBEAT_URL) {
123 failTest('Heartbeat message with unexpected defaultURL: ' + e.defaultURL); 149 failTest('Heartbeat message with unexpected defaultURL: ' + e.defaultURL);
124 return; 150 return;
125 } 151 }
126 } 152 }
127 153
154 function getFileIOTestResult(e) {
155 // Only External Clear Key sends a FILEIOTESTRESULT message.
156 if (e.keySystem != EXTERNAL_CLEAR_KEY_FILE_IO_TEST_KEY_SYSTEM) {
157 failTest('Unexpected CDM file IO test result from ' + e.keySystem);
158 return false;
159 }
160
161 // The test result is either '0' or '1' appended to the header.
162 if (e.message.length != FILE_IO_TEST_RESULT_HEADER.length + 1)
163 return false;
164
165 var result_index = FILE_IO_TEST_RESULT_HEADER.length;
166 return String.fromCharCode(e.message[result_index]) == 1;
167 }
168
128 video.addEventListener('webkitneedkey', onNeedKey); 169 video.addEventListener('webkitneedkey', onNeedKey);
129 video.addEventListener('webkitkeymessage', onKeyMessage); 170 video.addEventListener('webkitkeymessage', onKeyMessage);
130 video.addEventListener('webkitkeyerror', function() { 171 video.addEventListener('webkitkeyerror', function() {
131 setResultInTitle("KeyError"); 172 setResultInTitle("KeyError");
132 }); 173 });
133 video.addEventListener('webkitkeyadded', onKeyAdded); 174 video.addEventListener('webkitkeyadded', onKeyAdded);
134 installTitleEventHandler(video, 'error'); 175 installTitleEventHandler(video, 'error');
135 176
136 if (useMSE) { 177 if (useMSE) {
137 var mediaSource = loadMediaSource(mediaFile, mediaType, 178 var mediaSource = loadMediaSource(mediaFile, mediaType,
138 appendSourceCallbackFn); 179 appendSourceCallbackFn);
139 video.src = window.URL.createObjectURL(mediaSource); 180 video.src = window.URL.createObjectURL(mediaSource);
140 } else { 181 } else {
141 video.src = mediaFile; 182 video.src = mediaFile;
142 } 183 }
143 } 184 }
144 185
145 function getInitDataFromKeyId(keyID) { 186 function getInitDataFromKeyId(keyID) {
146 var init_key_id = new Uint8Array(keyID.length); 187 var init_key_id = new Uint8Array(keyID.length);
147 for(var i = 0; i < keyID.length; i++) { 188 for(var i = 0; i < keyID.length; i++) {
148 init_key_id[i] = keyID.charCodeAt(i); 189 init_key_id[i] = keyID.charCodeAt(i);
149 } 190 }
150 return init_key_id; 191 return init_key_id;
151 } 192 }
OLDNEW
« no previous file with comments | « chrome/renderer/media/chrome_key_systems.cc ('k') | media/cdm/ppapi/cdm_file_io_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698