summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dpub-aria/inuse-manual.html
blob: cd6af1e7358b84952e57d1ad0e1d62eb12306df6 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!doctype html>
<html>
<head>
  <title>Check for Dpub Vocabulary Role Usage</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({explicit_timeout: true, explicit_done: true });

var theRoles = [
  "doc-abstract",
  "doc-acknowledgments",
  "doc-afterword",
  "doc-appendix",
  "doc-backlink",
  "doc-biblioentry",
  "doc-bibliography",
  "doc-biblioref",
  "doc-chapter",
  "doc-colophon",
  "doc-conclusion",
  "doc-cover",
  "doc-credit",
  "doc-credits",
  "doc-dedication",
  "doc-endnote",
  "doc-endnotes",
  "doc-epigraph",
  "doc-epilogue",
  "doc-errata",
  "doc-example",
  "doc-footnote",
  "doc-foreword",
  "doc-glossary",
  "doc-glossref",
  "doc-index",
  "doc-introduction",
  "doc-noteref",
  "doc-notice",
  "doc-pagebreak",
  "doc-pagelist",
  "doc-part",
  "doc-preface",
  "doc-prologue",
  "doc-pullquote",
  "doc-qna",
  "doc-subtitle",
  "doc-tip",
  "doc-toc"
  ];

  /* runTests - run tests against the content
   *
   * @param content - a string with the content to test
   */
  function runTests(content) {
    'use strict';
    // keep track of the test number executed
    var testCounter = 1;
    // create a DOM tree for the content
    var theDOM = document.createElement("body");

    // check the content - if it has a body element, strip up to it and after the
    // close

    content = content.replace(/\n/g, " ");

    if (content.search(/<body/i) !== -1) {
      // there is an opening body tag
      content = content.replace(/^.*<body[^>]*>/i, '');
      if (content.search(/<\/[^>]*body/i) !== -1) {
        content = content.replace(/<\/[^>]*body.*$/i, '');
      }
    }

    var parseFail = false ;
    var parseMessage  = "" ;

    if ("" === content || content.search(/^ +$/) !== -1 ) {
      // there is NO content
      parseFail = true;
      parseMessage = "Content is empty";
    } else {
      try {
        // add the content into the created body element
        theDOM.innerHTML = content;
      }
      catch(err) {
        parseFail = true;
        parseMessage =  err;
      }
    }

    test(function() {
      assert_false(parseFail, parseMessage);
    }, testCounter + " Can parse submitted content");

    testCounter += 1;

    // loop over the tree looking for roles with the values in theRoles

    theRoles.forEach(function(role) {
      var tName = testCounter + " " + "Uses role " + role;
      testCounter += 1;
      var nodes = theDOM.querySelectorAll('[role~="'+role+'"]');
      if (nodes.length) {
        // there are matching nodes
        test(function() {
          assert_true(true, "Found the role");
        }, tName);
      }
    });

    done();
  };

on_event(document, "DOMContentLoaded", function() {
  var runButton = document.getElementById('dpub-run') ;
  var closeButton = document.getElementById('dpub-close') ;

  on_event(runButton, "click", function() {
    var content = document.getElementById("dpub-input");

    runTests(content.value);
  });
});
</script>
</head>
<body>
  <p>Fill the textarea below with the contents of a <code>body</code> element
  from HTML markup from that reflects your usage of
  DPub-ARIA roles.  Then select "Run Test" to evaluate the content.</p>
  <form name="dpub" id="dpub">
    <textarea name="dpub-input" id="dpub-input" style="width: 90%; height: 10em" ></textarea>
    <p><input type="button" id="dpub-run" name="Run Test" value="Run Test">
    <input style="display: none" type="button" id="dpub-close"
                                               name="Close" value="Close"></p>
  </form>
  <div id="log"></div>
</body>
</html>