test-xul-app.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. var xulApp = require("sdk/system/xul-app");
  5. exports["test xulapp"] = function(assert) {
  6. assert.equal(typeof(xulApp.ID), "string",
  7. "ID is a string");
  8. assert.equal(typeof(xulApp.name), "string",
  9. "name is a string");
  10. assert.equal(typeof(xulApp.version), "string",
  11. "version is a string");
  12. assert.equal(typeof(xulApp.platformVersion), "string",
  13. "platformVersion is a string");
  14. assert.throws(function() { xulApp.is("blargy"); },
  15. /Unkown Mozilla Application: blargy/,
  16. "is() throws error on bad app name");
  17. assert.throws(function() { xulApp.isOneOf(["blargy"]); },
  18. /Unkown Mozilla Application: blargy/,
  19. "isOneOf() throws error on bad app name");
  20. function testSupport(name) {
  21. var item = xulApp.is(name);
  22. assert.ok(item === true || item === false,
  23. "is('" + name + "') is true or false.");
  24. }
  25. var apps = ["Firefox", "Mozilla", "Sunbird", "SeaMonkey",
  26. "Fennec", "Thunderbird"];
  27. apps.forEach(testSupport);
  28. assert.ok(xulApp.isOneOf(apps) == true ||
  29. xulApp.isOneOf(apps) == false,
  30. "isOneOf() returns true or false.");
  31. assert.equal(xulApp.versionInRange(xulApp.platformVersion, "1.9", "*"),
  32. true, "platformVersion in range [1.9, *)");
  33. assert.equal(xulApp.versionInRange("3.6.4", "3.6.4", "3.6.*"),
  34. true, "3.6.4 in [3.6.4, 3.6.*)");
  35. assert.equal(xulApp.versionInRange("1.9.3", "1.9.2", "1.9.3"),
  36. false, "1.9.3 not in [1.9.2, 1.9.3)");
  37. };
  38. exports["test satisfies version range"] = function (assert) {
  39. [ ["1.0.0 - 2.0.0", "1.2.3"],
  40. ["1.0.0", "1.0.0"],
  41. [">=*", "0.2.4"],
  42. ["", "1.0.0"],
  43. ["*", "1.2.3"],
  44. [">=1.0.0", "1.0.0"],
  45. [">=1.0.0", "1.0.1"],
  46. [">=1.0.0", "1.1.0"],
  47. [">1.0.0", "1.0.1"],
  48. [">1.0.0", "1.1.0"],
  49. ["<=2.0.0", "2.0.0"],
  50. ["<=2.0.0", "1.9999.9999"],
  51. ["<=2.0.0", "0.2.9"],
  52. ["<2.0.0", "1.9999.9999"],
  53. ["<2.0.0", "0.2.9"],
  54. [">= 1.0.0", "1.0.0"],
  55. [">= 1.0.0", "1.0.1"],
  56. [">= 1.0.0", "1.1.0"],
  57. ["> 1.0.0", "1.0.1"],
  58. ["> 1.0.0", "1.1.0"],
  59. ["<1", "1.0.0beta"],
  60. ["< 1", "1.0.0beta"],
  61. ["<= 2.0.0", "2.0.0"],
  62. ["<= 2.0.0", "1.9999.9999"],
  63. ["<= 2.0.0", "0.2.9"],
  64. ["< 2.0.0", "1.9999.9999"],
  65. ["<\t2.0.0", "0.2.9"],
  66. [">=0.1.97", "0.1.97"],
  67. ["0.1.20 || 1.2.4", "1.2.4"],
  68. [">=0.2.3 || <0.0.1", "0.0.0"],
  69. [">=0.2.3 || <0.0.1", "0.2.3"],
  70. [">=0.2.3 || <0.0.1", "0.2.4"],
  71. ["||", "1.3.4"],
  72. ["2.x.x", "2.1.3"],
  73. ["1.2.x", "1.2.3"],
  74. ["1.2.x || 2.x", "2.1.3"],
  75. ["1.2.x || 2.x", "1.2.3"],
  76. ["x", "1.2.3"],
  77. ["2.*.*", "2.1.3"],
  78. ["1.2.*", "1.2.3"],
  79. ["1.2.* || 2.*", "2.1.3"],
  80. ["1.2.* || 2.*", "1.2.3"],
  81. ["*", "1.2.3"],
  82. ["2.*", "2.1.2"],
  83. [">=1", "1.0.0"],
  84. [">= 1", "1.0.0"],
  85. ["<1.2", "1.1.1"],
  86. ["< 1.2", "1.1.1"],
  87. ["=0.7.x", "0.7.2"],
  88. [">=0.7.x", "0.7.2"],
  89. ["<=0.7.x", "0.6.2"],
  90. ["<=0.7.x", "0.7.2"]
  91. ].forEach(function (v) {
  92. assert.ok(xulApp.satisfiesVersion(v[1], v[0]), v[0] + " satisfied by " + v[1]);
  93. });
  94. }
  95. exports["test not satisfies version range"] = function (assert) {
  96. [ ["1.0.0 - 2.0.0", "2.2.3"],
  97. ["1.0.0", "1.0.1"],
  98. [">=1.0.0", "0.0.0"],
  99. [">=1.0.0", "0.0.1"],
  100. [">=1.0.0", "0.1.0"],
  101. [">1.0.0", "0.0.1"],
  102. [">1.0.0", "0.1.0"],
  103. ["<=2.0.0", "3.0.0"],
  104. ["<=2.0.0", "2.9999.9999"],
  105. ["<=2.0.0", "2.2.9"],
  106. ["<2.0.0", "2.9999.9999"],
  107. ["<2.0.0", "2.2.9"],
  108. [">=0.1.97", "v0.1.93"],
  109. [">=0.1.97", "0.1.93"],
  110. ["0.1.20 || 1.2.4", "1.2.3"],
  111. [">=0.2.3 || <0.0.1", "0.0.3"],
  112. [">=0.2.3 || <0.0.1", "0.2.2"],
  113. ["2.x.x", "1.1.3"],
  114. ["2.x.x", "3.1.3"],
  115. ["1.2.x", "1.3.3"],
  116. ["1.2.x || 2.x", "3.1.3"],
  117. ["1.2.x || 2.x", "1.1.3"],
  118. ["2.*.*", "1.1.3"],
  119. ["2.*.*", "3.1.3"],
  120. ["1.2.*", "1.3.3"],
  121. ["1.2.* || 2.*", "3.1.3"],
  122. ["1.2.* || 2.*", "1.1.3"],
  123. ["2", "1.1.2"],
  124. ["2.3", "2.3.1"],
  125. ["2.3", "2.4.1"],
  126. ["<1", "1.0.0"],
  127. [">=1.2", "1.1.1"],
  128. ["1", "2.0.0beta"],
  129. ["=0.7.x", "0.8.2"],
  130. [">=0.7.x", "0.6.2"],
  131. ].forEach(function (v) {
  132. assert.ok(!xulApp.satisfiesVersion(v[1], v[0]), v[0] + " not satisfied by " + v[1]);
  133. });
  134. }
  135. require("test").run(exports);