Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/webaudio/resources/audit.js |
| diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/audit.js b/third_party/WebKit/LayoutTests/webaudio/resources/audit.js |
| index f96e85e4036818a08ff57caaa7168aa985a24f85..cab69684c27d58084a64a50d5062f002181c815d 100644 |
| --- a/third_party/WebKit/LayoutTests/webaudio/resources/audit.js |
| +++ b/third_party/WebKit/LayoutTests/webaudio/resources/audit.js |
| @@ -331,8 +331,9 @@ window.Audit = (function () { |
| * "FAIL X My promise rejected *INCORRECTLY* with _ERROR_." |
| */ |
| beResolved () { |
| - return this._actual.then(function () { |
| + 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.
|
| this._assert(true, '${actual} resolved correctly.', null); |
| + return result; |
| }.bind(this), function (error) { |
| this._assert(false, null, |
| '${actual} rejected incorrectly with ' + error + '.'); |
| @@ -1095,6 +1096,51 @@ window.Audit = (function () { |
| } |
| + /** |
| + * Load file from a given URL and pass ArrayBuffer to the following promise. |
| + * @param {String} fileUrl file URL. |
| + * @return {Promise} |
| + * |
| + * @example |
| + * Audit.loadFile('resources/my-sound.ogg').then((response) => { |
| + * audioContext.decodeAudioData(response).then((audioBuffer) => { |
| + * // Do something with AudioBuffer. |
| + * }); |
| + * }); |
| + */ |
| + 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.
|
| + return new Promise((resolve, reject) => { |
| + let xhr = new XMLHttpRequest(); |
| + xhr.open('GET', fileUrl); |
| + xhr.responseType = 'arraybuffer'; |
| + |
| + xhr.onload = () => { |
| + if (xhr.status === 200) { |
| + resolve(xhr.response); |
| + } else { |
| + let errorMessage = 'loadFile: Request failed when loading ' + |
| + fileUrl + '. (' + xhr.statusText + ')'; |
| + if (reject) { |
| + reject(errorMessage); |
| + } else { |
| + new Error(errorMessage); |
| + } |
| + } |
| + }; |
| + |
| + xhr.onerror = (event) => { |
| + let errorMessage = 'loadFile: Network failure when loading ' + |
| + fileUrl + '.'; |
| + if (reject) { |
| + reject(errorMessage); |
| + } else { |
| + new Error(errorMessage); |
| + } |
| + }; |
| + |
| + xhr.send(); |
| + }); |
| + } |
| /** |
| * @class Audit |
| @@ -1125,7 +1171,13 @@ window.Audit = (function () { |
| } |
| return new TaskRunner(); |
| - } |
| + }, |
| + |
| + /** |
| + * Load file from a given URL and pass ArrayBuffer to the following promise. |
| + * See |loadFileAtUrl| method for the detail. |
| + */ |
| + loadFileAtUrl: loadFileAtUrl |
| }; |