Chromium Code Reviews| 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); | 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| should be acceptable here because the server used by |
| 1199 // run-webkit-test has cross-domain file access issue. | |
|
Raymond Toy
2017/03/21 21:16:33
Do we actually know this (cross-domain)?
hongchan
2017/03/21 23:07:57
Comment fixed.
| |
| 1200 if (xhr.status === 200 || xhr.status === 0) { | |
| 1199 resolve(xhr.response); | 1201 resolve(xhr.response); |
| 1200 } else { | 1202 } else { |
| 1201 let errorMessage = 'loadFile: Request failed when loading ' + | 1203 let errorMessage = 'loadFile: Request failed when loading ' + |
| 1202 fileUrl + '. (' + xhr.statusText + ')'; | 1204 fileUrl + '. ' + xhr.statusText + '. (status = ' + |
| 1205 xhr.status + ')'; | |
| 1203 if (reject) { | 1206 if (reject) { |
| 1204 reject(errorMessage); | 1207 reject(errorMessage); |
| 1205 } else { | 1208 } else { |
| 1206 new Error(errorMessage); | 1209 new Error(errorMessage); |
| 1207 } | 1210 } |
| 1208 } | 1211 } |
| 1209 }; | 1212 }; |
| 1210 | 1213 |
| 1211 xhr.onerror = (event) => { | 1214 xhr.onerror = (event) => { |
| 1212 let errorMessage = | 1215 let errorMessage = |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1255 | 1258 |
| 1256 /** | 1259 /** |
| 1257 * Load file from a given URL and pass ArrayBuffer to the following promise. | 1260 * Load file from a given URL and pass ArrayBuffer to the following promise. |
| 1258 * See |loadFileFromUrl| method for the detail. | 1261 * See |loadFileFromUrl| method for the detail. |
| 1259 */ | 1262 */ |
| 1260 loadFileFromUrl: loadFileFromUrl | 1263 loadFileFromUrl: loadFileFromUrl |
| 1261 | 1264 |
| 1262 }; | 1265 }; |
| 1263 | 1266 |
| 1264 })(); | 1267 })(); |
| OLD | NEW |