summaryrefslogtreecommitdiffstats
path: root/dom/xul/templates/tests/chrome/test_sortservice.xul
diff options
context:
space:
mode:
Diffstat (limited to 'dom/xul/templates/tests/chrome/test_sortservice.xul')
-rw-r--r--dom/xul/templates/tests/chrome/test_sortservice.xul70
1 files changed, 70 insertions, 0 deletions
diff --git a/dom/xul/templates/tests/chrome/test_sortservice.xul b/dom/xul/templates/tests/chrome/test_sortservice.xul
new file mode 100644
index 000000000..af1de3f0e
--- /dev/null
+++ b/dom/xul/templates/tests/chrome/test_sortservice.xul
@@ -0,0 +1,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>