1 window.testIsAsync = true;
2 description("Tests whether SVG event bubbling works across shadow trees.");
4 var svgNS = "http://www.w3.org/2000/svg";
5 var xhtmlNS = "http://www.w3.org/1999/xhtml";
6 var expected = new Array(4);
11 function log(message) {
12 var logDiv = document.getElementById("console");
13 var newDiv = document.createElementNS(xhtmlNS, "div");
14 newDiv.appendChild(document.createTextNode(message));
15 logDiv.appendChild(newDiv);
18 function eventHandler(evt, label) {
19 var targetId = evt.target.correspondingElement ? evt.target.correspondingElement.id : evt.target.id;
20 var curTargetId = evt.currentTarget.correspondingElement ? evt.currentTarget.correspondingElement.id : evt.currentTarget.id;
23 switch (evt.eventPhase) {
24 case 1: phaseString = "CAPTURING"; break;
25 case 2: phaseString = "AT_TARGET"; break;
26 case 3: phaseString = "BUBBLING"; break;
29 msg = '[EventHandler ' + label + '] type: ' + evt.type + ' phase: ' + phaseString +
30 ' target: ' + evt.target + ' (id: ' + targetId + ')' +
31 ' currentTarget: ' + evt.currentTarget + ' (id: ' + curTargetId + ')';
33 shouldBeEqualToString("msg", expected[eventCounter]);
37 setTimeout(label == tests ? finishTest : nextTest, 0);
42 successfullyParsed = true;
44 rectContainer.setAttribute("fill", "green");
45 shouldBeTrue("successfullyParsed");
46 debug('<br /><span class="pass">TEST COMPLETE</span>');
58 rect.onclick = function(evt) { eventHandler(evt, 1); };
59 expected[0] = "[EventHandler 1] type: click phase: AT_TARGET target: [object SVGRectElement] (id: rect) currentTarget: [object SVGRectElement] (id: rect)";
63 rectContainer.addEventListener("click", function(evt) { eventHandler(evt, 2) }, false);
64 expected[1] = "[EventHandler 2] type: click phase: BUBBLING target: [object SVGRectElement] (id: rect) currentTarget: [object SVGGElement] (id: rectParent)";
68 use.setAttribute("onclick", "eventHandler(evt, 3)");
69 expected[2] = "[EventHandler 3] type: click phase: AT_TARGET target: [object SVGUseElement] (id: use) currentTarget: [object SVGUseElement] (id: use)";
73 useContainer.onclick = function(evt) { eventHandler(evt, 4) };
74 expected[3] = "[EventHandler 4] type: click phase: BUBBLING target: [object SVGUseElement] (id: use) currentTarget: [object SVGGElement] (id: useParent)";
80 function testListeners()
82 if (window.eventSender) {
83 eventSender.mouseMoveTo(50, 50);
84 eventSender.mouseDown();
85 eventSender.mouseUp();
89 // Create root element
90 var svg = document.createElementNS(svgNS, "svg");
92 svg.setAttribute("width", 100);
93 svg.setAttribute("height", 100);
94 document.body.insertBefore(svg, document.body.firstChild);
96 // Create defs section
97 var defs = document.createElementNS(svgNS, "defs");
98 svg.appendChild(defs);
100 var rectContainer = document.createElementNS(svgNS, "g");
101 rectContainer.id = "rectParent";
102 defs.appendChild(rectContainer);
104 var rect = document.createElementNS(svgNS, "rect");
106 rect.style.fill = "blue";
107 rect.width.baseVal.value = 100;
108 rect.height.baseVal.value = 100;
109 rectContainer.appendChild(rect);
111 // Create content section
112 var useContainer = document.createElementNS(svgNS, "g");
113 useContainer.id = "useParent";
114 svg.appendChild(useContainer);
116 var use = document.createElementNS(svgNS, "use");
118 use.href.baseVal = "#rectParent";
119 useContainer.appendChild(use);
121 function repaintTest() {