OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // CDM unit test player is used to run a specific test within the CDM. The test |
| 6 // result is reported via a special key message with UNIT_TEST_RESULT_HEADER |
| 7 // followed by 1 for success, and 0 for failure. |
| 8 function UnitTestPlayer(video, testConfig) { |
| 9 this.video = video; |
| 10 this.testConfig = testConfig; |
| 11 } |
| 12 |
| 13 UnitTestPlayer.prototype.init = function() { |
| 14 // Returns a promise. |
| 15 return PlayerUtils.initEMEPlayer(this); |
| 16 }; |
| 17 |
| 18 UnitTestPlayer.prototype.registerEventListeners = function() { |
| 19 // Returns a promise. |
| 20 return PlayerUtils.registerEMEEventListeners(this); |
| 21 }; |
| 22 |
| 23 handleMessage = function(message) { |
| 24 // The test result is either '0' or '1' appended to the header. |
| 25 var msg = Utils.convertToUint8Array(message.message); |
| 26 if (Utils.hasPrefix(msg, UNIT_TEST_RESULT_HEADER)) { |
| 27 if (msg.length != UNIT_TEST_RESULT_HEADER.length + 1) { |
| 28 Utils.failTest('Unexpected CDM Unit Test message' + msg); |
| 29 return; |
| 30 } |
| 31 var result_index = UNIT_TEST_RESULT_HEADER.length; |
| 32 var success = String.fromCharCode(msg[result_index]) == 1; |
| 33 Utils.timeLog('CDM unit test: ' + (success ? 'Success' : 'Fail')); |
| 34 if (success) |
| 35 Utils.setResultInTitle(UNIT_TEST_SUCCESS); |
| 36 else |
| 37 Utils.failTest('CDM unit test failed.'); |
| 38 } |
| 39 }; |
| 40 |
| 41 UnitTestPlayer.prototype.onMessage = handleMessage; |
OLD | NEW |