|
1 <?xml version="1.0" ?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
|
4 |
|
5 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
6 |
|
7 <vbox id="box"/> |
|
8 |
|
9 <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> |
|
10 |
|
11 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
12 |
|
13 <script type="application/x-javascript"> |
|
14 <![CDATA[ |
|
15 |
|
16 var tests = [ |
|
17 [["One", "Two", "Three", "Four"], "", ["Four One Three Two"]], |
|
18 [["One", "Two", "Three", "Four"], "integer", ["Four One Three Two"]], |
|
19 [["One", "Two", "Three", "Four"], "descending", ["Two Three One Four"]], |
|
20 [["One", "Two", "Three", "Four"], "descending integer", ["Two Three One Four"]], |
|
21 [["One", "Two", "Three", "Four"], "integer cat descending", ["Two Three One Four"]], |
|
22 [["1", "13", "2", "7", "12", "240", "2", "170", "222", "98"], "", ["1 12 13 170 2 2 222 240 7 98"]], |
|
23 [["1", "13", "2", "7", "12", "240", "2", "170", "222", "98"], "integer", ["1 2 2 7 12 13 98 170 222 240"]], |
|
24 [["1", "13", "2", "7", "12", "240", "2", "170", "222", "98"], "ascending integer", ["1 2 2 7 12 13 98 170 222 240"]], |
|
25 [["1", "13", "2", "7", "12", "240", "2", "170", "222", "98"], "integer descending", ["240 222 170 98 13 12 7 2 2 1"]], |
|
26 [["Cat", "cat", "Candy", "candy"], "comparecase", ["Candy Cat candy cat"]], |
|
27 [["1", "102", "22", "One", "40", "Two"], "integer", ["1 22 40 102 One Two"]], |
|
28 ]; |
|
29 |
|
30 SimpleTest.waitForExplicitFinish(); |
|
31 |
|
32 function doTests() |
|
33 { |
|
34 var box = document.getElementById("box"); |
|
35 |
|
36 const sortService = Components.classes["@mozilla.org/xul/xul-sort-service;1"]. |
|
37 getService(Components.interfaces.nsIXULSortService); |
|
38 |
|
39 for (let t = 0; t < tests.length; t++) { |
|
40 var test = tests[t]; |
|
41 |
|
42 for (let e = 0; e < test[0].length; e++) { |
|
43 var label = document.createElement("label"); |
|
44 label.setAttribute("value", test[0][e]); |
|
45 box.appendChild(label); |
|
46 } |
|
47 |
|
48 sortService.sort(box, "value", test[1]); |
|
49 |
|
50 var actual = ""; |
|
51 for (let e = 0; e < box.childNodes.length; e++) { |
|
52 if (actual) |
|
53 actual += " "; |
|
54 actual += box.childNodes[e].getAttribute("value"); |
|
55 } |
|
56 is(actual, test[2], "sorted step " + (t + 1)); |
|
57 |
|
58 while(box.hasChildNodes()) |
|
59 box.removeChild(box.firstChild); |
|
60 box.removeAttribute("sortDirection"); |
|
61 } |
|
62 |
|
63 SimpleTest.finish(); |
|
64 } |
|
65 |
|
66 window.addEventListener("load", doTests, false); |
|
67 |
|
68 ]]> |
|
69 </script> |
|
70 </window> |