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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/resources/audit.js

Issue 2697733004: Refactor decode-audio-data-basic.html to use testharness (Closed)
Patch Set: Fixed type after l-g-t-m 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-expected.txt ('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 7e732952a3968ed6ea2c9586d92c71a9b353ce83..0b511c84bcc6132d538d9fddab6d7de4e764e04e 100644
--- a/third_party/WebKit/LayoutTests/webaudio/resources/audit.js
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/audit.js
@@ -321,18 +321,23 @@ window.Audit = (function () {
}
/**
- * Check if |actual| promise is resolved correctly.
+ * Check if |actual| promise is resolved correctly. Note that the returned
+ * result from promise object will be passed to the following then()
+ * function.
*
* @example
- * should('My promise', promise).beResolve().then(nextStuff);
+ * should('My promise', promise).beResolve().then((result) => {
+ * console.log(result);
+ * });
*
* @result
* "PASS My promise resolved correctly."
* "FAIL X My promise rejected *INCORRECTLY* with _ERROR_."
*/
beResolved () {
- return this._actual.then(function () {
+ return this._actual.then(function (result) {
this._assert(true, '${actual} resolved correctly.', null);
+ return result;
}.bind(this), function (error) {
this._assert(false, null,
'${actual} rejected incorrectly with ' + error + '.');
@@ -1099,6 +1104,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.loadFileFromUrl('resources/my-sound.ogg').then((response) => {
+ * audioContext.decodeAudioData(response).then((audioBuffer) => {
+ * // Do something with AudioBuffer.
+ * });
+ * });
+ */
+ function loadFileFromUrl (fileUrl) {
+ 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
@@ -1129,7 +1179,13 @@ window.Audit = (function () {
}
return new TaskRunner();
- }
+ },
+
+ /**
+ * Load file from a given URL and pass ArrayBuffer to the following promise.
+ * See |loadFileFromUrl| method for the detail.
+ */
+ loadFileFromUrl: loadFileFromUrl
};
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/decodeAudioData/decode-audio-data-basic-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698