Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / dispatch-mouse-events-to-window-always.html
blob8ac3fd28515ca565a46eb3cffeabfa2fb4240b7c
1 <!DOCTYPE html>
2 <style>
3 * {
4 padding: 0;
5 margin: 0;
8 ::-webkit-scrollbar {
9 display: none;
12 html, body {
13 height: 400px;
14 width: 400px;
15 background: #eee;
16 padding: 0;
17 margin: 0;
20 div#child {
21 position: absolute;
22 top : 0;
23 left: 400px;
24 width: 400px;
25 height: 10000px;
26 background: #ddd;
29 </style>
31 <body>
32 <div id='child'></div>
33 <div id='console'></div>
34 </body>
36 <script src="../../resources/js-test.js"></script>
37 <script>
38 jsTestIsAsync = true;
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.');
43 onload = function() {
44 if (!window.eventSender) {
45 testFailed('window.eventSender is required for this test.');
46 return;
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]);
67 finishJSTest();
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;}));
99 </script>