chromium/third_party/blink/web_tests/editing/spelling/cold_mode_no_leak_detached_node.html

<!doctype html>
<title>Spellchecker should not keep an unbounded number of detached nodes alive</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/gc.js"></script>
<body>
<script>
// Spins spellchecker until idle. Return whether it's actually run.
function spinSpellChecker() {
  let spellCheckerIsRun = false;
  while (internals.idleTimeSpellCheckerState(document) !== 'Inactive') {
    internals.runIdleTimeSpellChecker(document);
    spellCheckerIsRun = true;
  }
  return spellCheckerIsRun;
}

function raf() {
  return new Promise(resolve => requestAnimationFrame(resolve));
}

promise_setup(async () => {
  assert_own_property(window, 'internals', 'This test requires internals')
});

promise_test(async () => {
  await asyncGC();

  const numLiveNodesBefore = internals.numberOfLiveNodes();

  const n = 5;
  for (let i = 0; i < n; ++i) {
    let div = document.createElement('div');
    div.contentEditable = true;
    document.body.appendChild(div);
    div.focus();
    assert_true(spinSpellChecker(), 'spellchecker is run');
    div.remove();
    div = null;
  }

  await raf();
  await raf();
  await asyncGC();

  const numLiveNodesAfter = internals.numberOfLiveNodes();
  assert_equals(numLiveNodesAfter, numLiveNodesBefore);
});
</script>
</body>