OLD | NEW |
(Empty) | |
| 1 dart_library.library('lib/html/event_test', null, /* Imports */[ |
| 2 'dart_sdk', |
| 3 'unittest' |
| 4 ], function load__event_test(exports, dart_sdk, unittest) { |
| 5 'use strict'; |
| 6 const core = dart_sdk.core; |
| 7 const html = dart_sdk.html; |
| 8 const dart = dart_sdk.dart; |
| 9 const dartx = dart_sdk.dartx; |
| 10 const unittest$ = unittest.unittest; |
| 11 const src__matcher__expect = unittest.src__matcher__expect; |
| 12 const src__matcher__core_matchers = unittest.src__matcher__core_matchers; |
| 13 const html_config = unittest.html_config; |
| 14 const event_test = Object.create(null); |
| 15 let VoidToEvent = () => (VoidToEvent = dart.constFn(dart.functionType(html.Eve
nt, [])))(); |
| 16 let dynamicTovoid = () => (dynamicTovoid = dart.constFn(dart.functionType(dart
.void, [dart.dynamic])))(); |
| 17 let dynamicTovoid$ = () => (dynamicTovoid$ = dart.constFn(dart.definiteFunctio
nType(dart.void, [dart.dynamic])))(); |
| 18 let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.definiteFunctionT
ype(dart.dynamic, [])))(); |
| 19 let StringAndFnAndFn__Todynamic = () => (StringAndFnAndFn__Todynamic = dart.co
nstFn(dart.definiteFunctionType(dart.dynamic, [core.String, VoidToEvent(), dynam
icTovoid()], [core.String])))(); |
| 20 let VoidToCompositionEvent = () => (VoidToCompositionEvent = dart.constFn(dart
.definiteFunctionType(html.CompositionEvent, [])))(); |
| 21 let VoidToEvent$ = () => (VoidToEvent$ = dart.constFn(dart.definiteFunctionTyp
e(html.Event, [])))(); |
| 22 let VoidToHashChangeEvent = () => (VoidToHashChangeEvent = dart.constFn(dart.d
efiniteFunctionType(html.HashChangeEvent, [])))(); |
| 23 let VoidToMouseEvent = () => (VoidToMouseEvent = dart.constFn(dart.definiteFun
ctionType(html.MouseEvent, [])))(); |
| 24 let VoidToStorageEvent = () => (VoidToStorageEvent = dart.constFn(dart.definit
eFunctionType(html.StorageEvent, [])))(); |
| 25 let VoidToUIEvent = () => (VoidToUIEvent = dart.constFn(dart.definiteFunctionT
ype(html.UIEvent, [])))(); |
| 26 let VoidToWheelEvent = () => (VoidToWheelEvent = dart.constFn(dart.definiteFun
ctionType(html.WheelEvent, [])))(); |
| 27 event_test.eventTest = function(name, eventFn, validate, type) { |
| 28 if (type === void 0) type = 'foo'; |
| 29 unittest$.test(name, dart.fn(() => { |
| 30 let el = html.Element.tag('div'); |
| 31 let fired = false; |
| 32 el[dartx.on].get(type).listen(dart.fn(ev => { |
| 33 fired = true; |
| 34 dart.dcall(validate, ev); |
| 35 }, dynamicTovoid$())); |
| 36 el[dartx.dispatchEvent](eventFn()); |
| 37 src__matcher__expect.expect(fired, src__matcher__core_matchers.isTrue, {re
ason: 'Expected event to be dispatched.'}); |
| 38 }, VoidTodynamic())); |
| 39 }; |
| 40 dart.fn(event_test.eventTest, StringAndFnAndFn__Todynamic()); |
| 41 event_test.main = function() { |
| 42 html_config.useHtmlConfiguration(); |
| 43 event_test.eventTest('CompositionEvent', dart.fn(() => html.CompositionEvent
.new('compositionstart', {view: html.window, data: 'data'}), VoidToCompositionEv
ent()), dart.fn(ev => { |
| 44 src__matcher__expect.expect(dart.dload(ev, 'data'), 'data'); |
| 45 }, dynamicTovoid$()), 'compositionstart'); |
| 46 event_test.eventTest('Event', dart.fn(() => html.Event.new('foo', {canBubble
: false, cancelable: false}), VoidToEvent$()), dart.fn(ev => { |
| 47 src__matcher__expect.expect(dart.dload(ev, 'type'), src__matcher__core_mat
chers.equals('foo')); |
| 48 src__matcher__expect.expect(dart.dload(ev, 'bubbles'), src__matcher__core_
matchers.isFalse); |
| 49 src__matcher__expect.expect(dart.dload(ev, 'cancelable'), src__matcher__co
re_matchers.isFalse); |
| 50 }, dynamicTovoid$())); |
| 51 event_test.eventTest('HashChangeEvent', dart.fn(() => html.HashChangeEvent.n
ew('foo', {oldUrl: 'http://old.url', newUrl: 'http://new.url'}), VoidToHashChang
eEvent()), dart.fn(ev => { |
| 52 src__matcher__expect.expect(dart.dload(ev, 'oldUrl'), src__matcher__core_m
atchers.equals('http://old.url')); |
| 53 src__matcher__expect.expect(dart.dload(ev, 'newUrl'), src__matcher__core_m
atchers.equals('http://new.url')); |
| 54 }, dynamicTovoid$())); |
| 55 event_test.eventTest('MouseEvent', dart.fn(() => html.MouseEvent.new('foo',
{view: html.window, detail: 1, screenX: 2, screenY: 3, clientX: 4, clientY: 5, b
utton: 6, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true, relatedTar
get: html.document[dartx.body]}), VoidToMouseEvent()), dart.fn(ev => { |
| 56 src__matcher__expect.expect(dart.dload(ev, 'detail'), 1); |
| 57 src__matcher__expect.expect(dart.dload(dart.dload(ev, 'screen'), 'x'), 2); |
| 58 src__matcher__expect.expect(dart.dload(dart.dload(ev, 'screen'), 'y'), 3); |
| 59 src__matcher__expect.expect(dart.dload(dart.dload(ev, 'client'), 'x'), 4); |
| 60 src__matcher__expect.expect(dart.dload(dart.dload(ev, 'client'), 'y'), 5); |
| 61 src__matcher__expect.expect(dart.dload(dart.dload(ev, 'offset'), 'x'), 4); |
| 62 src__matcher__expect.expect(dart.dload(dart.dload(ev, 'offset'), 'y'), 5); |
| 63 src__matcher__expect.expect(dart.dload(ev, 'button'), 6); |
| 64 src__matcher__expect.expect(dart.dload(ev, 'ctrlKey'), src__matcher__core_
matchers.isTrue); |
| 65 src__matcher__expect.expect(dart.dload(ev, 'altKey'), src__matcher__core_m
atchers.isTrue); |
| 66 src__matcher__expect.expect(dart.dload(ev, 'shiftKey'), src__matcher__core
_matchers.isTrue); |
| 67 src__matcher__expect.expect(dart.dload(ev, 'metaKey'), src__matcher__core_
matchers.isTrue); |
| 68 }, dynamicTovoid$())); |
| 69 event_test.eventTest('StorageEvent', dart.fn(() => html.StorageEvent.new('fo
o', {key: 'key', url: 'http://example.url', storageArea: html.window[dartx.local
Storage], canBubble: true, cancelable: true, oldValue: 'old', newValue: 'new'}),
VoidToStorageEvent()), dart.fn(ev => { |
| 70 src__matcher__expect.expect(dart.dload(ev, 'key'), 'key'); |
| 71 src__matcher__expect.expect(dart.dload(ev, 'url'), 'http://example.url'); |
| 72 src__matcher__expect.expect(dart.dload(ev, 'storageArea'), src__matcher__c
ore_matchers.isNotNull); |
| 73 src__matcher__expect.expect(dart.dload(ev, 'oldValue'), 'old'); |
| 74 src__matcher__expect.expect(dart.dload(ev, 'newValue'), 'new'); |
| 75 }, dynamicTovoid$())); |
| 76 event_test.eventTest('UIEvent', dart.fn(() => html.UIEvent.new('foo', {view:
html.window, detail: 12}), VoidToUIEvent()), dart.fn(ev => { |
| 77 src__matcher__expect.expect(html.window, dart.dload(ev, 'view')); |
| 78 src__matcher__expect.expect(12, dart.dload(ev, 'detail')); |
| 79 }, dynamicTovoid$())); |
| 80 event_test.eventTest('WheelEvent', dart.fn(() => html.WheelEvent.new("mousew
heel", {deltaX: 1, deltaY: 0, detail: 4, screenX: 3, screenY: 4, clientX: 5, cli
entY: 6, ctrlKey: true, altKey: true, shiftKey: true, metaKey: true}), VoidToWhe
elEvent()), dart.fn(ev => { |
| 81 src__matcher__expect.expect(dart.dload(ev, 'deltaX'), 1); |
| 82 src__matcher__expect.expect(dart.dload(ev, 'deltaY'), 0); |
| 83 src__matcher__expect.expect(dart.dload(dart.dload(ev, 'screen'), 'x'), 3); |
| 84 src__matcher__expect.expect(dart.dload(dart.dload(ev, 'screen'), 'y'), 4); |
| 85 src__matcher__expect.expect(dart.dload(dart.dload(ev, 'client'), 'x'), 5); |
| 86 src__matcher__expect.expect(dart.dload(dart.dload(ev, 'client'), 'y'), 6); |
| 87 src__matcher__expect.expect(dart.dload(ev, 'ctrlKey'), src__matcher__core_
matchers.isTrue); |
| 88 src__matcher__expect.expect(dart.dload(ev, 'altKey'), src__matcher__core_m
atchers.isTrue); |
| 89 src__matcher__expect.expect(dart.dload(ev, 'shiftKey'), src__matcher__core
_matchers.isTrue); |
| 90 src__matcher__expect.expect(dart.dload(ev, 'metaKey'), src__matcher__core_
matchers.isTrue); |
| 91 }, dynamicTovoid$()), 'mousewheel'); |
| 92 }; |
| 93 dart.fn(event_test.main, VoidTodynamic()); |
| 94 // Exports: |
| 95 exports.event_test = event_test; |
| 96 }); |
OLD | NEW |