haikuwebkit/LayoutTests/media/remoteplayback-watch-availa...

66 lines
1.6 KiB
HTML
Raw Permalink Normal View History

RemotePlayback must keep its media element alive when there is a pending activity https://bugs.webkit.org/show_bug.cgi?id=227471 <rdar://79694015> Reviewed by Geoffrey Garen. Source/WebCore: Fixed the bug that the media element's JS wrapper can be collected while there is still a pending activity for RemotePlayback. In fact, the newly added test demonstrates that the media element can be deleted without this patch. This patch also introduces new extended IDL interface attribute GenerateAddOpaqueRoot to make adding an opaque root as a part of visitChildren easy in the DOM code. Test: media/remoteplayback-watch-availability-gc.html * Modules/remoteplayback/RemotePlayback.cpp: (WebCore::RemotePlayback::ownerNode const): * Modules/remoteplayback/RemotePlayback.h: * Modules/remoteplayback/RemotePlayback.idl: * bindings/scripts/CodeGeneratorJS.pm: (InstanceNeedsVisitChildren): (GenerateImplementation): * bindings/scripts/IDLAttributes.json: * bindings/scripts/test/BindingTestGlobalConstructors.idl: * bindings/scripts/test/JS/JSTestGenerateAddOpaqueRoot.cpp: Added. (WebCore::JSTestGenerateAddOpaqueRootDOMConstructor::prototypeForStructure): (WebCore::JSTestGenerateAddOpaqueRootDOMConstructor::initializeProperties): (WebCore::JSTestGenerateAddOpaqueRootPrototype::finishCreation): (WebCore::JSTestGenerateAddOpaqueRoot::JSTestGenerateAddOpaqueRoot): (WebCore::JSTestGenerateAddOpaqueRoot::finishCreation): (WebCore::JSTestGenerateAddOpaqueRoot::createPrototype): (WebCore::JSTestGenerateAddOpaqueRoot::prototype): (WebCore::JSTestGenerateAddOpaqueRoot::getConstructor): (WebCore::JSTestGenerateAddOpaqueRoot::destroy): (WebCore::JSC_DEFINE_CUSTOM_GETTER): (WebCore::jsTestGenerateAddOpaqueRoot_someAttributeGetter): (WebCore::JSTestGenerateAddOpaqueRoot::subspaceForImpl): (WebCore::JSTestGenerateAddOpaqueRoot::visitChildrenImpl): (WebCore::JSTestGenerateAddOpaqueRoot::analyzeHeap): (WebCore::JSTestGenerateAddOpaqueRootOwner::isReachableFromOpaqueRoots): (WebCore::JSTestGenerateAddOpaqueRootOwner::finalize): (WebCore::toJSNewlyCreated): (WebCore::toJS): (WebCore::JSTestGenerateAddOpaqueRoot::toWrapped): * bindings/scripts/test/JS/JSTestGenerateAddOpaqueRoot.h: Added. (WebCore::JSTestGenerateAddOpaqueRoot::create): (WebCore::JSTestGenerateAddOpaqueRoot::createStructure): (WebCore::JSTestGenerateAddOpaqueRoot::subspaceFor): (WebCore::wrapperOwner): (WebCore::wrapperKey): (WebCore::toJS): (WebCore::toJSNewlyCreated): * bindings/scripts/test/JS/JSTestGlobalObject.cpp: (WebCore::jsTestGlobalObject_TestGenerateAddOpaqueRootConstructorGetter): (WebCore::JSC_DEFINE_CUSTOM_GETTER): * bindings/scripts/test/SupplementalDependencies.dep: * bindings/scripts/test/TestGenerateAddOpaqueRoot.idl: Added. * testing/Internals.cpp: (WebCore::Internals::isElementAlive const): (WebCore::Internals::mediaElementCount): * testing/Internals.h: * testing/Internals.idl: LayoutTests: Added a GC test. * media/remoteplayback-watch-availability-gc-expected.txt: Added. * media/remoteplayback-watch-availability-gc.html: Added. Canonical link: https://commits.webkit.org/239299@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279443 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-30 23:53:16 +00:00
<!DOCTYPE html>
<html>
<head>
<script>
if (window.testRunner) {
testRunner.waitUntilDone();
testRunner.dumpAsText();
}
let elementIdentifier = null;
let parentIdentifier = null;
let iterationCount = 20;
let watchdogTimer = null;
function runTest() {
if (!iterationCount)
return endTest('PASS');
internals.queueTask('DOMManipulation', () => {
GCController.collect();
});
(() => {
const element = document.createElement('video');
elementIdentifier = internals.elementIdentifier(element);
const parentNode = document.createElement('div');
parentIdentifier = internals.elementIdentifier(parentNode);
parentNode.appendChild(element);
element.remote.watchAvailability(checkElement);
watchdogTimer = setTimeout(() => endTest('FAIL - the callback was never called'), 3000);
})();
GCController.collect();
}
function checkElement()
{
clearTimeout(watchdogTimer);
if (!internals.isElementAlive(elementIdentifier))
return endTest('FAIL - element is no longer alive');
if (!internals.isElementAlive(parentIdentifier))
return endTest('FAIL - parent is no longer alive');
--iterationCount;
setTimeout(() => runTest(), 0);
}
function endTest(status)
{
result.textContent = status;
if (window.testRunner)
testRunner.notifyDone();
}
</script>
</head>
<body onload='runTest()'>
<p>This tests that calling watchAvailability will keep the media element alive until the callback is called. You should see PASS below:</p>
<p id="result">Running</p>
</body>
</html>