tor-browser

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

test_extra_inherit_initial.html (3291B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=940229
      5 -->
      6 <head>
      7  <title>Test handling extra inherit/initial/unset in CSS declarations (Bug 940229)</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script type="text/javascript" src="property_database.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=940229">Mozilla Bug 940229</a>
     14 <p id="display"></p>
     15 <div id="content" style="display: none">
     16 
     17 <div id="testnode"></div>
     18  
     19 </div>
     20 <pre id="test">
     21 <script class="testbody" type="application/javascript">
     22 
     23 /*
     24 * Inspired by mistake in quotes noticed while reviewing bug 189519.
     25 */
     26 
     27 let gPropsNeedComma = {
     28  "font": true,
     29  "font-family": true,
     30  "voice-family": true,
     31 };
     32 
     33 let gElement = document.getElementById("testnode");
     34 let gDeclaration = gElement.style;
     35 
     36 let kValuesToTestThoroughly = 3;
     37 
     38 function test_property(property)
     39 {
     40  let info = gCSSProperties[property];
     41 
     42  let delim = (property in gPropsNeedComma) ? ", " : " ";
     43 
     44  function test_value_pair(relation, val1, val2, extraval) {
     45    let decl = property + ": " + val1 + delim + val2;
     46    gElement.setAttribute("style", decl);
     47    if ("subproperties" in info) {
     48      // Shorthand property; inspect each subproperty value.
     49      for (let subprop of info.subproperties) {
     50        is(gDeclaration.getPropertyValue(subprop), "",
     51           ["expected", extraval, "ignored", relation, "value in",
     52            "'" + decl + "'", "when looking at subproperty",
     53            "'" + subprop + "'"].join(" "));
     54      }
     55    } else {
     56      // Longhand property.
     57      is(gDeclaration.getPropertyValue(property), "",
     58         ["expected", extraval, "ignored", relation, "value in",
     59          "'" + decl + "'"].join(" "));
     60    }
     61  }
     62 
     63  function test_value(value, valueIdx) {
     64    let specialKeywords = [ "inherit", "initial", "unset" ];
     65 
     66    if (valueIdx < kValuesToTestThoroughly) {
     67      // For the first few values, we test each special-keyword both before
     68      // and after the value.
     69      for (let keyword of specialKeywords) {
     70        test_value_pair("before", keyword, value, keyword);
     71        test_value_pair("after", value, keyword, keyword);
     72      }
     73    } else {
     74      // For later values, only test one keyword before & after it.
     75      let keywordIdx =
     76        (valueIdx - kValuesToTestThoroughly) % specialKeywords.length;
     77      keyword = specialKeywords[keywordIdx];
     78      test_value_pair("before", keyword, value, keyword);
     79      test_value_pair("after", value, keyword, keyword);
     80    }
     81  }
     82 
     83  for (let idx in info.initial_values) {
     84    test_value(info.initial_values[idx], idx);
     85  }
     86  for (let idx in info.other_values) {
     87    test_value(info.initial_values[idx], idx);
     88  }
     89 }
     90 
     91 SimpleTest.waitForExplicitFinish();
     92 SimpleTest.requestLongerTimeout(4);
     93 
     94 function start_test() {
     95  for (let prop in gCSSProperties) {
     96    test_property(prop);
     97  }
     98  SimpleTest.finish();
     99 }
    100 
    101 // Turn off CSS error reporting for this test, since it's a bit expensive,
    102 // and we're expecting to generate tons and tons of parse errors here.
    103 SpecialPowers.pushPrefEnv({ "set": [["layout.css.report_errors", false]] },
    104                          start_test);
    105 
    106 </script>
    107 </pre>
    108 </body>
    109 </html>