haikuwebkit/LayoutTests/webanimations/js-wrapper-kept-alive.html

33 lines
1.1 KiB
HTML
Raw Permalink Normal View History

[Web Animations] JS wrapper may be deleted while animation is yet to dispatch its finish event https://bugs.webkit.org/show_bug.cgi?id=196118 <rdar://problem/46614137> Reviewed by Chris Dumez. Source/WebCore: Test: webanimations/js-wrapper-kept-alive.html We need to teach WebAnimation to keep its JS wrapper alive if it's relevant or could become relevant again by virtue of having a timeline. We also need to ensure that the new implementation of hasPendingActivity() does not interfere with the ability of pages to enter the page cache when running animations. * animation/WebAnimation.cpp: (WebCore::WebAnimation::canSuspendForDocumentSuspension const): (WebCore::WebAnimation::stop): (WebCore::WebAnimation::hasPendingActivity const): * animation/WebAnimation.h: LayoutTests: Add a test that starts a short animation, sets a custom property on it, registers a "finish" event listener on it and deletes the sole reference to it in the JS world before triggering garbage collection. Prior to this fix, this test would time out because the JS wrapper would be garbage-collected prior to the animation completing and thus the event listener would not be called. To complete successfully, this test checks that it receives the event and its target is the same animation object that was originally created by checking the custom property is still set. We also make sure that a test, which was found to have regressed with a previous version of this patch, uses the animation engine that it is expected to be testing. * legacy-animation-engine/animations/resume-after-page-cache.html: * webanimations/js-wrapper-kept-alive-expected.txt: Added. * webanimations/js-wrapper-kept-alive.html: Added. Canonical link: https://commits.webkit.org/210970@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244031 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-04-08 18:49:04 +00:00
<!DOCTYPE html>
<html>
<body>
<div id="target"></div>
<script src="../resources/js-test-pre.js"></script>
<script>
description("This test checks that registering an event listener on an animation whose JS wrapper would otherwise be garbage-collected still fires registered event listeners.");
if (window.internals)
jsTestIsAsync = true;
// A longer animation that could not be garbage-collected under any circumstance allows us to finish the test
// with a reasonable delay without hard-coding a timeout.
const timeoutAnimation = document.getElementById("target").animate({ marginRight: ["0px", "100px"] }, 1000);
timeoutAnimation.addEventListener("finish", finishJSTest);
function runTest() {
const animation = document.getElementById("target").animate({ marginLeft: ["0px", "100px"] }, 100);
animation._isMyAnimation = true;
animation.addEventListener("finish", event => {
shouldBeTrue("event.target._isMyAnimation");
finishJSTest();
});
}
gc();
runTest();
gc();
</script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>