part 3. Add testing for what mutation observers happen when doing DOMTokenList.replace.
bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1444909
gecko-commit: bb405d71ba671812bddc20aaa935f1a2bbe53499
gecko-integration-branch: central
gecko-reviewers: qdot
diff --git a/dom/nodes/Element-classlist.html b/dom/nodes/Element-classlist.html
index 2b376d4..5453da9 100644
--- a/dom/nodes/Element-classlist.html
+++ b/dom/nodes/Element-classlist.html
@@ -31,6 +31,13 @@
}
setClass(e, before);
+ var obs;
+ // If we have MutationObservers available, do some checks to make
+ // sure attribute sets are happening at sane times.
+ if (self.MutationObserver) {
+ obs = new MutationObserver(() => {});
+ obs.observe(e, { attributes: true });
+ }
if (shouldThrow) {
assert_throws(expectedException, function() {
var list = e.classList;
@@ -40,6 +47,21 @@
var list = e.classList;
var res = list[funcName].apply(list, args);
}
+ if (obs) {
+ var mutationRecords = obs.takeRecords();
+ obs.disconnect();
+ if (shouldThrow) {
+ assert_equals(mutationRecords.length, 0,
+ "There should have been no mutation");
+ } else if (funcName == "replace") {
+ assert_equals(mutationRecords.length == 1,
+ expectedRes,
+ "Should have a mutation exactly when replace() returns true");
+ } else {
+ // For other functions, would need to check when exactly
+ // mutations are supposed to happen.
+ }
+ }
if (!shouldThrow) {
assert_equals(res, expectedRes, "wrong return value");
}