testcommon.js (1224B)
1 /** 2 * The const var for SVG and xlink namespaces 3 */ 4 const SVGNS = 'http://www.w3.org/2000/svg'; 5 const XLINKNS = 'http://www.w3.org/1999/xlink'; 6 7 /** 8 * Appends a svg element to the parent. 9 * 10 * @param test The testharness.js Test object. If provided, this will be used 11 * to register a cleanup callback to remove the div when the test 12 * finishes. 13 * @param tag The element tag name. 14 * @param parent The parent element of this new created svg element. 15 * @param attrs A dictionary object with attribute names and values to set on 16 * the div. 17 */ 18 function createSVGElement(test, tag, parent, attrs) { 19 var elem = document.createElementNS(SVGNS, tag); 20 if (attrs) { 21 for (var attrName in attrs) { 22 elem.setAttribute(attrName, attrs[attrName]); 23 } 24 } 25 parent.appendChild(elem); 26 if (test) { 27 test.add_cleanup(function() { 28 elem.remove(); 29 }); 30 } 31 return elem; 32 } 33 34 /** 35 * Create a Promise object which resolves when a specific event fires. 36 * 37 * @param object The event target. 38 * @param name The event name. 39 */ 40 function waitEvent(object, name) { 41 return new Promise(function(resolve) { 42 object.addEventListener(name, resolve, { once: true }); 43 }); 44 }