1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/test/bug426082.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,160 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=426082 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 426082</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.13 + <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script> 1.14 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.15 + <style> 1.16 + canvas { 1.17 + display: none; 1.18 + } 1.19 + </style> 1.20 +</head> 1.21 +<body onload="runTests()"> 1.22 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=426082">Mozilla Bug 426082</a> 1.23 +<p id="display"></p> 1.24 +<div id="content" style="display: none"> 1.25 + 1.26 +</div> 1.27 +<p><input type="button" value="Button" id="button"></p> 1.28 +<p><label for="button" id="label">Label</label></p> 1.29 +<p id="outside">Something under the label</p> 1.30 +<pre id="test"> 1.31 +<script type="application/javascript;version=1.8"> 1.32 + 1.33 +/** Test for Bug 426082 **/ 1.34 + 1.35 +var normalButtonCanvas, pressedButtonCanvas, normalFocusedButtonCanvas, 1.36 + pressedFocusedButtonCanvas, currentSnapshot, button, label, outside; 1.37 + 1.38 +function runTests() { 1.39 + button = $("button"); 1.40 + label = $("label"); 1.41 + outside = $("outside"); 1.42 + SimpleTest.executeSoon(executeTests); 1.43 +} 1.44 + 1.45 +function isRectContainedInRectFromRegion(rect, region) { 1.46 + return Array.some(region, function (r) { 1.47 + return rect.left >= r.left && 1.48 + rect.top >= r.top && 1.49 + rect.right <= r.right && 1.50 + rect.bottom <= r.bottom; 1.51 + }); 1.52 +} 1.53 + 1.54 +function paintListener(e) { 1.55 + if (isRectContainedInRectFromRegion(buttonRect(), SpecialPowers.wrap(e).clientRects)) { 1.56 + gNeedsPaint = false; 1.57 + currentSnapshot = takeSnapshot(); 1.58 + } 1.59 +} 1.60 + 1.61 +var gNeedsPaint = false; 1.62 +function executeTests() { 1.63 + var testYielder = tests(); 1.64 + function execNext() { 1.65 + try { 1.66 + if (!gNeedsPaint) { 1.67 + testYielder.next(); 1.68 + button.getBoundingClientRect(); // Flush. 1.69 + gNeedsPaint = true; 1.70 + } 1.71 + SimpleTest.executeSoon(execNext); 1.72 + } catch (e) {} 1.73 + } 1.74 + execNext(); 1.75 +} 1.76 + 1.77 +function tests() { 1.78 + window.addEventListener("MozAfterPaint", paintListener, false); 1.79 + normalButtonCanvas = takeSnapshot(); 1.80 + // Press the button. 1.81 + sendMouseEvent("mousemove", button); 1.82 + sendMouseEvent("mousedown", button); 1.83 + yield undefined; 1.84 + pressedFocusedButtonCanvas = takeSnapshot(); 1.85 + compareSnapshots_(normalButtonCanvas, pressedFocusedButtonCanvas, false, "Pressed focused buttons should look different from normal buttons."); 1.86 + // Release. 1.87 + sendMouseEvent("mouseup", button); 1.88 + yield undefined; 1.89 + // make sure the button is focused as this doesn't happen on click on Mac 1.90 + button.focus(); 1.91 + normalFocusedButtonCanvas = takeSnapshot(); 1.92 + compareSnapshots_(normalFocusedButtonCanvas, pressedFocusedButtonCanvas, false, "Pressed focused buttons should look different from normal focused buttons."); 1.93 + // Unfocus the button. 1.94 + sendMouseEvent("mousedown", outside); 1.95 + sendMouseEvent("mouseup", outside); 1.96 + yield undefined; 1.97 + 1.98 + // Press the label. 1.99 + sendMouseEvent("mousemove", label); 1.100 + sendMouseEvent("mousedown", label); 1.101 + yield undefined; 1.102 + compareSnapshots_(normalButtonCanvas, currentSnapshot, false, "Pressing the label should have pressed the button."); 1.103 + pressedButtonCanvas = takeSnapshot(); 1.104 + // Move the mouse down from the label. 1.105 + sendMouseEvent("mousemove", outside); 1.106 + yield undefined; 1.107 + compareSnapshots_(normalButtonCanvas, currentSnapshot, true, "Moving the mouse down from the label should have unpressed the button."); 1.108 + // ... and up again. 1.109 + sendMouseEvent("mousemove", label); 1.110 + yield undefined; 1.111 + compareSnapshots_(pressedButtonCanvas, currentSnapshot, true, "Moving the mouse back on top of the label should have pressed the button."); 1.112 + // Release. 1.113 + sendMouseEvent("mouseup", label); 1.114 + yield undefined; 1.115 + compareSnapshots_(normalFocusedButtonCanvas, currentSnapshot, true, "Releasing the mouse over the label should have unpressed (and focused) the button."); 1.116 + // Press the label and remove it. 1.117 + sendMouseEvent("mousemove", label); 1.118 + sendMouseEvent("mousedown", label); 1.119 + yield undefined; 1.120 + label.parentNode.removeChild(label); 1.121 + yield undefined; 1.122 + compareSnapshots_(normalButtonCanvas, currentSnapshot, true, "Removing the label should have unpressed the button."); 1.123 + sendMouseEvent("mouseup", label); 1.124 + window.removeEventListener("MozAfterPaint", paintListener, false); 1.125 + window.opener.finishTests(); 1.126 + } 1.127 + 1.128 +function sendMouseEvent(t, elem) { 1.129 + var r = elem.getBoundingClientRect(); 1.130 + synthesizeMouse(elem, r.width / 2, r.height / 2, {type: t}); 1.131 +} 1.132 + 1.133 +function compareSnapshots_(c1, c2, shouldBeIdentical, msg) { 1.134 + var [correct, c1url, c2url] = compareSnapshots(c1, c2, shouldBeIdentical); 1.135 + if (correct) { 1.136 + if (shouldBeIdentical) { 1.137 + window.opener.ok(true, msg + " - expected " + c1url); 1.138 + } else { 1.139 + window.opener.ok(true, msg + " - got " + c1url + " and " + c2url); 1.140 + } 1.141 + } else { 1.142 + if (shouldBeIdentical) { 1.143 + window.opener.ok(false, msg + " - expected " + c1url + " but got " + c2url); 1.144 + } else { 1.145 + window.opener.ok(false, msg + " - expected something other than " + c1url); 1.146 + } 1.147 + } 1.148 +} 1.149 + 1.150 +function takeSnapshot() { 1.151 + var r = buttonRect(); 1.152 + adjustedRect = { left: r.left - 2, top: r.top - 2, 1.153 + width: r.width + 4, height: r.height + 4 }; 1.154 + return SpecialPowers.snapshotRect(window, adjustedRect); 1.155 +} 1.156 + 1.157 +function buttonRect() { 1.158 + return button.getBoundingClientRect(); 1.159 +} 1.160 +</script> 1.161 +</pre> 1.162 +</body> 1.163 +</html>