Bug 1346424 - Wait for the button to become paused instead of the timeline-data-changed event; r=test-only draft
authorPatrick Brosset <pbrosset@mozilla.com>
Wed, 22 Mar 2017 14:37:51 +0100
changeset 553739 4265b6b6a6283469379ab3d7ea72e1f74aad9437
parent 553738 ea529794cc08aa46881cfae43928edee3d659267
child 622165 477d994761d4d14bfbc865899d8834b8a059e87e
push id51745
push userbmo:pbrosset@mozilla.com
push dateThu, 30 Mar 2017 15:19:41 +0000
reviewerstest-only
bugs1346424
milestone55.0a1
Bug 1346424 - Wait for the button to become paused instead of the timeline-data-changed event; r=test-only MozReview-Commit-ID: 9xsx5gguspP
devtools/client/animationinspector/test/browser_animation_timeline_pause_button_03.js
--- a/devtools/client/animationinspector/test/browser_animation_timeline_pause_button_03.js
+++ b/devtools/client/animationinspector/test/browser_animation_timeline_pause_button_03.js
@@ -10,45 +10,51 @@ requestLongerTimeout(2);
 // reached the end of the timeline: continues to be in playing mode for infinite
 // animations, goes to paused mode otherwise.
 // And test that clicking the button once the scrubber has reached the end of
 // the timeline does the right thing.
 
 add_task(function* () {
   yield addTab(URL_ROOT + "doc_simple_animation.html");
 
-  let {panel, inspector} = yield openAnimationInspector();
-  let timeline = panel.animationsTimelineComponent;
+  let {panel, controller, inspector} = yield openAnimationInspector();
   let btn = panel.playTimelineButtonEl;
 
   // For a finite animation, once the scrubber reaches the end of the timeline, the pause
   // button should go back to paused mode.
   info("Select a finite animation and wait for the animation to complete");
   yield selectNodeAndWaitForAnimations(".negative-delay", inspector);
 
-  let onScrubberStopped = waitForScrubberStopped(timeline);
+  let onButtonPaused = waitForButtonPaused(btn);
+  let onTimelineUpdated = controller.once(controller.PLAYERS_UPDATED_EVENT);
   // The page is reloaded to avoid missing the animation.
   yield reloadTab(inspector);
-  yield onScrubberStopped;
+  yield onTimelineUpdated;
+  yield onButtonPaused;
 
   ok(btn.classList.contains("paused"),
      "The button is in paused state once finite animations are done");
   yield assertScrubberMoving(panel, false);
 
   info("Click again on the button to play the animation from the start again");
   yield clickTimelinePlayPauseButton(panel);
 
   ok(!btn.classList.contains("paused"),
      "Clicking the button once finite animations are done should restart them");
   yield assertScrubberMoving(panel, true);
 });
 
-function waitForScrubberStopped(timeline) {
+function waitForButtonPaused(btn) {
   return new Promise(resolve => {
-    timeline.on("timeline-data-changed",
-      function onTimelineData(e, {isMoving}) {
-        if (!isMoving) {
-          timeline.off("timeline-data-changed", onTimelineData);
+    let observer = new btn.ownerDocument.defaultView.MutationObserver(mutations => {
+      for (let mutation of mutations) {
+        if (mutation.type === "attributes" &&
+            mutation.attributeName === "class" &&
+            !mutation.oldValue.includes("paused") &&
+            btn.classList.contains("paused")) {
+          observer.disconnect();
           resolve();
         }
-      });
+      }
+    });
+    observer.observe(btn, { attributes: true, attributeOldValue: true });
   });
 }