Bug 1343589 - Add animation mutation observer test for reverse() when it throws an exception draft
authorBrian Birtles <birtles@gmail.com>
Tue, 28 Mar 2017 14:51:52 +0900
changeset 552237 84df06f0196f7cf501ce19946e84ccef04dcd124
parent 552223 e562d64a4543e2359a9c79bc1c30bc6206b71ca2
child 552238 ae9aa20c7ed0ff7aeb3a02217877121f57c74d44
push id51295
push userbbirtles@mozilla.com
push dateTue, 28 Mar 2017 06:38:47 +0000
bugs1343589
milestone55.0a1
Bug 1343589 - Add animation mutation observer test for reverse() when it throws an exception This patch adds a test that when reverse throws an exception we don't report anything to animation mutation observers. I have verified that this added test fails without the early return added to Animation::Reverse() earlier in this patch series. MozReview-Commit-ID: 64yX4G7iaIt
dom/animation/test/chrome/test_animation_observers_sync.html
--- a/dom/animation/test/chrome/test_animation_observers_sync.html
+++ b/dom/animation/test/chrome/test_animation_observers_sync.html
@@ -730,16 +730,52 @@ function createPseudo(test, element, typ
 
     animations[0].reverse();
 
     // We should get no notifications.
     assert_equals_records(observer.takeRecords(),
       [], "records after calling reverse()");
   }, "reverse_with_zero_playbackRate");
 
+  // Test that reverse() on an Animation does *not* dispatch a changed
+  // notification when it throws an exception.
+  test(t => {
+    // Start an infinite animation
+    var div = addDiv(t, { style: "animation: anim 10s infinite" });
+    var observer =
+      setupSynchronousObserver(t,
+                               aOptions.subtree ? div.parentNode : div,
+                               aOptions.subtree);
+
+    var animations = div.getAnimations();
+    assert_equals(animations.length, 1,
+      "getAnimations().length after animation start");
+
+    assert_equals_records(observer.takeRecords(),
+      [{ added: animations, changed: [], removed: [] }],
+      "records after animation start");
+
+    // Shift the animation into the future such that when we call reverse
+    // it will try to seek to the (infinite) end.
+    animations[0].startTime = 100 * MS_PER_SEC;
+
+    assert_equals_records(observer.takeRecords(),
+      [{ added: [], changed: animations, removed: [] }],
+      "records after adjusting startTime");
+
+    // Reverse: should throw
+    assert_throws('InvalidStateError', () => {
+      animations[0].reverse();
+    }, 'reverse() on future infinite animation throws an exception');
+
+    // We should get no notifications.
+    assert_equals_records(observer.takeRecords(),
+      [], "records after calling reverse()");
+  }, "reverse_with_exception");
+
   // Test that attempting to start an animation that should already be finished
   // does not send any notifications.
   test(t => {
     // Start an animation that should already be finished.
     var div = addDiv(t, { style: "animation: anim 1s -2s;" });
     var observer =
       setupSynchronousObserver(t,
                                aOptions.subtree ? div.parentNode : div,