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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/audiosource-premature-gc.html

Issue 1593763002: Keep AudioSourceNode from premature GC with ScriptWrappable::hasPendingActivity() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify changes (-AbstractAudioContext) Created 4 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/audiosource-premature-gc.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/audiosource-premature-gc.html b/third_party/WebKit/LayoutTests/webaudio/audiosource-premature-gc.html
new file mode 100644
index 0000000000000000000000000000000000000000..6de2538a522562537aa947a4b1f21d05f3fca945
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/webaudio/audiosource-premature-gc.html
@@ -0,0 +1,64 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Test premature GC upon OscillatorNode and AudioBufferSourceNode</title>
+ <script src="../resources/js-test.js"></script>
+ </head>
+
+ <body>
+ <script type="text/javascript">
+ description("Test premature GC upon OscillatorNode and AudioBufferSourceNode");
+ window.jsTestIsAsync = true;
+
+ var sampleRate = 44100;
+ var renderLength = 2 * sampleRate;
+
+ var context = new OfflineAudioContext(1, renderLength, sampleRate);
+
+ // Immediately execute this code inside of the closure. This way |osc| is
+ // contained in the scope and will be a possible target of GC. However,
+ // it will survive GC since it has a pending activity because it is
+ // scheduled. Thus |onended| will be fired eventually.
+ (function () {
+ var osc = context.createOscillator();
+ osc.connect(context.destination);
+ osc.onended = function () {
+ testPassed('OscillatorNode survived GC and onended event fired.');
+ };
+
+ // Play the oscillator for 1 second.
+ osc.start();
+ osc.stop(1);
+ })();
+
+ // The below does the same thing, but with AudioBufferSourceNode.
+ (function () {
+ var source = context.createBufferSource();
+ var dummy = context.createBuffer(1, 44100 * 1.5, 44100);
Raymond Toy 2016/02/22 17:43:51 The oscillator test runs for 1 sec. Any particula
hongchan 2016/02/23 18:01:33 None. I'll make it same.
+ source.buffer = dummy;
+
+ source.connect(context.destination);
+
+ source.onended = function () {
+ testPassed('AudioBufferSourceNode survived GC and onended event fired.');
+ };
+
+ var now = context.currentTime;
+ source.start(now);
+ })();
+
+ // Suspend the rendering at 0.1 second and perform GC. The reference to
+ // the oscillator and the buffer source should not be collected.
+ context.suspend(0.1).then(function () {
Raymond Toy 2016/02/22 17:43:51 Why perform a GC after 0.1 sec? Should you try a
hongchan 2016/02/23 18:01:33 0.1 is just an arbitrary time position after the s
+ gc();
+ context.resume();
+ });
+
+ context.startRendering().then(function () {
+ finishJSTest();
+ });
+
+ succesfullyParsed = true;
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698