OLD | NEW |
1 dart_library.library('lib/html/event_customevent_test', null, /* Imports */[ | 1 dart_library.library('lib/html/event_customevent_test', null, /* Imports */[ |
2 'dart_sdk', | 2 'dart_sdk', |
3 'unittest' | 3 'unittest' |
4 ], function load__event_customevent_test(exports, dart_sdk, unittest) { | 4 ], function load__event_customevent_test(exports, dart_sdk, unittest) { |
5 'use strict'; | 5 'use strict'; |
6 const core = dart_sdk.core; | 6 const core = dart_sdk.core; |
7 const html = dart_sdk.html; | 7 const html = dart_sdk.html; |
8 const js = dart_sdk.js; | 8 const js = dart_sdk.js; |
9 const async = dart_sdk.async; | 9 const async = dart_sdk.async; |
10 const dart = dart_sdk.dart; | 10 const dart = dart_sdk.dart; |
(...skipping 18 matching lines...) Expand all Loading... |
29 constructors: () => ({new: dart.definiteFunctionType(event_customevent_test.
DartPayloadData, [dart.dynamic])}) | 29 constructors: () => ({new: dart.definiteFunctionType(event_customevent_test.
DartPayloadData, [dart.dynamic])}) |
30 }); | 30 }); |
31 event_customevent_test.main = function() { | 31 event_customevent_test.main = function() { |
32 html_config.useHtmlConfiguration(); | 32 html_config.useHtmlConfiguration(); |
33 unittest$.test('custom events', dart.fn(() => { | 33 unittest$.test('custom events', dart.fn(() => { |
34 let provider = new (EventStreamProviderOfCustomEvent())('foo'); | 34 let provider = new (EventStreamProviderOfCustomEvent())('foo'); |
35 let el = html.DivElement.new(); | 35 let el = html.DivElement.new(); |
36 let fired = false; | 36 let fired = false; |
37 provider.forTarget(el).listen(dart.fn(ev => { | 37 provider.forTarget(el).listen(dart.fn(ev => { |
38 fired = true; | 38 fired = true; |
39 src__matcher__expect.expect(ev[dartx.detail], dart.map({type: 'detail'})
); | 39 src__matcher__expect.expect(ev[dartx.detail], dart.map({type: 'detail'},
core.String, core.String)); |
40 }, CustomEventTovoid())); | 40 }, CustomEventTovoid())); |
41 let ev = html.CustomEvent.new('foo', {canBubble: false, cancelable: false,
detail: dart.map({type: 'detail'})}); | 41 let ev = html.CustomEvent.new('foo', {canBubble: false, cancelable: false,
detail: dart.map({type: 'detail'}, core.String, core.String)}); |
42 el[dartx.dispatchEvent](ev); | 42 el[dartx.dispatchEvent](ev); |
43 src__matcher__expect.expect(fired, src__matcher__core_matchers.isTrue); | 43 src__matcher__expect.expect(fired, src__matcher__core_matchers.isTrue); |
44 }, VoidTodynamic())); | 44 }, VoidTodynamic())); |
45 unittest$.test('custom events from JS', dart.fn(() => { | 45 unittest$.test('custom events from JS', dart.fn(() => { |
46 let scriptContents = ' var event = document.createEvent("CustomEvent"
);\n event.initCustomEvent("js_custom_event", true, true, {type: "detail"})
;\n window.dispatchEvent(event);\n '; | 46 let scriptContents = ' var event = document.createEvent("CustomEvent"
);\n event.initCustomEvent("js_custom_event", true, true, {type: "detail"})
;\n window.dispatchEvent(event);\n '; |
47 let fired = false; | 47 let fired = false; |
48 html.window[dartx.on].get('js_custom_event').listen(dart.fn(ev => { | 48 html.window[dartx.on].get('js_custom_event').listen(dart.fn(ev => { |
49 fired = true; | 49 fired = true; |
50 src__matcher__expect.expect(dart.dload(ev, 'detail'), dart.map({type: 'd
etail'})); | 50 src__matcher__expect.expect(dart.dload(ev, 'detail'), dart.map({type: 'd
etail'}, core.String, core.String)); |
51 }, dynamicTovoid())); | 51 }, dynamicTovoid())); |
52 let script = html.ScriptElement.new(); | 52 let script = html.ScriptElement.new(); |
53 script[dartx.text] = scriptContents; | 53 script[dartx.text] = scriptContents; |
54 html.document[dartx.body][dartx.append](script); | 54 html.document[dartx.body][dartx.append](script); |
55 src__matcher__expect.expect(fired, src__matcher__core_matchers.isTrue); | 55 src__matcher__expect.expect(fired, src__matcher__core_matchers.isTrue); |
56 }, VoidTodynamic())); | 56 }, VoidTodynamic())); |
57 unittest$.test('custom events to JS', dart.fn(() => { | 57 unittest$.test('custom events to JS', dart.fn(() => { |
58 src__matcher__expect.expect(js.context.get('gotDartEvent'), src__matcher__
core_matchers.isNull); | 58 src__matcher__expect.expect(js.context.get('gotDartEvent'), src__matcher__
core_matchers.isNull); |
59 let scriptContents = ' window.addEventListener(\'dart_custom_event\',
function(e) {\n if (e.detail == \'dart_message\') {\n e.prevent
Default();\n window.gotDartEvent = true;\n }\n window.con
sole.log(\'here\' + e.detail);\n }, false);'; | 59 let scriptContents = ' window.addEventListener(\'dart_custom_event\',
function(e) {\n if (e.detail == \'dart_message\') {\n e.prevent
Default();\n window.gotDartEvent = true;\n }\n window.con
sole.log(\'here\' + e.detail);\n }, false);'; |
60 html.document[dartx.body][dartx.append]((() => { | 60 html.document[dartx.body][dartx.append]((() => { |
(...skipping 12 matching lines...) Expand all Loading... |
73 src__matcher__expect.expect(dart.dload(event[dartx.detail], 'dartValue')
, 666); | 73 src__matcher__expect.expect(dart.dload(event[dartx.detail], 'dartValue')
, 666); |
74 }, dynamicTodynamic())); | 74 }, dynamicTodynamic())); |
75 html.document[dartx.body][dartx.dispatchEvent](event); | 75 html.document[dartx.body][dartx.dispatchEvent](event); |
76 return future; | 76 return future; |
77 }, VoidToFuture())); | 77 }, VoidToFuture())); |
78 }; | 78 }; |
79 dart.fn(event_customevent_test.main, VoidTodynamic()); | 79 dart.fn(event_customevent_test.main, VoidTodynamic()); |
80 // Exports: | 80 // Exports: |
81 exports.event_customevent_test = event_customevent_test; | 81 exports.event_customevent_test = event_customevent_test; |
82 }); | 82 }); |
OLD | NEW |