4 <p>This tests the target, currentEvent, and phase of a complete trace through event bubbling and capture.</p>
5 <pre id="console"></pre>
8 <div id="Parent" style="background-color:lightblue;border:1px solid #000000; padding: 10px; margin: 10px;">
10 <div id="Self" style="background-color:blue; border:1px solid black; padding: 10px; margin: 10px;">
16 if (window.layoutTestController)
17 layoutTestController.dumpAsText();
21 document.getElementById('console').appendChild(document.createTextNode(msg + "\n"));
24 function traceEvent(event)
26 function targetString(target)
30 if (target instanceof window.Element)
31 return target.toString() + " (ID: " + target.id + ")";
32 return target.toString();
35 function phaseString(eventPhase)
37 if (eventPhase == Event.NONE)
39 else if (eventPhase == Event.CAPTURING_PHASE)
41 else if (eventPhase == Event.BUBBLING_PHASE)
43 else if (eventPhase == Event.AT_TARGET)
47 var target = targetString(event.target);
48 var currentTarget = targetString(event.currentTarget);
49 var phase = phaseString(event.eventPhase);
51 log("Target = " + target + "; Phase = " + phase + "; CurrentTarget = " + currentTarget + ";");
55 window.addEventListener("customevent", traceEvent, true);
56 document.addEventListener("customevent", traceEvent, true);
57 document.getElementById("HTML").addEventListener("customevent", traceEvent, true);
58 document.getElementById("Body").addEventListener("customevent", traceEvent, true);
59 document.getElementById("Parent").addEventListener("customevent", traceEvent, true);
60 document.getElementById("Self").addEventListener("customevent", traceEvent, true);
62 window.addEventListener("customevent", traceEvent, false);
63 document.addEventListener("customevent", traceEvent, false);
64 document.getElementById("HTML").addEventListener("customevent", traceEvent, false);
65 document.getElementById("Body").addEventListener("customevent", traceEvent, false);
66 document.getElementById("Parent").addEventListener("customevent", traceEvent, false);
67 document.getElementById("Self").addEventListener("customevent", traceEvent, false);
69 var theEvent = document.createEvent("Event");
70 theEvent.initEvent("customevent", true, true);
72 // Trace before dispatch.
75 document.getElementById("Self").dispatchEvent(theEvent);