Bug 1333759 - use waitUntil instead of mutations in aboutdebugging test helper;r=ochameau
Several aboutdebugging test helpers rely on mutations to know when the UI is updated.
Since we are using React, we don't have any control on the actual mutations that
will be performed by the framework to reach a target UI state.
Using waitUntil with a DOM predicate should be more stable and less intermittent prone.
MozReview-Commit-ID: AnrEItpWkWL
--- a/devtools/client/aboutdebugging/test/head.js
+++ b/devtools/client/aboutdebugging/test/head.js
@@ -349,24 +349,35 @@ function waitForServiceWorkerRegistered(
* promise that will resolve when it has successfully unregistered itself and the
* about:debugging UI has fully processed this update.
*
* @param {Tab} tab
* @param {Node} serviceWorkersElement
* @return {Promise} Resolves when the service worker is unregistered.
*/
function* unregisterServiceWorker(tab, serviceWorkersElement) {
- let onMutation = waitForMutation(serviceWorkersElement, { childList: true });
+ // Get the initial count of service worker registrations.
+ let registrations = serviceWorkersElement.querySelectorAll(".target-container");
+ let registrationCount = registrations.length;
+
+ // Wait until the registration count is decreased by one.
+ let isRemoved = waitUntil(() => {
+ registrations = serviceWorkersElement.querySelectorAll(".target-container");
+ return registrations.length === registrationCount - 1;
+ }, 100);
+
+ // Unregister the service worker from the content page
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
// Retrieve the `sw` promise created in the html page
let { sw } = content.wrappedJSObject;
let registration = yield sw;
yield registration.unregister();
});
- return onMutation;
+
+ return isRemoved;
}
/**
* Waits for the creation of a new window, usually used with create private
* browsing window.
* Returns a promise that will resolve when the window is successfully created.
* @param {window} win
*/