tor-browser

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

DOMStringMap.html (4894B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>Custom Elements: CEReactions on DOMStringMap interface</title>
      5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
      6 <meta name="assert" content="setter and deleter of DOMStringMap interface must have CEReactions">
      7 <meta name="help" content="https://html.spec.whatwg.org/#domstringmap">
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 <script src="../resources/custom-elements-helpers.js"></script>
     11 <script src="./resources/reactions.js"></script>
     12 </head>
     13 <body>
     14 <div id="log"></div>
     15 <script>
     16 
     17 test(function () {
     18    var element = define_new_custom_element(['data-foo']);
     19    var instance = document.createElement(element.name);
     20    assert_array_equals(element.takeLog().types(), ['constructed']);
     21    instance.dataset.foo = 'bar';
     22    var logEntries = element.takeLog();
     23    assert_array_equals(logEntries.types(), ['attributeChanged']);
     24    assert_attribute_log_entry(logEntries.last(), {name: 'data-foo', oldValue: null, newValue: 'bar', namespace: null});
     25 }, 'setter on DOMStringMap must enqueue an attributeChanged reaction when adding an observed data attribute');
     26 
     27 test(function () {
     28    var element = define_new_custom_element(['data-bar']);
     29    var instance = document.createElement(element.name);
     30    assert_array_equals(element.takeLog().types(), ['constructed']);
     31    instance.dataset.foo = 'bar';
     32    assert_array_equals(element.takeLog().types(), []);
     33 }, 'setter on DOMStringMap must not enqueue an attributeChanged reaction when adding an unobserved data attribute');
     34 
     35 test(function () {
     36    var element = define_new_custom_element(['data-foo']);
     37    var instance = document.createElement(element.name);
     38    instance.dataset.foo = 'bar';
     39    assert_array_equals(element.takeLog().types(), ['constructed', 'attributeChanged']);
     40    instance.dataset.foo = 'baz';
     41    var logEntries = element.takeLog();
     42    assert_array_equals(logEntries.types(), ['attributeChanged']);
     43    assert_attribute_log_entry(logEntries.last(), {name: 'data-foo', oldValue: 'bar', newValue: 'baz', namespace: null});
     44 }, 'setter on DOMStringMap must enqueue an attributeChanged reaction when mutating the value of an observed data attribute');
     45 
     46 test(function () {
     47    var element = define_new_custom_element(['data-foo']);
     48    var instance = document.createElement(element.name);
     49    instance.dataset.foo = 'bar';
     50    assert_array_equals(element.takeLog().types(), ['constructed', 'attributeChanged']);
     51    instance.dataset.foo = 'bar';
     52    var logEntries = element.takeLog();
     53    assert_array_equals(logEntries.types(), ['attributeChanged']);
     54    assert_attribute_log_entry(logEntries.last(), {name: 'data-foo', oldValue: 'bar', newValue: 'bar', namespace: null});
     55 }, 'setter on DOMStringMap must enqueue an attributeChanged reaction when mutating the value of an observed data attribute to the same value');
     56 
     57 test(function () {
     58    var element = define_new_custom_element(['data-zero']);
     59    var instance = document.createElement(element.name);
     60    instance.dataset.foo = 'bar';
     61    assert_array_equals(element.takeLog().types(), ['constructed']);
     62    instance.dataset.foo = 'baz';
     63    assert_array_equals(element.takeLog().types(), []);
     64 }, 'setter on DOMStringMap must not enqueue an attributeChanged reaction when mutating the value of an unobserved data attribute');
     65 
     66 test(function () {
     67    var element = define_new_custom_element(['data-foo']);
     68    var instance = document.createElement(element.name);
     69    instance.dataset.foo = 'bar';
     70    assert_array_equals(element.takeLog().types(), ['constructed', 'attributeChanged']);
     71    delete instance.dataset.foo;
     72    var logEntries = element.takeLog();
     73    assert_array_equals(logEntries.types(), ['attributeChanged']);
     74    assert_attribute_log_entry(logEntries.last(), {name: 'data-foo', oldValue: 'bar', newValue: null, namespace: null});
     75 }, 'deleter on DOMStringMap must enqueue an attributeChanged reaction when removing an observed data attribute');
     76 
     77 test(function () {
     78    var element = define_new_custom_element(['data-bar']);
     79    var instance = document.createElement(element.name);
     80    instance.dataset.foo = 'bar';
     81    assert_array_equals(element.takeLog().types(), ['constructed']);
     82    delete instance.dataset.foo;
     83    assert_array_equals(element.takeLog().types(), []);
     84 }, 'deleter on DOMStringMap must not enqueue an attributeChanged reaction when removing an unobserved data attribute');
     85 
     86 test(function () {
     87    var element = define_new_custom_element(['data-foo']);
     88    var instance = document.createElement(element.name);
     89    assert_array_equals(element.takeLog().types(), ['constructed']);
     90    delete instance.dataset.foo;
     91    assert_array_equals(element.takeLog().types(), []);
     92 }, 'deleter on DOMStringMap must not enqueue an attributeChanged reaction when it does not remove a data attribute');
     93 
     94 </script>
     95 </body>
     96 </html>