summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_UrlbarUtils_unEscapeURIForUI.js
blob: 6efc6711c6ab0b193ae19b17fb0a8ff50969f3e1 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Test for unEscapeURIForUI function in UrlbarUtils.
 */

"use strict";

const TEST_DATA = [
  {
    description: "Test for characters including percent encoded chars",
    input: "A%E3%81%82%F0%A0%AE%B7%21",
    expected: "Aあ𠮷!",
    testMessage: "Unescape given characters correctly",
  },
  {
    description: "Test for characters over the limit",
    input: "A%E3%81%82%F0%A0%AE%B7%21".repeat(
      Math.ceil(UrlbarUtils.MAX_TEXT_LENGTH / 25)
    ),
    expected: "A%E3%81%82%F0%A0%AE%B7%21".repeat(
      Math.ceil(UrlbarUtils.MAX_TEXT_LENGTH / 25)
    ),
    testMessage: "Return given characters as it is because of over the limit",
  },
];

add_task(function () {
  for (const { description, input, expected, testMessage } of TEST_DATA) {
    info(description);

    const result = UrlbarUtils.unEscapeURIForUI(input);
    Assert.equal(result, expected, testMessage);
  }
});