summaryrefslogtreecommitdiffstats
path: root/toolkit/components/certviewer/tests/chrome/test_kebabCaseInAdjustCertInformation.html
blob: b9f7b98d89c92597cefdd17d72d740a512f0be69 (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
<!DOCTYPE html>
<html>
  <head>
    <title>certviewer adjustCertInformation test</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
  </head>
<body>
  <script type="module">
    function isKebabCase(str) {
      if (str === "") return true;
      return /^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/.test(str);
    }

    function validateIsKebabCase() {
      let tests = [
        {
          input: "",
          expected: true
        },
        {
          input: "A",
          expected: false
        },
        {
          input: "Ab",
          expected: false
        },
        {
          input: "Ab-ad",
          expected: false
        },
        {
          input: "ad-Az",
          expected: false
        },
        {
          input: "ad- z",
          expected: false
        },
        {
          input: "ad-z ",
          expected: false
        },
        {
          input: "ad z",
          expected: false
        },
        {
          input: "ad--fz",
          expected: false
        },
        {
          input: "-a-b-c",
          expected: false
        },
        {
          input: "ad-fz",
          expected: true
        },
        {
          input: "ad",
          expected: true
        },
        {
          input: "a-b-c",
          expected: true
        },
      ];

      for (let test of tests) {
        let result = isKebabCase(test.input);
        is(result, test.expected, `${test.input} should${test.expected === false ? "n't" : ""} be a kebab-case string`);
      }
    }

    async function doTest() {
      const { adjustCertInformation } = await import("chrome://global/content/certviewer/certviewer.mjs");
      const { parseOutput } = await import("./parseOutput.mjs");

      ok(adjustCertInformation, "adjustCertInformation should be available in this context");
      ok(parseOutput, "parseOutput should be available in this context");
      is(typeof(parseOutput), 'object', "parseOutput must be an object");

      validateIsKebabCase();

      for (let cert of parseOutput) {
        let adjustedCerts = adjustCertInformation(cert);
        adjustedCerts.certItems.forEach(item => {
          ok(isKebabCase(item.sectionId), `${item.sectionId} should be a valid kebab-case string`);
          item.sectionItems.forEach(element => {
            ok(isKebabCase(element.label), `${element.label} should be a valid kebab-case string`);
          });
        });
      }

      SimpleTest.finish();
    }

    SimpleTest.waitForExplicitFinish();
    doTest();

  </script>
</body>
</html>