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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/audit.js

Issue 2766883002: Allow status = 0 when XHR is completed in Audit.loadFileFromUrl(). (Closed)
Patch Set: Fixed threshold after revert Created 3 years, 9 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
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 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 * @example 1184 * @example
1185 * Audit.loadFileFromUrl('resources/my-sound.ogg').then((response) => { 1185 * Audit.loadFileFromUrl('resources/my-sound.ogg').then((response) => {
1186 * audioContext.decodeAudioData(response).then((audioBuffer) => { 1186 * audioContext.decodeAudioData(response).then((audioBuffer) => {
1187 * // Do something with AudioBuffer. 1187 * // Do something with AudioBuffer.
1188 * }); 1188 * });
1189 * }); 1189 * });
1190 */ 1190 */
1191 function loadFileFromUrl (fileUrl) { 1191 function loadFileFromUrl (fileUrl) {
1192 return new Promise((resolve, reject) => { 1192 return new Promise((resolve, reject) => {
1193 let xhr = new XMLHttpRequest(); 1193 let xhr = new XMLHttpRequest();
1194 xhr.open('GET', fileUrl); 1194 xhr.open('GET', fileUrl, true);
1195 xhr.responseType = 'arraybuffer'; 1195 xhr.responseType = 'arraybuffer';
1196 1196
1197 xhr.onload = () => { 1197 xhr.onload = () => {
1198 if (xhr.status === 200) { 1198 // |status = 0| is a workaround for the run-webkit-test server. We are
1199 // speculating the server quits the transaction prematurely without
1200 // completing the request.
1201 if (xhr.status === 200 || xhr.status === 0) {
1199 resolve(xhr.response); 1202 resolve(xhr.response);
1200 } else { 1203 } else {
1201 let errorMessage = 'loadFile: Request failed when loading ' + 1204 let errorMessage = 'loadFile: Request failed when loading ' +
1202 fileUrl + '. (' + xhr.statusText + ')'; 1205 fileUrl + '. ' + xhr.statusText + '. (status = ' +
1206 xhr.status + ')';
1203 if (reject) { 1207 if (reject) {
1204 reject(errorMessage); 1208 reject(errorMessage);
1205 } else { 1209 } else {
1206 new Error(errorMessage); 1210 new Error(errorMessage);
1207 } 1211 }
1208 } 1212 }
1209 }; 1213 };
1210 1214
1211 xhr.onerror = (event) => { 1215 xhr.onerror = (event) => {
1212 let errorMessage = 1216 let errorMessage =
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 1259
1256 /** 1260 /**
1257 * Load file from a given URL and pass ArrayBuffer to the following promise. 1261 * Load file from a given URL and pass ArrayBuffer to the following promise.
1258 * See |loadFileFromUrl| method for the detail. 1262 * See |loadFileFromUrl| method for the detail.
1259 */ 1263 */
1260 loadFileFromUrl: loadFileFromUrl 1264 loadFileFromUrl: loadFileFromUrl
1261 1265
1262 }; 1266 };
1263 1267
1264 })(); 1268 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698