Bug 1346424 - Wait for the button to become paused instead of the timeline-data-changed event; r=test-only
MozReview-Commit-ID: 9xsx5gguspP
--- 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 });
});
}