2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-06-20 08:21:43 -04:00
|
|
|
import { test, assertEquals, assertNotEquals } from "./test_util.ts";
|
2019-01-05 10:02:44 -05:00
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function eventInitializedWithType(): void {
|
2019-01-05 10:02:44 -05:00
|
|
|
const type = "click";
|
|
|
|
const event = new Event(type);
|
|
|
|
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(event.isTrusted, false);
|
|
|
|
assertEquals(event.target, null);
|
|
|
|
assertEquals(event.currentTarget, null);
|
|
|
|
assertEquals(event.type, "click");
|
|
|
|
assertEquals(event.bubbles, false);
|
|
|
|
assertEquals(event.cancelable, false);
|
2019-01-05 10:02:44 -05:00
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function eventInitializedWithTypeAndDict(): void {
|
2019-01-05 10:02:44 -05:00
|
|
|
const init = "submit";
|
|
|
|
const eventInitDict = new EventInit({ bubbles: true, cancelable: true });
|
|
|
|
const event = new Event(init, eventInitDict);
|
|
|
|
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(event.isTrusted, false);
|
|
|
|
assertEquals(event.target, null);
|
|
|
|
assertEquals(event.currentTarget, null);
|
|
|
|
assertEquals(event.type, "submit");
|
|
|
|
assertEquals(event.bubbles, true);
|
|
|
|
assertEquals(event.cancelable, true);
|
2019-01-05 10:02:44 -05:00
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function eventComposedPathSuccess(): void {
|
2019-01-05 10:02:44 -05:00
|
|
|
const type = "click";
|
|
|
|
const event = new Event(type);
|
|
|
|
const composedPath = event.composedPath();
|
|
|
|
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(composedPath, []);
|
2019-01-05 10:02:44 -05:00
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function eventStopPropagationSuccess(): void {
|
2019-01-05 10:02:44 -05:00
|
|
|
const type = "click";
|
|
|
|
const event = new Event(type);
|
|
|
|
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(event.cancelBubble, false);
|
2019-01-05 10:02:44 -05:00
|
|
|
event.stopPropagation();
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(event.cancelBubble, true);
|
2019-01-05 10:02:44 -05:00
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function eventStopImmediatePropagationSuccess(): void {
|
2019-01-05 10:02:44 -05:00
|
|
|
const type = "click";
|
|
|
|
const event = new Event(type);
|
|
|
|
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(event.cancelBubble, false);
|
|
|
|
assertEquals(event.cancelBubbleImmediately, false);
|
2019-01-05 10:02:44 -05:00
|
|
|
event.stopImmediatePropagation();
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(event.cancelBubble, true);
|
|
|
|
assertEquals(event.cancelBubbleImmediately, true);
|
2019-01-05 10:02:44 -05:00
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function eventPreventDefaultSuccess(): void {
|
2019-01-05 10:02:44 -05:00
|
|
|
const type = "click";
|
|
|
|
const event = new Event(type);
|
|
|
|
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(event.defaultPrevented, false);
|
2019-01-05 10:02:44 -05:00
|
|
|
event.preventDefault();
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(event.defaultPrevented, false);
|
2019-01-05 10:02:44 -05:00
|
|
|
|
|
|
|
const eventInitDict = new EventInit({ bubbles: true, cancelable: true });
|
|
|
|
const cancelableEvent = new Event(type, eventInitDict);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(cancelableEvent.defaultPrevented, false);
|
2019-01-05 10:02:44 -05:00
|
|
|
cancelableEvent.preventDefault();
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(cancelableEvent.defaultPrevented, true);
|
2019-01-05 10:02:44 -05:00
|
|
|
});
|
2019-03-26 07:42:26 -04:00
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function eventInitializedWithNonStringType(): void {
|
2019-03-26 07:42:26 -04:00
|
|
|
const type = undefined;
|
|
|
|
const event = new Event(type);
|
|
|
|
|
|
|
|
assertEquals(event.isTrusted, false);
|
|
|
|
assertEquals(event.target, null);
|
|
|
|
assertEquals(event.currentTarget, null);
|
|
|
|
assertEquals(event.type, "undefined");
|
|
|
|
assertEquals(event.bubbles, false);
|
|
|
|
assertEquals(event.cancelable, false);
|
|
|
|
});
|
2019-06-20 08:21:43 -04:00
|
|
|
|
|
|
|
// ref https://github.com/web-platform-tests/wpt/blob/master/dom/events/Event-isTrusted.any.js
|
|
|
|
test(function eventIsTrusted(): void {
|
|
|
|
const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
|
|
|
|
assertNotEquals(desc1, undefined);
|
|
|
|
assertEquals(typeof desc1.get, "function");
|
|
|
|
|
|
|
|
const desc2 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
|
|
|
|
assertNotEquals(desc2, undefined);
|
|
|
|
assertEquals(typeof desc2.get, "function");
|
|
|
|
|
|
|
|
assertEquals(desc1.get, desc2.get);
|
|
|
|
});
|