1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/xul/templates/tests/chrome/test_sortservice.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 1.4 +<?xml version="1.0" ?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> 1.7 + 1.8 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.9 + 1.10 +<vbox id="box"/> 1.11 + 1.12 +<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> 1.13 + 1.14 +<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.15 + 1.16 +<script type="application/x-javascript"> 1.17 +<![CDATA[ 1.18 + 1.19 +var tests = [ 1.20 + [["One", "Two", "Three", "Four"], "", ["Four One Three Two"]], 1.21 + [["One", "Two", "Three", "Four"], "integer", ["Four One Three Two"]], 1.22 + [["One", "Two", "Three", "Four"], "descending", ["Two Three One Four"]], 1.23 + [["One", "Two", "Three", "Four"], "descending integer", ["Two Three One Four"]], 1.24 + [["One", "Two", "Three", "Four"], "integer cat descending", ["Two Three One Four"]], 1.25 + [["1", "13", "2", "7", "12", "240", "2", "170", "222", "98"], "", ["1 12 13 170 2 2 222 240 7 98"]], 1.26 + [["1", "13", "2", "7", "12", "240", "2", "170", "222", "98"], "integer", ["1 2 2 7 12 13 98 170 222 240"]], 1.27 + [["1", "13", "2", "7", "12", "240", "2", "170", "222", "98"], "ascending integer", ["1 2 2 7 12 13 98 170 222 240"]], 1.28 + [["1", "13", "2", "7", "12", "240", "2", "170", "222", "98"], "integer descending", ["240 222 170 98 13 12 7 2 2 1"]], 1.29 + [["Cat", "cat", "Candy", "candy"], "comparecase", ["Candy Cat candy cat"]], 1.30 + [["1", "102", "22", "One", "40", "Two"], "integer", ["1 22 40 102 One Two"]], 1.31 +]; 1.32 + 1.33 +SimpleTest.waitForExplicitFinish(); 1.34 + 1.35 +function doTests() 1.36 +{ 1.37 + var box = document.getElementById("box"); 1.38 + 1.39 + const sortService = Components.classes["@mozilla.org/xul/xul-sort-service;1"]. 1.40 + getService(Components.interfaces.nsIXULSortService); 1.41 + 1.42 + for (let t = 0; t < tests.length; t++) { 1.43 + var test = tests[t]; 1.44 + 1.45 + for (let e = 0; e < test[0].length; e++) { 1.46 + var label = document.createElement("label"); 1.47 + label.setAttribute("value", test[0][e]); 1.48 + box.appendChild(label); 1.49 + } 1.50 + 1.51 + sortService.sort(box, "value", test[1]); 1.52 + 1.53 + var actual = ""; 1.54 + for (let e = 0; e < box.childNodes.length; e++) { 1.55 + if (actual) 1.56 + actual += " "; 1.57 + actual += box.childNodes[e].getAttribute("value"); 1.58 + } 1.59 + is(actual, test[2], "sorted step " + (t + 1)); 1.60 + 1.61 + while(box.hasChildNodes()) 1.62 + box.removeChild(box.firstChild); 1.63 + box.removeAttribute("sortDirection"); 1.64 + } 1.65 + 1.66 + SimpleTest.finish(); 1.67 +} 1.68 + 1.69 +window.addEventListener("load", doTests, false); 1.70 + 1.71 +]]> 1.72 +</script> 1.73 +</window>