blob: 68ea6e29c3d02e6c42db4cdcb1b16921ba070218 [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/js-test.js"></script>
<script>
description('This tests navigating away from a document after setting a selection deletes the document.');
jsTestIsAsync = true;
function appendIframe()
{
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.contentDocument.body.innerHTML = '<p>hello</p>';
return iframe;
}
function setEditorStates(iframe)
{
iframe.contentDocument.designMode = 'on';
iframe.contentWindow.getSelection().setPosition(iframe.contentDocument.body, 1);
iframe.contentDocument.execCommand('bold', false, null);
}
function wait(duration)
{
return new Promise(function (resolve) {
setTimeout(resolve, 0);
});
}
var frame;
var initialDocumentCount;
async function runTest()
{
initialDocumentCount = internals.numberOfLiveDocuments();
let frames = [];
const count = 200;
for (let i = 0; i < count; ++i)
frames.push(appendIframe());
await wait(0); // Make sure the transient document created by inserting an iframe is removed.
GCController.collect();
for (let frame of frames)
setEditorStates(frame);
await wait(0); // Wait for UI update timer to fire.
let resolved = 0;
for (let frame of frames) {
frame.src = "resources/select-iframe-focusin-document-crash-frame.html";
frame.onload = () => {
++resolved;
if (resolved !== count)
return;
let before = internals.numberOfLiveDocuments();
GCController.collect();
let after = internals.numberOfLiveDocuments();
let delta = before - after;
if (delta > 0.15 * count)
debug("PASS freed more than 15% of documents");
else
debug("FAIL freed less than 15% of documents");
finishJSTest();
};
}
}
if (!window.GCController || !window.internals) {
debug('This test requires GCController and internals');
} else {
// Clear out any lingering documents from the previous tests.
GCController.collect();
GCController.collect();
runTest();
}
</script>
</body>
</html>