1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>CSS Transitions Test: Transitions do not run for a disconnected element</title>
<meta name="assert" content="If an element is not in the document during that
style change event or was not in the document during the previous style change
event, then transitions are not started for that element in that style change
event.">
<meta name="assert" content="If an element is no longer in the document,
implementations must cancel any running transitions on it and remove transitions
on it from the completed transitions.">
<link rel="help" title="Starting transitions"
href="https://drafts.csswg.org/css-transitions/#starting">
<script src="/resources/testharness.js" type="text/javascript"></script>
<script src="/resources/testharnessreport.js" type="text/javascript"></script>
<script src="./support/helper.js" type="text/javascript"></script>
</head>
<body>
<div id="log"></div>
<script>
promise_test(async t => {
// Create element and remove it from the document
const div = addDiv(t, {
style: 'transition: background-color 100s; background-color: red',
});
div.remove();
// Attach event listeners
div.addEventListener('transitionrun', t.step_func(() => {
assert_unreached('transitionrun event should not be fired');
}));
// Resolve before-change style
getComputedStyle(div).backgroundColor;
// Set up and resolve after-change style
div.style.backgroundColor = 'green';
getComputedStyle(div).backgroundColor;
// There should be no events received for the triggered transition.
await waitForFrame();
await waitForFrame();
}, 'Transitions do not run on an element not in the document');
test(t => {
// Create element but do not attach it to the document
const div = addDiv(t, {
style: 'transition: background-color 100s; background-color: red',
});
div.remove();
// Resolve before-change style
getComputedStyle(div).backgroundColor;
// Add to document
document.documentElement.append(div);
// Set up and resolve after-change style
div.style.backgroundColor = 'green';
getComputedStyle(div).backgroundColor;
// We should have jumped immediately to the after-change style rather than
// transitioning to it.
assert_equals(
getComputedStyle(div).backgroundColor,
'rgb(0, 128, 0)',
'No transition should run'
);
}, 'Transitions do not run for an element newly added to the document');
promise_test(async t => {
// Create element and attach it to the document
const div = addDiv(t, {
style: 'transition: background-color 100s; background-color: red',
});
// Attach event listeners
div.addEventListener('transitionrun', t.step_func(() => {
assert_unreached('transitionrun event should not be fired');
}));
// Resolve before-change style
getComputedStyle(div).backgroundColor;
// Set up after-change style
div.style.backgroundColor = 'green';
// But remove the document before the next style change event
div.remove();
// There should be no events received for the triggered transition.
await waitForFrame();
await waitForFrame();
}, 'Transitions do not run for an element newly removed from the document');
promise_test(async t => {
// Create element and attach it to the document
const div = addDiv(t, {
style: 'transition: background-color 100s; background-color: red',
});
// Attach event listeners
const eventWatcher = new EventWatcher(t, div, [
'transitionrun',
'transitioncancel',
]);
// Trigger transition
getComputedStyle(div).backgroundColor;
div.style.backgroundColor = 'green';
getComputedStyle(div).backgroundColor;
await eventWatcher.wait_for('transitionrun');
// Remove the element from the document
div.remove();
await eventWatcher.wait_for('transitioncancel');
}, 'Transitions are canceled when an element is removed from the document');
promise_test(async t => {
// Create a container element. We'll need this later.
const container = addDiv(t);
// Create element and attach it to the document
const div = addDiv(t, {
style: 'transition: background-color 100s; background-color: red',
});
// Attach event listeners
const eventWatcher = new EventWatcher(t, div, [
'transitionrun',
'transitioncancel',
]);
// Trigger transition
getComputedStyle(div).backgroundColor;
div.style.backgroundColor = 'green';
getComputedStyle(div).backgroundColor;
await eventWatcher.wait_for('transitionrun');
// Re-parent element
container.append(div);
await eventWatcher.wait_for('transitioncancel');
assert_equals(
getComputedStyle(div).backgroundColor,
'rgb(0, 128, 0)',
'There should be no transition after re-parenting'
);
}, 'Transitions are canceled when an element is re-parented');
promise_test(async t => {
// Create element and attach it to the document
const div = addDiv(t, {
style: 'transition: background-color 100s; background-color: red',
});
// Attach event listeners
const eventWatcher = new EventWatcher(t, div, [
'transitionrun',
'transitioncancel',
]);
// Trigger transition
getComputedStyle(div).backgroundColor;
div.style.backgroundColor = 'green';
getComputedStyle(div).backgroundColor;
await eventWatcher.wait_for('transitionrun');
// Re-parent element to same parent
document.documentElement.append(div);
await eventWatcher.wait_for('transitioncancel');
assert_equals(
getComputedStyle(div).backgroundColor,
'rgb(0, 128, 0)',
'There should be no transition after re-parenting'
);
}, 'Transitions are canceled when an element is re-parented to the same node');
</script>
</body>
</html>
|