Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=633602 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Bug 633602 - file_retargetMouseEvents.html</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"> |
michael@0 | 9 | </script> |
michael@0 | 10 | <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 11 | <script type="application/javascript" src="pointerlock_utils.js"></script> |
michael@0 | 12 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 13 | </head> |
michael@0 | 14 | <body> |
michael@0 | 15 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633602"> |
michael@0 | 16 | Mozilla Bug 633602 |
michael@0 | 17 | </a> |
michael@0 | 18 | |
michael@0 | 19 | <div id="parent"> |
michael@0 | 20 | <div id="child" style="width: 100%; height: 100%;"> |
michael@0 | 21 | </div> |
michael@0 | 22 | </div> |
michael@0 | 23 | |
michael@0 | 24 | <pre id="test"> |
michael@0 | 25 | <script type="application/javascript"> |
michael@0 | 26 | /* |
michael@0 | 27 | * Test for Bug 633602 |
michael@0 | 28 | * Retarget mouse events to the locked element |
michael@0 | 29 | */ |
michael@0 | 30 | |
michael@0 | 31 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 32 | |
michael@0 | 33 | function MouseEventStats() { |
michael@0 | 34 | this.mouseMove = false; |
michael@0 | 35 | this.mouseDown = false; |
michael@0 | 36 | this.mouseUp = false; |
michael@0 | 37 | this.mouseClick = false; |
michael@0 | 38 | this.mouseScroll = false; |
michael@0 | 39 | this.wheel = false; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | var parent = document.getElementById("parent") |
michael@0 | 43 | , child = document.getElementById("child") |
michael@0 | 44 | , parentStats = new MouseEventStats() |
michael@0 | 45 | , childStats = new MouseEventStats(); |
michael@0 | 46 | |
michael@0 | 47 | function runTests () { |
michael@0 | 48 | is(childStats.mouseMove, false, "Child shound not receive mousemove event."); |
michael@0 | 49 | is(childStats.mouseDown, false, "Child should not receive mousedown event."); |
michael@0 | 50 | is(childStats.mouseUp, false, "Child should not receive mouseup event."); |
michael@0 | 51 | is(childStats.mouseClick, false, "Child should not receive click event."); |
michael@0 | 52 | is(childStats.mouseScroll, false, "Child should not receive DOMMouseScroll event."); |
michael@0 | 53 | is(childStats.wheel, false, "Child should not receive wheel event."); |
michael@0 | 54 | |
michael@0 | 55 | ok(parentStats.mouseMove, "Parent should receive mousemove event."); |
michael@0 | 56 | ok(parentStats.mouseDown, "Parent should receive mousedown event."); |
michael@0 | 57 | ok(parentStats.mouseUp, "Parent should receive mouseup event."); |
michael@0 | 58 | ok(parentStats.mouseClick, "Parent should receive click event."); |
michael@0 | 59 | ok(parentStats.mouseScroll, "Parent should receive DOMMouseScroll event."); |
michael@0 | 60 | ok(parentStats.wheel, "Parent should receive wheel event."); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * The event listeners for the child element shouldn't be fired |
michael@0 | 66 | * Mouse events will only happen when the pointer is locked |
michael@0 | 67 | * and if the pointer is locked all the mouse events should be |
michael@0 | 68 | * retargetted to the locked element |
michael@0 | 69 | **/ |
michael@0 | 70 | var childMoveTest = function() { |
michael@0 | 71 | childStats.mouseMove = true; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | var childDownTest = function() { |
michael@0 | 75 | childStats.mouseDown = true; |
michael@0 | 76 | }; |
michael@0 | 77 | |
michael@0 | 78 | var childUpTest = function() { |
michael@0 | 79 | childStats.mouseUp = true; |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | var childClickTest = function() { |
michael@0 | 83 | childStats.mouseClick = true; |
michael@0 | 84 | }; |
michael@0 | 85 | |
michael@0 | 86 | var childScrollTest = function() { |
michael@0 | 87 | childStats.mouseScroll = true; |
michael@0 | 88 | }; |
michael@0 | 89 | |
michael@0 | 90 | var childWheelTest = function() { |
michael@0 | 91 | childStats.wheel = true; |
michael@0 | 92 | }; |
michael@0 | 93 | |
michael@0 | 94 | // Event listeners for the parent element |
michael@0 | 95 | var startMouseTests = function() { |
michael@0 | 96 | parent.removeEventListener("mousemove", startMouseTests); |
michael@0 | 97 | parent.addEventListener("DOMMouseScroll", parentScrollTest); |
michael@0 | 98 | child.addEventListener("DOMMouseScroll", childScrollTest); |
michael@0 | 99 | synthesizeWheel(child, 5, 5, {'deltaY': 10, 'lineOrPageDeltaY': 10, |
michael@0 | 100 | 'deltaMode': WheelEvent.DOM_DELTA_LINE}); |
michael@0 | 101 | }; |
michael@0 | 102 | |
michael@0 | 103 | var parentScrollTest = function (e) { |
michael@0 | 104 | parentStats.mouseScroll = true; |
michael@0 | 105 | parent.removeEventListener("DOMMouseScroll", parentScrollTest); |
michael@0 | 106 | child.removeEventListener("DOMMouseScroll", childScrollTest); |
michael@0 | 107 | parent.addEventListener("wheel", parentWheelTest); |
michael@0 | 108 | child.addEventListener("wheel", childWheelTest); |
michael@0 | 109 | synthesizeWheel(child, 5, 5, {'deltaY': 10, 'lineOrPageDeltaY': 10, |
michael@0 | 110 | 'deltaMode': WheelEvent.DOM_DELTA_LINE}); |
michael@0 | 111 | }; |
michael@0 | 112 | |
michael@0 | 113 | var parentWheelTest = function (e) { |
michael@0 | 114 | parentStats.wheel = true; |
michael@0 | 115 | parent.removeEventListener("wheel", parentWheelTest); |
michael@0 | 116 | child.removeEventListener("wheel", childWheelTest); |
michael@0 | 117 | parent.addEventListener("mousedown", parentDownTest); |
michael@0 | 118 | child.addEventListener("mousedown", childDownTest); |
michael@0 | 119 | synthesizeMouseAtCenter(child, {type: "mousedown"}, window); |
michael@0 | 120 | }; |
michael@0 | 121 | |
michael@0 | 122 | var parentDownTest = function (e) { |
michael@0 | 123 | parentStats.mouseDown = true; |
michael@0 | 124 | parent.removeEventListener("mousedown", parentDownTest); |
michael@0 | 125 | child.removeEventListener("mousedown", childDownTest); |
michael@0 | 126 | parent.addEventListener("mouseup", parentUpTest); |
michael@0 | 127 | child.addEventListener("mouseup", childUpTest); |
michael@0 | 128 | synthesizeMouseAtCenter(child, {type: "mouseup"}, window); |
michael@0 | 129 | }; |
michael@0 | 130 | |
michael@0 | 131 | var parentUpTest = function (e) { |
michael@0 | 132 | parentStats.mouseUp = true; |
michael@0 | 133 | parent.removeEventListener("mouseup", parentUpTest); |
michael@0 | 134 | child.removeEventListener("mouseup", childUpTest); |
michael@0 | 135 | parent.addEventListener("click", parentClickTest); |
michael@0 | 136 | child.addEventListener("click", childClickTest); |
michael@0 | 137 | synthesizeMouseAtCenter(child, {type: "click"}, window); |
michael@0 | 138 | }; |
michael@0 | 139 | |
michael@0 | 140 | var parentClickTest = function (e) { |
michael@0 | 141 | parentStats.mouseClick = true; |
michael@0 | 142 | parent.removeEventListener("click", parentClickTest); |
michael@0 | 143 | child.removeEventListener("click", childClickTest); |
michael@0 | 144 | parent.addEventListener("mousemove", parentMoveTest); |
michael@0 | 145 | child.addEventListener("mousemove", childMoveTest); |
michael@0 | 146 | synthesizeMouseAtCenter(child, {type: "mousemove"}, window); |
michael@0 | 147 | }; |
michael@0 | 148 | |
michael@0 | 149 | var parentMoveTest = function (e) { |
michael@0 | 150 | parentStats.mouseMove = true; |
michael@0 | 151 | parent.removeEventListener("mousemove", parentMoveTest); |
michael@0 | 152 | child.removeEventListener("mousemove", childMoveTest); |
michael@0 | 153 | document.mozCancelFullScreen(); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | document.addEventListener("mozpointerlockchange", function (e) { |
michael@0 | 157 | if (document.mozPointerLockElement === parent) { |
michael@0 | 158 | parent.addEventListener("mousemove", startMouseTests); |
michael@0 | 159 | child.addEventListener("mousemove", childMoveTest); |
michael@0 | 160 | synthesizeMouseAtCenter(parent, {type: "mousemove"}, window); |
michael@0 | 161 | } |
michael@0 | 162 | }, false); |
michael@0 | 163 | |
michael@0 | 164 | document.addEventListener("mozfullscreenchange", function (e) { |
michael@0 | 165 | if (document.mozFullScreenElement === parent) { |
michael@0 | 166 | parent.mozRequestPointerLock(); |
michael@0 | 167 | } else { |
michael@0 | 168 | runTests(); |
michael@0 | 169 | SimpleTest.finish(); |
michael@0 | 170 | } |
michael@0 | 171 | }, false); |
michael@0 | 172 | |
michael@0 | 173 | function start() { |
michael@0 | 174 | parent.mozRequestFullScreen(); |
michael@0 | 175 | } |
michael@0 | 176 | </script> |
michael@0 | 177 | </pre> |
michael@0 | 178 | </body> |
michael@0 | 179 | </html> |