32 <div id='child'
></div>
33 <div id='console'
></div>
36 <script src=
"../../resources/js-test.js"></script>
39 setPrintTestResultsLazily();
40 description('Test that wheel and mouse events are dispatched to document ' +
41 'and window even if they do not hit any element in the page.');
44 if (!window
.eventSender
) {
45 testFailed('window.eventSender is required for this test.');
49 window
.receivers
= new Map();
50 var eventTypes
= ['wheel', 'click', 'mousedown', 'mouseup'];
51 var eventTargets
= [window
, document
, document
.body
, document
.getElementById('child')];
53 for (var eventType
of eventTypes
) {
54 window
.receivers
[eventType
] = [];
55 for (var target
of eventTargets
) {
56 target
.addEventListener(eventType
, registerEvent
.bind(target
));
60 debug('outside body, inside element'); // received by element, body, doc, window
61 generateEventsAndVerify(500, 500, [document
.getElementById('child'), document
.body
, document
, window
]);
62 debug('inside body, outside element'); // received by body, doc, window
63 generateEventsAndVerify(10, 10, [document
.body
, document
, window
]);
64 debug('outside body, outside element, inside frame'); // received by doc, window
65 generateEventsAndVerify(10, 500, [document
, window
]);
69 function registerEvent(e
) {
70 window
.receivers
[e
.type
].push(this);
73 function generateEventsAndVerify(x
, y
, expectedReceivers
) {
74 eventSender
.mouseMoveTo(x
, y
);
75 eventSender
.mouseDown();
76 verifyReceivers('mousedown', expectedReceivers
);
78 eventSender
.mouseUp();
79 verifyReceivers('mouseup', expectedReceivers
);
80 verifyReceivers('click', expectedReceivers
);
82 eventSender
.mouseScrollBy(10, 10);
83 verifyReceivers('wheel', expectedReceivers
);
86 function verifyReceivers(eventType
, expectedReceivers
) {
87 debug('eventType: ' + eventType
);
88 window
.actualReceivers
= window
.receivers
[eventType
];
89 shouldBeEqualToString('objectsToString(actualReceivers)', objectsToString(expectedReceivers
));
91 window
.receivers
[eventType
] = [];
95 function objectsToString(objects
) {
96 return String(objects
.map(function(o
) {return o
.constructor.name
;}));