Bug 201603 - Synchronize MathML WPT tests against upstream
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / mathml / relations / html5-tree / clipboard-event-handlers.tentative.html
1 <!DOCTYPE html>
2 <title>DocumentAndElementEventHandlers / clipboard events for MathML</title>
3 <link rel="help" href="https://mathml-refresh.github.io/mathml-core/#dom-and-javascript"/>
4 <link rel="help" href="https://html.spec.whatwg.org/multipage/webappapis.html#documentandelementeventhandlers"/>
5 <link rel="help" href="https://w3c.github.io/clipboard-apis/#clipboard-event-copy"/>
6 <link rel="help" href="https://w3c.github.io/clipboard-apis/#clipboard-event-cut"/>
7 <link rel="help" href="https://w3c.github.io/clipboard-apis/#clipboard-event-paste"/>
8 <meta
9   name="assert"
10   content="MathMLElements incorporate a functional DocumentAndElementEventHandlers interface"
11 />
12
13 <script src="/resources/testharness.js"></script>
14 <script src="/resources/testharnessreport.js"></script>
15 <div id="log"></div>
16 <math
17   oncopy="window.copyHappened = true"
18   oncut="window.cutHappened = true"
19   onpaste="window.pasteHappened = true"
20 >
21   <mi>E</mi>
22 </math>
23 <script>
24   const EVENTS = ["copy", "cut", "paste"];
25   const el = document.querySelector("math");
26
27   function addEventListenerTest(name) {
28     async_test(test => {
29       el.addEventListener(
30         name,
31         test.step_func_done(e => {
32           assert_true(
33             true,
34             "MathML Elements should be able to receive ${name} events"
35           );
36         })
37       );
38       const event = new ClipboardEvent(name, {
39         bubbles: true,
40         cancellable: true
41       });
42       el.dispatchEvent(event);
43     }, `math.addEventListener for ${name}`);
44   }
45
46   function evaluatedHandlerTest(name) {
47     const handlerName = "on" + name;
48
49     test(() => {
50       const compiledHandler = el[handlerName];
51
52       assert_equals(
53         typeof compiledHandler,
54         "function",
55         `The ${handlerName} property must be a function`
56       );
57       compiledHandler();
58       assert_true(
59         window[name + "Happened"],
60         "Calling the handler must run the code"
61       );
62     }, `${handlerName}: the content attribute must be compiled into a function as the corresponding property`);
63   }
64
65   EVENTS.forEach(name => {
66     addEventListenerTest(name);
67     evaluatedHandlerTest(name);
68   });
69 </script>