зеркало из https://github.com/mozilla/gecko-dev.git
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. --HG-- extra : rebase_source : 7783609faa96ba9a321156f781101244acd9ae2d extra : histedit_source : 171b976aa669f59342d31dbe278cda3769988c2b%2C5c1851a0090c961e04c26ecdc167b4c4b965c73f
This commit is contained in:
Родитель
7bebde2a3b
Коммит
9900719f1f
|
@ -48,6 +48,7 @@ registerCleanupFunction(function*() {
|
||||||
|
|
||||||
const TEST_URL_ROOT = "http://mochi.test:8888/browser/browser/devtools/markupview/test/";
|
const TEST_URL_ROOT = "http://mochi.test:8888/browser/browser/devtools/markupview/test/";
|
||||||
const CHROME_BASE = "chrome://mochitests/content/browser/browser/devtools/markupview/test/";
|
const CHROME_BASE = "chrome://mochitests/content/browser/browser/devtools/markupview/test/";
|
||||||
|
const COMMON_FRAME_SCRIPT_URL = "chrome://browser/content/devtools/frame-script-utils.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new test tab in the browser and load the given url.
|
* Add a new test tab in the browser and load the given url.
|
||||||
|
@ -66,6 +67,9 @@ function addTab(url) {
|
||||||
let tab = window.gBrowser.selectedTab = window.gBrowser.addTab(url);
|
let tab = window.gBrowser.selectedTab = window.gBrowser.addTab(url);
|
||||||
let linkedBrowser = tab.linkedBrowser;
|
let linkedBrowser = tab.linkedBrowser;
|
||||||
|
|
||||||
|
info("Loading the helper frame script " + COMMON_FRAME_SCRIPT_URL);
|
||||||
|
linkedBrowser.messageManager.loadFrameScript(COMMON_FRAME_SCRIPT_URL, false);
|
||||||
|
|
||||||
linkedBrowser.addEventListener("load", function onload() {
|
linkedBrowser.addEventListener("load", function onload() {
|
||||||
linkedBrowser.removeEventListener("load", onload, true);
|
linkedBrowser.removeEventListener("load", onload, true);
|
||||||
info("URL '" + url + "' loading complete");
|
info("URL '" + url + "' loading complete");
|
||||||
|
@ -124,6 +128,50 @@ function openInspector() {
|
||||||
return def.promise;
|
return def.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait for a content -> chrome message on the message manager (the window
|
||||||
|
* messagemanager is used).
|
||||||
|
* @param {String} name The message name
|
||||||
|
* @return {Promise} A promise that resolves to the response data when the
|
||||||
|
* message has been received
|
||||||
|
*/
|
||||||
|
function waitForContentMessage(name) {
|
||||||
|
info("Expecting message " + name + " from content");
|
||||||
|
|
||||||
|
let mm = gBrowser.selectedBrowser.messageManager;
|
||||||
|
|
||||||
|
let def = promise.defer();
|
||||||
|
mm.addMessageListener(name, function onMessage(msg) {
|
||||||
|
mm.removeMessageListener(name, onMessage);
|
||||||
|
def.resolve(msg.data);
|
||||||
|
});
|
||||||
|
return def.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send an async message to the frame script (chrome -> content) and wait for a
|
||||||
|
* response message with the same name (content -> chrome).
|
||||||
|
* @param {String} name The message name. Should be one of the messages defined
|
||||||
|
* in doc_frame_script.js
|
||||||
|
* @param {Object} data Optional data to send along
|
||||||
|
* @param {Object} objects Optional CPOW objects to send along
|
||||||
|
* @param {Boolean} expectResponse If set to false, don't wait for a response
|
||||||
|
* with the same name from the content script. Defaults to true.
|
||||||
|
* @return {Promise} Resolves to the response data if a response is expected,
|
||||||
|
* immediately resolves otherwise
|
||||||
|
*/
|
||||||
|
function executeInContent(name, data={}, objects={}, expectResponse=true) {
|
||||||
|
info("Sending message " + name + " to content");
|
||||||
|
let mm = gBrowser.selectedBrowser.messageManager;
|
||||||
|
|
||||||
|
mm.sendAsyncMessage(name, data, objects);
|
||||||
|
if (expectResponse) {
|
||||||
|
return waitForContentMessage(name);
|
||||||
|
} else {
|
||||||
|
return promise.resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple DOM node accesor function that takes either a node or a string css
|
* Simple DOM node accesor function that takes either a node or a string css
|
||||||
* selector as argument and returns the corresponding node
|
* selector as argument and returns the corresponding node
|
||||||
|
|
|
@ -133,6 +133,36 @@ addMessageListener("devtools:test:setStyle", function(msg) {
|
||||||
sendAsyncMessage("devtools:test:setStyle");
|
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.
|
* Set a given attribute value on a node.
|
||||||
* @param {Object} data
|
* @param {Object} data
|
||||||
|
|
Загрузка…
Ссылка в новой задаче