chromium/third_party/blink/web_tests/fast/dom/Element/scrollingElement-null-body-documentElement.html

<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<iframe id="nullbody" src="resources/quirks-empty.html"></iframe><br>
<iframe id="nullroot" src="resources/quirks-empty.html"></iframe><br>
<script>
  description("Verifies that asking for the scrollingElement of a document with null body or null documentElement doesn't crash");
  var jsTestIsAsync = true;

  function runtests()
  {
    // Verify scrollTopLeftInterop is actually enabled.
    shouldBe("document.scrollingElement", "document.documentElement");

    // Verify null body doesn't crash.
    var nullbody = document.getElementById("nullbody");
    nullbody.contentDocument.documentElement.removeChild(nullbody.contentDocument.body);
    shouldBeEqualToString("nullbody.contentDocument.compatMode", "BackCompat");
    shouldBeNull("nullbody.contentDocument.body");
    shouldBeNull("nullbody.contentDocument.scrollingElement");

    // Verify null documentElement doesn't crash.
    var nullroot = document.getElementById("nullroot");
    nullroot.contentDocument.removeChild(nullroot.contentDocument.documentElement);
    shouldBeEqualToString("nullroot.contentDocument.compatMode", "BackCompat");
    shouldBeNull("nullroot.contentDocument.documentElement");
    shouldBeNull("nullroot.contentDocument.body");
    shouldBeNull("nullroot.contentDocument.scrollingElement")

    finishJSTest();
  }

  function onload(e) {
    e.target.loaded = true;
    if (nullbody.loaded && nullroot.loaded)
        runtests();
  }

  nullbody.addEventListener('load', onload);
  nullroot.addEventListener('load', onload);
  
</script>