summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/text-level-semantics/the-data-element/data.value-001.html
blob: 9fc827b9b886163290b813176ba4159fcfdea27c (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html>
    <head>
        <title>HTMLDataElement.value getting</title>
        <link rel="author" title="ofekd" href="mailto:ofek@outlook.com">
        <link rel="help" href="https://html.spec.whatwg.org/multipage/semantics.html#dom-data-value">
        <script src=/resources/testharness.js></script>
        <script src=/resources/testharnessreport.js></script>
    </head>
    <body>
        <div id="log"></div>
        <div id="container">
            <data value=""></data>
            <data value="40">Forty</data>
        </div>
        <script>
            var newData, datasArr, container;

            container = document.getElementById('container')

            newData = document.createElement('data');
            newData.textContent = 'Five';
            newData.setAttribute('value', '5');
            container.appendChild(newData);

            datasArr = container.getElementsByTagName('data');

            test(function () {
                test(function() {
                    assert_equals(datasArr[0].value, '');
                }, 'data[value] #0 getter test');

                test(function() {
                    assert_equals(datasArr[1].value, '40');
                }, 'data[value] #1 getter test');

                test(function() {
                    assert_equals(datasArr[2].value, '5');
                }, 'data[value] #2 getter test');
            }, 'Getter tests');

            test(function () {
                var i;

                for (i = 0; i < datasArr.length; i++) {
                    datasArr[i].textContent = 'Twenty';
                    datasArr[i].value = 20;

                    test(function() {
                        assert_equals(datasArr[i].getAttribute('value'), '20');
                    }, 'data[value] #' + i + ' setter test');
                }

                newData = document.createElement('data');
                newData.textContent = 'Twenty';
                newData.value = '20';
                container.appendChild(newData);

                test(function() {
                    assert_equals(datasArr[3].getAttribute('value'), '20');
                }, 'data[value] #3 setter test');

            }, 'Setter tests');
        </script>
    </body>
</html>