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.

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

mercurial