summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/tabular-data/the-caption-element/caption_001.html
blob: ecb1bef85436167bd2329c380a4b1e9c45fe7649 (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
67
68
69
70
<!DOCTYPE HTML>
<html>
  <head>
    <title>HTML5 Table API Tests</title>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
    <link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
    <link rel="help" href="https://html.spec.whatwg.org/multipage/#the-caption-element" />
  </head>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <body>
    <div id="log"></div>
    <table id="table1" style="display:none">
      <tr><td></td></tr>
      <caption>first caption</caption>
      <caption>second caption</caption>
    </table>
    <table id="table2" style="display:none">
      <tr><td></td></tr>
    </table>
    <table id="table3" style="display:none">
      <tr><td></td></tr>
    </table>
    <table id="table4" style="display:none">
      <tr><td></td></tr>
      <caption>first caption</caption>
    </table>
    <script>
      test(function () {
        assert_equals(document.getElementById('table1').caption.innerHTML, "first caption");
      }, "first caption element child of the first table element");

      test(function () {
        var caption = document.createElement("caption");
        caption.innerHTML = "new caption";
        var table = document.getElementById('table1');
        table.caption = caption;

        assert_equals(caption.parentNode, table);
        assert_equals(table.firstChild, caption);
        assert_equals(table.caption.innerHTML, "new caption");

        captions = table.getElementsByTagName('caption');
        assert_equals(captions.length, 2);
        assert_equals(captions[0].innerHTML, "new caption");
        assert_equals(captions[1].innerHTML, "second caption");
      }, "setting caption on a table");

      test(function () {
        assert_equals(document.getElementById('table2').caption, null);
      }, "caption IDL attribute is null");

      test(function () {
        var table = document.getElementById('table3');
        var caption = document.createElement("caption")
        table.rows[0].appendChild(caption);
        assert_equals(table.caption, null);
      }, "caption of the third table element should be null");

      test(function () {
        assert_not_equals(document.getElementById('table4').caption, null);

        var parent = document.getElementById('table4').caption.parentNode;
        parent.removeChild(document.getElementById('table4').caption);

        assert_equals(document.getElementById('table4').caption, null);
      }, "dynamically removing caption on a table");
    </script>
  </body>
</html>