tor-browser

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

quirks.window.js (3857B)


      1 test(t => {
      2  const frame = document.body.appendChild(document.createElement("iframe"));
      3  t.add_cleanup(() => frame.contentDocument.close());
      4  assert_equals(frame.contentDocument.compatMode, "BackCompat");
      5  frame.contentDocument.open();
      6  assert_equals(frame.contentDocument.compatMode, "CSS1Compat");
      7  frame.contentDocument.close();
      8  assert_equals(frame.contentDocument.compatMode, "BackCompat");
      9 }, "document.open() sets document to no-quirks mode (write no doctype)");
     10 
     11 test(t => {
     12  const frame = document.body.appendChild(document.createElement("iframe"));
     13  t.add_cleanup(() => frame.contentDocument.close());
     14  assert_equals(frame.contentDocument.compatMode, "BackCompat");
     15  frame.contentDocument.open();
     16  assert_equals(frame.contentDocument.compatMode, "CSS1Compat");
     17  frame.contentDocument.write("<!doctype html public");
     18  assert_equals(frame.contentDocument.compatMode, "CSS1Compat");
     19  frame.contentDocument.write(" \"-//IETF//DTD HTML 3//\"");
     20  assert_equals(frame.contentDocument.compatMode, "CSS1Compat");
     21  frame.contentDocument.write(">");
     22  assert_equals(frame.contentDocument.compatMode, "BackCompat");
     23  frame.contentDocument.close();
     24  assert_equals(frame.contentDocument.compatMode, "BackCompat");
     25 }, "document.open() sets document to no-quirks mode (write old doctype)");
     26 
     27 test(t => {
     28  const frame = document.body.appendChild(document.createElement("iframe"));
     29  t.add_cleanup(() => frame.contentDocument.close());
     30  assert_equals(frame.contentDocument.compatMode, "BackCompat");
     31  frame.contentDocument.open();
     32  assert_equals(frame.contentDocument.compatMode, "CSS1Compat");
     33  frame.contentDocument.write("<!doctype html");
     34  assert_equals(frame.contentDocument.compatMode, "CSS1Compat");
     35  frame.contentDocument.write(">");
     36  assert_equals(frame.contentDocument.compatMode, "CSS1Compat");
     37  frame.contentDocument.close();
     38  assert_equals(frame.contentDocument.compatMode, "CSS1Compat");
     39 }, "document.open() sets document to no-quirks mode (write new doctype)");
     40 
     41 // This tests the document.open() call in fact sets the document to no-quirks
     42 // mode, not limited-quirks mode. It is derived from
     43 // quirks/blocks-ignore-line-height.html in WPT, as there is no direct way to
     44 // distinguish between a no-quirks document and a limited-quirks document. It
     45 // assumes that the user agent passes the linked test, which at the time of
     46 // writing is all major web browsers.
     47 test(t => {
     48  const frame = document.body.appendChild(document.createElement("iframe"));
     49  t.add_cleanup(() => frame.contentDocument.close());
     50  assert_equals(frame.contentDocument.compatMode, "BackCompat");
     51  frame.contentDocument.open();
     52  assert_equals(frame.contentDocument.compatMode, "CSS1Compat");
     53 
     54  // Create the DOM tree manually rather than going through document.write() to
     55  // bypass the parser, which resets the document mode.
     56  const html = frame.contentDocument.appendChild(frame.contentDocument.createElement("html"));
     57  const body = html.appendChild(frame.contentDocument.createElement("body"));
     58  assert_equals(frame.contentDocument.body, body);
     59  body.innerHTML = `
     60    <style>#ref { display:block }</style>
     61    <div id=test><font size=1>x</font></div>
     62    <font id=ref size=1>x</font>
     63    <div id=s_ref>x</div>
     64  `;
     65  assert_equals(frame.contentDocument.compatMode, "CSS1Compat");
     66 
     67  const idTest = frame.contentDocument.getElementById("test");
     68  const idRef = frame.contentDocument.getElementById("ref");
     69  const idSRef = frame.contentDocument.getElementById("s_ref");
     70  assert_equals(frame.contentWindow.getComputedStyle(idTest).height,
     71                frame.contentWindow.getComputedStyle(idSRef).height);
     72  assert_not_equals(frame.contentWindow.getComputedStyle(idTest).height,
     73                    frame.contentWindow.getComputedStyle(idRef).height);
     74 }, "document.open() sets document to no-quirks mode, not limited-quirks mode");