summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/nodes/characterset-helper.js
blob: ecbe556ae219f7d534c5f275719f406616407e0f (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
function runCharacterSetTests(encodingMap) {
  // Add spaces and mix up case
  Object.keys(encodingMap).forEach(function(name) {
    var lower = encodingMap[name];
    var upper = encodingMap[name].map(function(s) { return s.toUpperCase() });
    var mixed = encodingMap[name].map(function(s) {
      var ret = "";
      for (var i = 0; i < s.length; i += 2) {
        ret += s[i].toUpperCase();
        if (i + 1 < s.length) {
          ret += s[i + 1];
        }
      }
      return ret;
    });
    var spacey = encodingMap[name].map(function(s) {
      return " \t\n\f\r" + s + " \t\n\f\r";
    });
    encodingMap[name] = [];
    for (var i = 0; i < lower.length; i++) {
      encodingMap[name].push(lower[i]);
      /*
      if (lower[i] != upper[i]) {
        encodingMap[name].push(upper[i]);
      }
      if (lower[i] != mixed[i] && upper[i] != mixed[i]) {
        encodingMap[name].push(mixed[i]);
      }
      encodingMap[name].push(spacey[i]);
      */
    }
  });

  Object.keys(encodingMap).forEach(function(name) {
    encodingMap[name].forEach(function(label) {
      var iframe = document.createElement("iframe");
      var t = async_test("Name " + format_value(name) +
                        " has label " + format_value(label) + " (characterSet)");
      var t2 = async_test("Name " + format_value(name) +
                        " has label " + format_value(label) + " (inputEncoding)");
      var t3 = async_test("Name " + format_value(name) +
                        " has label " + format_value(label) + " (charset)");
      iframe.src = "encoding.py?label=" + label;
      iframe.onload = function() {
        t.step(function() {
          assert_equals(iframe.contentDocument.characterSet, name);
        });
        t2.step(function() {
          assert_equals(iframe.contentDocument.inputEncoding, name);
        });
        t3.step(function() {
          assert_equals(iframe.contentDocument.charset, name);
        });
        document.body.removeChild(iframe);
        t.done();
        t2.done();
        t3.done();
      };
      document.body.appendChild(iframe);
    });
  });
}