Commit 99463643 994636433dcaa58e2e0913cdcfeea59a0c903902 by Nicolas Perriault

safer version comparisons

1 parent 2d4371b7
......@@ -45,7 +45,7 @@ var Mouse = function Mouse(casper) {
var slice = Array.prototype.slice,
nativeEvents = ['mouseup', 'mousedown', 'click', 'mousemove'];
if (phantom.version.major >= 1 && phantom.version.minor >= 8) {
if (utils.gteVersion(phantom.version, '1.8.0')) {
nativeEvents.push('doubleclick');
}
var emulatedEvents = ['mouseover', 'mouseout'],
......
......@@ -579,3 +579,59 @@ function unique(array) {
return r;
}
exports.unique = unique;
/**
* Compare two version numbers represented as strings.
*
* @param String a Version a
* @param String b Version b
* @return Number
*/
function cmpVersion(a, b) {
var i, cmp, len, re = /(\.0)+[^\.]*$/;
function versionToString(version) {
if (isObject(version)) {
try {
return [version.major, version.minor, version.patch].join('.');
} catch (e) {}
}
return version;
}
a = versionToString(a);
b = versionToString(b);
a = (a + '').replace(re, '').split('.');
b = (b + '').replace(re, '').split('.');
len = Math.min(a.length, b.length);
for (i = 0; i < len; i++) {
cmp = parseInt(a[i], 10) - parseInt(b[i], 10);
if (cmp !== 0) {
return cmp;
}
}
return a.length - b.length;
}
exports.cmpVersion = cmpVersion;
/**
* Checks if a version number string is greater or equals another.
*
* @param String a Version a
* @param String b Version b
* @return Boolean
*/
function gteVersion(a, b) {
return cmpVersion(a, b) >= 0;
}
exports.gteVersion = gteVersion;
/**
* Checks if a version number string is less than another.
*
* @param String a Version a
* @param String b Version b
* @return Boolean
*/
function ltVersion(a, b) {
return cmpVersion(a, b) < 0;
}
exports.ltVersion = ltVersion;
......
/*global casper*/
/*jshint strict:false maxstatements: 99*/
var utils = require('utils');
casper.start('tests/site/index.html', function() {
this.click('a[href="test.html"]');
});
......@@ -57,7 +59,7 @@ casper.then(function() {
results = this.getGlobal('results');
this.test.assertEquals(results.testmove, [200, 100], 'Mouse.move() has moved to the specified position');
if (phantom.version.major >= 1 && phantom.version.minor >= 8) {
if (utils.gteVersion(phantom.version, '1.8.0')) {
this.test.comment('Mouse.doubleclick()');
this.mouse.doubleclick(200, 100);
results = this.getGlobal('results');
......
/*jshint strict:false*/
/*global CasperError casper console phantom require*/
if (phantom.version.major === 1 && phantom.version.minor < 8) {
var utils = require('utils')
if (utils.ltVersion(phantom.version, '1.8.0')) {
// https://github.com/n1k0/casperjs/issues/101
casper.warn('document.location is broken under phantomjs < 1.8');
casper.test.done();
......