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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/audit.js

Issue 2697733004: Refactor decode-audio-data-basic.html to use testharness (Closed)
Patch Set: Fixed type after l-g-t-m Created 3 years, 10 months 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
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/decodeAudioData/decode-audio-data-basic-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } catch (error) { 314 } catch (error) {
315 didThrowCorrectly = true; 315 didThrowCorrectly = true;
316 failDetail = '${actual} incorrectly threw ' + error.name + ': "' 316 failDetail = '${actual} incorrectly threw ' + error.name + ': "'
317 + error.message + '".'; 317 + error.message + '".';
318 } 318 }
319 319
320 return this._assert(!didThrowCorrectly, passDetail, failDetail); 320 return this._assert(!didThrowCorrectly, passDetail, failDetail);
321 } 321 }
322 322
323 /** 323 /**
324 * Check if |actual| promise is resolved correctly. 324 * Check if |actual| promise is resolved correctly. Note that the returned
325 * result from promise object will be passed to the following then()
326 * function.
325 * 327 *
326 * @example 328 * @example
327 * should('My promise', promise).beResolve().then(nextStuff); 329 * should('My promise', promise).beResolve().then((result) => {
330 * console.log(result);
331 * });
328 * 332 *
329 * @result 333 * @result
330 * "PASS My promise resolved correctly." 334 * "PASS My promise resolved correctly."
331 * "FAIL X My promise rejected *INCORRECTLY* with _ERROR_." 335 * "FAIL X My promise rejected *INCORRECTLY* with _ERROR_."
332 */ 336 */
333 beResolved () { 337 beResolved () {
334 return this._actual.then(function () { 338 return this._actual.then(function (result) {
335 this._assert(true, '${actual} resolved correctly.', null); 339 this._assert(true, '${actual} resolved correctly.', null);
340 return result;
336 }.bind(this), function (error) { 341 }.bind(this), function (error) {
337 this._assert(false, null, 342 this._assert(false, null,
338 '${actual} rejected incorrectly with ' + error + '.'); 343 '${actual} rejected incorrectly with ' + error + '.');
339 }.bind(this)); 344 }.bind(this));
340 } 345 }
341 346
342 /** 347 /**
343 * Check if |actual| promise is rejected correctly. 348 * Check if |actual| promise is rejected correctly.
344 * 349 *
345 * @example 350 * @example
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 return; 1097 return;
1093 } 1098 }
1094 1099
1095 // Start the first task. 1100 // Start the first task.
1096 this._currentTaskIndex = 0; 1101 this._currentTaskIndex = 0;
1097 this._runNextTask(); 1102 this._runNextTask();
1098 } 1103 }
1099 1104
1100 } 1105 }
1101 1106
1107 /**
1108 * Load file from a given URL and pass ArrayBuffer to the following promise.
1109 * @param {String} fileUrl file URL.
1110 * @return {Promise}
1111 *
1112 * @example
1113 * Audit.loadFileFromUrl('resources/my-sound.ogg').then((response) => {
1114 * audioContext.decodeAudioData(response).then((audioBuffer) => {
1115 * // Do something with AudioBuffer.
1116 * });
1117 * });
1118 */
1119 function loadFileFromUrl (fileUrl) {
1120 return new Promise((resolve, reject) => {
1121 let xhr = new XMLHttpRequest();
1122 xhr.open('GET', fileUrl);
1123 xhr.responseType = 'arraybuffer';
1124
1125 xhr.onload = () => {
1126 if (xhr.status === 200) {
1127 resolve(xhr.response);
1128 } else {
1129 let errorMessage = 'loadFile: Request failed when loading ' +
1130 fileUrl + '. (' + xhr.statusText + ')';
1131 if (reject) {
1132 reject(errorMessage);
1133 } else {
1134 new Error(errorMessage);
1135 }
1136 }
1137 };
1138
1139 xhr.onerror = (event) => {
1140 let errorMessage =
1141 'loadFile: Network failure when loading ' + fileUrl + '.';
1142 if (reject) {
1143 reject(errorMessage);
1144 } else {
1145 new Error(errorMessage);
1146 }
1147 };
1148
1149 xhr.send();
1150 });
1151 }
1102 1152
1103 /** 1153 /**
1104 * @class Audit 1154 * @class Audit
1105 * @description A WebAudio layout test task manager. 1155 * @description A WebAudio layout test task manager.
1106 * @example 1156 * @example
1107 * let audit = Audit.createTaskRunner(); 1157 * let audit = Audit.createTaskRunner();
1108 * audit.define('first-task', function (task, should) { 1158 * audit.define('first-task', function (task, should) {
1109 * task.describe('the first task'); 1159 * task.describe('the first task');
1110 * should(someValue).beEqualTo(someValue); 1160 * should(someValue).beEqualTo(someValue);
1111 * task.done(); 1161 * task.done();
(...skipping 10 matching lines...) Expand all
1122 * comparison with the expected 1172 * comparison with the expected
1123 * result file. 1173 * result file.
1124 */ 1174 */
1125 createTaskRunner: function (options) { 1175 createTaskRunner: function (options) {
1126 if (options && options.requireResultFile == true) { 1176 if (options && options.requireResultFile == true) {
1127 _logError('this test requires the explicit comparison with the ' 1177 _logError('this test requires the explicit comparison with the '
1128 + 'expected result when it runs with run-webkit-tests.'); 1178 + 'expected result when it runs with run-webkit-tests.');
1129 } 1179 }
1130 1180
1131 return new TaskRunner(); 1181 return new TaskRunner();
1132 } 1182 },
1183
1184 /**
1185 * Load file from a given URL and pass ArrayBuffer to the following promise.
1186 * See |loadFileFromUrl| method for the detail.
1187 */
1188 loadFileFromUrl: loadFileFromUrl
1133 1189
1134 }; 1190 };
1135 1191
1136 })(); 1192 })();
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/decodeAudioData/decode-audio-data-basic-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698