Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
f3656832
Commit
f3656832
authored
Feb 23, 2012
by
Mike Sherov
Committed by
Dave Methvin
Feb 24, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes #10693, generalizes the "test something in an iframe" code when a callback isn't needed
parent
a619cb30
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
84 deletions
+44
-84
testinit.js
test/data/testinit.js
+32
-0
offset.js
test/unit/offset.js
+8
-40
selector.js
test/unit/selector.js
+4
-44
No files found.
test/data/testinit.js
View file @
f3656832
...
@@ -119,4 +119,36 @@ function url(value) {
...
@@ -119,4 +119,36 @@ function url(value) {
oldActive
=
jQuery
.
active
;
oldActive
=
jQuery
.
active
;
}
}
};
};
this
.
testIframe
=
function
(
fileName
,
name
,
fn
)
{
test
(
name
,
function
()
{
// pause execution for now
stop
();
// load fixture in iframe
var
iframe
=
loadFixture
(),
win
=
iframe
.
contentWindow
,
interval
=
setInterval
(
function
()
{
if
(
win
&&
win
.
jQuery
&&
win
.
jQuery
.
isReady
)
{
clearInterval
(
interval
);
// continue
start
();
// call actual tests passing the correct jQuery instance to use
fn
.
call
(
this
,
win
.
jQuery
,
win
,
win
.
document
);
document
.
body
.
removeChild
(
iframe
);
iframe
=
null
;
}
},
15
);
});
function
loadFixture
()
{
var
src
=
"./data/"
+
fileName
+
".html?"
+
parseInt
(
Math
.
random
()
*
1000
,
10
),
iframe
=
jQuery
(
"<iframe />"
).
css
({
width
:
500
,
height
:
500
,
position
:
"absolute"
,
top
:
-
600
,
left
:
-
600
,
visibility
:
"hidden"
}).
appendTo
(
"body"
)[
0
];
iframe
.
contentWindow
.
location
=
src
;
return
iframe
;
}
};
}());
}());
\ No newline at end of file
test/unit/offset.js
View file @
f3656832
...
@@ -11,7 +11,7 @@ test("disconnected node", function() {
...
@@ -11,7 +11,7 @@ test("disconnected node", function() {
var
supportsScroll
=
false
;
var
supportsScroll
=
false
;
test
offset
(
"absolute"
,
function
(
$
,
iframe
)
{
test
Iframe
(
"offset/absolute"
,
"absolute"
,
function
(
$
,
iframe
)
{
expect
(
4
);
expect
(
4
);
var
doc
=
iframe
.
document
,
tests
;
var
doc
=
iframe
.
document
,
tests
;
...
@@ -51,7 +51,7 @@ testoffset("absolute", function($, iframe) {
...
@@ -51,7 +51,7 @@ testoffset("absolute", function($, iframe) {
forceScroll
.
remove
();
forceScroll
.
remove
();
});
});
test
offset
(
"absolute"
,
function
(
jQuery
)
{
test
Iframe
(
"offset/absolute"
,
"absolute"
,
function
(
jQuery
)
{
expect
(
178
);
expect
(
178
);
// get offset tests
// get offset tests
...
@@ -136,7 +136,7 @@ testoffset("absolute", function( jQuery ) {
...
@@ -136,7 +136,7 @@ testoffset("absolute", function( jQuery ) {
});
});
});
});
test
offset
(
"relative"
,
function
(
jQuery
)
{
test
Iframe
(
"offset/relative"
,
"relative"
,
function
(
jQuery
)
{
expect
(
60
);
expect
(
60
);
// IE is collapsing the top margin of 1px
// IE is collapsing the top margin of 1px
...
@@ -197,7 +197,7 @@ testoffset("relative", function( jQuery ) {
...
@@ -197,7 +197,7 @@ testoffset("relative", function( jQuery ) {
});
});
});
});
test
offset
(
"static"
,
function
(
jQuery
)
{
test
Iframe
(
"offset/static"
,
"static"
,
function
(
jQuery
)
{
expect
(
80
);
expect
(
80
);
// IE is collapsing the top margin of 1px
// IE is collapsing the top margin of 1px
...
@@ -264,7 +264,7 @@ testoffset("static", function( jQuery ) {
...
@@ -264,7 +264,7 @@ testoffset("static", function( jQuery ) {
});
});
});
});
test
offset
(
"fixed"
,
function
(
jQuery
)
{
test
Iframe
(
"offset/fixed"
,
"fixed"
,
function
(
jQuery
)
{
expect
(
30
);
expect
(
30
);
var
tests
=
[
var
tests
=
[
...
@@ -331,7 +331,7 @@ testoffset("fixed", function( jQuery ) {
...
@@ -331,7 +331,7 @@ testoffset("fixed", function( jQuery ) {
}
}
});
});
test
offset
(
"table"
,
function
(
jQuery
)
{
test
Iframe
(
"offset/table"
,
"table"
,
function
(
jQuery
)
{
expect
(
4
);
expect
(
4
);
equal
(
jQuery
(
"#table-1"
).
offset
().
top
,
6
,
"jQuery('#table-1').offset().top"
);
equal
(
jQuery
(
"#table-1"
).
offset
().
top
,
6
,
"jQuery('#table-1').offset().top"
);
...
@@ -341,7 +341,7 @@ testoffset("table", function( jQuery ) {
...
@@ -341,7 +341,7 @@ testoffset("table", function( jQuery ) {
equal
(
jQuery
(
"#th-1"
).
offset
().
left
,
10
,
"jQuery('#th-1').offset().left"
);
equal
(
jQuery
(
"#th-1"
).
offset
().
left
,
10
,
"jQuery('#th-1').offset().left"
);
});
});
test
offset
(
"scroll"
,
function
(
jQuery
,
win
)
{
test
Iframe
(
"offset/scroll"
,
"scroll"
,
function
(
jQuery
,
win
)
{
expect
(
24
);
expect
(
24
);
var
ie
=
jQuery
.
browser
.
msie
&&
parseInt
(
jQuery
.
browser
.
version
,
10
)
<
8
;
var
ie
=
jQuery
.
browser
.
msie
&&
parseInt
(
jQuery
.
browser
.
version
,
10
)
<
8
;
...
@@ -399,7 +399,7 @@ testoffset("scroll", function( jQuery, win ) {
...
@@ -399,7 +399,7 @@ testoffset("scroll", function( jQuery, win ) {
strictEqual
(
jQuery
().
scrollLeft
(),
null
,
"jQuery().scrollLeft(100) testing setter on empty jquery object"
);
strictEqual
(
jQuery
().
scrollLeft
(),
null
,
"jQuery().scrollLeft(100) testing setter on empty jquery object"
);
});
});
test
offset
(
"body"
,
function
(
jQuery
)
{
test
Iframe
(
"offset/body"
,
"body"
,
function
(
jQuery
)
{
expect
(
2
);
expect
(
2
);
equal
(
jQuery
(
"body"
).
offset
().
top
,
1
,
"jQuery('#body').offset().top"
);
equal
(
jQuery
(
"body"
).
offset
().
top
,
1
,
"jQuery('#body').offset().top"
);
...
@@ -466,35 +466,3 @@ test("fractions (see #7730 and #7885)", function() {
...
@@ -466,35 +466,3 @@ test("fractions (see #7730 and #7885)", function() {
div
.
remove
();
div
.
remove
();
});
});
function
testoffset
(
name
,
fn
)
{
test
(
name
,
function
()
{
// pause execution for now
stop
();
// load fixture in iframe
var
iframe
=
loadFixture
(),
win
=
iframe
.
contentWindow
,
interval
=
setInterval
(
function
()
{
if
(
win
&&
win
.
jQuery
&&
win
.
jQuery
.
isReady
)
{
clearInterval
(
interval
);
// continue
start
();
// call actual tests passing the correct jQuery isntance to use
fn
.
call
(
this
,
win
.
jQuery
,
win
);
document
.
body
.
removeChild
(
iframe
);
iframe
=
null
;
}
},
15
);
});
function
loadFixture
()
{
var
src
=
"./data/offset/"
+
name
+
".html?"
+
parseInt
(
Math
.
random
()
*
1000
,
10
),
iframe
=
jQuery
(
"<iframe />"
).
css
({
width
:
500
,
height
:
500
,
position
:
"absolute"
,
top
:
-
600
,
left
:
-
600
,
visibility
:
"hidden"
}).
appendTo
(
"body"
)[
0
];
iframe
.
contentWindow
.
location
=
src
;
return
iframe
;
}
}
test/unit/selector.js
View file @
f3656832
...
@@ -6,47 +6,7 @@
...
@@ -6,47 +6,7 @@
module
(
"selector - jQuery only"
,
{
teardown
:
moduleTeardown
});
module
(
"selector - jQuery only"
,
{
teardown
:
moduleTeardown
});
/**
testIframe
(
"selector/html5_selector"
,
"attributes - jQuery.attr"
,
function
(
jQuery
,
window
,
document
)
{
* Loads an iframe for the selector context
* @param {String} fileName - Name of the html file to load
* @param {String} name - Test name
* @param {Function} fn - Test callback containing the tests to run
*/
var
testIframe
=
function
(
fileName
,
name
,
fn
)
{
var
loadFixture
=
function
()
{
// Creates iframe with cache disabled
var
src
=
"./data/selector/"
+
fileName
+
".html?"
+
parseInt
(
Math
.
random
()
*
1000
,
10
),
iframe
=
jQuery
(
"<iframe />"
).
css
({
width
:
500
,
height
:
500
,
position
:
"absolute"
,
top
:
-
600
,
left
:
-
600
,
visibility
:
"hidden"
}).
appendTo
(
"body"
)[
0
];
iframe
.
contentWindow
.
location
=
src
;
return
iframe
;
};
test
(
name
,
function
()
{
// pause execution for now
stop
();
// load fixture in iframe
var
iframe
=
loadFixture
(),
win
=
iframe
.
contentWindow
,
interval
=
setInterval
(
function
()
{
if
(
win
&&
win
.
jQuery
&&
win
.
jQuery
.
isReady
)
{
clearInterval
(
interval
);
// continue
start
();
// call actual tests passing the correct jQuery instance to use
fn
.
call
(
this
,
win
.
jQuery
,
win
,
win
.
document
);
document
.
body
.
removeChild
(
iframe
);
iframe
=
null
;
}
},
15
);
});
};
testIframe
(
"html5_selector"
,
"attributes - jQuery.attr"
,
function
(
jQuery
,
window
,
document
)
{
expect
(
34
);
expect
(
34
);
/**
/**
...
@@ -61,7 +21,7 @@ testIframe("html5_selector", "attributes - jQuery.attr", function( jQuery, windo
...
@@ -61,7 +21,7 @@ testIframe("html5_selector", "attributes - jQuery.attr", function( jQuery, windo
}
}
return
r
;
return
r
;
}
}
/**
/**
* Asserts that a select matches the given IDs * @example t("Check for something", "//[a]", ["foo", "baar"]);
* Asserts that a select matches the given IDs * @example t("Check for something", "//[a]", ["foo", "baar"]);
* @param {String} a - Assertion name
* @param {String} a - Assertion name
...
@@ -72,7 +32,7 @@ testIframe("html5_selector", "attributes - jQuery.attr", function( jQuery, windo
...
@@ -72,7 +32,7 @@ testIframe("html5_selector", "attributes - jQuery.attr", function( jQuery, windo
var
f
=
jQuery
(
b
).
get
(),
var
f
=
jQuery
(
b
).
get
(),
s
=
""
,
s
=
""
,
i
=
0
;
i
=
0
;
for
(
;
i
<
f
.
length
;
i
++
)
{
for
(
;
i
<
f
.
length
;
i
++
)
{
s
+=
(
s
&&
","
)
+
'"'
+
f
[
i
].
id
+
'"'
;
s
+=
(
s
&&
","
)
+
'"'
+
f
[
i
].
id
+
'"'
;
}
}
...
@@ -132,7 +92,7 @@ testIframe("html5_selector", "attributes - jQuery.attr", function( jQuery, windo
...
@@ -132,7 +92,7 @@ testIframe("html5_selector", "attributes - jQuery.attr", function( jQuery, windo
t
(
"Improperly named form elements do not interfere with form selections (#9570)"
,
"form[name='formName']"
,
[
"form1"
]);
t
(
"Improperly named form elements do not interfere with form selections (#9570)"
,
"form[name='formName']"
,
[
"form1"
]);
});
});
testIframe
(
"sizzle_cache"
,
"Sizzle cache collides with multiple Sizzles on a page"
,
function
(
jQuery
,
window
,
document
)
{
testIframe
(
"s
elector/s
izzle_cache"
,
"Sizzle cache collides with multiple Sizzles on a page"
,
function
(
jQuery
,
window
,
document
)
{
var
$cached
=
window
.
$cached
;
var
$cached
=
window
.
$cached
;
expect
(
3
);
expect
(
3
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment