Bug 1714009 - [devtools] Remove testActor#getProperty. r=jdescottes.

The method is replaced by an helper in shared-head that uses SpecialPowers.spawn
to access the element.

Differential Revision: https://phabricator.services.mozilla.com/D116556
This commit is contained in:
Nicolas Chevobbe 2021-06-02 08:11:05 +00:00
Родитель 88318b537a
Коммит 28ba5d4a26
8 изменённых файлов: 110 добавлений и 77 удалений

Просмотреть файл

@ -14,8 +14,8 @@ const TEST_DATA = [
selector: "#one",
oldHTML: '<div id="one">First <em>Div</em></div>',
newHTML: '<div id="one">First Div</div>',
validate: async function({ testActor }) {
const text = await testActor.getProperty("#one", "textContent");
validate: async function() {
const text = await getContentPageElementProperty("#one", "textContent");
is(text, "First Div", "New div has expected text content");
const num = await getNumberOfMatchingElementsInContentPage("#one em");
is(num, 0, "No em remaining");
@ -41,9 +41,12 @@ const TEST_DATA = [
newHTML:
'<div id="addedAttribute" class="important" disabled checked>' +
"addedAttribute</div>",
validate: async function({ pageNodeFront, selectedNodeFront, testActor }) {
validate: async function({ pageNodeFront, selectedNodeFront }) {
is(pageNodeFront, selectedNodeFront, "Original element is selected");
const html = await testActor.getProperty("#addedAttribute", "outerHTML");
const html = await getContentPageElementProperty(
"#addedAttribute",
"outerHTML"
);
is(
html,
'<div id="addedAttribute" class="important" disabled="" ' +
@ -64,23 +67,26 @@ const TEST_DATA = [
'<div id="siblings-before-sibling">before sibling</div>' +
'<div id="siblings">siblings (updated)</div>' +
'<div id="siblings-after-sibling">after sibling</div>',
validate: async function({ selectedNodeFront, inspector, testActor }) {
validate: async function({ selectedNodeFront, inspector }) {
const beforeSiblingFront = await getNodeFront(
"#siblings-before-sibling",
inspector
);
is(beforeSiblingFront, selectedNodeFront, "Sibling has been selected");
const text = await testActor.getProperty("#siblings", "textContent");
const text = await getContentPageElementProperty(
"#siblings",
"textContent"
);
is(text, "siblings (updated)", "New div has expected text content");
const beforeText = await testActor.getProperty(
const beforeText = await getContentPageElementProperty(
"#siblings-before-sibling",
"textContent"
);
is(beforeText, "before sibling", "Sibling has been inserted");
const afterText = await testActor.getProperty(
const afterText = await getContentPageElementProperty(
"#siblings-after-sibling",
"textContent"
);

Просмотреть файл

@ -60,11 +60,11 @@ const TEST_DATA = [
validate: async function({ pageNodeFront, selectedNodeFront, testActor }) {
is(pageNodeFront, selectedNodeFront, "Original element is selected");
const emText = await testActor.getProperty(
const emText = await getContentPageElementProperty(
"#badMarkup3 em",
"textContent"
);
const strongText = await testActor.getProperty(
const strongText = await getContentPageElementProperty(
"#badMarkup3 strong",
"textContent"
);
@ -79,11 +79,23 @@ const TEST_DATA = [
validate: async function({ pageNodeFront, selectedNodeFront, testActor }) {
is(pageNodeFront, selectedNodeFront, "Original element is selected");
const divText = await testActor.getProperty("#badMarkup4", "textContent");
const divTag = await testActor.getProperty("#badMarkup4", "tagName");
const divText = await getContentPageElementProperty(
"#badMarkup4",
"textContent"
);
const divTag = await getContentPageElementProperty(
"#badMarkup4",
"tagName"
);
const pText = await testActor.getProperty("#badMarkup4 p", "textContent");
const pTag = await testActor.getProperty("#badMarkup4 p", "tagName");
const pText = await getContentPageElementProperty(
"#badMarkup4 p",
"textContent"
);
const pTag = await getContentPageElementProperty(
"#badMarkup4 p",
"tagName"
);
is(divText, "badMarkup4", "textContent is correct");
is(divTag, "DIV", "did not change to <p> tag");
@ -102,14 +114,20 @@ const TEST_DATA = [
"#badMarkup5 div"
);
const pText = await testActor.getProperty("#badMarkup5", "textContent");
const pTag = await testActor.getProperty("#badMarkup5", "tagName");
const pText = await getContentPageElementProperty(
"#badMarkup5",
"textContent"
);
const pTag = await getContentPageElementProperty(
"#badMarkup5",
"tagName"
);
const divText = await testActor.getProperty(
const divText = await getContentPageElementProperty(
"#badMarkup5 ~ div",
"textContent"
);
const divTag = await testActor.getProperty(
const divTag = await getContentPageElementProperty(
"#badMarkup5 ~ div",
"tagName"
);

Просмотреть файл

@ -21,30 +21,30 @@ const NEW_HTML = '<div id="keyboard">Edited</div>';
requestLongerTimeout(2);
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(TEST_URL);
const { inspector } = await openInspectorForURL(TEST_URL);
inspector.markup._frame.focus();
info("Check that pressing escape cancels edits");
await testEscapeCancels(inspector, testActor);
await testEscapeCancels(inspector);
info("Check that pressing F2 commits edits");
await testF2Commits(inspector, testActor);
await testF2Commits(inspector);
info("Check that editing the <body> element works like other nodes");
await testBody(inspector, testActor);
await testBody(inspector);
info("Check that editing the <head> element works like other nodes");
await testHead(inspector, testActor);
await testHead(inspector);
info("Check that editing the <html> element works like other nodes");
await testDocumentElement(inspector, testActor);
await testDocumentElement(inspector);
info("Check (again) that editing the <html> element works like other nodes");
await testDocumentElement2(inspector, testActor);
await testDocumentElement2(inspector);
});
async function testEscapeCancels(inspector, testActor) {
async function testEscapeCancels(inspector) {
await selectNode(SELECTOR, inspector);
const onHtmlEditorCreated = once(inspector.markup, "begin-editing");
@ -53,7 +53,7 @@ async function testEscapeCancels(inspector, testActor) {
ok(inspector.markup.htmlEditor._visible, "HTML Editor is visible");
is(
await testActor.getProperty(SELECTOR, "outerHTML"),
await getContentPageElementProperty(SELECTOR, "outerHTML"),
OLD_HTML,
"The node is starting with old HTML."
);
@ -66,13 +66,13 @@ async function testEscapeCancels(inspector, testActor) {
ok(!inspector.markup.htmlEditor._visible, "HTML Editor is not visible");
is(
await testActor.getProperty(SELECTOR, "outerHTML"),
await getContentPageElementProperty(SELECTOR, "outerHTML"),
OLD_HTML,
"Escape cancels edits"
);
}
async function testF2Commits(inspector, testActor) {
async function testF2Commits(inspector) {
const onEditorShown = once(inspector.markup.htmlEditor, "popupshown");
inspector.markup._frame.contentDocument.documentElement.focus();
EventUtils.sendKey("F2", inspector.markup._frame.contentWindow);
@ -80,7 +80,7 @@ async function testF2Commits(inspector, testActor) {
ok(inspector.markup.htmlEditor._visible, "HTML Editor is visible");
is(
await testActor.getProperty(SELECTOR, "outerHTML"),
await getContentPageElementProperty(SELECTOR, "outerHTML"),
OLD_HTML,
"The node is starting with old HTML."
);
@ -93,14 +93,17 @@ async function testF2Commits(inspector, testActor) {
ok(!inspector.markup.htmlEditor._visible, "HTML Editor is not visible");
is(
await testActor.getProperty(SELECTOR, "outerHTML"),
await getContentPageElementProperty(SELECTOR, "outerHTML"),
NEW_HTML,
"F2 commits edits - the node has new HTML."
);
}
async function testBody(inspector, testActor) {
const currentBodyHTML = await testActor.getProperty("body", "outerHTML");
async function testBody(inspector) {
const currentBodyHTML = await getContentPageElementProperty(
"body",
"outerHTML"
);
const bodyHTML = '<body id="updated"><p></p></body>';
const bodyFront = await getNodeFront("body", inspector);
@ -114,17 +117,20 @@ async function testBody(inspector, testActor) {
await onReselected;
await onUpdated;
const newBodyHTML = await testActor.getProperty("body", "outerHTML");
const newBodyHTML = await getContentPageElementProperty("body", "outerHTML");
is(newBodyHTML, bodyHTML, "<body> HTML has been updated");
const headsNum = await getNumberOfMatchingElementsInContentPage("head");
is(headsNum, 1, "no extra <head>s have been added");
}
async function testHead(inspector, testActor) {
async function testHead(inspector) {
await selectNode("head", inspector);
const currentHeadHTML = await testActor.getProperty("head", "outerHTML");
const currentHeadHTML = await getContentPageElementProperty(
"head",
"outerHTML"
);
const headHTML =
'<head id="updated"><title>New Title</title>' +
'<script>window.foo="bar";</script></head>';
@ -143,7 +149,7 @@ async function testHead(inspector, testActor) {
is(await getDocumentTitle(), "New Title", "New title has been added");
is(await getWindowFoo(), undefined, "Script has not been executed");
is(
await testActor.getProperty("head", "outerHTML"),
await getContentPageElementProperty("head", "outerHTML"),
headHTML,
"<head> HTML has been updated"
);
@ -154,7 +160,7 @@ async function testHead(inspector, testActor) {
);
}
async function testDocumentElement(inspector, testActor) {
async function testDocumentElement(inspector) {
const currentDocElementOuterHMTL = await getDocumentOuterHTML();
const docElementHTML =
'<html id="updated" foo="bar"><head>' +
@ -193,7 +199,7 @@ async function testDocumentElement(inspector, testActor) {
"<html> attribute has been updated"
);
is(
await testActor.getProperty("html", "outerHTML"),
await getContentPageElementProperty("html", "outerHTML"),
docElementHTML,
"<html> HTML has been updated"
);
@ -208,13 +214,13 @@ async function testDocumentElement(inspector, testActor) {
"no extra <body>s have been added"
);
is(
await testActor.getProperty("body", "textContent"),
await getContentPageElementProperty("body", "textContent"),
"Hello",
"document.body.textContent has been updated"
);
}
async function testDocumentElement2(inspector, testActor) {
async function testDocumentElement2(inspector) {
const currentDocElementOuterHMTL = await getDocumentOuterHTML();
const docElementHTML =
'<html id="somethingelse" class="updated"><head>' +
@ -253,7 +259,7 @@ async function testDocumentElement2(inspector, testActor) {
"<html> attribute has been removed"
);
is(
await testActor.getProperty("html", "outerHTML"),
await getContentPageElementProperty("html", "outerHTML"),
docElementHTML,
"<html> HTML has been updated"
);
@ -268,7 +274,7 @@ async function testDocumentElement2(inspector, testActor) {
"no extra <body>s have been added"
);
is(
await testActor.getProperty("body", "textContent"),
await getContentPageElementProperty("body", "textContent"),
"Hello again",
"document.body.textContent has been updated"
);

Просмотреть файл

@ -15,18 +15,18 @@ const TEST_URL =
requestLongerTimeout(2);
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(TEST_URL);
const { inspector } = await openInspectorForURL(TEST_URL);
inspector.markup._frame.focus();
info("Check that editing the <svg> element works like other nodes");
await testDocumentElement(inspector, testActor);
await testDocumentElement(inspector);
info("Check (again) that editing the <svg> element works like other nodes");
await testDocumentElement2(inspector, testActor);
await testDocumentElement2(inspector);
});
async function testDocumentElement(inspector, testActor) {
async function testDocumentElement(inspector) {
const currentDocElementOuterHTML = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
@ -57,13 +57,13 @@ async function testDocumentElement(inspector, testActor) {
"<svg> height has been updated"
);
is(
await testActor.getProperty("svg", "outerHTML"),
await getContentPageElementProperty("svg", "outerHTML"),
docElementSVG,
"<svg> markup has been updated"
);
}
async function testDocumentElement2(inspector, testActor) {
async function testDocumentElement2(inspector) {
const currentDocElementOuterHTML = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
@ -94,7 +94,7 @@ async function testDocumentElement2(inspector, testActor) {
"<svg> height has been updated"
);
is(
await testActor.getProperty("svg", "outerHTML"),
await getContentPageElementProperty("svg", "outerHTML"),
docElementSVG,
"<svg> markup has been updated"
);

Просмотреть файл

@ -13,17 +13,17 @@ const PASTE_AS_LAST_CHILD =
add_task(async function() {
const clipboard = require("devtools/shared/platform/clipboard");
const { inspector, testActor } = await openInspectorForURL(TEST_URL);
const { inspector } = await openInspectorForURL(TEST_URL);
const refSelector = "svg";
const oldHTML = await testActor.getProperty(refSelector, "innerHTML");
const oldHTML = await getContentPageElementProperty(refSelector, "innerHTML");
await selectNode(refSelector, inspector);
const markupTagLine = getContainerForSelector(refSelector, inspector).tagLine;
await pasteContent("node-menu-pastefirstchild", PASTE_AS_FIRST_CHILD);
await pasteContent("node-menu-pastelastchild", PASTE_AS_LAST_CHILD);
const html = await testActor.getProperty(refSelector, "innerHTML");
const html = await getContentPageElementProperty(refSelector, "innerHTML");
const expectedHtml = PASTE_AS_FIRST_CHILD + oldHTML + PASTE_AS_LAST_CHILD;
is(html, expectedHtml, "The innerHTML of the SVG node is correct");

Просмотреть файл

@ -65,7 +65,7 @@ add_task(async function() {
info("Waiting for inspector selection to update");
await onNodeReselected;
const outerHTML = await testActor.getProperty("body", "outerHTML");
const outerHTML = await getContentPageElementProperty("body", "outerHTML");
ok(
outerHTML.includes(clipboard.getText()),
"Clipboard content was pasted into the node's outer HTML."
@ -87,7 +87,7 @@ add_task(async function() {
);
const innerHTMLSelector = "#paste-area .inner";
const getInnerHTML = () =>
testActor.getProperty(innerHTMLSelector, "innerHTML");
getContentPageElementProperty(innerHTMLSelector, "innerHTML");
const origInnerHTML = await getInnerHTML();
const nodeFront = await getNodeFront(innerHTMLSelector, inspector);
@ -141,7 +141,10 @@ add_task(async function() {
await onMutation;
}
let html = await testActor.getProperty(adjacentNodeSelector, "innerHTML");
let html = await getContentPageElementProperty(
adjacentNodeSelector,
"innerHTML"
);
ok(
html.trim() === '1<span class="ref">234</span><span>5</span>',
"The Paste as Last Child / as First Child / Before / After worked as " +
@ -149,7 +152,10 @@ add_task(async function() {
);
await undoChange(inspector);
html = await testActor.getProperty(adjacentNodeSelector, "innerHTML");
html = await getContentPageElementProperty(
adjacentNodeSelector,
"innerHTML"
);
ok(
html.trim() === '1<span class="ref">234</span>',
"Undo works for paste adjacent HTML"

Просмотреть файл

@ -798,3 +798,20 @@ function getNumberOfMatchingElementsInContentPage(selector) {
return content.document.querySelectorAll(innerSelector).length;
});
}
/**
* Get the property of an element in the content page
*
* @param {string} selector: The selector to get the element we want the property of
* @param {string} propertyName: The name of the property we want the value of
* @returns {Promise} A promise that returns with the value of the property for the element
*/
function getContentPageElementProperty(selector, propertyName) {
return SpecialPowers.spawn(
gBrowser.selectedBrowser,
[selector, propertyName],
function(innerSelector, innerPropertyName) {
return content.document.querySelector(innerSelector)[innerPropertyName];
}
);
}

Просмотреть файл

@ -175,15 +175,6 @@ var testSpec = protocol.generateActorSpec({
},
response: {},
},
getProperty: {
request: {
selector: Arg(0, "string"),
property: Arg(1, "string"),
},
response: {
value: RetVal("string"),
},
},
reload: {
request: {},
response: {},
@ -560,17 +551,6 @@ var TestActor = protocol.ActorClassWithSpec(testSpec, {
node[property] = value;
},
/**
* Get a JS property on a DOM Node.
* @param {String} selector The node selector
* @param {String} property The property name
* @return {String} value The attribute value
*/
getProperty: function(selector, property) {
const node = this._querySelector(selector);
return node[property];
},
/**
* Reload the content window.
*/