tor-browser

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

Element-hasAttributes.html (1703B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title></title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <body>
      7 
      8 <button></button>
      9 <div id="foo"></div>
     10 <p data-foo=""></p>
     11 
     12 <script>
     13 test(function() {
     14    var buttonElement = document.getElementsByTagName('button')[0];
     15    assert_equals(buttonElement.hasAttributes(), false, 'hasAttributes() on empty element must return false.');
     16 
     17    var emptyDiv = document.createElement('div');
     18    assert_equals(emptyDiv.hasAttributes(), false, 'hasAttributes() on dynamically created empty element must return false.');
     19 
     20 }, 'element.hasAttributes() must return false when the element does not have attribute.');
     21 
     22 test(function() {
     23    var divWithId = document.getElementById('foo');
     24    assert_equals(divWithId.hasAttributes(), true, 'hasAttributes() on element with id attribute must return true.');
     25 
     26    var divWithClass = document.createElement('div');
     27    divWithClass.setAttribute('class', 'foo');
     28    assert_equals(divWithClass.hasAttributes(), true, 'hasAttributes() on dynamically created element with class attribute must return true.');
     29 
     30    var pWithCustomAttr = document.getElementsByTagName('p')[0];
     31    assert_equals(pWithCustomAttr.hasAttributes(), true, 'hasAttributes() on element with custom attribute must return true.');
     32 
     33    var divWithCustomAttr = document.createElement('div');
     34    divWithCustomAttr.setAttribute('data-custom', 'foo');
     35    assert_equals(divWithCustomAttr.hasAttributes(), true, 'hasAttributes() on dynamically created element with custom attribute must return true.');
     36 
     37 }, 'element.hasAttributes() must return true when the element has attribute.');
     38 
     39 </script>
     40 </body>