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

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: Comments and clang-format (clean up #2) 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(
335 this._assert(true, '${actual} resolved correctly.', null); 339 function(result) {
336 }.bind(this), function (error) { 340 this._assert(true, '${actual} resolved correctly.', null);
337 this._assert(false, null, 341 return result;
338 '${actual} rejected incorrectly with ' + error + '.'); 342 }.bind(this),
339 }.bind(this)); 343 function(error) {
344 this._assert(
345 false, null,
346 '${actual} rejected incorrectly with ' + error + '.');
347 }.bind(this));
340 } 348 }
341 349
342 /** 350 /**
343 * Check if |actual| promise is rejected correctly. 351 * Check if |actual| promise is rejected correctly.
344 * 352 *
345 * @example 353 * @example
346 * should('My promise', promise).beRejected().then(nextStuff); 354 * should('My promise', promise).beRejected().then(nextStuff);
347 * 355 *
348 * @result 356 * @result
349 * "PASS My promise rejected correctly (with _ERROR_)." 357 * "PASS My promise rejected correctly (with _ERROR_)."
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 return; 1096 return;
1089 } 1097 }
1090 1098
1091 // Start the first task. 1099 // Start the first task.
1092 this._currentTaskIndex = 0; 1100 this._currentTaskIndex = 0;
1093 this._runNextTask(); 1101 this._runNextTask();
1094 } 1102 }
1095 1103
1096 } 1104 }
1097 1105
1106 /**
1107 * Load file from a given URL and pass ArrayBuffer to the following promise.
1108 * @param {String} fileUrl file URL.
1109 * @return {Promise}
1110 *
1111 * @example
1112 * Audit.loadFileFromUrl('resources/my-sound.ogg').then((response) => {
1113 * audioContext.decodeAudioData(response).then((audioBuffer) => {
1114 * // Do something with AudioBuffer.
1115 * });
1116 * });
1117 */
1118 function loadFileFromUrl(fileUrl) {
1119 return new Promise((resolve, reject) => {
1120 let xhr = new XMLHttpRequest();
1121 xhr.open('GET', fileUrl);
1122 xhr.responseType = 'arraybuffer';
1123
1124 xhr.onload = () => {
1125 if (xhr.status === 200) {
1126 resolve(xhr.response);
1127 } else {
1128 let errorMessage = 'loadFile: Request failed when loading ' +
1129 fileUrl + '. (' + xhr.statusText + ')';
1130 if (reject) {
1131 reject(errorMessage);
1132 } else {
1133 new Error(errorMessage);
1134 }
1135 }
1136 };
1137
1138 xhr.onerror = (event) => {
1139 let errorMessage =
1140 'loadFile: Network failure when loading ' + fileUrl + '.';
Raymond Toy 2017/02/15 23:15:53 Is this the only way for xhr to fail? (Network fai
hongchan 2017/02/15 23:40:36 Nope. See l.1130. If the request status is not 200
1141 if (reject) {
1142 reject(errorMessage);
1143 } else {
1144 new Error(errorMessage);
1145 }
1146 };
1147
1148 xhr.send();
1149 });
1150 }
1098 1151
1099 /** 1152 /**
1100 * @class Audit 1153 * @class Audit
1101 * @description A WebAudio layout test task manager. 1154 * @description A WebAudio layout test task manager.
1102 * @example 1155 * @example
1103 * let audit = Audit.createTaskRunner(); 1156 * let audit = Audit.createTaskRunner();
1104 * audit.define('first-task', function (task, should) { 1157 * audit.define('first-task', function (task, should) {
1105 * task.describe('the first task'); 1158 * task.describe('the first task');
1106 * should(someValue).beEqualTo(someValue); 1159 * should(someValue).beEqualTo(someValue);
1107 * task.done(); 1160 * task.done();
1108 * }); 1161 * });
1109 * audit.run(); 1162 * audit.run();
1110 */ 1163 */
1111 return { 1164 return {
1112 1165
1113 /** 1166 /**
1114 * Creates an instance of Audit task runner. 1167 * Creates an instance of Audit task runner.
1115 * @param {Object} options Options for task runner. 1168 * @param {Object} options Options for task runner.
1116 * @param {Boolean} options.requireResultFile True if the test suite 1169 * @param {Boolean} options.requireResultFile True if the test suite
1117 * requires explicit text 1170 * requires explicit text
1118 * comparison with the expected 1171 * comparison with the expected
1119 * result file. 1172 * result file.
1120 */ 1173 */
1121 createTaskRunner: function (options) { 1174 createTaskRunner: function(options) {
1122 if (options && options.requireResultFile == true) { 1175 if (options && options.requireResultFile == true) {
1123 _logError('this test requires the explicit comparison with the ' 1176 _logError('this test requires the explicit comparison with the '
1124 + 'expected result when it runs with run-webkit-tests.'); 1177 + 'expected result when it runs with run-webkit-tests.');
1125 } 1178 }
1126 1179
1127 return new TaskRunner(); 1180 return new TaskRunner();
1128 } 1181 },
1182
1183 /**
1184 * Load file from a given URL and pass ArrayBuffer to the following promise.
1185 * See |loadFileFromUrl| method for the detail.
1186 */
1187 loadFileFromUrl: loadFileFromUrl
1129 1188
1130 }; 1189 };
1131 1190
1132 })(); 1191 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698