content/xul/templates/tests/chrome/test_sortservice.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial