Skip to content

Commit

Permalink
Update tests for slot change events (#5954)
Browse files Browse the repository at this point in the history
This corresponds to the DOM Standard change:
whatwg/dom#459.

We might want to clean up tests further because this patch is rather
the minimum effort to catch up the DOM Standard's change, but should be
good enough.
  • Loading branch information
hayatoito authored and Takayoshi Kochi committed Jun 9, 2017
1 parent 242de2b commit ce33325
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
36 changes: 20 additions & 16 deletions shadow-dom/slotchange-event.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@
testSlotchangeDoesNotFireWhenOtherSlotsChange('open', false);
testSlotchangeDoesNotFireWhenOtherSlotsChange('closed', false);

function testSlotchangeDoesNotFireForMutationBeforeOrAfterSlotWasPresent(mode, connectedToDocument)
function testSlotchangeDoesFireAtInsertedAndDoesNotFireForMutationAfterRemoved(mode, connectedToDocument)
{
var test = async_test('slotchange event must not fire on a slot element inside '
+ treeName(mode, connectedToDocument)
+ ' when the shadow host was mutated before the slot was inserted or after the slot was removed');
var test = async_test('slotchange event must fire on a slot element when a shadow host has a slotable and the slot was inserted'
+ ' and must not fire when the shadow host was mutated after the slot was removed inside '
+ treeName(mode, connectedToDocument));

var host;
var slot;
Expand Down Expand Up @@ -273,32 +273,32 @@

setTimeout(function () {
test.step(function () {
assert_equals(eventCount, 0,
'slotchange must not be fired on a slot element if the assigned nodes changed before the slot was inserted');
assert_equals(eventCount, 1,
'slotchange must be fired on a slot element if there is assigned nodes when the slot was inserted');
host.removeChild(host.firstChild);
});

setTimeout(function () {
test.step(function () {
assert_equals(eventCount, 1,
'slotchange must be fired exactly once after the assigned nodes change on a slot while the slot element was in the tree');
assert_equals(eventCount, 2,
'slotchange must be fired after the assigned nodes change on a slot while the slot element was in the tree');
slot.parentNode.removeChild(slot);
host.appendChild(document.createElement('span'));
});

setTimeout(function () {
assert_equals(eventCount, 1,
'slotchange must not be fired on a slot element if the assigned nodes changed after the slot was removed');
assert_equals(eventCount, 2,
'slotchange must not be fired on a slot element if the assigned nodes changed after the slot was removed');
test.done();
}, 1);
}, 1);
}, 1);
}

testSlotchangeDoesNotFireForMutationBeforeOrAfterSlotWasPresent('open', true);
testSlotchangeDoesNotFireForMutationBeforeOrAfterSlotWasPresent('closed', true);
testSlotchangeDoesNotFireForMutationBeforeOrAfterSlotWasPresent('open', false);
testSlotchangeDoesNotFireForMutationBeforeOrAfterSlotWasPresent('closed', false);
testSlotchangeDoesFireAtInsertedAndDoesNotFireForMutationAfterRemoved('open', true);
testSlotchangeDoesFireAtInsertedAndDoesNotFireForMutationAfterRemoved('closed', true);
testSlotchangeDoesFireAtInsertedAndDoesNotFireForMutationAfterRemoved('open', false);
testSlotchangeDoesFireAtInsertedAndDoesNotFireForMutationAfterRemoved('closed', false);

function testSlotchangeFiresOnTransientlyPresentSlot(mode, connectedToDocument)
{
Expand Down Expand Up @@ -505,7 +505,11 @@
innerSlot.addEventListener('slotchange', function (event) {
event.stopPropagation();
test.step(function () {
assert_equals(event.target, outerSlot, 'slotchange event\'s target must be the outer slot element');
if (innerSlotEventCount === 0) {
assert_equals(event.target, innerSlot, 'slotchange event\'s target must be the inner slot element at 1st slotchange');
} else if (innerSlotEventCount === 1) {
assert_equals(event.target, outerSlot, 'slotchange event\'s target must be the outer slot element at 2nd sltochange');
}
});
innerSlotEventCount++;
});
Expand All @@ -521,7 +525,7 @@
test.step(function () {
assert_equals(outerSlotEventCount, 1,
'slotchange must be fired on a slot element if the assigned nodes changed');
assert_equals(innerSlotEventCount, 1,
assert_equals(innerSlotEventCount, 2,
'slotchange must be fired on a slot element and must bubble');
});
test.done();
Expand Down
5 changes: 2 additions & 3 deletions shadow-dom/slots-fallback-in-document.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@

test(() => {
assert_array_equals(n1.innerSlot.assignedNodes(), [n1.slot]);
assert_array_equals(n1.innerSlot.assignedNodes({ flatten: true }),
[n1.fallback]);
}, 'Slot fallback content in document tree should be counted in flattened ' +
assert_array_equals(n1.innerSlot.assignedNodes({ flatten: true }), [n1.slot]);
}, 'Children of a slot in a document tree should not be counted in flattened ' +
'assigned nodes.');
</script>

Expand Down
3 changes: 2 additions & 1 deletion shadow-dom/slots-fallback.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@

assert_array_equals(n.s1.assignedNodes(), []);

assert_array_equals(n.s1.assignedNodes({ flatten: true }), [n.f1]);
assert_array_equals(n.s1.assignedNodes({ flatten: true }), [],
'fall back contents should be empty because s1 is not in a shadow tree.');
assert_array_equals(n.s2.assignedNodes({ flatten: true }), [n.f2]);
assert_array_equals(n.s3.assignedNodes({ flatten: true }), [n.f2]);
assert_array_equals(n.s4.assignedNodes({ flatten: true }), [n.f2, n.f4]);
Expand Down
6 changes: 3 additions & 3 deletions shadow-dom/slots.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
assert_array_equals(n.s2.assignedNodes(), []);
assert_array_equals(n.s3.assignedNodes(), []);

assert_array_equals(n.s1.assignedNodes({ flatten: true }), [n.c1]);
assert_array_equals(n.s2.assignedNodes({ flatten: true }), [n.c2, n.c3_1, n.c3_2]);
assert_array_equals(n.s3.assignedNodes({ flatten: true }), [n.c3_1, n.c3_2]);
assert_array_equals(n.s1.assignedNodes({ flatten: true }), []);
assert_array_equals(n.s2.assignedNodes({ flatten: true }), []);
assert_array_equals(n.s3.assignedNodes({ flatten: true }), []);
}, 'Slots: Distributed nooes for Slots not in a shadow tree.');
</script>

Expand Down

0 comments on commit ce33325

Please sign in to comment.