summaryrefslogtreecommitdiffstats
path: root/dom/xul/templates/tests/chrome/test_sortservice.xul
blob: af1de3f0ef36ba6c321ba21f0c2c4ae0eca53296 (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
<?xml version="1.0" ?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<vbox id="box"/>

<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>

<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      

<script type="application/x-javascript">
<![CDATA[

var tests = [
  [["One", "Two", "Three", "Four"], "", "Four One Three Two"],
  [["One", "Two", "Three", "Four"], "integer", "Four One Three Two"],
  [["One", "Two", "Three", "Four"], "descending", "Two Three One Four"],
  [["One", "Two", "Three", "Four"], "descending integer", "Two Three One Four"],
  [["One", "Two", "Three", "Four"], "integer cat descending", "Two Three One Four"],
  [["1", "13", "2", "7", "12", "240", "2", "170", "222", "98"], "", "1 12 13 170 2 2 222 240 7 98"],
  [["1", "13", "2", "7", "12", "240", "2", "170", "222", "98"], "integer", "1 2 2 7 12 13 98 170 222 240"],
  [["1", "13", "2", "7", "12", "240", "2", "170", "222", "98"], "ascending integer", "1 2 2 7 12 13 98 170 222 240"],
  [["1", "13", "2", "7", "12", "240", "2", "170", "222", "98"], "integer descending", "240 222 170 98 13 12 7 2 2 1"],
  [["Cat", "cat", "Candy", "candy"], "comparecase", "Candy Cat candy cat"],
  [["1", "102", "22", "One", "40", "Two"], "integer", "1 22 40 102 One Two"],
];

SimpleTest.waitForExplicitFinish();

function doTests()
{
  var box = document.getElementById("box");

  const sortService = Components.classes["@mozilla.org/xul/xul-sort-service;1"].
                        getService(Components.interfaces.nsIXULSortService);

  for (let t = 0; t < tests.length; t++) {
    var test = tests[t];

    for (let e = 0; e < test[0].length; e++) {
      var label = document.createElement("label");
      label.setAttribute("value", test[0][e]);
      box.appendChild(label);
    }

    sortService.sort(box, "value", test[1]);

    var actual = "";
    for (let e = 0; e < box.childNodes.length; e++) {
      if (actual)
        actual += " ";
      actual += box.childNodes[e].getAttribute("value");
    }
    is(actual, test[2], "sorted step " + (t + 1));

    while(box.hasChildNodes())
      box.removeChild(box.firstChild);
    box.removeAttribute("sortDirection");
  }

  SimpleTest.finish();
}

window.addEventListener("load", doTests, false);

]]>
</script>
</window>