9b3095a1511d654c11d015e28452fc3ef8e37858
[WebKit-https.git] / LayoutTests / fast / events / wheelevent-in-scrolling-div.html
1 <html>
2     <head>
3         <script src="../js/resources/js-test-pre.js"></script>
4         <script>
5             var expectedScrollTop = 200;
6             var expectedScrollLeft = 100;
7             var event;
8             var div;
9
10             if (window.testRunner)
11                 testRunner.waitUntilDone();
12
13             function dispatchWheelEvent()
14             {
15                 var overflowElement = document.getElementById("overflow");
16                 if (overflowElement) {
17                     overflowElement.addEventListener("mousewheel", mousewheelHandler, false);
18
19                     var wheelEvent = document.createEvent("WheelEvent");
20                     wheelEvent.initWebKitWheelEvent(-window.expectedScrollLeft, -window.expectedScrollTop, window, 0, 0, 0, 0, false, false, false, false);
21                     overflowElement.dispatchEvent(wheelEvent);
22                 }
23
24                 setTimeout('checkOffsets();', 100);
25             }
26
27             function checkOffsets()
28             {
29                 div = document.getElementById("overflow");
30                 shouldBe("div.scrollTop", "window.expectedScrollTop");
31                 shouldBe("div.scrollLeft", "window.expectedScrollLeft");
32
33                 if (window.testRunner)
34                     window.testRunner.notifyDone();
35             }
36
37             function mousewheelHandler(e)
38             {
39                 event = e;
40                 shouldBe("event.wheelDeltaY", "window.expectedScrollTop*-120");
41                 shouldBe("event.wheelDeltaX", "window.expectedScrollLeft*-120");
42
43                 if (e.wheelDeltaY)
44                     shouldBe("event.wheelDelta", "window.expectedScrollTop*-120");
45                 else
46                     shouldBe("event.wheelDelta", "window.expectedScrollLeft*-120");
47             }
48         </script>
49     </head>
50
51     <body style="margin:0" onload="setTimeout('dispatchWheelEvent();', 100)">
52         <div id="overflow" style="border:2px solid black;overflow:auto;height:200px;width:200px;">
53             <div style="background-color:red;height:200px;width:400px;"></div>
54             <div style="background-color:green;height:200px;width:400px;"></div>
55             <div style="background-color:red;height:200px;width:400px;"></div>
56         </div>
57         <div id="console"></div>
58     </body>
59 </html>