servo/tests/wpt/css-tests/css-regions-1_dev/xhtml1/mouse-events-005.xht

191 lines
No EOL
4.4 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head>
<meta charset="UTF-8" />
<title>CSS Regions: Adding and removing regions on mouse events</title>
<link href="mailto:mibalan@adobe.com" rel="author" title="Mihai Balan" />
<link href="http://www.w3.org/TR/css3-regions/#the-flow-into-property" rel="help" />
<link href="http://www.w3.org/TR/css3-regions/#flow-from" rel="help" />
<meta content="Altering the region chain via DOM manipulation in response to user gestures should not change the rendering of the content inside regions" name="assert" />
<meta content="interact" name="flags" />
<style>
body {
margin: 0;
padding: 20px;
}
p {
margin: 0;
}
.box {
width: 200px;
height: 200px;
float: left;
margin: 20px;
position: absolute;
}
.smallbox {
width: 200px;
height: 90px;
float: left;
margin: 20px;
position: absolute;
}
#wrapper {
position: relative;
height: 240px;
}
#content {
background-color: lightcyan;
top: 0;
left: 0;
}
#content p {
margin-bottom: 10px;
width: 100%;
height: 80px;
flow-into: flow;
}
.region {
flow-from: flow;
}
.region p {
margin-top: 100px;
width: 100%;
height: 100px;
background-color: red;
}
.first-region {
top: 0;
left: 33%;
}
.second-region {
top: 0;
left: 66%;
}
#result {
font-weight: bold;
}
.pass {
color: green;
}
.fail {
color: red;
}
.clickable {
background-color: yellow;
}
.phase0 {
background-color: green;
}
.phase1 {
background-color: seagreen;
}
.phase2 {
background-color: lime;
}
.phase3 {
background-color: lightgreen;
}
</style>
</head>
<body>
The test fails if you see any red, the text "FAIL" below the three rectangles below or if any of the expected results below don't happen.
<ol>
<li>Move the mouse over the yellow rectangle on the right. <strong>Expected: </strong>The green rectangle in the middle should change to a lighter green.</li>
<li>Click in the yellow rectangle. <strong>Expected: </strong>The green rectangle in the middle should change again to a yet lighter green.</li>
<li>Move the mouse out from the yellow rectangle.</li>
<li><strong>Expected: </strong>The color of the green rectangle should change yet again to a pale green. There should be a green text below that says "PASS".</li>
</ol>
<div id="wrapper">
<div id="content" class="box">
<p></p>
<p class="clickable"></p>
</div>
<div class="first-region region smallbox phase0">
<p></p>
</div>
<div class="second-region region box">
<p></p>
</div>
</div>
<div id="result"></div>
<script type="text/javascript">
var events = [ {
name: "mouseover",
hit: false
}, {
name: "click",
hit: false
}, {
name: "mouseout",
hit: false
} ],
target = document.querySelector("#content"),
callCount = 0;
function setResult(value) {
var tag = document.querySelector("#result");
tag.innerHTML = value;
tag.classList.add(value.toLowerCase());
}
function finishTest() {
if (window.testRunner) {
testRunner.notifyDone();
}
}
function handlerForEvent(eventName, index) {
return function(evt) {
if ((evt.target === evt.currentTarget) || (events[index].hit))
return;
callCount++;
events[index].hit = true;
var nodeToRemove = document.querySelector(".first-region"),
nodeParent = nodeToRemove.parentNode;
nodeParent.removeChild(nodeToRemove);
document.body.offsetTop;
var newNode = document.createElement("div");
newNode.classList.add("first-region", "region", "smallbox", "phase" + callCount);
nodeParent.insertBefore(newNode, document.querySelector(".second-region"));
document.body.offsetTop;
if (callCount == 3) {
setResult("PASS");
finishTest();
}
}
}
function runScript() {
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
var boxLocation = document.querySelector(".second-region").getBoundingClientRect();
eventSender.mouseMoveTo(boxLocation.left + 40, boxLocation.top + 50);
eventSender.mouseDown();
eventSender.mouseUp();
eventSender.mouseMoveTo(boxLocation.left + boxLocation.width - 40, boxLocation.top + boxLocation.height - 40);
eventSender.mouseDown();
eventSender.mouseUp();
}
}
events.forEach(function(item, index) {
target.addEventListener(item.name, handlerForEvent(item, index));
});
runScript();
</script>
</body></html>