| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library wheel_event_test; | 5 library wheel_event_test; |
| 6 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
| 7 import '../../pkg/unittest/lib/html_config.dart'; | 7 import '../../pkg/unittest/lib/html_config.dart'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 | 9 |
| 10 | 10 |
| 11 main() { | 11 main() { |
| 12 | 12 |
| 13 useHtmlConfiguration(); | 13 useHtmlConfiguration(); |
| 14 | 14 |
| 15 var userAgent = window.navigator.userAgent; | |
| 16 | |
| 17 // Lame platform-dependent check to validate that our assumptions about | |
| 18 // which event is being used is correct. | |
| 19 var wheelEvent = 'wheel'; | |
| 20 if (userAgent.contains("Opera", 0)) { | |
| 21 wheelEvent = 'mousewheel'; | |
| 22 } else if (userAgent.contains("MSIE", 0)) { | |
| 23 wheelEvent = 'mousewheel'; | |
| 24 } else if (userAgent.contains('Firefox')) { | |
| 25 // FF appears to have recently added support for wheel. | |
| 26 wheelEvent = 'wheel'; | |
| 27 } else if (userAgent.contains('WebKit', 0)) { | |
| 28 wheelEvent = 'mousewheel'; | |
| 29 } | |
| 30 | |
| 31 test('wheelEvent', () { | 15 test('wheelEvent', () { |
| 32 var element = new DivElement(); | 16 var element = new DivElement(); |
| 17 var eventType = Element.mouseWheelEvent.getEventType(element); |
| 18 |
| 33 element.onMouseWheel.listen(expectAsync1((e) { | 19 element.onMouseWheel.listen(expectAsync1((e) { |
| 34 expect(e.screenX, 100); | 20 expect(e.screenX, 100); |
| 35 expect(e.deltaX, 0); | 21 expect(e.deltaX, 0); |
| 36 expect(e.deltaY, 240); | 22 expect(e.deltaY, 240); |
| 37 })); | 23 })); |
| 38 var event = new WheelEvent(wheelEvent, | 24 var event = new WheelEvent(eventType, |
| 39 deltaX: 0, | 25 deltaX: 0, |
| 40 deltaY: 240, | 26 deltaY: 240, |
| 41 screenX: 100); | 27 screenX: 100); |
| 42 element.dispatchEvent(event); | 28 element.dispatchEvent(event); |
| 43 }); | 29 }); |
| 44 | 30 |
| 45 test('wheelEvent Stream', () { | 31 test('wheelEvent Stream', () { |
| 46 var element = new DivElement(); | 32 var element = new DivElement(); |
| 33 var eventType = Element.mouseWheelEvent.getEventType(element); |
| 34 |
| 47 element.onMouseWheel.listen(expectAsync1((e) { | 35 element.onMouseWheel.listen(expectAsync1((e) { |
| 48 expect(e.screenX, 100); | 36 expect(e.screenX, 100); |
| 49 expect(e.deltaX, 0); | 37 expect(e.deltaX, 0); |
| 50 expect(e.deltaY, 240); | 38 expect(e.deltaY, 240); |
| 51 })); | 39 })); |
| 52 var event = new WheelEvent(wheelEvent, | 40 var event = new WheelEvent(eventType, |
| 53 deltaX: 0, | 41 deltaX: 0, |
| 54 deltaY: 240, | 42 deltaY: 240, |
| 55 screenX: 100); | 43 screenX: 100); |
| 56 element.dispatchEvent(event); | 44 element.dispatchEvent(event); |
| 57 }); | 45 }); |
| 58 } | 46 } |
| OLD | NEW |