gecko/layout/generic/test/window_selection_scrolling.html

1486 lines
52 KiB
HTML

<!DOCTYPE>
<html>
<head>
<title>selection scrolling test</title>
<script type="text/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<style type="text/css">
/* this is opened in 300px x 300px window */
#container {
width: 500px;
height: 500px;
}
#fixed {
position: fixed;
left: 30px;
right: 30px;
top: 30px;
bottom: 30px;
overflow: auto;
border: blue 1px solid;
}
#static_overflow {
margin: 30px;
width: 200px;
height: 200px;
overflow: auto;
border: orange 1px solid;
}
#static_overflow_inner {
margin: 30px;
width: 300px;
height: 300px;
overflow: auto;
border: red 1px solid;
}
#iframe {
margin: 30px;
width: 300px;
height: 300px;
}
#iframe2 {
margin: 70px;
width: 150px;
height: 150px;
}
#textarea {
margin: 30px;
width: 100px;
height: 100px;
}
.overflow_contents {
width: 400px;
height: 400px;
}
</style>
</head>
<body onunload="onUnload();">
<div id="container">
<div id="fixed">
<div class="overflow_contents"></div>
</div>
<input id="input" value="">
<div id="static_overflow">
<div id="static_overflow_contents" class="overflow_contents">
<div id="static_overflow_inner">
<div class="overflow_contents"></div>
</div>
<iframe id="iframe"
src="data:text/html,<div style='height:400px; width:400px;'></div>"></iframe>
</div>
</div>
<textarea id="textarea">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15</textarea>
<iframe id="iframe2"
src="data:text/html,<div style='height:400px; width:400px;'></div>"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
var body = document.body;
var div_fixed = document.getElementById("fixed");
var div_subframe1 = document.getElementById("static_overflow");
var div_subframe2 = document.getElementById("static_overflow_inner");
var iframe = document.getElementById("iframe");
var input = document.getElementById("input");
var textarea = document.getElementById("textarea");
var iframe2 = document.getElementById("iframe2");
function getBodyOfIframe(aIframe)
{
return aIframe.contentDocument.body;
}
function getScrollRightMost(aElement)
{
return aElement.scrollWidth - aElement.clientWidth;
}
function getScrollBottomMost(aElement)
{
return aElement.scrollHeight - aElement.clientHeight;
}
function getHeight(aElement)
{
return aElement.getBoundingClientRect().height;
}
function getWidth(aElement)
{
return aElement.getBoundingClientRect().width;
}
function ok(aCondition, aDesc)
{
window.opener.SimpleTest.ok(aCondition, aDesc);
}
function is(aLeft, aRight, aDesc)
{
window.opener.SimpleTest.is(aLeft, aRight, aDesc);
}
function isnot(aLeft, aRight, aDesc)
{
window.opener.SimpleTest.isnot(aLeft, aRight, aDesc);
}
/**
* gTests
*
* description:
* String, required.
* This is used for logs of tests.
*
* prepare:
* Function, optional.
* This is called before test(). You can initialize something in this
* function.
*
* test:
* Function, required.
* This is called after prepare() by timer. If all of its jobs are done,
* return true. Otherwise, e.g., some elements have never been ready yet,
* return false. Then, the caller recall test() after some delay.
* If this returns false many times, the test will be marked as failed.
*
* resetAllElementsBeforeTest:
* Boolean, required.
* If all elements should be reintialized, e.g., all elements should be
* hidden, all elements should be reset the scroll position, set true.
* Otherwise, false. Typically, true is set by first test of consecutive
* similar tests.
*
* testTarget:
* Function, required.
* The function must return an element which should be checked the
* scroll position at the end of the test.
*
* expectedScrollTop:
* Function, required.
* This function must return expected Y position of the testTarget().
*
* expectedScrollLeft:
* Function, required.
* This function must return expected X position of the testTarget().
*
* scrollIsExpected:
* Boolean, required.
* This means whether the test() should cause the testTarget scrolling.
* If the target should be scrolled, set true. Otherwise, set false.
*/
var gTestingIndex = -1;
var gTests = [
// Scroll the selection root (body) element
// visible scrollable elements: body
{
description: "Selection root (body) element should be scrolled by moving mouse to right of body",
test: function () {
synthesizeMouse(body, 100, 100, { type: "mousedown" });
synthesizeMouse(body, 400, 100, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return body; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return getScrollRightMost(body); },
scrollIsExpected: true,
},
{
description: "Selection root (body) element should be scrolled by moving mouse to left of body",
test: function () {
synthesizeMouse(body, 100, 100, { type: "mousedown" });
synthesizeMouse(body, -100, 100, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return body; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "Selection root (body) element should be scrolled by moving mouse to bottom of body",
test: function () {
synthesizeMouse(body, 100, 100, { type: "mousedown" });
synthesizeMouse(body, 100, 400, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return body; },
expectedScrollTop: function () { return getScrollBottomMost(body); },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "Selection root (body) element should be scrolled by moving mouse to top of body",
test: function () {
synthesizeMouse(body, 100, 100, { type: "mousedown" });
synthesizeMouse(body, 100, -100, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return body; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
// Don't scroll the selection root (body) element on its edge
// visible scrollable elements: body
{
description: "Selection root (body) element should NOT be scrolled by moving mouse to right edge of body",
prepare: function () {
body.scrollTop = 50;
body.scrollLeft = 50;
},
test: function () {
synthesizeMouse(body, 100, 100, { type: "mousedown" });
synthesizeMouse(body, body.clientWidth - 10, 100, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return body; },
expectedScrollTop: function () { return 50; },
expectedScrollLeft: function () { return 50; },
scrollIsExpected: false,
},
{
description: "Selection root (body) element should NOT be scrolled by moving mouse to left edge of body",
test: function () {
synthesizeMouse(body, 100, 100, { type: "mousedown" });
synthesizeMouse(body, 100, body.clientHeight - 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return body; },
expectedScrollTop: function () { return 50; },
expectedScrollLeft: function () { return 50; },
scrollIsExpected: false,
},
{
description: "Selection root (body) element should NOT be scrolled by moving mouse to bottom edge of body",
test: function () {
synthesizeMouse(body, 100, 100, { type: "mousedown" });
synthesizeMouse(body, 100, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return body; },
expectedScrollTop: function () { return 50; },
expectedScrollLeft: function () { return 50; },
scrollIsExpected: false,
},
{
description: "Selection root (body) element should NOT be scrolled by moving mouse to top edge of body",
test: function () {
synthesizeMouse(body, 100, 100, { type: "mousedown" });
synthesizeMouse(body, 10, 100, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return body; },
expectedScrollTop: function () { return 50; },
expectedScrollLeft: function () { return 50; },
scrollIsExpected: false,
},
// Scroll fixed div on its edge (from fixed div)
// visible scrollable elements: body, div_fixed
{
description: "The fixed div element should be scrolled by moving mouse from inner of it to its right edge",
prepare: function () {
div_fixed.style.display = "block";
},
test: function () {
synthesizeMouse(div_fixed, 50, 50, { type: "mousedown" });
synthesizeMouse(div_fixed, div_fixed.clientWidth - 10, 50,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return div_fixed; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return getScrollRightMost(div_fixed); },
scrollIsExpected: true,
},
{
description: "The fixed div element should be scrolled by moving mouse from inner of it to its left edge",
test: function () {
synthesizeMouse(div_fixed, 50, 50, { type: "mousedown" });
synthesizeMouse(div_fixed, 10, 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_fixed; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The fixed div element should be scrolled by moving mouse from inner of it to its bottom edge",
test: function () {
synthesizeMouse(div_fixed, 50, 50, { type: "mousedown" });
synthesizeMouse(div_fixed, 50, div_fixed.clientHeight - 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_fixed; },
expectedScrollTop: function () { return getScrollBottomMost(div_fixed); },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The fixed div element should be scrolled by moving mouse from inner of it to its top edge",
test: function () {
synthesizeMouse(div_fixed, 50, 50, { type: "mousedown" });
synthesizeMouse(div_fixed, 50, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_fixed; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
// Don't scroll fixed div by the cursor moved outside (from fixed_div)
// visible scrollable elements: body, div_fixed
{
description: "The fixed div element should NOT be scrolled by moving mouse from inner of it to right outside of it",
prepare: function () {
div_fixed.style.display = "block";
div_fixed.scrollTop = 30;
div_fixed.scrollLeft = 30;
},
test: function () {
synthesizeMouse(div_fixed, 50, 50, { type: "mousedown" });
synthesizeMouse(div_fixed, getWidth(div_fixed) + 10, 100,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return div_fixed; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
{
description: "The fixed div element should NOT be scrolled by moving mouse from inner of it to left outside of it",
test: function () {
synthesizeMouse(div_fixed, 50, 50, { type: "mousedown" });
synthesizeMouse(div_fixed, -10, 100, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_fixed; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
{
description: "The fixed div element should NOT be scrolled by moving mouse from inner of it to below outside of it",
test: function () {
synthesizeMouse(div_fixed, 50, 50, { type: "mousedown" });
synthesizeMouse(div_fixed, 100, getHeight(div_fixed) + 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_fixed; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
{
description: "The fixed div element should NOT be scrolled by moving mouse from inner of it to upper outside of it",
test: function () {
synthesizeMouse(div_fixed, 50, 50, { type: "mousedown" });
synthesizeMouse(div_fixed, 100, -10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_fixed; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
// Scroll fixed div on its edge (from body)
// visible scrollable elements: body, div_fixed
{
description: "The fixed div element should be scrolled by moving mouse from body to the right edge of the fixed div",
prepare: function () {
div_fixed.style.display = "block";
},
test: function () {
synthesizeMouse(div_fixed, -5, -5, { type: "mousedown" });
synthesizeMouse(div_fixed, div_fixed.clientWidth - 10, 50,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return div_fixed; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return getScrollRightMost(div_fixed); },
scrollIsExpected: true,
},
{
description: "The fixed div element should be scrolled by moving mouse from body to the left edge of the fixed div",
test: function () {
synthesizeMouse(div_fixed, -5, -5, { type: "mousedown" });
synthesizeMouse(div_fixed, 10, 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_fixed; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The fixed div element should be scrolled by moving mouse from body to the bottom edge of the fixed div",
test: function () {
synthesizeMouse(div_fixed, -5, -5, { type: "mousedown" });
synthesizeMouse(div_fixed, 50, div_fixed.clientHeight - 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_fixed; },
expectedScrollTop: function () { return getScrollBottomMost(div_fixed); },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The fixed div element should be scrolled by moving mouse from body to the top edge of the fixed div",
test: function () {
synthesizeMouse(div_fixed, -5, -5, { type: "mousedown" });
synthesizeMouse(div_fixed, 50, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_fixed; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
// Scroll subframe1 on its edge (from subframe1)
// visible scrollable elements: body, div_subframe1
{
description: "The scrollable div element (subframe1) should be scrolled by moving mouse from inner of it to its right edge",
prepare: function () {
div_subframe1.style.display = "block";
},
test: function () {
synthesizeMouse(div_subframe1, 50, 50, { type: "mousedown" });
synthesizeMouse(div_subframe1, div_subframe1.clientWidth - 10, 50,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return getScrollRightMost(div_subframe1); },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled by moving mouse from inner of it to its left edge",
test: function () {
synthesizeMouse(div_subframe1, 50, 50, { type: "mousedown" });
synthesizeMouse(div_subframe1, 10, 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled by moving mouse from inner of it to its bottom edge",
test: function () {
synthesizeMouse(div_subframe1, 50, 50, { type: "mousedown" });
synthesizeMouse(div_subframe1, 50, div_subframe1.clientHeight - 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return getScrollBottomMost(div_subframe1); },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled by moving mouse from inner of it to its top edge",
test: function () {
synthesizeMouse(div_subframe1, 50, 50, { type: "mousedown" });
synthesizeMouse(div_subframe1, 50, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
// Don't scroll div_subframe1 by the cursor moved outside (from div_subframe1)
// visible scrollable elements: body, div_subframe1
{
description: "The scrollable div element (subframe1) should NOT be scrolled by moving mouse from inner of it to right outside of it",
prepare: function () {
div_subframe1.style.display = "block";
div_subframe1.scrollTop = 30;
div_subframe1.scrollLeft = 30;
},
test: function () {
synthesizeMouse(div_subframe1, 50, 50, { type: "mousedown" });
synthesizeMouse(div_subframe1, getWidth(div_subframe1) + 10, 100,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
{
description: "The scrollable div element (subframe1) should NOT be scrolled by moving mouse from inner of it to left outside of it",
test: function () {
synthesizeMouse(div_subframe1, 50, 50, { type: "mousedown" });
synthesizeMouse(div_subframe1, -10, 100, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
{
description: "The scrollable div element (subframe1) should NOT be scrolled by moving mouse from inner of it to below outside of it",
test: function () {
synthesizeMouse(div_subframe1, 50, 50, { type: "mousedown" });
synthesizeMouse(div_subframe1, 100, getHeight(div_subframe1) + 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
{
description: "The scrollable div element (subframe1) should NOT be scrolled by moving mouse from inner of it to upper outside of it",
test: function () {
synthesizeMouse(div_subframe1, 50, 50, { type: "mousedown" });
synthesizeMouse(div_subframe1, 100, -10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
// Scroll subframe1 on its edge (from body)
// visible scrollable elements: body, div_subframe1
{
description: "The scrollable div element (subframe1) should be scrolled by moving mouse from body to the right edge of the div element",
prepare: function () {
div_subframe1.style.display = "block";
},
test: function () {
synthesizeMouse(div_subframe1, -5, -5, { type: "mousedown" });
synthesizeMouse(div_subframe1, div_subframe1.clientWidth - 10, 50,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return getScrollRightMost(div_subframe1); },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled by moving mouse from body to the left edge of the div element",
test: function () {
synthesizeMouse(div_subframe1, -5, -5, { type: "mousedown" });
synthesizeMouse(div_subframe1, 10, 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled by moving mouse from body to the bottom edge of the div element",
test: function () {
synthesizeMouse(div_subframe1, -5, -5, { type: "mousedown" });
synthesizeMouse(div_subframe1, 50, div_subframe1.clientHeight - 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return getScrollBottomMost(div_subframe1); },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled by moving mouse from body to the top edge of the div element",
test: function () {
synthesizeMouse(div_subframe1, -5, -5, { type: "mousedown" });
synthesizeMouse(div_subframe1, 50, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
// Scroll subframe1 even if subframe2 is moved under the cursor
// visible scrollable elements: body, div_subframe1, div_subframe2
{
description: "The scrollable div element (subframe1) should be scrolled even if another scrollable div element (subframe2) is moved under the cursor #1",
prepare: function () {
div_subframe1.style.display = "block";
div_subframe2.style.display = "block";
},
test: function () {
synthesizeMouse(div_subframe1, 5, 5, { type: "mousedown" });
synthesizeMouse(div_subframe1, div_subframe1.clientWidth - 10, 50,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return getScrollRightMost(div_subframe1); },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled even if another scrollable div element (subframe2) is moved under the cursor #2",
test: function () {
synthesizeMouse(div_subframe1, div_subframe1.clientWidth - 10, 5,
{ type: "mousedown" });
synthesizeMouse(div_subframe1, 10, 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled even if another scrollable div element (subframe2) is moved under the cursor #3",
test: function () {
synthesizeMouse(div_subframe1, 5, 5, { type: "mousedown" });
synthesizeMouse(div_subframe1, 50, div_subframe1.clientHeight - 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return getScrollBottomMost(div_subframe1); },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled even if another scrollable div element (subframe2) is moved under the cursor #4",
test: function () {
synthesizeMouse(div_subframe1, 5, div_subframe1.clientHeight - 10,
{ type: "mousedown" });
synthesizeMouse(div_subframe1, 50, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
// Scroll subframe1 even if iframe is moved under the cursor
// visible scrollable elements: body, div_subframe1, iframe
{
description: "The scrollable div element (subframe1) should be scrolled even if iframe element is moved under the cursor #1",
prepare: function () {
div_subframe1.style.display = "block";
iframe.style.display = "block";
},
test: function () {
synthesizeMouse(div_subframe1, 5, 5, { type: "mousedown" });
synthesizeMouse(div_subframe1, div_subframe1.clientWidth - 10, 50,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return getScrollRightMost(div_subframe1); },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled even if iframe element is moved under the cursor #2",
test: function () {
synthesizeMouse(div_subframe1, div_subframe1.clientWidth - 10, 5,
{ type: "mousedown" });
synthesizeMouse(div_subframe1, 10, 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled even if iframe element is moved under the cursor #3",
test: function () {
synthesizeMouse(div_subframe1, 5, 5, { type: "mousedown" });
synthesizeMouse(div_subframe1, 50, div_subframe1.clientHeight - 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return getScrollBottomMost(div_subframe1); },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled even if iframe element is moved under the cursor #4",
test: function () {
synthesizeMouse(div_subframe1, 5, div_subframe1.clientHeight - 10,
{ type: "mousedown" });
synthesizeMouse(div_subframe1, 50, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
// Don't scroll subframe1 when selecting in input
// visible scrollable elements: body, input, div_subframe1
{
description: "The scrollable div element (subframe1) should NOT be scrolled when dragging for selection is started in input element (cursor is moved to right edge)",
prepare: function () {
div_subframe1.style.display = "block";
input.style.display = "inline";
div_subframe1.scrollTop = 30;
div_subframe1.scrollLeft = 30;
},
test: function () {
synthesizeMouse(input, 10, 10, { type: "mousedown" });
synthesizeMouse(div_subframe1, div_subframe1.clientWidth - 10, 50,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
{
description: "The scrollable div element (subframe1) should NOT be scrolled when dragging for selection is started in input element (cursor is moved to left edge)",
test: function () {
synthesizeMouse(input, 10, 10, { type: "mousedown" });
synthesizeMouse(div_subframe1, 10, 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
{
description: "The scrollable div element (subframe1) should NOT be scrolled when dragging for selection is started in input element (cursor is moved to bottom edge)",
test: function () {
synthesizeMouse(input, 10, 10, { type: "mousedown" });
synthesizeMouse(div_subframe1, 50, div_subframe1.clientHeight - 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
{
description: "The scrollable div element (subframe1) should NOT be scrolled when dragging for selection is started in input element (cursor is moved to top edge)",
test: function () {
synthesizeMouse(input, 10, 10, { type: "mousedown" });
synthesizeMouse(div_subframe1, 50, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
// Don't scroll textarea when selecting body
// visible scrollable elements: body, textarea
{
description: "The textarea element should NOT be scrolled when dragging for selection is started in body element (cursor is moved to bottom edge)",
prepare: function () {
textarea.style.display = "inline";
textarea.scrollTop = 30;
},
test: function () {
if (textarea.scrollTop != 30) {
textarea.scrollTop = 30;
return false;
}
synthesizeMouse(body, 10, 10, { type: "mousedown" });
synthesizeMouse(textarea, 50, textarea.clientHeight - 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return textarea; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: false,
},
{
description: "The textarea element should NOT be scrolled when dragging for selection is started in body element (cursor is moved to top edge)",
test: function () {
synthesizeMouse(body, 10, 10, { type: "mousedown" });
synthesizeMouse(textarea, 50, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return textarea; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: false,
},
// Scroll the textarea element
// visible scrollable elements: body, textarea
{
description: "The textarea element should be scrolled by moving mouse to below outside of it",
prepare: function () {
textarea.style.display = "inline";
},
test: function () {
synthesizeMouse(textarea, 50, 50, { type: "mousedown" });
synthesizeMouse(textarea, 50, getHeight(textarea) + 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return textarea; },
expectedScrollTop: function () { return getScrollBottomMost(textarea); },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The textarea element should be scrolled by moving mouse to upper outside of it",
test: function () {
synthesizeMouse(textarea, 50, 50, { type: "mousedown" });
synthesizeMouse(textarea, 50, -50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return textarea; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
// Don't scroll the textarea element on its edge
// visible scrollable elements: body, textarea
{
description: "The textarea element should NOT be scrolled by moving mouse to its bottom edge",
prepare: function () {
textarea.style.display = "inline";
textarea.scrollTop = 30;
},
test: function () {
if (textarea.scrollTop != 30) {
textarea.scrollTop = 30;
return false;
}
synthesizeMouse(textarea, 50, 50, { type: "mousedown" });
synthesizeMouse(textarea, 50, textarea.clientHeight - 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return textarea; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: false,
},
{
description: "The textarea element should NOT be scrolled by moving mouse to its top edge",
test: function () {
synthesizeMouse(textarea, 50, 50, { type: "mousedown" });
synthesizeMouse(textarea, 50, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return textarea; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: false,
},
// Don't scroll iframe when selecting parent's body
// visible scrollable elements: body, iframe (child of body)
{
description: "The iframe element should NOT be scrolled when dragging for selection is started from its parent's body element (cursor is moved to the right edge of the iframe)",
prepare: function () {
iframe2.style.display = "inline";
getBodyOfIframe(iframe2).scrollTop = 50;
getBodyOfIframe(iframe2).scrollLeft = 50;
},
test: function () {
synthesizeMouse(body, 10, 10, { type: "mousedown" });
synthesizeMouse(iframe2, iframe2.clientWidth - 10, 100,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return getBodyOfIframe(iframe2); },
expectedScrollTop: function () { return 50; },
expectedScrollLeft: function () { return 50; },
scrollIsExpected: false,
},
{
description: "The iframe element should NOT be scrolled when dragging for selection is started from its parent's body element (cursor is moved to the left edge of the iframe)",
test: function () {
synthesizeMouse(body, 10, 10, { type: "mousedown" });
synthesizeMouse(iframe2, 10, 100, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return getBodyOfIframe(iframe2); },
expectedScrollTop: function () { return 50; },
expectedScrollLeft: function () { return 50; },
scrollIsExpected: false,
},
{
description: "The iframe element should NOT be scrolled when dragging for selection is started from its parent's body element (cursor is moved to the bottom edge of the iframe)",
test: function () {
synthesizeMouse(body, 10, 10, { type: "mousedown" });
synthesizeMouse(iframe2, 100, iframe2.clientHeight - 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return getBodyOfIframe(iframe2); },
expectedScrollTop: function () { return 50; },
expectedScrollLeft: function () { return 50; },
scrollIsExpected: false,
},
{
description: "The iframe element should NOT be scrolled when dragging for selection is started from its parent's body element (cursor is moved to the top edge of the iframe)",
test: function () {
synthesizeMouse(body, 100, 100, { type: "mousedown" });
synthesizeMouse(iframe2, 100, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return getBodyOfIframe(iframe2); },
expectedScrollTop: function () { return 50; },
expectedScrollLeft: function () { return 50; },
scrollIsExpected: false,
},
// Scroll the iframe element when cursor is outside of it
// visible scrollable elements: body, iframe (child of body)
{
description: "The iframe element should be scrolled by moving mouse to right outside of it",
prepare: function () {
iframe2.style.display = "inline";
},
test: function () {
synthesizeMouse(iframe2, 50, 50, { type: "mousedown" });
synthesizeMouse(iframe2, getWidth(iframe2) + 50, 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return getBodyOfIframe(iframe2); },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return getScrollRightMost(this.testTarget()); },
scrollIsExpected: true,
},
{
description: "The iframe element should be scrolled by moving mouse to left outside of it",
test: function () {
synthesizeMouse(iframe2, 50, 50, { type: "mousedown" });
synthesizeMouse(iframe2, -50, 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return getBodyOfIframe(iframe2); },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The iframe element should be scrolled by moving mouse to below outside of it",
test: function () {
synthesizeMouse(iframe2, 50, 50, { type: "mousedown" });
synthesizeMouse(iframe2, 50, getHeight(iframe2) + 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return getBodyOfIframe(iframe2); },
expectedScrollTop: function () { return getScrollBottomMost(this.testTarget()); },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The iframe element should be scrolled by moving mouse to upper outside of it",
test: function () {
synthesizeMouse(iframe2, 50, 50, { type: "mousedown" });
synthesizeMouse(iframe2, 50, -50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return getBodyOfIframe(iframe2); },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
// Don't scroll the iframe on its edge
// visible scrollable elements: body, iframe (child of body)
{
description: "The iframe element should NOT be scrolled by moving mouse to its right edge",
prepare: function () {
iframe2.style.display = "inline";
getBodyOfIframe(iframe2).scrollTop = 50;
getBodyOfIframe(iframe2).scrollLeft = 50;
},
test: function () {
synthesizeMouse(iframe2, 100, 100, { type: "mousedown" });
synthesizeMouse(iframe2, getBodyOfIframe(iframe2).clientWidth - 10, 100,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return getBodyOfIframe(iframe2); },
expectedScrollTop: function () { return 50; },
expectedScrollLeft: function () { return 50; },
scrollIsExpected: false,
},
{
description: "The iframe element should NOT be scrolled by moving mouse to its left edge",
test: function () {
synthesizeMouse(iframe2, 100, 100, { type: "mousedown" });
synthesizeMouse(iframe2, 10, 100, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return getBodyOfIframe(iframe2); },
expectedScrollTop: function () { return 50; },
expectedScrollLeft: function () { return 50; },
scrollIsExpected: false,
},
{
description: "The iframe element should NOT be scrolled by moving mouse to its bottom edge",
test: function () {
synthesizeMouse(iframe2, 100, 100, { type: "mousedown" });
synthesizeMouse(iframe2, 100, getBodyOfIframe(iframe2).clientHeight - 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return getBodyOfIframe(iframe2); },
expectedScrollTop: function () { return 50; },
expectedScrollLeft: function () { return 50; },
scrollIsExpected: false,
},
{
description: "The iframe element should NOT be scrolled by moving mouse to its top edge",
test: function () {
synthesizeMouse(iframe2, 100, 100, { type: "mousedown" });
synthesizeMouse(iframe2, 100, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return getBodyOfIframe(iframe2); },
expectedScrollTop: function () { return 50; },
expectedScrollLeft: function () { return 50; },
scrollIsExpected: false,
},
// Scroll the div_subframe1 when it captures mouse events and the cursor
// in outside of it.
// visible scrollable elements: body, div_subframe1
{
description: "The scrollable div element (subframe1) should be scrolled by moving mouse to right outside of it when it captures mouse events",
prepare: function () {
div_subframe1.style.display = "block";
div_subframe1.onmousedown = function () { div_subframe1.setCapture(); }
},
test: function () {
synthesizeMouse(div_subframe1, 50, 50, { type: "mousedown" });
synthesizeMouse(div_subframe1, getWidth(div_subframe1) + 50, 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return getScrollRightMost(div_subframe1); },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled by moving mouse to left outside of it when it captures mouse events",
test: function () {
synthesizeMouse(div_subframe1, 50, 50, { type: "mousedown" });
synthesizeMouse(div_subframe1, -50, 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled by moving mouse to below outside of it when it captures mouse events",
test: function () {
synthesizeMouse(div_subframe1, 50, 50, { type: "mousedown" });
synthesizeMouse(div_subframe1, 50, getHeight(div_subframe1) + 50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return getScrollBottomMost(div_subframe1); },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
{
description: "The scrollable div element (subframe1) should be scrolled by moving mouse to upper outside of it when it captures mouse events",
test: function () {
synthesizeMouse(div_subframe1, 50, 50, { type: "mousedown" });
synthesizeMouse(div_subframe1, 50, -50, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 0; },
expectedScrollLeft: function () { return 0; },
scrollIsExpected: true,
},
// Don't scroll the div_subframe1 when it captures mouse events and the
// cursor is on its edge.
// visible scrollable elements: body, div_subframe1
{
description: "The scrollable div element (subframe1) should NOT be scrolled by moving mouse to its right edge when it captures mouse events",
prepare: function () {
div_subframe1.style.display = "block";
div_subframe1.onmousedown = function () { div_subframe1.setCapture(); }
div_subframe1.scrollTop = 30;
div_subframe1.scrollLeft = 30;
},
test: function () {
synthesizeMouse(div_subframe1, 100, 100, { type: "mousedown" });
synthesizeMouse(div_subframe1, div_subframe1.clientWidth - 10, 100,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: true,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
{
description: "The scrollable div element (subframe1) should NOT be scrolled by moving mouse to its left edge when it captures mouse events",
test: function () {
synthesizeMouse(div_subframe1, 100, 100, { type: "mousedown" });
synthesizeMouse(div_subframe1, 10, 100, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
{
description: "The scrollable div element (subframe1) should NOT be scrolled by moving mouse to its bottom edge when it captures mouse events",
test: function () {
synthesizeMouse(div_subframe1, 100, 100, { type: "mousedown" });
synthesizeMouse(div_subframe1, 100, div_subframe1.clientHeight - 10,
{ type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
{
description: "The scrollable div element (subframe1) should NOT be scrolled by moving mouse to its top edge when it captures mouse events",
test: function () {
synthesizeMouse(div_subframe1, 100, 100, { type: "mousedown" });
synthesizeMouse(div_subframe1, 100, 10, { type: "mousemove" });
return true;
},
resetAllElementsBeforeTest: false,
testTarget: function () { return div_subframe1; },
expectedScrollTop: function () { return 30; },
expectedScrollLeft: function () { return 30; },
scrollIsExpected: false,
},
];
var gTimer;
const kTimeoutTimeForNonScrollingTest = 1000;
function initScrollEventHandler(aHandler)
{
document.onscroll = aHandler;
div_fixed.onscroll = aHandler;
div_subframe1.onscroll = aHandler;
div_subframe2.onscroll = aHandler;
iframe.contentDocument.onscroll = aHandler;
iframe2.contentDocument.onscroll = aHandler;
textarea.onscroll = aHandler;
}
function checkResult(aTimedOut)
{
var test = gTests[gTestingIndex];
if (test.scrollIsExpected) {
ok(!aTimedOut, test.description + ": timed out");
} else {
ok(aTimedOut, test.description + ": not timed out");
}
is(test.testTarget().scrollTop, test.expectedScrollTop(),
test.description + ": unexpected vertial scroll position");
is(test.testTarget().scrollLeft, test.expectedScrollLeft(),
test.description + ": unexpected horizontal scroll position");
cleanupTest();
}
function cleanupTest()
{
initScrollEventHandler(null);
synthesizeMouse(body, 10, 10, { type: "mouseup" });
runTests();
}
function onScroll(aEvent)
{
function getScrollEventTarget(aScrollElement)
{
return aScrollElement == aScrollElement.ownerDocument.body ?
aScrollElement.ownerDocument : aScrollElement;
}
var test = gTests[gTestingIndex];
if (aEvent.target != getScrollEventTarget(test.testTarget())) {
is(aEvent.target, getScrollEventTarget(test.testTarget()),
test.description + ": Unexpected element was scrolled");
return;
}
clearTimeout(gTimer);
gTimer = 0;
var expectedScrollPosition =
(test.testTarget().scrollTop == test.expectedScrollTop() &&
test.testTarget().scrollLeft == test.expectedScrollLeft());
if (test.scrollIsExpected) {
if (expectedScrollPosition) {
// scroll is finished
checkResult(false);
return;
}
// if this test failed, it would be timeout.
} else {
if (expectedScrollPosition) {
// XXX If the unexpected scroll event is for initialization, we should
// ignore this event.
gTimer = setTimeout(checkResult, kTimeoutTimeForNonScrollingTest, true);
return;
}
checkResult(false);
}
}
function doTest(aTest)
{
if (!aTest.test()) {
// retry until timeout
setTimeout(doTest, 0, aTest);
return;
}
initScrollEventHandler(onScroll);
if (aTest.scrollIsExpected) {
// if this test failed, it would be timeout.
} else {
gTimer = setTimeout(checkResult, kTimeoutTimeForNonScrollingTest, true);
}
}
function runTests()
{
if (++gTestingIndex == gTests.length) {
window.close();
return;
}
disableNonTestMouseEvents(true);
try {
window.getSelection().removeAllRanges();
} catch (e) { }
try {
iframe.contentWindow.getSelection().removeAllRanges();
} catch (e) { }
try {
iframe2.contentWindow.getSelection().removeAllRanges();
} catch (e) { }
var test = gTests[gTestingIndex];
if (test.resetAllElementsBeforeTest) {
body.scrollTop = 0;
body.scrollLeft = 0;
input.style.position = "static";
input.style.display = "none";
div_fixed.scrollTop = 0;
div_fixed.scrollLeft = 0;
div_fixed.style.display = "none";
div_subframe1.onmousedown = null;
div_subframe1.scrollTop = 0;
div_subframe1.scrollLeft = 0;
div_subframe1.style.display = "none";
div_subframe2.scrollTop = 0;
div_subframe2.scrollLeft = 0;
div_subframe2.style.display = "none";
getBodyOfIframe(iframe).scrollTop = 0;
getBodyOfIframe(iframe).scrollLeft = 0;
iframe.style.display = "none";
getBodyOfIframe(iframe2).scrollTop = 0;
getBodyOfIframe(iframe2).scrollLeft = 0;
iframe2.style.display = "none";
textarea.scrollTop = 0;
textarea.scrollLeft = 0;
textarea.style.display = "none";
}
if (test.prepare) {
test.prepare();
}
setTimeout(doTest, 0, test);
}
function onUnload()
{
is(gTestingIndex, gTests.length,
"Some tests are not tested");
disableNonTestMouseEvents(false);
window.opener.SimpleTest.finish();
}
window.opener.SimpleTest.waitForFocus(runTests, window);
</script>
</pre>
</body>
</html>