diff --git a/test/data/offset/absolute.html b/test/data/offset/absolute.html new file mode 100644 index 00000000..5b8b7edb --- /dev/null +++ b/test/data/offset/absolute.html @@ -0,0 +1,26 @@ + + + + + absolute + + + + + +
absolute-1 +
absolute-1-1 +
absolute-1-1-1
+
+
+
absolute-2
+ + \ No newline at end of file diff --git a/test/data/offset/relative.html b/test/data/offset/relative.html new file mode 100644 index 00000000..dc78976b --- /dev/null +++ b/test/data/offset/relative.html @@ -0,0 +1,32 @@ + + + + + relative + + + + + +
relative-1 +
relative-1-1 +
relative-1-1-1
+
+
+
relative-2
+
+ + \ No newline at end of file diff --git a/test/offset.html b/test/offset.html new file mode 100644 index 00000000..f802dea3 --- /dev/null +++ b/test/offset.html @@ -0,0 +1,27 @@ + + + + + jQuery Offset Test Suite + + + + + + + +

jQuery Offset Test Suite

+ +

+ + +
+ + +
    + + diff --git a/test/unit/offset.js b/test/unit/offset.js new file mode 100644 index 00000000..835df89e --- /dev/null +++ b/test/unit/offset.js @@ -0,0 +1,51 @@ +module("offset"); + +// opens a new window to run the tests against +var testwin = function(name, fn) { + testwin[name] = load_offset_fixture(name); + var interval = setInterval(function() { + if (testwin[name] && testwin[name].$ && testwin[name].$.isReady) { + clearInterval(interval); + test(name, fn); + } + }, 0); + + function load_offset_fixture(name) { + var win = window.open( "./data/offset/" + name + ".html?num"+parseInt(Math.random()*1000), name, 'left=0,top=0,width=500,height=500,toolbar=1,resizable=0' ); + if ( !win ) { + alert("Please disable your popup blocker for the offset test suite"); + throw "Please disable your popup blocker for the offset test suite"; + } + return win; + } +}; + +testwin("absolute", function() { + var $w = testwin["absolute"].$; + + equals( $w('#absolute-1').offset().top, 1, "$('#absolute-1').offset().top" ); + equals( $w('#absolute-1').offset().left, 1, "$('#absolute-1').offset().left" ); + + equals( $w('#absolute-1-1').offset().top, 5, "$('#absolute-1-1').offset().top" ); + equals( $w('#absolute-1-1').offset().left, 5, "$('#absolute-1-1').offset().left" ); + + equals( $w('#absolute-1-1-1').offset().top, 9, "$('#absolute-1-1-1').offset().top" ); + equals( $w('#absolute-1-1-1').offset().left, 9, "$('#absolute-1-1-1').offset().left" ); + + equals( $w('#absolute-2').offset().top, 20, "$('#absolute-2').offset().top" ); + equals( $w('#absolute-2').offset().left, 20, "$('#absolute-2').offset().left" ); + + testwin["absolute"].close(); +}); + +testwin("relative", function() { + var $w = testwin["relative"].$; + + equals( $w('#relative-1').offset().top, jQuery.browser.msie ? 6 : 7, "$('#relative-1').offset().top" ); + equals( $w('#relative-1').offset().left, 7, "$('#relative-1').offset().left" ); + + equals( $w('#relative-2').offset().top, jQuery.browser.msie ? 141 : 142, "$('#relative-2').offset().top" ); + equals( $w('#relative-2').offset().left, 27, "$('#relative-2').offset().left" ); + + testwin["relative"].close(); +}); \ No newline at end of file