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

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

Issue 2728613003: Add support creating and saving a new reference file. (Closed)
Patch Set: Fix typo 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-util.js
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/audit-util.js b/third_party/WebKit/LayoutTests/webaudio/resources/audit-util.js
index 74c6972957a5be4e0d4c31175d7d9284d33cfde3..16f94c98a615f7276f9656fdf516cc03bf35afaa 100644
--- a/third_party/WebKit/LayoutTests/webaudio/resources/audit-util.js
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/audit-util.js
@@ -109,6 +109,35 @@ function finishAudioTest(event) {
testRunner.notifyDone();
}
+// Save the given |audioBuffer| to a 16-bit WAV file using the name
+// given by |filename|. This is intended to be run from a browser.
+// The developer is expected to use the console to run
+// downloadAudioBuffer when necessary to create a new reference file
+// for a test.
+function downloadAudioBuffer(audioBuffer, filename) {
+ // Don't download if testRunner is defined; we're running a layout
+ // test where this won't be useful in general.
+ if (window.testRunner)
+ return false;
+ // Convert the audio buffer to an array containing the WAV file
+ // contents. Then convert it to a blob that can be saved as a WAV
+ // file.
+ let wavData = createAudioData(audioBuffer);
+ let blob = new Blob([wavData], {type: 'audio/wav'});
+ // Manually create html tags for downloading, and simulate a click
+ // to download the file to the given file name.
+ let a = document.createElement('a');
+ a.style.display = 'none';
+ a.download = filename;
+ let audioURL = window.URL.createObjectURL(blob);
+ let audio = new Audio();
+ audio.src = audioURL;
+ a.href = audioURL;
+ document.body.appendChild(a);
+ a.click();
+ return true;
+}
+
// Compare two arrays (commonly extracted from buffer.getChannelData()) with
// constraints:
// options.thresholdSNR: Minimum allowed SNR between the actual and expected

Powered by Google App Engine
This is Rietveld 408576698