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

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: Initial Commit 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.html ('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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 * Check if |actual| promise is resolved correctly. 324 * Check if |actual| promise is resolved correctly.
325 * 325 *
326 * @example 326 * @example
327 * should('My promise', promise).beResolve().then(nextStuff); 327 * should('My promise', promise).beResolve().then(nextStuff);
328 * 328 *
329 * @result 329 * @result
330 * "PASS My promise resolved correctly." 330 * "PASS My promise resolved correctly."
331 * "FAIL X My promise rejected *INCORRECTLY* with _ERROR_." 331 * "FAIL X My promise rejected *INCORRECTLY* with _ERROR_."
332 */ 332 */
333 beResolved () { 333 beResolved () {
334 return this._actual.then(function () { 334 return this._actual.then(function (result) {
Raymond Toy 2017/02/14 22:47:56 This needs to be documented somehow.
hongchan 2017/02/14 22:54:39 Done.
335 this._assert(true, '${actual} resolved correctly.', null); 335 this._assert(true, '${actual} resolved correctly.', null);
336 return result;
336 }.bind(this), function (error) { 337 }.bind(this), function (error) {
337 this._assert(false, null, 338 this._assert(false, null,
338 '${actual} rejected incorrectly with ' + error + '.'); 339 '${actual} rejected incorrectly with ' + error + '.');
339 }.bind(this)); 340 }.bind(this));
340 } 341 }
341 342
342 /** 343 /**
343 * Check if |actual| promise is rejected correctly. 344 * Check if |actual| promise is rejected correctly.
344 * 345 *
345 * @example 346 * @example
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 return; 1089 return;
1089 } 1090 }
1090 1091
1091 // Start the first task. 1092 // Start the first task.
1092 this._currentTaskIndex = 0; 1093 this._currentTaskIndex = 0;
1093 this._runNextTask(); 1094 this._runNextTask();
1094 } 1095 }
1095 1096
1096 } 1097 }
1097 1098
1099 /**
1100 * Load file from a given URL and pass ArrayBuffer to the following promise.
1101 * @param {String} fileUrl file URL.
1102 * @return {Promise}
1103 *
1104 * @example
1105 * Audit.loadFile('resources/my-sound.ogg').then((response) => {
1106 * audioContext.decodeAudioData(response).then((audioBuffer) => {
1107 * // Do something with AudioBuffer.
1108 * });
1109 * });
1110 */
1111 function loadFileAtUrl (fileUrl) {
Raymond Toy 2017/02/14 22:47:56 Documentation says loadFile, but the function is l
hongchan 2017/02/14 22:54:39 Done. A good question. I have no idea for now.
1112 return new Promise((resolve, reject) => {
1113 let xhr = new XMLHttpRequest();
1114 xhr.open('GET', fileUrl);
1115 xhr.responseType = 'arraybuffer';
1116
1117 xhr.onload = () => {
1118 if (xhr.status === 200) {
1119 resolve(xhr.response);
1120 } else {
1121 let errorMessage = 'loadFile: Request failed when loading ' +
1122 fileUrl + '. (' + xhr.statusText + ')';
1123 if (reject) {
1124 reject(errorMessage);
1125 } else {
1126 new Error(errorMessage);
1127 }
1128 }
1129 };
1130
1131 xhr.onerror = (event) => {
1132 let errorMessage = 'loadFile: Network failure when loading ' +
1133 fileUrl + '.';
1134 if (reject) {
1135 reject(errorMessage);
1136 } else {
1137 new Error(errorMessage);
1138 }
1139 };
1140
1141 xhr.send();
1142 });
1143 }
1098 1144
1099 /** 1145 /**
1100 * @class Audit 1146 * @class Audit
1101 * @description A WebAudio layout test task manager. 1147 * @description A WebAudio layout test task manager.
1102 * @example 1148 * @example
1103 * let audit = Audit.createTaskRunner(); 1149 * let audit = Audit.createTaskRunner();
1104 * audit.define('first-task', function (task, should) { 1150 * audit.define('first-task', function (task, should) {
1105 * task.describe('the first task'); 1151 * task.describe('the first task');
1106 * should(someValue).beEqualTo(someValue); 1152 * should(someValue).beEqualTo(someValue);
1107 * task.done(); 1153 * task.done();
(...skipping 10 matching lines...) Expand all
1118 * comparison with the expected 1164 * comparison with the expected
1119 * result file. 1165 * result file.
1120 */ 1166 */
1121 createTaskRunner: function (options) { 1167 createTaskRunner: function (options) {
1122 if (options && options.requireResultFile == true) { 1168 if (options && options.requireResultFile == true) {
1123 _logError('this test requires the explicit comparison with the ' 1169 _logError('this test requires the explicit comparison with the '
1124 + 'expected result when it runs with run-webkit-tests.'); 1170 + 'expected result when it runs with run-webkit-tests.');
1125 } 1171 }
1126 1172
1127 return new TaskRunner(); 1173 return new TaskRunner();
1128 } 1174 },
1175
1176 /**
1177 * Load file from a given URL and pass ArrayBuffer to the following promise.
1178 * See |loadFileAtUrl| method for the detail.
1179 */
1180 loadFileAtUrl: loadFileAtUrl
1129 1181
1130 }; 1182 };
1131 1183
1132 })(); 1184 })();
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/decodeAudioData/decode-audio-data-basic.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698