tor-browser

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

test_datalist_element.html (3492B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for the datalist element</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      7 </head>
      8 <body>
      9 <p id="display"></p>
     10 <div id="content" style="display: none">
     11  <datalist>
     12  </datalist>
     13 </div>
     14 <pre id="test">
     15 <script type="application/javascript">
     16 
     17 /** Test for Bug 555840 */
     18 
     19 function checkClassesAndAttributes()
     20 {
     21  var d = document.getElementsByTagName('datalist');
     22  is(d.length, 1, "One datalist has been found");
     23 
     24  d = d[0];
     25  ok(d instanceof HTMLDataListElement,
     26     "The datalist should be instance of HTMLDataListElement");
     27 
     28  ok('options' in d, "datalist has an options IDL attribute");
     29 
     30  ok(d.options, "options IDL attribute is not null");
     31  ok(!d.getAttribute('options'), "datalist has no options content attribute");
     32 
     33  ok(d.options instanceof HTMLCollection,
     34     "options IDL attribute should be instance of HTMLCollection");
     35 }
     36 
     37 function checkOptions()
     38 {
     39  var testData = [
     40    /* [ Child list, Function modifying children, Recognized options ] */
     41    [['option'], null, 1],
     42    [['option', 'option', 'option', 'option'], null, 4],
     43    /* Disabled options are not valid. */
     44    [['option'], function(d) { d.childNodes[0].disabled = true; }, 0],
     45    [['option', 'option'], function(d) { d.childNodes[0].disabled = true; }, 1],
     46    /* Non-option elements are not recognized. */
     47    [['input'], null, 0],
     48    [['input', 'option'], null, 1],
     49    [['input', 'textarea'], null, 0],
     50    /* .value and .label are not needed to be valid options. */
     51    [['option', 'option'], function(d) { d.childNodes[0].value = 'value'; }, 2],
     52    [['option', 'option'], function(d) { d.childNodes[0].label = 'label'; }, 2],
     53    [['option', 'option'], function(d) { d.childNodes[0].value = 'value'; d.childNodes[0].label = 'label'; }, 2],
     54    [['select'],
     55     function(d) {
     56       var s = d.childNodes[0];
     57       s.appendChild(new Option("foo"));
     58       s.appendChild(new Option("bar"));
     59     },
     60     2],
     61    [['select'],
     62     function(d) {
     63       var s = d.childNodes[0];
     64       s.appendChild(new Option("foo"));
     65       s.appendChild(new Option("bar"));
     66       var label = document.createElement("label");
     67       d.appendChild(label);
     68       label.appendChild(new Option("foobar"));
     69     },
     70     3],
     71    [['select'],
     72     function(d) {
     73       var s = d.childNodes[0];
     74       s.appendChild(new Option("foo"));
     75       s.appendChild(new Option("bar"));
     76       var label = document.createElement("label");
     77       d.appendChild(label);
     78       label.appendChild(new Option("foobar"));
     79       s.appendChild(new Option())
     80     },
     81     4],
     82     [[], function(d) { d.appendChild(document.createElementNS("foo", "option")); }, 0]
     83  ];
     84 
     85  var d = document.getElementsByTagName('datalist')[0];
     86  var cachedOptions = d.options;
     87 
     88  testData.forEach(function(data) {
     89    data[0].forEach(function(e) {
     90      d.appendChild(document.createElement(e));
     91    })
     92 
     93    /* Modify children. */
     94    if (data[1]) {
     95      data[1](d);
     96    }
     97 
     98    is(d.options, cachedOptions, "Should get the same object")
     99    is(d.options.length, data[2],
    100       "The number of recognized options should be " + data[2])
    101 
    102    for (var i = 0; i < d.options.length; ++i) {
    103      is(d.options[i].localName, "option",
    104         "Should get an option for d.options[" + i + "]")
    105    }
    106 
    107    /* Cleaning-up. */
    108    d.textContent = "";
    109  })
    110 }
    111 
    112 checkClassesAndAttributes();
    113 checkOptions();
    114 
    115 </script>
    116 </pre>
    117 </body>
    118 </html>