| OLD | NEW |
| 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 Loading... |
| 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, true); | 1194 xhr.open('GET', fileUrl); |
| 1195 xhr.responseType = 'arraybuffer'; | 1195 xhr.responseType = 'arraybuffer'; |
| 1196 | 1196 |
| 1197 xhr.onload = () => { | 1197 xhr.onload = () => { |
| 1198 // |status = 0| is a workaround for the run-webkit-test server. We are | 1198 if (xhr.status === 200) { |
| 1199 // speculating the server quits the transaction prematurely without | |
| 1200 // completing the request. | |
| 1201 if (xhr.status === 200 || xhr.status === 0) { | |
| 1202 resolve(xhr.response); | 1199 resolve(xhr.response); |
| 1203 } else { | 1200 } else { |
| 1204 let errorMessage = 'loadFile: Request failed when loading ' + | 1201 let errorMessage = 'loadFile: Request failed when loading ' + |
| 1205 fileUrl + '. ' + xhr.statusText + '. (status = ' + | 1202 fileUrl + '. (' + xhr.statusText + ')'; |
| 1206 xhr.status + ')'; | |
| 1207 if (reject) { | 1203 if (reject) { |
| 1208 reject(errorMessage); | 1204 reject(errorMessage); |
| 1209 } else { | 1205 } else { |
| 1210 new Error(errorMessage); | 1206 new Error(errorMessage); |
| 1211 } | 1207 } |
| 1212 } | 1208 } |
| 1213 }; | 1209 }; |
| 1214 | 1210 |
| 1215 xhr.onerror = (event) => { | 1211 xhr.onerror = (event) => { |
| 1216 let errorMessage = | 1212 let errorMessage = |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 | 1255 |
| 1260 /** | 1256 /** |
| 1261 * Load file from a given URL and pass ArrayBuffer to the following promise. | 1257 * Load file from a given URL and pass ArrayBuffer to the following promise. |
| 1262 * See |loadFileFromUrl| method for the detail. | 1258 * See |loadFileFromUrl| method for the detail. |
| 1263 */ | 1259 */ |
| 1264 loadFileFromUrl: loadFileFromUrl | 1260 loadFileFromUrl: loadFileFromUrl |
| 1265 | 1261 |
| 1266 }; | 1262 }; |
| 1267 | 1263 |
| 1268 })(); | 1264 })(); |
| OLD | NEW |