tor-browser

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

test_descriptor_storage.html (3426B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 -->
      5 <head>
      6  <title>Test for parsing, storage, and serialization of CSS @font-face descriptor values</title>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <script type="text/javascript" src="descriptor_database.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     10 </head>
     11 <body>
     12 <p id="display"></p>
     13 <div id="content" style="display: none">
     14 </div>
     15 <pre id="test">
     16 <script class="testbody" type="text/javascript">
     17 
     18 /** Test for parsing, storage, and serialization of CSS @font-face descriptor values */
     19 
     20 /*
     21 * For explanation of some of the more interesting tests here, see the comment
     22 * in test_value_storage.html .
     23 */
     24 
     25 var gStyleElement = document.createElement("style");
     26 gStyleElement.setAttribute("type", "text/css");
     27 document.getElementsByTagName("head")[0].appendChild(gStyleElement);
     28 var gSheet = gStyleElement.sheet;
     29 gSheet.insertRule("@font-face { }", 0);
     30 var gRule = gSheet.cssRules[0];
     31 var gDeclaration = gRule.style;
     32 
     33 function fake_set_property(descriptor, value) {
     34  gSheet.deleteRule(0);
     35  gSheet.insertRule("@font-face { " + descriptor + ": " + value + "}", 0);
     36  gRule = gSheet.cssRules[0];
     37  gDeclaration = gRule.style;
     38 }
     39 
     40 function xfail_parse(descriptor, value) {
     41  switch (descriptor) {
     42    case "src":
     43      // not clear whether this is an error or not, so mark todo for now
     44      return value == "local(serif)";
     45  }
     46  return false;
     47 }
     48 
     49 function test_descriptor(descriptor)
     50 {
     51  var info = gCSSFontFaceDescriptors[descriptor];
     52 
     53  function test_value(value) {
     54 //    // We don't implement SetProperty yet (bug 443978).
     55 //    gDeclaration.setProperty(descriptor, value, "");
     56    fake_set_property(descriptor, value);
     57 
     58    var idx;
     59 
     60    var step1val = gDeclaration.getPropertyValue(descriptor);
     61    var step1ser = gDeclaration.cssText;
     62 
     63    var func = xfail_parse(descriptor, value) ? todo_isnot : isnot;
     64    func(step1val, "", "setting '" + value + "' on '" + descriptor + "'");
     65 
     66    // We don't care particularly about the whitespace or the placement of
     67    // semicolons, but for simplicity we'll test the current behavior.
     68    var expected_serialization = "";
     69    if (step1val != "")
     70      expected_serialization = descriptor + ": " + step1val + "; ";
     71    is(step1ser, expected_serialization,
     72       "serialization should match descriptor value");
     73 
     74    gDeclaration.removeProperty(descriptor);
     75 //    // We don't implement SetProperty yet (bug 443978).
     76 //    gDeclaration.setProperty(descriptor, step1val, "");
     77    fake_set_property(descriptor, step1val);
     78 
     79    is(gDeclaration.getPropertyValue(descriptor), step1val,
     80       "parse+serialize should be idempotent for '" +
     81         descriptor + ": " + value + "'");
     82 
     83    gDeclaration.removeProperty(descriptor);
     84  }
     85 
     86  var idx;
     87  for (idx in info.values)
     88    test_value(info.values[idx]);
     89 }
     90 
     91 // To avoid triggering the slow script dialog, we have to test one
     92 // descriptor at a time.
     93 SimpleTest.waitForExplicitFinish();
     94 function runTest() {
     95  var descs = [];
     96  for (var desc in gCSSFontFaceDescriptors)
     97    descs.push(desc);
     98  descs = descs.reverse();
     99  function do_one() {
    100    if (descs.length == 0) {
    101      SimpleTest.finish();
    102      return;
    103    }
    104    test_descriptor(descs.pop());
    105    SimpleTest.executeSoon(do_one);
    106  }
    107  SimpleTest.executeSoon(do_one);
    108 }
    109 
    110 SimpleTest.waitForExplicitFinish();
    111 SimpleTest.requestLongerTimeout(5);
    112 
    113 runTest();
    114 
    115 </script>
    116 </pre>
    117 </body>
    118 </html>