layout/style/test/test_descriptor_storage.html

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     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 type="text/javascript" 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">
    18 /** Test for parsing, storage, and serialization of CSS @font-face descriptor values **/
    20 /*
    21  * For explanation of some of the more interesting tests here, see the comment
    22  * in test_value_storage.html .
    23  */
    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;
    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 }
    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 }
    49 function test_descriptor(descriptor)
    50 {
    51   var info = gCSSFontFaceDescriptors[descriptor];
    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);
    58     var idx;
    60     var step1val = gDeclaration.getPropertyValue(descriptor);
    61     var step1ser = gDeclaration.cssText;
    63     var func = xfail_parse(descriptor, value) ? todo_isnot : isnot;
    64     func(step1val, "", "setting '" + value + "' on '" + descriptor + "'");
    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 + ";\n";
    71     is(step1ser, expected_serialization,
    72        "serialization should match descriptor value");
    74     gDeclaration.removeProperty(descriptor);
    75 //    // We don't implement SetProperty yet (bug 443978).
    76 //    gDeclaration.setProperty(descriptor, step1val, "");
    77     fake_set_property(descriptor, step1val);
    79     is(gDeclaration.getPropertyValue(descriptor), step1val,
    80        "parse+serialize should be idempotent for '" +
    81          descriptor + ": " + value + "'");
    83     gDeclaration.removeProperty(descriptor);
    84   }
    86   var idx;
    87   for (idx in info.values)
    88     test_value(info.values[idx]);
    89 }
    91 // To avoid triggering the slow script dialog, we have to test one
    92 // descriptor at a time.
    93 SimpleTest.waitForExplicitFinish();
    94 var descs = [];
    95 for (var desc in gCSSFontFaceDescriptors)
    96   descs.push(desc);
    97 descs = descs.reverse();
    98 function do_one() {
    99   if (descs.length == 0) {
   100     SimpleTest.finish();
   101     return;
   102   }
   103   test_descriptor(descs.pop());
   104   SimpleTest.executeSoon(do_one);
   105 }
   106 SimpleTest.executeSoon(do_one);
   108 </script>
   109 </pre>
   110 </body>
   111 </html>

mercurial