Permalink
Browse files

Defer globalTimeout to start after each audio loadedmetadata event

  • Loading branch information...
1 parent f31ef36 commit 85608f8fad473d6180a9dc0da02fd4dab7abf423 Tomás Senart committed Nov 16, 2011
Showing with 75 additions and 77 deletions.
  1. +20 −21 public/js/awpy.js
  2. +1 −2 public/tests/attribute-autoplay.js
  3. +1 −1 public/tests/attribute-preload-metadata.js
  4. +1 −1 public/tests/event-abort.js
  5. +1 −1 public/tests/event-canplay.js
  6. +1 −1 public/tests/event-canplaythrough.js
  7. +1 −1 public/tests/event-durationchange.js
  8. +1 −1 public/tests/event-emptied.js
  9. +1 −1 public/tests/event-ended.js
  10. +1 −1 public/tests/event-error.js
  11. +1 −1 public/tests/event-loadeddata.js
  12. +1 −1 public/tests/event-loadedmetadata.js
  13. +1 −1 public/tests/event-loadstart.js
  14. +1 −1 public/tests/event-pause.js
  15. +1 −1 public/tests/event-play.js
  16. +1 −1 public/tests/event-playing.js
  17. +1 −1 public/tests/event-progress.js
  18. +1 −1 public/tests/event-ratechange.js
  19. +1 −1 public/tests/event-seeked.js
  20. +1 −1 public/tests/event-seeking.js
  21. +1 −1 public/tests/event-stalled.js
  22. +1 −1 public/tests/event-suspend.js
  23. +1 −1 public/tests/event-timeupdate.js
  24. +1 −1 public/tests/event-volumechange.js
  25. +1 −1 public/tests/property-buffered.js
  26. +1 −1 public/tests/property-currentTime.js
  27. +1 −1 public/tests/property-defaultPlaybackRate.js
  28. +1 −1 public/tests/property-duration.js
  29. +1 −1 public/tests/property-muted.js
  30. +1 −1 public/tests/property-paused.js
  31. +1 −1 public/tests/property-playbackRate.js
  32. +1 −1 public/tests/property-played.js
  33. +1 −1 public/tests/property-seekable.js
  34. +1 −1 public/tests/property-seeking.js
  35. +1 −1 public/tests/property-volume.js
  36. +1 −2 public/tests/support-consistent-playback-delay.js
  37. +1 −1 public/tests/support-consistent-timeupdate-interval.js
  38. +1 −1 public/tests/support-crossorigin-ssl-redirection.js
  39. +1 −1 public/tests/support-format-aac.js
  40. +1 −1 public/tests/support-format-mp3.js
  41. +1 −1 public/tests/support-format-ogg.js
  42. +1 −1 public/tests/support-format-wav.js
  43. +1 −1 public/tests/support-hot-swapping-src.js
  44. +12 −11 public/tests/support-multiple-playing.js
  45. +1 −1 public/tests/support-seeking-unbuffered-position.js
View
@@ -34,42 +34,40 @@ AWPY.tests = (function() {
run: function(testName, callback) {
var single = !!testName;
var globalCleanup = function(test) {
- if (!test.audio) {
- return;
- }
- test.audio = (test.audio.length > 1) ? test.audio : [test.audio];
- test.audio.forEach(function(audio){
+ [].concat(test.audio || []).forEach(function(audio){
audio.pause();
audio.removeAttribute('src');
audio.load();
delete audio;
});
};
+ var finishTest = function(test, result) {
+ test.finished = true;
+ globalCleanup(test);
+ test.result = result;
+ callback.call(null, test);
+ };
var tests = list.filter(function(test) {
return (single ? test.name === testName : true) && !test.finished;
});
(function run(tests, i) {
var test = tests[i];
- var failTimeout = setTimeout(function() {
- test.finished = true;
- test.result = false;
- globalCleanup(test);
- callback.call(null, test);
- if (tests[i + 1]) {
- run(tests, i + 1);
- }
- }, 15000);
+ test.audio = new Audio();
+ test.audio.addEventListener('loadedmetadata', function() {
+ setTimeout(function() {
+ if (!test.finished) {
+ finishTest(test, false);
+ if (tests[i + 1]) {
+ run(tests, i + 1);
+ }
+ }
+ }, 15000);
+ }, false);
test.assert(function(result) {
- if (failTimeout) {
- clearTimeout(failTimeout);
- }
if (!test.finished) {
- test.finished = true;
- globalCleanup(test);
- test.result = result;
- callback.call(null, test);
+ finishTest(test, result);
if (tests[i + 1]) {
run(tests, i + 1);
}
@@ -83,6 +81,7 @@ AWPY.tests = (function() {
});
},
save: function() {
+ return;
var data = {}, newScript, firstScript;
this.finished().forEach(function(test) {
@@ -3,8 +3,7 @@
description: 'Attribute "autoplay"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#attr-media-autoplay',
assert: function(finish) {
- var audio = this.audio = new Audio();
-
+ var audio = this.audio;
audio.addEventListener('loadedmetadata', function() {
audio.volume = 0;
audio.addEventListener('timeupdate', function() {
@@ -3,7 +3,7 @@
description: 'Attribute "preload" with value "metadata"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#attr-media-preload',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('loadedmetadata', function() {
setTimeout(function() {
@@ -3,7 +3,7 @@
description: 'Event "abort"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-abort',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('abort', function() {
finish(true); // WIN
@@ -3,7 +3,7 @@
description: 'Event "canplay"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-canplay',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('canplay', function() {
finish(true); // WIN
@@ -3,7 +3,7 @@
description: 'Event "canplaythrough"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-canplaythrough',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('canplaythrough', function() {
finish(true); // WIN
@@ -3,7 +3,7 @@
description: 'Event "durationchange"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-durationchange',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('durationchange', function() {
finish(true); // WIN
@@ -3,7 +3,7 @@
description: 'Event "emptied"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-emptied',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('emptied', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "ended"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-ended',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('ended', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "error"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-error',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('error', function() {
finish(true); // WIN
@@ -3,7 +3,7 @@
description: 'Event "loadeddata"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-loadeddata',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('loadeddata', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "loadedmetadata"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-loadedmetadata',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('loadedmetadata', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "loadstart"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-loadstart',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('loadstart', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "pause"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-pause',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('pause', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "play"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-play',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('play', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "playing"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-playing',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('playing', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "progress"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-progress',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('progress', function() {
finish(true);
@@ -9,7 +9,7 @@
}
},
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('ratechange', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "seeked"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-seeked',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('seeked', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "seeking"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-seeking',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('seeking', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "stalled"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-stalled',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('stalled', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "suspend"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-suspend',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('suspend', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "timeupdate"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-timeupdate',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('timeupdate', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Event "volumechange"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#event-media-volumechange',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('volumechange', function() {
finish(true);
@@ -3,7 +3,7 @@
description: 'Property "buffered"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#dom-media-buffered',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('loadedmetadata', function() {
finish(audio.buffered && audio.buffered.length);
@@ -3,7 +3,7 @@
description: 'Property "currentTime"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#dom-media-currenttime',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('loadedmetadata', function() {
audio.currentTime = 1;
@@ -9,7 +9,7 @@
}
},
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
if (!('defaultPlaybackRate' in audio)) {
finish(false);
@@ -3,7 +3,7 @@
description: 'Property "duration"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#dom-media-duration',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
finish('duration' in audio);
}
@@ -3,7 +3,7 @@
description: 'Property "muted"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#dom-media-muted',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
if (!('muted' in audio)) {
finish(false);
@@ -3,7 +3,7 @@
description: 'Property "paused"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#dom-media-paused',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
finish('paused' in audio);
}
@@ -9,7 +9,7 @@
}
},
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
if (!('playbackRate' in audio)) {
finish(false);
@@ -9,7 +9,7 @@
}
},
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('timeupdate', function() {
if (audio.currentTime > 0) {
@@ -3,7 +3,7 @@
description: 'Property "seekable"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#dom-media-seekable',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
audio.addEventListener('loadedmetadata', function() {
finish(audio.seekable && audio.seekable.length);
@@ -3,7 +3,7 @@
description: 'Property "seeking"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#dom-media-seeking',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
if (!('seeking' in audio)) {
finish(false);
@@ -3,7 +3,7 @@
description: 'Property "volume"',
spec: 'http://dev.w3.org/html5/spec/the-iframe-element.html#dom-media-volume',
assert: function(finish) {
- var audio = this.audio = new Audio();
+ var audio = this.audio;
if (!('volume' in audio)) {
finish(false);
@@ -2,8 +2,7 @@
name: 'support-consistent-playback-delay',
description: 'Consistent time between play() and actual playback (< 20ms)',
assert: function(finish) {
- var audio = this.audio = new Audio(),
- playTime;
+ var audio = this.audio, playTime;
audio.addEventListener('playing', function() {
finish(Date.now() - playTime < 20);
@@ -2,7 +2,7 @@
name: 'support-consistent-timeupdate-interval',
description: 'Consistent timeupdate interval (15ms - 250ms)',
assert: function(finish) {
- var audio = this.audio = new Audio(),
+ var audio = this.audio,
lastTime, count = 0;
audio.addEventListener('timeupdate', function() {
Oops, something went wrong. Retry.

0 comments on commit 85608f8

Please sign in to comment.