Bug 1146566 - 1 - Use devtools common frame-script in markupview tests and add helper; r=bgrins

This change loads the devtools common frame-script-utils.js frame-script in the browser message
manager when a new test tab is opened by a test, and it adds a new getDomElementInfo message
listener useful for many tests to retrieve data about a node without having to go through a
CPOW.
This commit is contained in:
Patrick Brosset
2015-03-25 10:53:24 +01:00
parent bcb2055449
commit dd9c1738cc
2 changed files with 78 additions and 0 deletions

View File

@@ -133,6 +133,36 @@ addMessageListener("devtools:test:setStyle", function(msg) {
sendAsyncMessage("devtools:test:setStyle");
});
/**
* Get information about a DOM element, identified by a selector.
* @param {Object} data
* - {String} selector The CSS selector to get the node (can be a "super"
* selector).
* @return {Object} data Null if selector didn't match any node, otherwise:
* - {String} tagName.
* - {String} namespaceURI.
* - {Number} numChildren The number of children in the element.
* - {Array} attributes An array of {name, value, namespaceURI} objects.
*/
addMessageListener("devtools:test:getDomElementInfo", function(msg) {
let {selector} = msg.data;
let node = superQuerySelector(selector);
let info = null;
if (node) {
info = {
tagName: node.tagName,
namespaceURI: node.namespaceURI,
numChildren: node.children.length,
attributes: [...node.attributes].map(({name, value, namespaceURI}) => {
return {name, value, namespaceURI};
})
};
}
sendAsyncMessage("devtools:test:getDomElementInfo", info);
});
/**
* Set a given attribute value on a node.
* @param {Object} data