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
Wrap
Text File
|
2006-08-07
|
3KB
|
81 lines
function G_MozVersionNumber(version) {
this.debugZone = "mozversion";
this.version_ = version;
this.components_ = this.version_.split(".");
this.comparator_ = Cc["@mozilla.org/xpcom/version-comparator;1"]
.getService(Ci.nsIVersionComparator);
}
G_MozVersionNumber.prototype.compareToString = function(v) {
return this.comparator_.compare(this.version_, v);
}
G_MozVersionNumber.prototype.isVersionOf = function(v) {
if (this.version_.indexOf("+") != -1 || v.indexOf("+") != -1)
return this.compareToString(v) == 0;
if (this.compareToString(v) == 0)
return true;
var vComponents = v.split(".");
if (vComponents.length > this.components_)
return false;
for (var i = 0; i < vComponents.length; i++)
if (vComponents[i] != this.components_[i])
return false;
return true;
}
G_MozVersionNumber.prototype.getVersion = function() {
return this.version_;
}
function G_ThisFirefoxVersion() {
var version;
try {
var appInfo = Cc["@mozilla.org/xre/app-info;1"]
.getService(Ci.nsIXULAppInfo);
version = appInfo.version;
} catch(e) {
G_Debug(this, "Getting nsIXULAppInfo threw; trying app.version pref");
version = (new G_Preferences()).getPref("app.version");
}
if (!version)
throw new Error("Couldn't get application version!");
G_MozVersionNumber.call(this, version);
this.debugZone = "firefoxversion";
}
G_ThisFirefoxVersion.inherits(G_MozVersionNumber);
function TEST_G_MozVersionNumber() {
if (G_GDEBUG) {
var z = "mozversion UNITTEST";
G_debugService.enableZone(z);
G_Debug(z, "Starting");
var v = G_MozVersionNumber;
G_Assert(z, (new v("1.0")).compareToString("1.0") == 0,
"exact equality broken");
G_Assert(z, (new v("1.0.0.0")).compareToString("1.0") == 0,
"mutlidot equality broken");
G_Assert(z, (new v("1.0.2.1")).compareToString("1.1") < 0,
"less than broken");
G_Assert(z, (new v("1.1")).compareToString("1.0.2.1") > 0,
"greater than broken");
G_Assert(z, (new v("1.0+")).compareToString("1.1pre") == 0,
"+ broken");
G_Assert(z, (new v("1.5")).isVersionOf("1.5"), "exact versionof broken");
G_Assert(z, (new v("1.5.*")).isVersionOf("1.5"), "star versionof broken");
G_Assert(z, (new v("1.5.1.3")).isVersionOf("1.5"),
"long versionof broken");
G_Assert(z, (new v("1.1pre0")).isVersionOf("1.0+"), "+'s broken");
G_Assert(z, !((new v("1.0pre0")).isVersionOf("1.1+")), "+'s broken");
G_Assert(z, !(new v("1.5")).isVersionOf("1.6"), "not versionof broken");
G_Assert(z, !(new v("1.5")).isVersionOf("1.5.*"),
"not versionof star broken");
G_Debug(z, "PASSED");
}
}
function TEST_G_ThisFirefoxVersion() {
if (G_GDEBUG) {
var z = "firefoxversion UNITTEST";
G_debugService.enableZone(z);
G_Debug(z, "Starting");
var v = new G_ThisFirefoxVersion();
G_Assert(z, v.isVersionOf(v.version_), "Firefox version broken");
G_Debug(z, "PASSED");
}
}