bug426082.html (4081B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=426082 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 9 <title>Test for Bug 426082</title> 10 <script src="/tests/SimpleTest/SimpleTest.js"></script> 11 <script src="/tests/SimpleTest/EventUtils.js"></script> 12 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 13 </head> 14 <body> 15 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=426082">Mozilla Bug 426082</a> 16 <p id="display"></p> 17 <div id="content" style="display: none"> 18 </div> 19 <p><input type="button" value="Button" id="button"></p> 20 <p><label for="button" id="label">Label</label></p> 21 <p id="outside">Something under the label</p> 22 <pre id="test"> 23 <script type="application/javascript"> 24 25 /** Test for Bug 426082 */ 26 27 function runTests() { 28 SimpleTest.executeSoon(tests); 29 } 30 31 SimpleTest.waitForFocus(runTests); 32 33 function oneTick() { 34 return new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 35 } 36 37 function stringifyOpenTag(aElement) { 38 return aElement.cloneNode(false).outerHTML; 39 } 40 41 function sendMouseEvent(t, elem) { 42 info(`Synthesizing ${t} on ${stringifyOpenTag(elem)}`); 43 let r = elem.getBoundingClientRect(); 44 synthesizeMouse(elem, r.width / 2, r.height / 2, {type: t}); 45 } 46 47 async function tests() { 48 let button = document.getElementById("button"); 49 let label = document.getElementById("label"); 50 let outside = document.getElementById("outside"); 51 52 let is = window.opener.is; 53 let ok = window.opener.ok; 54 55 function logMouseEvent(aEvent) { 56 info(`${aEvent.type} (${aEvent.clientX}, ${aEvent.clientY}) on ${ 57 stringifyOpenTag(event.target) 58 } (scrollTop=${document.documentElement.scrollTop})`); 59 } 60 addEventListener("mouseover", logMouseEvent, {capture: true}); 61 addEventListener("mousedown", logMouseEvent, {capture: true}); 62 addEventListener("mousemove", logMouseEvent, {capture: true}); 63 64 // Press the label. 65 sendMouseEvent("mousemove", label); 66 sendMouseEvent("mousedown", label); 67 68 await oneTick(); 69 70 ok(label.matches(":hover"), "Label is hovered"); 71 ok(button.matches(":hover"), "Button should be hovered too"); 72 73 ok(label.matches(":active"), "Label is active"); 74 ok(button.matches(":active"), "Button should be active too"); 75 76 // Move the mouse down from the label. 77 sendMouseEvent("mousemove", outside); 78 79 await oneTick(); 80 81 ok(!label.matches(":hover"), "Label is no longer hovered"); 82 ok(!button.matches(":hover"), "Button should not be hovered too"); 83 84 ok(label.matches(":active"), "Label is still active"); 85 ok(button.matches(":active"), "Button is still active too"); 86 87 // And up again. 88 sendMouseEvent("mousemove", label); 89 90 await oneTick(); 91 92 93 ok(label.matches(":hover"), "Label hovered again"); 94 ok(button.matches(":hover"), "Button be hovered again"); 95 ok(label.matches(":active"), "Label is still active"); 96 ok(button.matches(":active"), "Button is still active too"); 97 98 // Release. 99 sendMouseEvent("mouseup", label); 100 101 await oneTick(); 102 103 ok(!label.matches(":active"), "Label is no longer active"); 104 ok(!button.matches(":active"), "Button is no longer active"); 105 106 ok(label.matches(":hover"), "Label is still hovered"); 107 ok(button.matches(":hover"), "Button is still hovered"); 108 109 // Press the label and remove it. 110 sendMouseEvent("mousemove", label); 111 sendMouseEvent("mousedown", label); 112 113 await oneTick(); 114 115 label.remove(); 116 117 await oneTick(); 118 119 ok(!label.matches(":active"), "Removing label should have unpressed it"); 120 ok(!label.matches(":focus"), "Removing label should have unpressed it"); 121 ok(!label.matches(":hover"), "Removing label should have unhovered it"); 122 ok(!button.matches(":active"), "Removing label should have unpressed the button"); 123 ok(!button.matches(":focus"), "Removing label should have unpressed the button"); 124 ok(!button.matches(":hover"), "Removing label should have unhovered the button"); 125 126 sendMouseEvent("mouseup", label); 127 window.opener.finishTests(); 128 } 129 </script> 130 </pre> 131 </body> 132 </html>