prototype/test/unit/position.html

83 lines
2.8 KiB
HTML

<!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">
<head>
<title>Prototype Unit test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="../../dist/prototype.js" type="text/javascript"></script>
<script src="../lib/unittest.js" type="text/javascript"></script>
<link rel="stylesheet" href="../test.css" type="text/css" />
</head>
<body>
<div id="ensure_scrollbars" style="width:10000px; height:10000px; position:absolute" > </div>
<h1>Prototype Unit test file</h1>
<p>
Test of functions in position.js
</p>
<!-- Log output -->
<div id="testlog"> </div>
<div id="body_absolute" style="position: absolute; top: 10px; left: 10px">
<div id="absolute_absolute" style="position: absolute; top: 10px; left:10px"> </div>
<div id="absolute_relative" style="position: relative; top: 10px; left:10px">
<div style="height:10px;font-size:2px">test<span id="inline">test</span></div>
<div id="absolute_relative_undefined"> </div>
</div>
</div>
<!-- Tests follow -->
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[
var testVar = 'to be updated';
new Test.Unit.Runner({
setup: function() {
scrollTo(0,0);
Position.prepare();
Position.includeScrollOffsets = false;
},
teardown: function() {
scrollTo(0,0);
Position.prepare();
Position.includeScrollOffsets = false;
},
testPrepare: function() {
Position.prepare();
this.assertEqual(0, Position.deltaX);
this.assertEqual(0, Position.deltaY);
scrollTo(20,30);
Position.prepare();
this.assertEqual(20, Position.deltaX);
this.assertEqual(30, Position.deltaY);
},
testWithin: function() {
[true, false].each(function(withScrollOffsets) {
Position.includeScrollOffsets = withScrollOffsets;
this.assert(!Position.within($('body_absolute'), 9, 9), 'outside left/top');
this.assert(Position.within($('body_absolute'), 10, 10), 'left/top corner');
this.assert(Position.within($('body_absolute'), 10, 19), 'left/bottom corner');
this.assert(!Position.within($('body_absolute'), 10, 20), 'outside bottom');
}, this);
scrollTo(20,30);
Position.prepare();
Position.includeScrollOffsets = true;
this.assert(!Position.within($('body_absolute'), 9, 9), 'outside left/top');
this.assert(Position.within($('body_absolute'), 10, 10), 'left/top corner');
this.assert(Position.within($('body_absolute'), 10, 19), 'left/bottom corner');
this.assert(!Position.within($('body_absolute'), 10, 20), 'outside bottom');
}
});
// ]]>
</script>
</body>
</html>