tor-browser

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

dataset-get.html (2543B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>Dataset - Get</title>
      5    <script src="/resources/testharness.js"></script>
      6    <script src="/resources/testharnessreport.js"></script>
      7  </head>
      8  <body>
      9    <h1>Dataset - Get</h1>
     10    <div id="log"></div>
     11    <script>
     12      function testGet(attr, expected)
     13      {
     14        var d = document.createElement("div");
     15        d.setAttribute(attr, "value");
     16        return d.dataset[expected] == "value";
     17      }
     18 
     19      test(function() { assert_true(testGet('data-foo', 'foo')); },
     20        "Getting element.dataset['foo'] should return the value of element.getAttribute('data-foo')'");
     21      test(function() { assert_true(testGet('data-foo-bar', 'fooBar')); },
     22        "Getting element.dataset['fooBar'] should return the value of element.getAttribute('data-foo-bar')'");
     23      test(function() { assert_true(testGet('data--', '-')); },
     24        "Getting element.dataset['-'] should return the value of element.getAttribute('data--')'");
     25      test(function() { assert_true(testGet('data--foo', 'Foo')); },
     26        "Getting element.dataset['Foo'] should return the value of element.getAttribute('data--foo')'");
     27      test(function() { assert_true(testGet('data---foo', '-Foo')); },
     28        "Getting element.dataset['-Foo'] should return the value of element.getAttribute('data---foo')'");
     29      test(function() { assert_true(testGet('data-Foo', 'foo')); },
     30        "Getting element.dataset['foo'] should return the value of element.getAttribute('data-Foo')'");
     31      test(function() { assert_true(testGet('data-', '')); },
     32        "Getting element.dataset[''] should return the value of element.getAttribute('data-')'");
     33      test(function() { assert_true(testGet('data-\xE0', '\xE0')); },
     34        "Getting element.dataset['\xE0'] should return the value of element.getAttribute('data-\xE0')'");
     35      test(function() { assert_true(testGet('data-to-string', 'toString')); },
     36        "Getting element.dataset['toString'] should return the value of element.getAttribute('data-to-string')'");
     37 
     38      function matchesNothingInDataset(attr)
     39      {
     40        var d = document.createElement("div");
     41        d.setAttribute(attr, "value");
     42 
     43        if (!d.dataset)
     44          return false;
     45 
     46        var count = 0;
     47        for (var item in d.dataset)
     48          count++;
     49        return count == 0;
     50      }
     51 
     52      test(function() { assert_true(matchesNothingInDataset('dataFoo')); },
     53        "Tests that an attribute named dataFoo does not make an entry in the dataset DOMStringMap.");
     54 
     55    </script>
     56  </body>
     57 </html>