зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1444909 part 3. Add testing for what mutation observers happen when doing DOMTokenList.replace. r=qdot
MozReview-Commit-ID: AL1rU7AQlFb
This commit is contained in:
Родитель
c35649f885
Коммит
5f08375086
|
@ -58,6 +58,13 @@ function checkModification(e, funcName, args, expectedRes, before, after,
|
|||
gMutationEvents = [];
|
||||
e.addEventListener("DOMAttrModified", onAttrModified);
|
||||
// END LOCAL MODIFICATION
|
||||
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;
|
||||
|
@ -67,6 +74,21 @@ function checkModification(e, funcName, args, expectedRes, before, after,
|
|||
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.
|
||||
}
|
||||
}
|
||||
// BEGIN LOCAL MODIFICATION
|
||||
e.removeEventListener("DOMAttrModified", onAttrModified);
|
||||
// END LOCAL MODIFICATION
|
||||
|
|
|
@ -31,6 +31,13 @@ function checkModification(e, funcName, args, expectedRes, before, after,
|
|||
}
|
||||
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 @@ function checkModification(e, funcName, args, expectedRes, before, after,
|
|||
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");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче