summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/dom/elements/global-attributes/dataset-delete.html
blob: 65e131f445a409ddff840cad7d98c449d1bca042 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html>
  <head>
    <title>Dataset - Delete</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
  </head>
  <body>
    <h1>Dataset - Delete</h1>
    <div id="log"></div>
    <script>
      function testDelete(attr, prop)
      {
        var d = document.createElement("div");
        d.setAttribute(attr, "value");
        delete d.dataset[prop];
        return d.hasAttribute(attr) === false && d.getAttribute(attr) != "value";
      }

      function testDeleteNoAdd(prop)
      {
        var d = document.createElement("div");
        delete d.dataset[prop];
        return true;
      }

      test(function() { assert_true(testDelete('data-foo', 'foo')); },
        "Deleting element.dataset['foo'] should also remove an attribute with name 'data-foo' should it exist.");
      test(function() { assert_true(testDelete('data-foo-bar', 'fooBar')); },
        "Deleting element.dataset['fooBar'] should also remove an attribute with name 'data-foo-bar' should it exist.");
      test(function() { assert_true(testDelete('data--', '-')); },
        "Deleting element.dataset['-'] should also remove an attribute with name 'data--' should it exist.");
      test(function() { assert_true(testDelete('data--foo', 'Foo')); },
        "Deleting element.dataset['Foo'] should also remove an attribute with name 'data--foo' should it exist.");
      test(function() { assert_true(testDeleteNoAdd('data--foo', '-foo')); },
        "Deleting element.dataset['-foo'] should also remove an attribute with name 'data--foo' should it exist.");
      test(function() { assert_true(testDelete('data---foo', '-Foo')); },
        "Deleting element.dataset['-Foo'] should also remove an attribute with name 'data---foo' should it exist.");
      test(function() { assert_true(testDelete('data-', '')); },
        "Deleting element.dataset[''] should also remove an attribute with name 'data-' should it exist.");
      test(function() { assert_true(testDelete('data-\xE0', '\xE0')); },
        "Deleting element.dataset['\xE0'] should also remove an attribute with name 'data-\xE0' should it exist.");
      test(function() { assert_true(testDeleteNoAdd('foo')); },
        "Deleting element.dataset['foo'] should not throw if even if the element does now have an attribute with the name data-foo.");
    </script>
  </body>
</html>