graouts@webkit.org | 70d09c0 | 2020-03-23 08:17:26 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <body onload="runTest()"> |
| 4 | <script src="../resources/js-test.js"></script> |
| 5 | <script> |
| 6 | description("This test asserts that a CSSAnimation doesn't leak after it was removed declaratively and the document was replaced."); |
| 7 | |
| 8 | if (window.internals) |
| 9 | jsTestIsAsync = true; |
| 10 | |
| 11 | function runTest() { |
| 12 | if (!window.internals) |
| 13 | return; |
| 14 | |
| 15 | var frame = document.body.appendChild(document.createElement("iframe")); |
| 16 | |
| 17 | frame.addEventListener("load", async () => { |
| 18 | if (frame.src === 'about:blank') |
| 19 | return; |
| 20 | |
| 21 | const animationId = "leak-css-animation"; |
| 22 | |
| 23 | await (element => { |
| 24 | return new Promise(resolve => { |
| 25 | const animation = element.getAnimations()[0]; |
| 26 | if (!animation) { |
| 27 | testFailed("The expected CSS animation was not created."); |
| 28 | finishJSTest(); |
| 29 | } |
| 30 | |
| 31 | animation.id = animationId; |
| 32 | if (!internals.animationWithIdExists(animationId)) { |
| 33 | testFailed("The expected CSS animation with the provided ID was not initially found."); |
| 34 | finishJSTest(); |
| 35 | } |
| 36 | |
| 37 | requestAnimationFrame(() => { |
| 38 | element.style.animation = "none"; |
| 39 | resolve(); |
| 40 | }); |
| 41 | }); |
| 42 | })(frame.contentDocument.querySelector("div")); |
| 43 | |
| 44 | requestAnimationFrame(() => { |
| 45 | frame.remove(); |
| 46 | frame = null; |
| 47 | |
| 48 | gc(); |
| 49 | let timeout = 0; |
| 50 | const handle = setInterval(() => { |
| 51 | if (!internals.animationWithIdExists(animationId)) { |
| 52 | clearInterval(handle); |
| 53 | testPassed("The CSS animation was destroyed."); |
| 54 | finishJSTest(); |
| 55 | return; |
| 56 | } |
| 57 | timeout++; |
| 58 | if (timeout == 500) { |
| 59 | clearInterval(handle); |
| 60 | testFailed("The CSS animation was leaked."); |
| 61 | finishJSTest(); |
| 62 | return; |
| 63 | } |
| 64 | gc(); |
| 65 | }, 10); |
| 66 | }); |
| 67 | }); |
| 68 | |
| 69 | frame.src = 'resources/css-animation-leak-iframe.html'; |
| 70 | } |
| 71 | |
| 72 | </script> |
| 73 | </body> |
| 74 | </html> |