Beginnings of the offset test suite

This commit is contained in:
Brandon Aaron 2007-12-04 20:51:16 +00:00
parent 76e3a90153
commit f576ceeea9
4 changed files with 136 additions and 0 deletions

View file

@ -0,0 +1,26 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>absolute</title>
<style type="text/css" media="screen">
body { margin: 1px; padding: 5px; }
div.absolute { position: absolute; margin: 1px; border: 2px solid #000; padding: 5px; width: 100px; height: 100px; }
#absolute-1 { top: 0; left: 0; }
#absolute-1-1 { top: 1px; left: 1px; }
#absolute-1-1-1 { top: 1px; left: 1px; }
#absolute-2 { top: 19px; left: 19px; }
</style>
<script type="text/javascript" src="../../../dist/jquery.js"></script>
<script type="text/javascript" charset="utf-8"> $(function() { return; }); </script>
</head>
<body>
<div id="absolute-1" class="absolute">absolute-1
<div id="absolute-1-1" class="absolute">absolute-1-1
<div id="absolute-1-1-1" class="absolute">absolute-1-1-1</div>
</div>
</div>
<div id="absolute-2" class="absolute">absolute-2</div>
</body>
</html>

View file

@ -0,0 +1,32 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>relative</title>
<style type="text/css" media="screen">
body { margin: 1px; padding: 5px; }
div.relative { position: relative; margin: 1px; border: 2px solid #000; padding: 5px; width: 100px; height: 100px; background: #fff; overflow: hidden; }
#relative-2 { top: 20px; left: 20px; }
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style>
<script type="text/javascript" src="../../../dist/jquery.js"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
$('.relative').click(function() {
$('#marker').css( $(this).offset() );
return false;
});
});
</script>
</head>
<body>
<div id="relative-1" class="relative">relative-1
<div id="relative-1-1" class="relative">relative-1-1
<div id="relative-1-1-1" class="relative">relative-1-1-1</div>
</div>
</div>
<div id="relative-2" class="relative">relative-2</div>
<div id="marker"></div>
</body>
</html>

27
test/offset.html Normal file
View file

@ -0,0 +1,27 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Offset Test Suite</title>
<link rel="Stylesheet" media="screen" href="data/testsuite.css" />
<script type="text/javascript" src="../dist/jquery.js"></script>
<script type="text/javascript" src="data/testrunner.js"></script>
<script type="text/javascript" src="unit/offset.js"></script>
</head>
<body id="body">
<h1 id="header">jQuery Offset Test Suite</h1>
<h2 id="banner"></h2>
<h2 id="userAgent"></h2>
<!-- Test HTML -->
<div id="nothiddendiv" style="height:1px;background:white;"></div>
<dl id="dl" style="display:none;">
<div id="main" style="display: none;">
</div>
</dl>
<ol id="tests"></ol>
</body>
</html>

51
test/unit/offset.js Normal file
View file

@ -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();
});