tor-browser

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

cssstyledeclaration-csstext-setter.window.js (2641B)


      1 // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
      2 
      3 [
      4  document.body,
      5  document.createElement("cool-beans")
      6 ].forEach(element => {
      7  test(t => {
      8    t.add_cleanup(() => element.removeAttribute("style"));
      9 
     10    element.style.background = "red";
     11    assert_equals(element.getAttribute("style"), "background: red;");
     12 
     13    element.style.cssText = "background:red";
     14    assert_equals(element.getAttribute("style"), "background: red;");
     15  }, `cssText setter should set style attribute even when there are no style changes (${element.localName})`);
     16 
     17  test(t => {
     18    t.add_cleanup(() => element.removeAttribute("style"));
     19 
     20    element.setAttribute("style", "background:   red");
     21    assert_equals(element.getAttribute("style"), "background:   red");
     22 
     23    element.style.cssText = "background:red";
     24    assert_equals(element.getAttribute("style"), "background: red;");
     25  }, `cssText setter should set style attribute even when there are no style changes, part 2 (${element.localName})`);
     26 
     27  test(t => {
     28    t.add_cleanup(() => element.removeAttribute("style"));
     29 
     30    element.setAttribute("style", "background:   red");
     31    assert_equals(element.getAttribute("style"), "background:   red");
     32 
     33    element.style.cssText = "background:red "; // trailing space
     34    assert_equals(element.getAttribute("style"), "background: red;");
     35  }, `cssText setter should set style attribute even when there are no style changes, part 3 (${element.localName})`);
     36 
     37  test(t => {
     38    t.add_cleanup(() => element.removeAttribute("style"));
     39 
     40    element.setAttribute("style", "background:   red");
     41    assert_equals(element.getAttribute("style"), "background:   red");
     42 
     43    element.style.cssText = "background:red;";
     44    assert_equals(element.getAttribute("style"), "background: red;");
     45  }, `cssText setter should set style attribute even when there are no style changes, part 4 (${element.localName})`);
     46 });
     47 
     48 test(t => {
     49  const style = document.createElement("style");
     50  t.add_cleanup(() => {
     51    document.body.removeAttribute("style");
     52    style.remove();
     53  });
     54  style.textContent = `[style="background: red;"] { background:white !important; }`;
     55  document.body.appendChild(style);
     56 
     57  document.body.setAttribute("style", "background:red");
     58  assert_true(document.body.matches("[style=\"background:red\"]"));
     59  assert_equals(getComputedStyle(document.body).backgroundColor, "rgb(255, 0, 0)");
     60 
     61  document.body.style.cssText = "background:red";
     62  assert_equals(getComputedStyle(document.body).backgroundColor, "rgb(255, 255, 255)");
     63  assert_true(document.body.matches("[style=\"background: red;\"]"));
     64 }, `cssText setter and selector invalidation`);