home *** CD-ROM | disk | FTP | other *** search
/ Minami 83 / MINAMI83.iso / Extra / DivXInstaller.exe / $PLUGINSDIR / GoogleToolbarFirefox.msi / xpi / amulet-jslib / firefox / version-utils.js < prev   
Text File  |  2006-08-07  |  3KB  |  81 lines

  1. function G_MozVersionNumber(version) {
  2. this.debugZone = "mozversion";
  3. this.version_ = version;
  4. this.components_ = this.version_.split(".");
  5. this.comparator_ = Cc["@mozilla.org/xpcom/version-comparator;1"]
  6. .getService(Ci.nsIVersionComparator);
  7. }
  8. G_MozVersionNumber.prototype.compareToString = function(v) {
  9. return this.comparator_.compare(this.version_, v);
  10. }
  11. G_MozVersionNumber.prototype.isVersionOf = function(v) {
  12. if (this.version_.indexOf("+") != -1 || v.indexOf("+") != -1)
  13. return this.compareToString(v) == 0;
  14. if (this.compareToString(v) == 0)
  15. return true;
  16. var vComponents = v.split(".");
  17. if (vComponents.length > this.components_)
  18. return false;
  19. for (var i = 0; i < vComponents.length; i++)
  20. if (vComponents[i] != this.components_[i])
  21. return false;
  22. return true;
  23. }
  24. G_MozVersionNumber.prototype.getVersion = function() {
  25. return this.version_;
  26. }
  27. function G_ThisFirefoxVersion() {
  28. var version;
  29. try {
  30. var appInfo = Cc["@mozilla.org/xre/app-info;1"]
  31. .getService(Ci.nsIXULAppInfo);
  32. version = appInfo.version;
  33. } catch(e) {
  34. G_Debug(this, "Getting nsIXULAppInfo threw; trying app.version pref");
  35. version = (new G_Preferences()).getPref("app.version");
  36. }
  37. if (!version)
  38. throw new Error("Couldn't get application version!");
  39. G_MozVersionNumber.call(this, version);
  40. this.debugZone = "firefoxversion";
  41. }
  42. G_ThisFirefoxVersion.inherits(G_MozVersionNumber);
  43. function TEST_G_MozVersionNumber() {
  44. if (G_GDEBUG) {
  45. var z = "mozversion UNITTEST";
  46. G_debugService.enableZone(z);
  47. G_Debug(z, "Starting");
  48. var v = G_MozVersionNumber;
  49. G_Assert(z, (new v("1.0")).compareToString("1.0") == 0,
  50. "exact equality broken");
  51. G_Assert(z, (new v("1.0.0.0")).compareToString("1.0") == 0,
  52. "mutlidot equality broken");
  53. G_Assert(z, (new v("1.0.2.1")).compareToString("1.1") < 0,
  54. "less than broken");
  55. G_Assert(z, (new v("1.1")).compareToString("1.0.2.1") > 0,
  56. "greater than broken");
  57. G_Assert(z, (new v("1.0+")).compareToString("1.1pre") == 0,
  58. "+ broken");
  59. G_Assert(z, (new v("1.5")).isVersionOf("1.5"), "exact versionof broken");
  60. G_Assert(z, (new v("1.5.*")).isVersionOf("1.5"), "star versionof broken");
  61. G_Assert(z, (new v("1.5.1.3")).isVersionOf("1.5"),
  62. "long versionof broken");
  63. G_Assert(z, (new v("1.1pre0")).isVersionOf("1.0+"), "+'s broken");
  64. G_Assert(z, !((new v("1.0pre0")).isVersionOf("1.1+")), "+'s broken");
  65. G_Assert(z, !(new v("1.5")).isVersionOf("1.6"), "not versionof broken");
  66. G_Assert(z, !(new v("1.5")).isVersionOf("1.5.*"),
  67. "not versionof star broken");
  68. G_Debug(z, "PASSED");
  69. }
  70. }
  71. function TEST_G_ThisFirefoxVersion() {
  72. if (G_GDEBUG) {
  73. var z = "firefoxversion UNITTEST";
  74. G_debugService.enableZone(z);
  75. G_Debug(z, "Starting");
  76. var v = new G_ThisFirefoxVersion();
  77. G_Assert(z, v.isVersionOf(v.version_), "Firefox version broken");
  78. G_Debug(z, "PASSED");
  79. }
  80. }
  81.