| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 | 5 |
| 6 /** | 6 /** |
| 7 * @fileOverview WebAudio layout test utility library. Built around W3C's | 7 * @fileOverview WebAudio layout test utility library. Built around W3C's |
| 8 * testharness.js. Includes asynchronous test task manager, | 8 * testharness.js. Includes asynchronous test task manager, |
| 9 * assertion utilities. | 9 * assertion utilities. |
| 10 * @dependency testharness.js | 10 * @dependency testharness.js |
| 11 */ | 11 */ |
| 12 | 12 |
| 13 | 13 |
| 14 (function () { | 14 (function () { |
| 15 | 15 |
| 16 'use strict'; | 16 'use strict'; |
| 17 | 17 |
| 18 // Selected properties from testharness.js | 18 // Selected methods from testharness.js. |
| 19 let testharnessProperties = [ | 19 let testharnessProperties = [ |
| 20 'test', 'async_test', 'promise_test', 'promise_rejects', | 20 'test', 'async_test', 'promise_test', 'promise_rejects', |
| 21 'generate_tests', 'setup', 'done', 'assert_true', 'assert_false' | 21 'generate_tests', 'setup', 'done', 'assert_true', 'assert_false' |
| 22 ]; | 22 ]; |
| 23 | 23 |
| 24 // Check if testharness.js is properly loaded. Throw otherwise. | 24 // Check if testharness.js is properly loaded. Throw otherwise. |
| 25 for (let name in testharnessProperties) { | 25 for (let name in testharnessProperties) { |
| 26 if (!self.hasOwnProperty(testharnessProperties[name])) | 26 if (!self.hasOwnProperty(testharnessProperties[name])) |
| 27 throw new Error('Cannot proceed. testharness.js is not loaded.'); | 27 throw new Error('Cannot proceed. testharness.js is not loaded.'); |
| 28 } | 28 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 48 function _logFailed (message, detail) { | 48 function _logFailed (message, detail) { |
| 49 test(function () { | 49 test(function () { |
| 50 assert_true(false, detail); | 50 assert_true(false, detail); |
| 51 }, message); | 51 }, message); |
| 52 } | 52 } |
| 53 | 53 |
| 54 function _throwException (message) { | 54 function _throwException (message) { |
| 55 throw new Error(message); | 55 throw new Error(message); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // TODO(hongchan): remove this hack after confirming all the tests are |
| 59 // finished correctly. (crbug.com/708817) |
| 60 const _testharnessDone = window.done; |
| 61 window.done = () => { |
| 62 _throwException('Do NOT call done() method from the test code.'); |
| 63 }; |
| 64 |
| 58 // Generate a descriptive string from a target value in various types. | 65 // Generate a descriptive string from a target value in various types. |
| 59 function _generateDescription (target, options) { | 66 function _generateDescription (target, options) { |
| 60 let targetString; | 67 let targetString; |
| 61 | 68 |
| 62 switch (typeof target) { | 69 switch (typeof target) { |
| 63 case 'object': | 70 case 'object': |
| 64 // Handle Arrays. | 71 // Handle Arrays. |
| 65 if (target instanceof Array || target instanceof Float32Array || | 72 if (target instanceof Array || target instanceof Float32Array || |
| 66 target instanceof Float64Array || target instanceof Uint8Array) { | 73 target instanceof Float64Array || target instanceof Uint8Array) { |
| 67 let arrayElements = target.length < options.numberOfArrayElements | 74 let arrayElements = target.length < options.numberOfArrayElements |
| (...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 if (numberOfFailures > 0) { | 1137 if (numberOfFailures > 0) { |
| 1131 _logFailed(prefix + numberOfFailures + ' out of ' | 1138 _logFailed(prefix + numberOfFailures + ' out of ' |
| 1132 + this._taskSequence.length + ' tasks were failed.'); | 1139 + this._taskSequence.length + ' tasks were failed.'); |
| 1133 } else { | 1140 } else { |
| 1134 _logPassed(prefix + this._taskSequence.length | 1141 _logPassed(prefix + this._taskSequence.length |
| 1135 + ' tasks ran successfully.'); | 1142 + ' tasks ran successfully.'); |
| 1136 } | 1143 } |
| 1137 | 1144 |
| 1138 // From testharness.js, report back to the test infrastructure that | 1145 // From testharness.js, report back to the test infrastructure that |
| 1139 // the task runner completed all the tasks. | 1146 // the task runner completed all the tasks. |
| 1140 done(); | 1147 _testharnessDone(); |
| 1141 } | 1148 } |
| 1142 | 1149 |
| 1143 // |taskLabel| can be either a string or a dictionary. See Task constructor | 1150 // |taskLabel| can be either a string or a dictionary. See Task constructor |
| 1144 // for the detail. | 1151 // for the detail. |
| 1145 define (taskLabel, taskFunction) { | 1152 define (taskLabel, taskFunction) { |
| 1146 let task = new Task(this, taskLabel, taskFunction); | 1153 let task = new Task(this, taskLabel, taskFunction); |
| 1147 if (this._tasks.hasOwnProperty(task.label)) { | 1154 if (this._tasks.hasOwnProperty(task.label)) { |
| 1148 _throwException('Audit.define:: Duplicate task definition.'); | 1155 _throwException('Audit.define:: Duplicate task definition.'); |
| 1149 return; | 1156 return; |
| 1150 } | 1157 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1269 | 1276 |
| 1270 /** | 1277 /** |
| 1271 * Load file from a given URL and pass ArrayBuffer to the following promise. | 1278 * Load file from a given URL and pass ArrayBuffer to the following promise. |
| 1272 * See |loadFileFromUrl| method for the detail. | 1279 * See |loadFileFromUrl| method for the detail. |
| 1273 */ | 1280 */ |
| 1274 loadFileFromUrl: loadFileFromUrl | 1281 loadFileFromUrl: loadFileFromUrl |
| 1275 | 1282 |
| 1276 }; | 1283 }; |
| 1277 | 1284 |
| 1278 })(); | 1285 })(); |
| OLD | NEW |