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

Unified 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 side-by-side diff with in-line comments
Download patch
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..ed5f0297035d35edbd01b12a3ca8cecb8405c367 100644
--- a/third_party/WebKit/LayoutTests/webaudio/resources/audit.js
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/audit.js
@@ -321,22 +321,30 @@ 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 () {
- this._assert(true, '${actual} resolved correctly.', null);
- }.bind(this), function (error) {
- this._assert(false, null,
- '${actual} rejected incorrectly with ' + error + '.');
- }.bind(this));
+ 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 + '.');
+ }.bind(this));
}
/**
@@ -1095,6 +1103,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 + '.';
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
+ if (reject) {
+ reject(errorMessage);
+ } else {
+ new Error(errorMessage);
+ }
+ };
+
+ xhr.send();
+ });
+ }
/**
* @class Audit
@@ -1118,14 +1171,20 @@ window.Audit = (function () {
* comparison with the expected
* result file.
*/
- createTaskRunner: function (options) {
+ createTaskRunner: function(options) {
if (options && options.requireResultFile == true) {
_logError('this test requires the explicit comparison with the '
+ 'expected result when it runs with run-webkit-tests.');
}
return new TaskRunner();
- }
+ },
+
+ /**
+ * Load file from a given URL and pass ArrayBuffer to the following promise.
+ * See |loadFileFromUrl| method for the detail.
+ */
+ loadFileFromUrl: loadFileFromUrl
};

Powered by Google App Engine
This is Rietveld 408576698