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

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: Addressing feedback 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
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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 return; 1093 return;
1089 } 1094 }
1090 1095
1091 // Start the first task. 1096 // Start the first task.
1092 this._currentTaskIndex = 0; 1097 this._currentTaskIndex = 0;
1093 this._runNextTask(); 1098 this._runNextTask();
1094 } 1099 }
1095 1100
1096 } 1101 }
1097 1102
1103 /**
1104 * Load file from a given URL and pass ArrayBuffer to the following promise.
1105 * @param {String} fileUrl file URL.
1106 * @return {Promise}
1107 *
1108 * @example
1109 * Audit.loadFileFromUrl('resources/my-sound.ogg').then((response) => {
1110 * audioContext.decodeAudioData(response).then((audioBuffer) => {
1111 * // Do something with AudioBuffer.
1112 * });
1113 * });
1114 */
1115 function loadFileFromUrl (fileUrl) {
1116 return new Promise((resolve, reject) => {
1117 let xhr = new XMLHttpRequest();
1118 xhr.open('GET', fileUrl);
1119 xhr.responseType = 'arraybuffer';
1120
1121 xhr.onload = () => {
1122 if (xhr.status === 200) {
1123 resolve(xhr.response);
1124 } else {
1125 let errorMessage = 'loadFile: Request failed when loading ' +
1126 fileUrl + '. (' + xhr.statusText + ')';
1127 if (reject) {
1128 reject(errorMessage);
1129 } else {
1130 new Error(errorMessage);
1131 }
1132 }
1133 };
1134
1135 xhr.onerror = (event) => {
1136 let errorMessage =
1137 'loadFile: Network failure when loading ' + fileUrl + '.';
1138 if (reject) {
1139 reject(errorMessage);
1140 } else {
1141 new Error(errorMessage);
1142 }
1143 };
1144
1145 xhr.send();
1146 });
1147 }
1098 1148
1099 /** 1149 /**
1100 * @class Audit 1150 * @class Audit
1101 * @description A WebAudio layout test task manager. 1151 * @description A WebAudio layout test task manager.
1102 * @example 1152 * @example
1103 * let audit = Audit.createTaskRunner(); 1153 * let audit = Audit.createTaskRunner();
1104 * audit.define('first-task', function (task, should) { 1154 * audit.define('first-task', function (task, should) {
1105 * task.describe('the first task'); 1155 * task.describe('the first task');
1106 * should(someValue).beEqualTo(someValue); 1156 * should(someValue).beEqualTo(someValue);
1107 * task.done(); 1157 * task.done();
(...skipping 10 matching lines...) Expand all
1118 * comparison with the expected 1168 * comparison with the expected
1119 * result file. 1169 * result file.
1120 */ 1170 */
1121 createTaskRunner: function (options) { 1171 createTaskRunner: function (options) {
1122 if (options && options.requireResultFile == true) { 1172 if (options && options.requireResultFile == true) {
1123 _logError('this test requires the explicit comparison with the ' 1173 _logError('this test requires the explicit comparison with the '
1124 + 'expected result when it runs with run-webkit-tests.'); 1174 + 'expected result when it runs with run-webkit-tests.');
1125 } 1175 }
1126 1176
1127 return new TaskRunner(); 1177 return new TaskRunner();
1128 } 1178 },
1179
1180 /**
1181 * Load file from a given URL and pass ArrayBuffer to the following promise.
1182 * See |loadFileFromUrl| method for the detail.
1183 */
1184 loadFileFromUrl: loadFileFromUrl
1129 1185
1130 }; 1186 };
1131 1187
1132 })(); 1188 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698