xpcom/tests/unit/test_versioncomparator.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // Versions to test listed in ascending order, none can be equal
michael@0 2 var comparisons = [
michael@0 3 "0.9",
michael@0 4 "0.9.1",
michael@0 5 "1.0pre1",
michael@0 6 "1.0pre2",
michael@0 7 "1.0",
michael@0 8 "1.1pre",
michael@0 9 "1.1pre1a",
michael@0 10 "1.1pre1",
michael@0 11 "1.1pre10a",
michael@0 12 "1.1pre10",
michael@0 13 "1.1",
michael@0 14 "1.1.0.1",
michael@0 15 "1.1.1",
michael@0 16 "1.1.*",
michael@0 17 "1.*",
michael@0 18 "2.0",
michael@0 19 "2.1",
michael@0 20 "3.0.-1",
michael@0 21 "3.0"
michael@0 22 ];
michael@0 23
michael@0 24 // Every version in this list means the same version number
michael@0 25 var equality = [
michael@0 26 "1.1pre",
michael@0 27 "1.1pre0",
michael@0 28 "1.0+"
michael@0 29 ];
michael@0 30
michael@0 31 function run_test()
michael@0 32 {
michael@0 33 var vc = Components.classes["@mozilla.org/xpcom/version-comparator;1"]
michael@0 34 .getService(Components.interfaces.nsIVersionComparator);
michael@0 35
michael@0 36 for (var i = 0; i < comparisons.length; i++) {
michael@0 37 for (var j = 0; j < comparisons.length; j++) {
michael@0 38 var result = vc.compare(comparisons[i], comparisons[j]);
michael@0 39 if (i == j) {
michael@0 40 if (result != 0)
michael@0 41 do_throw(comparisons[i] + " should be the same as itself");
michael@0 42 }
michael@0 43 else if (i < j) {
michael@0 44 if (!(result < 0))
michael@0 45 do_throw(comparisons[i] + " should be less than " + comparisons[j]);
michael@0 46 }
michael@0 47 else if (!(result > 0)) {
michael@0 48 do_throw(comparisons[i] + " should be greater than " + comparisons[j]);
michael@0 49 }
michael@0 50 }
michael@0 51 }
michael@0 52
michael@0 53 for (i = 0; i < equality.length; i++) {
michael@0 54 for (j = 0; j < equality.length; j++) {
michael@0 55 if (vc.compare(equality[i], equality[j]) != 0)
michael@0 56 do_throw(equality[i] + " should equal " + equality[j]);
michael@0 57 }
michael@0 58 }
michael@0 59 }

mercurial