Make it possible to create reasonable subclasses of Event
After this CL, authors can create custom subclasses of Event that actually work in a reasonable way, including being able to dispatch. R=hansmuller@google.com, hansmuller@chromium.org Review URL: https://codereview.chromium.org/938003004
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
CONSOLE: unittest-suite-wait-for-done
|
||||
CONSOLE: PASS: should be able to dispatch
|
||||
CONSOLE:
|
||||
CONSOLE: All 1 tests passed.
|
||||
CONSOLE: unittest-suite-success
|
||||
DONE
|
||||
35
engine/src/flutter/tests/events/custom-event.sky
Normal file
35
engine/src/flutter/tests/events/custom-event.sky
Normal file
@@ -0,0 +1,35 @@
|
||||
<script>
|
||||
import "../resources/third_party/unittest/unittest.dart";
|
||||
import "../resources/unit.dart";
|
||||
|
||||
import "dart:sky";
|
||||
|
||||
class MyEvent extends Event {
|
||||
MyEvent() : super("awesome", bubbles: true);
|
||||
|
||||
bool get isCustom => true;
|
||||
}
|
||||
|
||||
void main() {
|
||||
initUnit();
|
||||
|
||||
test("should be able to dispatch", () {
|
||||
var event = new MyEvent();
|
||||
expect(event.isCustom, isTrue);
|
||||
expect(event.type, equals("awesome"));
|
||||
expect(event.bubbles, isTrue);
|
||||
expect(event.cancelable, isFalse);
|
||||
expect(event.isCustom, isTrue);
|
||||
|
||||
bool gotEvent = false;
|
||||
var element = document.createElement("div");
|
||||
element.addEventListener("awesome", (e) {
|
||||
expect(e, equals(event));
|
||||
expect(event.isCustom, isTrue);
|
||||
gotEvent = true;
|
||||
});
|
||||
element.dispatchEvent(event);
|
||||
expect(gotEvent, isTrue);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user