25 <script src=
"../../../resources/js-test.js"></script>
28 <div id=
"inert-div"></div>
30 <div id=
"dialog-div"></div>
33 description('Test for bug 110952. Ensure that mouse events are not ' +
34 'dispatched to an inert node. To test manually, move the mouse ' +
35 'to the blue box, click, and then move the mouse outside. Then ' +
36 'repeat for the red box. The test succeeds if both boxes turn ' +
39 function clickOn(element
)
41 if (!window
.eventSender
)
43 var rect
= element
.getBoundingClientRect();
44 eventSender
.mouseMoveTo(rect
.left
+ rect
.width
/ 2, rect
.top
+ rect
.height
/ 2);
45 eventSender
.mouseDown();
46 eventSender
.mouseUp();
47 eventSender
.mouseMoveTo(0, 0);
50 if (window
.testRunner
)
51 testRunner
.dumpAsText();
55 inertDivHandledEvent
= false;
56 inertDiv
= document
.getElementById('inert-div');
57 eventFiredOnInertNode = function(event
) {
58 inertDivHandledEvent
= true;
59 inertDiv
.style
.backgroundColor
= 'red';
62 events
= ['mousedown', 'mouseup', 'click', 'mousemove', 'mouseover', 'mouseout'];
63 dialogDiv
= document
.getElementById('dialog-div');
65 handledEvents
.dialogDiv
= {};
66 eventFiredOnDialog = function(event
) {
67 handledEvents
.dialogDiv
[event
.type
] = true;
68 if (Object
.keys(handledEvents
.dialogDiv
).length
== events
.length
)
69 dialogDiv
.style
.backgroundColor
= 'green';
72 handledEvents
.document
= {};
73 expectedEventCountForDocument
= events
.length
- 1; // document won't get 'mouseout'
74 eventFiredOnDocument = function(event
) {
75 handledEvents
.document
[event
.type
] = true;
76 if (Object
.keys(handledEvents
.document
).length
== document
.expectedEventCount
&& !inertDivHandledEvent
)
77 inertDiv
.style
.backgroundColor
= 'green';
80 for (var i
= 0; i
< events
.length
; ++i
) {
81 inertDiv
.addEventListener(events
[i
], eventFiredOnInertNode
);
82 dialogDiv
.addEventListener(events
[i
], eventFiredOnDialog
);
83 document
.addEventListener(events
[i
], eventFiredOnDocument
);
86 debug('Clicking on inert box');
88 shouldBeFalse('inertDivHandledEvent');
89 shouldBe('Object.keys(handledEvents.document).length', 'expectedEventCountForDocument');
91 debug('Clicking on non-inert box');
93 shouldBeFalse('inertDivHandledEvent');
94 shouldBe('Object.keys(handledEvents.dialogDiv).length', 'events.length');