Bug 1120343 - 3 - Tests for the current time control in the animation panel; r=miker

This commit is contained in:
Patrick Brosset
2015-03-18 12:17:07 +01:00
parent bb7c6f1bb5
commit 0a6a9e354e
12 changed files with 345 additions and 44 deletions

View File

@@ -112,3 +112,69 @@ addMessageListener("devtools:test:eval", function ({ data }) {
addEventListener("load", function() {
sendAsyncMessage("devtools:test:load");
}, true);
/**
* Set a given style property value on a node.
* @param {Object} data
* - {String} selector The CSS selector to get the node (can be a "super"
* selector).
* - {String} propertyName The name of the property to set.
* - {String} propertyValue The value for the property.
*/
addMessageListener("devtools:test:setStyle", function(msg) {
let {selector, propertyName, propertyValue} = msg.data;
let node = superQuerySelector(selector);
if (!node) {
return;
}
node.style[propertyName] = propertyValue;
sendAsyncMessage("devtools:test:setStyle");
});
/**
* Set a given attribute value on a node.
* @param {Object} data
* - {String} selector The CSS selector to get the node (can be a "super"
* selector).
* - {String} attributeName The name of the attribute to set.
* - {String} attributeValue The value for the attribute.
*/
addMessageListener("devtools:test:setAttribute", function(msg) {
let {selector, attributeName, attributeValue} = msg.data;
let node = superQuerySelector(selector);
if (!node) {
return;
}
node.setAttribute(attributeName, attributeValue);
sendAsyncMessage("devtools:test:setAttribute");
});
/**
* Like document.querySelector but can go into iframes too.
* ".container iframe || .sub-container div" will first try to find the node
* matched by ".container iframe" in the root document, then try to get the
* content document inside it, and then try to match ".sub-container div" inside
* this document.
* Any selector coming before the || separator *MUST* match a frame node.
* @param {String} superSelector.
* @return {DOMNode} The node, or null if not found.
*/
function superQuerySelector(superSelector, root=content.document) {
let frameIndex = superSelector.indexOf("||");
if (frameIndex === -1) {
return root.querySelector(superSelector);
} else {
let rootSelector = superSelector.substring(0, frameIndex).trim();
let childSelector = superSelector.substring(frameIndex+2).trim();
root = root.querySelector(rootSelector);
if (!root || !root.contentWindow) {
return null;
}
return superQuerySelector(childSelector, root.contentWindow.document);
}
}