summaryrefslogtreecommitdiff
path: root/op_crates/web/event_test.js
diff options
context:
space:
mode:
authorLuca Casonato <lucacasonato@yahoo.com>2021-03-12 16:17:18 +0100
committerGitHub <noreply@github.com>2021-03-12 16:17:18 +0100
commite83ff62ccbe33ad9c19cb9cab9154b6767d6d74b (patch)
tree9b37e4ff189e3c3aa4b454c9835b892fb0a9723a /op_crates/web/event_test.js
parent2f9d7c02dc87cfc57a6d37dc27bb0680b9ac7128 (diff)
chore: split web op crate (#9635)
This commit starts splitting out the deno_web op crate into multiple smaller crates. This commit splits out WebIDL and URL API, but in the future I want to split out each spec into its own crate. That means we will have (in rough order of loading): `webidl`, `dom`, `streams`, `console`, `encoding`, `url`, `file`, `fetch`, `websocket`, and `webgpu` crates.
Diffstat (limited to 'op_crates/web/event_test.js')
-rw-r--r--op_crates/web/event_test.js142
1 files changed, 0 insertions, 142 deletions
diff --git a/op_crates/web/event_test.js b/op_crates/web/event_test.js
deleted file mode 100644
index fa92a3e07..000000000
--- a/op_crates/web/event_test.js
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-"use strict";
-function assert(cond) {
- if (!cond) {
- throw Error("assert");
- }
-}
-
-function eventInitializedWithType() {
- const type = "click";
- const event = new Event(type);
-
- assert(event.isTrusted === false);
- assert(event.target === null);
- assert(event.currentTarget === null);
- assert(event.type === "click");
- assert(event.bubbles === false);
- assert(event.cancelable === false);
-}
-
-function eventInitializedWithTypeAndDict() {
- const init = "submit";
- const eventInit = { bubbles: true, cancelable: true };
- const event = new Event(init, eventInit);
-
- assert(event.isTrusted === false);
- assert(event.target === null);
- assert(event.currentTarget === null);
- assert(event.type === "submit");
- assert(event.bubbles === true);
- assert(event.cancelable === true);
-}
-
-function eventComposedPathSuccess() {
- const type = "click";
- const event = new Event(type);
- const composedPath = event.composedPath();
-
- assert(composedPath.length === 0);
-}
-
-function eventStopPropagationSuccess() {
- const type = "click";
- const event = new Event(type);
-
- assert(event.cancelBubble === false);
- event.stopPropagation();
- assert(event.cancelBubble === true);
-}
-
-function eventStopImmediatePropagationSuccess() {
- const type = "click";
- const event = new Event(type);
-
- assert(event.cancelBubble === false);
- event.stopImmediatePropagation();
- assert(event.cancelBubble === true);
-}
-
-function eventPreventDefaultSuccess() {
- const type = "click";
- const event = new Event(type);
-
- assert(event.defaultPrevented === false);
- event.preventDefault();
- assert(event.defaultPrevented === false);
-
- const eventInit = { bubbles: true, cancelable: true };
- const cancelableEvent = new Event(type, eventInit);
- assert(cancelableEvent.defaultPrevented === false);
- cancelableEvent.preventDefault();
- assert(cancelableEvent.defaultPrevented === true);
-}
-
-function eventInitializedWithNonStringType() {
- const type = undefined;
- const event = new Event(type);
-
- assert(event.isTrusted === false);
- assert(event.target === null);
- assert(event.currentTarget === null);
- assert(event.type === "undefined");
- assert(event.bubbles === false);
- assert(event.cancelable === false);
-}
-
-// ref https://github.com/web-platform-tests/wpt/blob/master/dom/events/Event-isTrusted.any.js
-function eventIsTrusted() {
- const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
- assert(desc1);
- assert(typeof desc1.get === "function");
-
- const desc2 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
- assert(desc2);
- assert(typeof desc2.get === "function");
-
- assert(desc1.get === desc2.get);
-}
-
-function eventIsTrustedGetterName() {
- const { get } = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
- assert(get.name === "get isTrusted");
- try {
- Reflect.construct(get);
- throw new Error("Should not have reached here");
- } catch (e) {
- assert(e.message.includes("not a constructor"));
- }
-}
-function eventAbortSignal() {
- let count = 0;
- function handler() {
- count++;
- }
- const et = new EventTarget();
- const controller = new AbortController();
- et.addEventListener("test", handler, { signal: controller.signal });
- et.dispatchEvent(new Event("test"));
- assert(count === 1);
- et.dispatchEvent(new Event("test"));
- assert(count === 2);
- controller.abort();
- et.dispatchEvent(new Event("test"));
- assert(count === 2);
- et.addEventListener("test", handler, { signal: controller.signal });
- et.dispatchEvent(new Event("test"));
- assert(count === 2);
-}
-function main() {
- eventInitializedWithType();
- eventInitializedWithTypeAndDict();
- eventComposedPathSuccess();
- eventStopPropagationSuccess();
- eventStopImmediatePropagationSuccess();
- eventPreventDefaultSuccess();
- eventInitializedWithNonStringType();
- eventIsTrusted();
- eventIsTrustedGetterName();
- eventAbortSignal();
-}
-
-main();