tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

scrollingElement.html (5901B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>cssom-view - scrollingElement</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <div id="log"></div>
      7 <script>
      8 function makeDescription(rootDisplay, bodyDisplay) {
      9  let a = [];
     10  if (rootDisplay) {
     11    a.push(`root ${rootDisplay}`);
     12  }
     13  if (bodyDisplay) {
     14    a.push(`body ${bodyDisplay}`);
     15  }
     16  let s = a.join(", ");
     17  if (s) {
     18    s = ` (${s})`;
     19  }
     20  return s;
     21 }
     22 
     23 function quirksTest(rootDisplay, bodyDisplay) {
     24  async_test(function() {
     25    let quirksFrame = document.createElement("iframe");
     26    quirksFrame.onload = this.step_func_done(function() {
     27      var quirksDoc = quirksFrame.contentDocument;
     28      assert_equals(quirksDoc.compatMode, "BackCompat", "Should be in quirks mode.");
     29      assert_not_equals(quirksDoc.body, null, "Should have a body element");
     30 
     31      quirksDoc.documentElement.style.display = rootDisplay;
     32      quirksDoc.body.style.display = bodyDisplay;
     33 
     34      // Tests for quirks mode document.
     35      assert_equals(quirksDoc.scrollingElement, quirksDoc.body,
     36        "scrollingElement in quirks mode should default to body element.");
     37 
     38      quirksDoc.documentElement.style.overflow = "clip";
     39      quirksDoc.body.style.overflow = "auto";
     40      assert_equals(quirksDoc.scrollingElement, null);
     41      quirksDoc.body.style.overflow = "hidden";
     42      assert_equals(quirksDoc.scrollingElement, null);
     43      quirksDoc.body.style.overflow = "scroll";
     44      assert_equals(quirksDoc.scrollingElement, null);
     45      quirksDoc.body.style.overflow = "visible";
     46      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);
     47      quirksDoc.body.style.overflow = "clip";
     48      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);
     49 
     50      quirksDoc.documentElement.style.overflow = "scroll";
     51      quirksDoc.body.style.overflow = "scroll";
     52      assert_equals(quirksDoc.scrollingElement, null,
     53        "scrollingElement in quirks mode should be null if overflow of body and root element isn't visible.");
     54      quirksDoc.documentElement.style.overflow = "visible";
     55      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);
     56      quirksDoc.documentElement.style.overflow = "scroll";
     57      quirksDoc.body.style.overflow = "visible";
     58      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);
     59      quirksDoc.documentElement.style.overflow = "visible";
     60      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);
     61 
     62      quirksDoc.body.style.display = "none";
     63      assert_equals(quirksDoc.scrollingElement, quirksDoc.body)
     64      quirksDoc.body.style.display = "block";
     65      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);
     66 
     67      quirksDoc.documentElement.appendChild(quirksDoc.createElement("body"));
     68      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);
     69      assert_equals(quirksDoc.scrollingElement, quirksDoc.getElementsByTagName("body")[0]);
     70      quirksDoc.documentElement.removeChild(quirksDoc.documentElement.lastChild);
     71      assert_equals(quirksDoc.scrollingElement, quirksDoc.body);
     72 
     73      quirksDoc.documentElement.removeChild(quirksDoc.body);
     74      assert_equals(quirksDoc.scrollingElement, null);
     75      quirksDoc.documentElement.appendChild(quirksDoc.createElementNS("foobarNS", "body"));
     76      assert_equals(quirksDoc.scrollingElement, null);
     77 
     78      quirksDoc.removeChild(quirksDoc.documentElement);
     79      assert_equals(quirksDoc.scrollingElement, null);
     80 
     81      quirksDoc.appendChild(quirksDoc.createElementNS("foobarNS", "html"));
     82      quirksDoc.documentElement.appendChild(quirksDoc.createElement("body"));
     83      assert_equals(quirksDoc.scrollingElement, null);
     84 
     85      quirksDoc.removeChild(quirksDoc.documentElement);
     86      quirksDoc.appendChild(quirksDoc.createElement("body"));
     87      assert_equals(quirksDoc.scrollingElement, null);
     88 
     89      quirksFrame.remove();
     90    });
     91    quirksFrame.src =
     92      URL.createObjectURL(new Blob([], { type: "text/html" }));
     93    document.body.append(quirksFrame);
     94  }, `scrollingElement in quirks mode${makeDescription(rootDisplay, bodyDisplay)}`);
     95 }
     96 
     97 function nonQuirksTest(rootDisplay, bodyDisplay) {
     98  async_test(function() {
     99    let nonQuirksFrame = document.createElement("iframe");
    100    nonQuirksFrame.onload = this.step_func_done(function() {
    101      var nonQuirksDoc = nonQuirksFrame.contentDocument;
    102      assert_equals(nonQuirksDoc.compatMode, "CSS1Compat", "Should be in standards mode.");
    103      assert_not_equals(nonQuirksDoc.body, null, "Should have a body element");
    104 
    105      nonQuirksDoc.documentElement.style.display = rootDisplay;
    106      nonQuirksDoc.body.style.display = bodyDisplay;
    107 
    108      assert_equals(nonQuirksDoc.scrollingElement, nonQuirksDoc.documentElement,
    109        "scrollingElement in standards mode should be the document element.");
    110 
    111      for (let rootOverflow of ["", "clip", "scroll", "hidden", "visible"]) {
    112        for (let bodyOverflow of ["", "clip", "scroll", "hidden", "visible"]) {
    113          nonQuirksDoc.documentElement.style.overflow = rootOverflow;
    114          nonQuirksDoc.body.style.overflow = bodyOverflow;
    115          assert_equals(nonQuirksDoc.scrollingElement, nonQuirksDoc.documentElement);
    116        }
    117      }
    118 
    119      nonQuirksDoc.removeChild(nonQuirksDoc.documentElement);
    120      assert_equals(nonQuirksDoc.scrollingElement, null);
    121      nonQuirksDoc.appendChild(nonQuirksDoc.createElement("foobar"));
    122      assert_equals(nonQuirksDoc.scrollingElement.localName, "foobar");
    123 
    124      nonQuirksFrame.remove();
    125    });
    126    nonQuirksFrame.src =
    127      URL.createObjectURL(new Blob([`<!doctype html>`], { type: "text/html" }));
    128    document.body.append(nonQuirksFrame);
    129  }, `scrollingElement in no-quirks mode ${makeDescription(rootDisplay, bodyDisplay)}`);
    130 }
    131 
    132 for (let rootDisplay of ["", "table"]) {
    133  for (let bodyDisplay of ["", "table"]) {
    134    quirksTest(rootDisplay, bodyDisplay);
    135    nonQuirksTest(rootDisplay, bodyDisplay);
    136  }
    137 }
    138 </script>