gecko/dom/tests/mochitest/general/test_domWindowUtils_scrollXY.html

68 lines
2.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>nsIDOMWindowUtils::elementFromPoint test</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
<style>
body {
/* Make room for scrolling */
width: 100000px;
height: 100000px;
}
</style>
</head>
<body id="body">
<p>Top</p>
<script type="application/javascript;version=1.8">
// Enable privileges so we can use nsIDOMWindowUtils interface
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var domWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
/*
void getScrollXY(in boolean aFlushLayout, out long aScrollX, out long aScrollY);
*/
function testScrollXY() {
function checkGetScrollXYState(flush, vals, testName) {
let scrollX = {}, scrollY = {};
domWindowUtils.getScrollXY(flush, scrollX, scrollY);
is(scrollX.value, vals[0], "getScrollXY x for test: " + testName);
is(scrollY.value, vals[1], "getScrollXY y for test: " + testName);
}
function checkWindowScrollState(vals, testName) {
is(window.scrollX, vals[0], "scrollX for test: " + testName);
is(window.scrollY, vals[1], "scrollY for test: " + testName);
}
// Check initial state (0, 0)
checkGetScrollXYState(false, [0, 0], "initial getScrollXY state");
checkGetScrollXYState(true, [0, 0], "initial getScrollXY state+flush");
checkWindowScrollState([0, 0], "initial window.scroll* state");
// scroll
window.scrollTo(900, 1000);
checkGetScrollXYState(false, [900, 1000], "after scroll getScrollXY state");
checkGetScrollXYState(true, [900, 1000], "after scroll getScrollXY state+flush");
checkWindowScrollState([900, 1000], "after scroll window.scroll* state");
// ensure flush=false works
document.body.style.width = 'auto';
document.body.style.height = 'auto';
checkGetScrollXYState(false, [900, 1000], "didn't flush layout for getScrollXY");
checkGetScrollXYState(true, [0, 0], "flushed layout for getScrollXY");
}
testScrollXY();
</script>
<p id="display"></p>
</body>
</html>