Bug 1109390 part 5 - Adjust tests to better handle asynchronous pausing; r=jwatt
authorBrian Birtles <birtles@gmail.com>
Fri, 27 Mar 2015 15:56:44 +0900
changeset 266391 71e33f9c871eb86bc81c1586db6c0bb7f1b7441c
parent 266390 1c4030c686d6cf5d143be795c6228368729581c5
child 266392 ff6b730f3a891749c00940dda54595e4c3e0cab7
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1109390
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1109390 part 5 - Adjust tests to better handle asynchronous pausing; r=jwatt A number of animation tests assume that pausing happens instantaneously. This patch adjust many of those tests so that they will continue to work when pausing happens asynchronously. In many cases this is possible because we know the ready promise on AnimationPlayer (soon to be Animation) objects will be resolved so we can wait on it and it will resolve immediately now, but when asynchronous pausing is introduced the test the promise won't resolve until after the pause operation is complete. There are some tests that can't be so easily adjusted and we will have to fix these at the same time as we turn on async pausing. However, taking care of this set of tests now should reduce the size of subsequent patches in this series.
dom/animation/test/css-animations/test_animation-pausing.html
dom/animation/test/css-animations/test_animation-player-currenttime.html
dom/animation/test/css-animations/test_animation-player-playstate.html
dom/animation/test/css-animations/test_animation-player-starttime.html
dom/animation/test/css-transitions/test_animation-player-starttime.html
--- a/dom/animation/test/css-animations/test_animation-pausing.html
+++ b/dom/animation/test/css-animations/test_animation-pausing.html
@@ -26,20 +26,21 @@ async_test(function(t) {
 
   assert_equals(getMarginLeft(cs), 0,
                 'Initial value of margin-left is zero');
   var previousAnimVal = getMarginLeft(cs);
 
   player.ready.then(waitForFrame).then(t.step_func(function() {
     assert_true(getMarginLeft(cs) > previousAnimVal,
                 'margin-left is initially increasing');
+    player.pause();
+    return player.ready;
+  })).then(t.step_func(function() {
     previousAnimVal = getMarginLeft(cs);
-
-    player.pause();
-    return player.ready.then(waitForFrame);
+    return waitForFrame();
   })).then(t.step_func(function() {
     assert_equals(getMarginLeft(cs), previousAnimVal,
                   'margin-left does not increase after calling pause()');
     t.done();
   }));
 }, 'pause() a running animation');
 
 async_test(function(t) {
@@ -97,23 +98,24 @@ async_test(function(t) {
 
   player.ready.then(function() {
     div.style.animationPlayState = 'running';
     cs.animationPlayState; // Trigger style resolution
     return waitForFrame();
   }).then(t.step_func(function() {
     assert_equals(cs.animationPlayState, 'running',
                   'animation-play-state is running');
-    previousAnimVal = getMarginLeft(cs);
     div.style.animationPlayState = 'paused';
-    cs.animationPlayState; // Trigger style resolution
-    return waitForFrame();
+    return player.ready;
   })).then(t.step_func(function() {
     assert_equals(cs.animationPlayState, 'paused',
                   'animation-play-state is paused');
+    previousAnimVal = getMarginLeft(cs);
+    return waitForFrame();
+  })).then(t.step_func(function() {
     assert_equals(getMarginLeft(cs), previousAnimVal,
                   'Animated value of margin-left does not change when'
                   + ' paused by style');
     t.done();
   }));
 }, 'play() is overridden by later setting "animation-play-state: paused"');
 
 async_test(function(t) {
@@ -147,31 +149,31 @@ async_test(function(t) {
   div.style.animation = 'anim 1000s paused';
 
   var player = div.getAnimationPlayers()[0];
   assert_equals(getMarginLeft(cs), 0,
                 'Initial value of margin-left is zero');
 
   // Unlike the previous test for play(), since calling pause() is sticky,
   // we'll apply it even if the underlying style also says we're paused.
-  // 
+  //
   // We would like to test that implementations flush styles before running
   // pause() but actually there's no style we can currently set that will
   // change the behavior of pause(). That may change in the future
   // (e.g. if we introduce animation-timeline or animation-playback-rate etc.).
   //
   // For now this just serves as a sanity check that we do the same thing
   // even if we set style before calling the API.
   div.style.animationPlayState = 'running';
   player.pause();
   var previousAnimVal = getMarginLeft(cs);
 
-  waitForFrame().then(t.step_func(function() {
+  player.ready.then(waitForFrame).then(t.step_func(function() {
     assert_equals(cs.animationPlayState, 'running',
-                  'animation-play-state is paused');
+                  'animation-play-state is running');
     assert_equals(getMarginLeft(cs), previousAnimVal,
                   'Paused value of margin-left does not change');
     t.done();
   }));
 }, 'pause() applies pending changes to animation-play-state first');
 // (Note that we can't actually test for this; see comment above, in test-body.)
 
 </script>
--- a/dom/animation/test/css-animations/test_animation-player-currenttime.html
+++ b/dom/animation/test/css-animations/test_animation-player-currenttime.html
@@ -583,34 +583,31 @@ async_test(function(t) {
 }, 'Setting currentTime to null');
 
 
 async_test(function(t) {
   var div = addDiv(t, {'class': 'animated-div'});
   div.style.animation = 'anim 100s';
 
   var player = div.getAnimationPlayers()[0];
+  var pauseTime;
 
   player.ready.then(t.step_func(function() {
-    var savedCurrentTime = player.currentTime;
-
     assert_not_equals(player.currentTime, null,
       'AnimationPlayer.currentTime not null on ready Promise resolve');
-
-    var prePauseCurrentTime = player.currentTime;
-
     player.pause();
-    // After bug 1109390 we will need to wait here for the ready promise again
-
-    assert_equals(player.currentTime, prePauseCurrentTime,
-      'AnimationPlayer.currentTime is unchanged after AnimationPlayer.pause()');
-    assert_equals(player.playState, 'paused',
-      'AnimationPlayer.playState is "paused" after pause() call');
+    return player.ready;
+  })).then(t.step_func(function() {
+    pauseTime = player.currentTime;
+    return waitForFrame();
+  })).then(t.step_func(function() {
+    assert_equals(player.currentTime, pauseTime,
+      'AnimationPlayer.currentTime is unchanged after pausing');
   })).catch(t.step_func(function(reason) {
     assert_unreached(reason);
   })).then(function() {
     t.done();
   });
-}, 'AnimationPlayer.currentTime after paused');
+}, 'AnimationPlayer.currentTime after pausing');
 
     </script>
   </body>
 </html>
--- a/dom/animation/test/css-animations/test_animation-player-playstate.html
+++ b/dom/animation/test/css-animations/test_animation-player-playstate.html
@@ -19,33 +19,47 @@ async_test(function(t) {
   assert_equals(player.playState, 'pending');
 
   player.ready.then(t.step_func(function() {
     assert_equals(player.playState, 'running');
     t.done();
   }));
 }, 'Player returns correct playState when running');
 
-test(function(t) {
+async_test(function(t) {
   var div = addDiv(t);
   var cs = window.getComputedStyle(div);
   div.style.animation = 'anim 1000s paused';
 
   var player = div.getAnimationPlayers()[0];
-  assert_equals(player.playState, 'paused');
+  // FIXME: When we turn on async pausing later in this patch series, enable
+  // this
+  //   assert_equals(player.playState, 'pending');
+
+  player.ready.then(t.step_func(function() {
+    assert_equals(player.playState, 'paused');
+    t.done();
+  }));
 }, 'Player returns correct playState when paused');
 
-test(function(t) {
+async_test(function(t) {
   var div = addDiv(t);
   var cs = window.getComputedStyle(div);
   div.style.animation = 'anim 1000s';
 
   var player = div.getAnimationPlayers()[0];
   player.pause();
-  assert_equals(player.playState, 'paused');
+  // FIXME: When we turn on async pausing later in this patch series, enable
+  // this
+  //   assert_equals(player.playState, 'pending');
+
+  player.ready.then(t.step_func(function() {
+    assert_equals(player.playState, 'paused');
+    t.done();
+  }));
 }, 'Player.playState updates when paused by script');
 
 test(function(t) {
   var div = addDiv(t);
   var cs = window.getComputedStyle(div);
   div.style.animation = 'anim 1000s paused';
 
   var player = div.getAnimationPlayers()[0];
--- a/dom/animation/test/css-animations/test_animation-player-starttime.html
+++ b/dom/animation/test/css-animations/test_animation-player-starttime.html
@@ -613,18 +613,18 @@ async_test(function(t) {
 
   player.ready.then(t.step_func(function() {
     var savedStartTime = player.startTime;
 
     assert_not_equals(player.startTime, null,
       'AnimationPlayer.startTime not null on ready Promise resolve');
 
     player.pause();
-    // After bug 1109390 we will need to wait here for the ready promise again
-
+    return player.ready;
+  })).then(t.step_func(function() {
     assert_equals(player.startTime, null,
       'AnimationPlayer.startTime is null after paused');
     assert_equals(player.playState, 'paused',
       'AnimationPlayer.playState is "paused" after pause() call');
   })).catch(t.step_func(function(reason) {
     assert_unreached(reason);
   })).then(function() {
     t.done();
--- a/dom/animation/test/css-transitions/test_animation-player-starttime.html
+++ b/dom/animation/test/css-transitions/test_animation-player-starttime.html
@@ -379,18 +379,18 @@ async_test(function(t) {
 
   player.ready.then(t.step_func(function() {
     var savedStartTime = player.startTime;
 
     assert_not_equals(player.startTime, null,
       'AnimationPlayer.startTime not null on ready Promise resolve');
 
     player.pause();
-    // After bug 1109390 we will need to wait here for the ready promise again
-
+    return player.ready;
+  })).then(t.step_func(function() {
     assert_equals(player.startTime, null,
       'AnimationPlayer.startTime is null after paused');
     assert_equals(player.playState, 'paused',
       'AnimationPlayer.playState is "paused" after pause() call');
   })).catch(t.step_func(function(reason) {
     assert_unreached(reason);
   })).then(function() {
     t.done();