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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-graph-manipulation.html

Issue 1405413004: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating UseCounter.h after L-G-T-M Created 5 years, 1 month 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/offlineaudiocontext-suspend-resume-graph-manipulation.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-graph-manipulation.html b/third_party/WebKit/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-graph-manipulation.html
new file mode 100644
index 0000000000000000000000000000000000000000..a996ac2cdb8eba5159d7392f0f9b83a78e8e4ec1
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-graph-manipulation.html
@@ -0,0 +1,93 @@
+<!doctype html>
+<html>
+ <head>
+ <script src="../resources/js-test.js"></script>
+ <script src="resources/compatibility.js"></script>
+ <script src="resources/audio-testing.js"></script>
+ </head>
+
+ <body>
+ <script>
+ description('Test synchronous graph manipulation with OfflineAudioContext.suspend() and OfflineAudioContext.resume().');
+ window.jsTestIsAsync = true;
+
+ var context;
+ var renderQuantum = 128;
+ var renderDuration = 3;
+
+ // The sample rate is multiple of the rendering quantum, so suspension
+ // times fall in to the render quantum boundary.
+ var sampleRate = renderQuantum * 100;
+
+ context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate);
+
+ // Create a constant buffer of 1.0.
+ var constantBuffer = createConstantBuffer(context, 1, 1.0);
+ var constantSource = context.createBufferSource();
+ constantSource.buffer = constantBuffer;
+ constantSource.loop = true;
+
+ // The audio output from the beginning (0.0 second) to the first suspend
+ // time should be 0.0 because there is no connection to the destination.
+
+ // Suspend at 1 second and activate the source node. The audio output
+ // should be 1.0 from |suspendTime1| to the next suspension.
+ var suspendTime1 = 1;
+ context.suspend(suspendTime1).then(function () {
+ if (context.currentTime === suspendTime1)
+ testPassed('Context is suspended at ' + suspendTime1 * sampleRate + ' frame as expected.');
+
+ constantSource.connect(context.destination);
+ constantSource.start();
+ testPassed('A constant buffer is connected to destination and started at ' +
+ suspendTime1 * sampleRate + ' frame.');
+
+ context.resume();
+ });
+
+ // Suspend at 2 seconds and disconnect the node. The audio output should
+ // be 0.0 from |suspendTime2| to the end.
+ var suspendTime2 = 2;
+ context.suspend(suspendTime2).then(function () {
+ if (context.currentTime === suspendTime2)
+ testPassed('Context is suspended at ' + suspendTime2 * sampleRate + ' frame as expected.');
+
+ constantSource.disconnect();
+ testPassed('A constant buffer is disconnected at ' + suspendTime2 * sampleRate + ' frame.');
+
+ context.resume();
+ });
+
+ context.startRendering().then(function (buffer) {
+ verifyResult(buffer);
+ finishJSTest();
+ });
+
+ function verifyResult(buffer) {
+ var data = buffer.getChannelData(0);
+
+ var suspendIndex1 = suspendTime1 * sampleRate;
+ var suspendIndex2 = suspendTime2 * sampleRate;
+ var endIndex = renderDuration * sampleRate;
+
+ // Split the rendered buffer into 3 segments:
+ // [0, suspendIndex1), [suspendIndex1, suspendIndex2), [suspendIndex2,
+ // endIndex).
+ var subarray0 = data.subarray(0, suspendIndex1);
+ var subarray1 = data.subarray(suspendIndex1, suspendIndex2);
+ var subarray2 = data.subarray(suspendIndex2, endIndex);
+
+ // Each segment should contain a constant value of 0, 1 and 0
+ // respectively.
+ Should('Buffer frame [0, ' + suspendIndex1 + ')', subarray0).beConstantValueOf(0);
+ Should('Buffer frame [' + suspendIndex1 + ', ' + suspendIndex2 + ')', subarray1)
+ .beConstantValueOf(1);
+ Should('Buffer frame [' + suspendIndex2 + ', ' + endIndex + ')', subarray2)
+ .beConstantValueOf(0);
+ }
+
+ successfullyParsed = true;
+ </script>
+
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698