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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/audiochannelmerger-disconnect.html

Issue 1488693006: Fix flaky WebAudio layout tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback (2) Created 5 years 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/audiochannelmerger-disconnect.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/audiochannelmerger-disconnect.html b/third_party/WebKit/LayoutTests/webaudio/audiochannelmerger-disconnect.html
index c100b8f4d629e8f188ba8484cd97c2aba019e9a7..958cb1206b07a46a45525e48e442f8cc2eb304f6 100644
--- a/third_party/WebKit/LayoutTests/webaudio/audiochannelmerger-disconnect.html
+++ b/third_party/WebKit/LayoutTests/webaudio/audiochannelmerger-disconnect.html
@@ -12,29 +12,27 @@
description('Test ChannelMergerNode behavior on dynamic input change.');
window.jsTestIsAsync = true;
- var sampleRate = 44100;
- var numberOfChannels = 2;
+ var renderQuantum = 128;
- // The test needs the long render length (20 seconds) to capture the
- // disconnection which happens after starting the rendering.
- var renderLength = sampleRate * 20;
+ var numberOfChannels = 2;
+ var sampleRate = 44100;
+ var renderDuration = 0.5;
+ var disconnectTime = 0.5 * renderDuration;
var audit = Audit.createTaskRunner();
// Task: Check if the merger outputs a silent channel when an input is
// disconnected.
audit.defineTask('silent-disconnect', function (done) {
- var context = new OfflineAudioContext(
- numberOfChannels, renderLength, sampleRate
- );
+ var context = new OfflineAudioContext(numberOfChannels, renderDuration * sampleRate, sampleRate);
var merger = context.createChannelMerger();
var source1 = context.createBufferSource();
var source2 = context.createBufferSource();
- // Create and assign a mono testing buffer.
- var bufferDCOffset = createTestingAudioBuffer(context, 1, renderLength);
- source1.buffer = bufferDCOffset;
- source2.buffer = bufferDCOffset;
+ // Create and assign a constant buffer.
+ var bufferDCOffset = createConstantBuffer(context, 1, 1);
+ source1.buffer = source2.buffer = bufferDCOffset;
+ source1.loop = source2.loop = true;
// Connect the output of source into the 4th input of merger. The merger
// should produce 6 channel output.
@@ -44,22 +42,31 @@
source1.start();
source2.start();
- // When the rendering begins, disconnect |source2| as soon as possible.
- context.onstatechange = function () {
- if (context.state === 'running')
- source2.disconnect();
- };
+ // Schedule the disconnection of |source2| at the half of render duration.
+ context.suspend(disconnectTime).then(function () {
+ source2.disconnect();
+ context.resume();
+ });
context.startRendering().then(function (buffer) {
-
// The entire first channel of the output should be 1.
Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(1);
+ // Calculate the first zero index in the second channel.
+ var channel1 = buffer.getChannelData(1);
+ var disconnectIndex = disconnectTime * sampleRate;
+ disconnectIndex -= (disconnectIndex) % renderQuantum;
+ var firstZeroIndex = channel1.findIndex(function (element, index) {
+ if (element === 0)
+ return index;
+ });
+
// The second channel should contain 1, and 0 after the disconnection.
- Should('Channel #1', buffer.getChannelData(1)).containValues([1, 0]);
+ Should('Channel #1', channel1).containValues([1, 0]);
+ Should('The index of first zero in the channel #1', firstZeroIndex)
+ .beEqualTo(disconnectIndex);
- done();
- });
+ }).then(done);
});
audit.defineTask('finish', function (done) {
@@ -67,10 +74,7 @@
done();
});
- audit.runTasks(
- 'silent-disconnect',
- 'finish'
- );
+ audit.runTasks();
successfullyParsed = true;
</script>

Powered by Google App Engine
This is Rietveld 408576698