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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
};
« 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