Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
99463643
...
994636433dcaa58e2e0913cdcfeea59a0c903902
authored
2013-01-05 15:53:48 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
safer version comparisons
1 parent
2d4371b7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
3 deletions
modules/mouse.js
modules/utils.js
tests/suites/casper/click.js
tests/suites/casper/location.js
modules/mouse.js
View file @
9946364
...
...
@@ -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'
],
...
...
modules/utils.js
View file @
9946364
...
...
@@ -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
;
...
...
tests/suites/casper/click.js
View file @
9946364
/*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'
);
...
...
tests/suites/casper/location.js
View file @
9946364
/*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
();
...
...
Please
register
or
sign in
to post a comment