Bug 1708252 - [devtools] Stop using test-actor eval r=nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D113714
This commit is contained in:
Julian Descottes 2021-04-29 07:31:11 +00:00
Родитель 9c9f57574e
Коммит 402cf47aab
44 изменённых файлов: 390 добавлений и 361 удалений

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

@ -12,20 +12,20 @@ const IFRAME2 = URL_ROOT + "doc_boxmodel_iframe2.html";
add_task(async function() {
const tab = await addTab(IFRAME1);
const browser = tab.linkedBrowser;
const { inspector, boxmodel, testActor } = await openLayoutView();
const { inspector, boxmodel } = await openLayoutView();
await testFirstPage(inspector, boxmodel, browser);
info("Navigate to the second page");
let onMarkupLoaded = waitForMarkupLoaded(inspector);
await testActor.eval(`location.href="${IFRAME2}"`);
await navigateTo(IFRAME2);
await onMarkupLoaded;
await testSecondPage(inspector, boxmodel, browser);
info("Go back to the first page");
onMarkupLoaded = waitForMarkupLoaded(inspector);
await testActor.eval("history.back();");
gBrowser.goBack();
await onMarkupLoaded;
await testBackToFirstPage(inspector, boxmodel, browser);

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

@ -45,13 +45,13 @@ const DOCUMENT_URL =
add_task(async function() {
await addTab(DOCUMENT_URL);
const { toolbox, inspector, view, testActor } = await openComputedView();
const { toolbox, inspector, view } = await openComputedView();
await selectNode("span", inspector);
await testInlineStyle(view);
await testFirstInlineStyleSheet(view, toolbox, testActor);
await testSecondInlineStyleSheet(view, toolbox, testActor);
await testExternalStyleSheet(view, toolbox, testActor);
await testFirstInlineStyleSheet(view, toolbox);
await testSecondInlineStyleSheet(view, toolbox);
await testExternalStyleSheet(view, toolbox);
});
async function testInlineStyle(view) {
@ -71,7 +71,7 @@ async function testInlineStyle(view) {
gBrowser.removeTab(tab);
}
async function testFirstInlineStyleSheet(view, toolbox, testActor) {
async function testFirstInlineStyleSheet(view, toolbox) {
info("Testing inline stylesheet");
info("Listening for toolbox switch to the styleeditor");
@ -83,10 +83,10 @@ async function testFirstInlineStyleSheet(view, toolbox, testActor) {
ok(true, "Switched to the style-editor panel in the toolbox");
await validateStyleEditorSheet(editor, 0, testActor);
await validateStyleEditorSheet(editor, 0);
}
async function testSecondInlineStyleSheet(view, toolbox, testActor) {
async function testSecondInlineStyleSheet(view, toolbox) {
info("Testing second inline stylesheet");
info("Waiting for the stylesheet editor to be selected");
@ -105,10 +105,10 @@ async function testSecondInlineStyleSheet(view, toolbox, testActor) {
"styleeditor",
"The style editor is selected again"
);
await validateStyleEditorSheet(editor, 1, testActor);
await validateStyleEditorSheet(editor, 1);
}
async function testExternalStyleSheet(view, toolbox, testActor) {
async function testExternalStyleSheet(view, toolbox) {
info("Testing external stylesheet");
info("Waiting for the stylesheet editor to be selected");
@ -127,14 +127,17 @@ async function testExternalStyleSheet(view, toolbox, testActor) {
"styleeditor",
"The style editor is selected again"
);
await validateStyleEditorSheet(editor, 2, testActor);
await validateStyleEditorSheet(editor, 2);
}
async function validateStyleEditorSheet(editor, expectedSheetIndex, testActor) {
async function validateStyleEditorSheet(editor, expectedSheetIndex) {
info("Validating style editor stylesheet");
const expectedHref = await testActor.eval(`
document.styleSheets[${expectedSheetIndex}].href;
`);
const expectedHref = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[expectedSheetIndex],
_expectedSheetIndex =>
content.document.styleSheets[_expectedSheetIndex].href
);
is(
editor.styleSheet.href,
expectedHref,

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

@ -21,7 +21,7 @@ const TEST_URI = `
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, flexboxInspector, testActor } = await openLayoutView();
const { inspector, flexboxInspector } = await openLayoutView();
const { document: doc } = flexboxInspector;
const onFlexItemSizingRendered = waitForDOM(doc, "ul.flex-item-sizing");
@ -32,9 +32,11 @@ add_task(async function() {
info("Changing the flexbox in the page.");
const onAccordionsChanged = waitForDOM(doc, ".accordion-item", 4);
testActor.eval(`
document.getElementById("item").className = "container";
`);
await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => (content.document.getElementById("item").className = "container")
);
const [flexItemPane, flexContainerPane] = await onAccordionsChanged;
ok(flexItemPane, "The flex item accordion pane is rendered.");

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

@ -19,7 +19,7 @@ const TEST_URI = `
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, flexboxInspector, testActor } = await openLayoutView();
const { inspector, flexboxInspector } = await openLayoutView();
const { document: doc } = flexboxInspector;
const onFlexItemListRendered = waitForDOM(doc, ".flex-item-list");
@ -36,10 +36,10 @@ add_task(async function() {
info("Changing the flexbox in the page.");
const onFlexItemListChanged = waitForDOM(doc, ".flex-item-list > button", 2);
testActor.eval(`
const div = document.createElement("div");
document.getElementById("container").appendChild(div);
`);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const div = content.document.createElement("div");
content.document.getElementById("container").appendChild(div);
});
const elements = await onFlexItemListChanged;
info("Checking the flex item list is correct.");

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

@ -18,7 +18,7 @@ const TEST_URI = `
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, flexboxInspector, testActor } = await openLayoutView();
const { inspector, flexboxInspector } = await openLayoutView();
const { document: doc } = flexboxInspector;
const onFlexItemSizingRendered = waitForDOM(doc, "ul.flex-item-sizing");
@ -38,9 +38,11 @@ add_task(async function() {
"ul.flex-item-sizing > li",
3
);
testActor.eval(`
document.getElementById("item").style.minWidth = "100px";
`);
SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => (content.document.getElementById("item").style.minWidth = "100px")
);
const elements = await onFlexItemSizingChanged;
info("Checking the flex item sizing info is correct.");

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

@ -11,7 +11,7 @@ const TEST_URI = URL_ROOT + "doc_iframe_reloaded.html";
add_task(async function() {
await addTab(TEST_URI);
const { gridInspector, inspector, testActor } = await openLayoutView();
const { gridInspector, inspector } = await openLayoutView();
const { document: doc } = gridInspector;
const { highlighters, store } = inspector;
const gridList = doc.getElementById("grid-list");
@ -46,7 +46,9 @@ add_task(async function() {
!state.grids[0].highlighted
);
const onHighlighterHidden = highlighters.once("grid-highlighter-hidden");
testActor.eval("window.wrappedJSObject.reloadIFrame();");
SpecialPowers.spawn(gBrowser.selectedBrowser, [], () =>
content.wrappedJSObject.reloadIFrame()
);
await onNewListUnchecked;
await onHighlighterHidden;

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

@ -24,7 +24,7 @@ const TEST_URI = `
add_task(async function() {
await pushPref("devtools.gridinspector.maxHighlighters", 1);
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, gridInspector, testActor } = await openLayoutView();
const { inspector, gridInspector } = await openLayoutView();
const { document: doc } = gridInspector;
const { highlighters, store } = inspector;
@ -55,9 +55,9 @@ add_task(async function() {
state.grids[0].highlighted &&
!state.grids[1].highlighted
);
testActor.eval(`
document.getElementById("grid2").classList.add("grid");
`);
SpecialPowers.spawn(gBrowser.selectedBrowser, [], () =>
content.document.getElementById("grid2").classList.add("grid")
);
await onGridListUpdate;
info("Checking the new Grid Inspector state.");

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

@ -20,7 +20,7 @@ const TEST_URI = `
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, gridInspector, testActor } = await openLayoutView();
const { inspector, gridInspector } = await openLayoutView();
const { document: doc } = gridInspector;
const { highlighters, store } = inspector;
@ -48,9 +48,9 @@ add_task(async function() {
info("Removing the #grid container in the content page.");
const onHighlighterHidden = highlighters.once("grid-highlighter-hidden");
onCheckboxChange = waitUntilState(store, state => state.grids.length == 0);
testActor.eval(`
document.getElementById("grid").remove();
`);
SpecialPowers.spawn(gBrowser.selectedBrowser, [], () =>
content.document.getElementById("grid").remove()
);
await onHighlighterHidden;
await onCheckboxChange;

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

@ -23,7 +23,7 @@ const TEST_URI = `
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, gridInspector, testActor } = await openLayoutView();
const { inspector, gridInspector } = await openLayoutView();
const { document: doc } = gridInspector;
const { highlighters, store } = inspector;
@ -50,11 +50,11 @@ add_task(async function() {
const onReflow = inspector.once("reflow-in-selected-target");
const onGridOutlineChanged = waitForDOM(doc, ".grid-outline-cell", 4);
testActor.eval(`
const div = document.createElement("div");
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const div = content.document.createElement("div");
div.textContent = "item 3";
document.querySelector(".container").appendChild(div);
`);
content.document.querySelector(".container").appendChild(div);
});
await onReflow;
elements = await onGridOutlineChanged;

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

@ -8,7 +8,7 @@
add_task(async function() {
await addTab(URL_ROOT + "doc_markup_image_and_canvas.html");
const { inspector, testActor } = await openInspector();
const { inspector } = await openInspector();
await selectNode("div", inspector);
await assertCopyImageDataNotAvailable(inspector);
@ -24,8 +24,11 @@ add_task(async function() {
await selectNode("canvas", inspector);
await assertCopyImageDataAvailable(inspector);
const expectedURL = await testActor.eval(`
document.querySelector(".canvas").toDataURL();`);
const expectedURL = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.document.querySelector(".canvas").toDataURL()
);
await triggerCopyImageUrlAndWaitForClipboard(expectedURL, inspector);
// Check again that the menu isn't available on the DIV (to make sure our

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

@ -34,11 +34,11 @@ const TEST_DATA = [
textContent: "grid",
visible: true,
},
changeStyle: async function(testActor) {
await testActor.eval(`
let node = document.getElementById("grid");
changeStyle: async function() {
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const node = content.document.getElementById("grid");
node.style.display = "block";
`);
});
},
after: {
visible: false,
@ -50,11 +50,11 @@ const TEST_DATA = [
before: {
visible: false,
},
changeStyle: async function(testActor) {
await testActor.eval(`
let node = document.getElementById("grid");
changeStyle: async function() {
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const node = content.document.getElementById("grid");
node.style.display = "grid";
`);
});
},
after: {
textContent: "grid",
@ -67,11 +67,11 @@ const TEST_DATA = [
before: {
visible: false,
},
changeStyle: async function(testActor) {
await testActor.eval(`
let node = document.getElementById("block");
changeStyle: async function() {
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const node = content.document.getElementById("block");
node.style.display = "grid";
`);
});
},
after: {
textContent: "grid",
@ -84,10 +84,10 @@ const TEST_DATA = [
before: {
visible: false,
},
changeStyle: async function(testActor) {
await testActor.eval(`
document.getElementById("flex").removeAttribute("hidden");
`);
changeStyle: async function() {
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () =>
content.document.getElementById("flex").removeAttribute("hidden")
);
},
after: {
textContent: "flex",
@ -97,19 +97,18 @@ const TEST_DATA = [
];
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(
const { inspector } = await openInspectorForURL(
"data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)
);
for (const data of TEST_DATA) {
info("Running test case: " + data.desc);
await runTestData(inspector, testActor, data);
await runTestData(inspector, data);
}
});
async function runTestData(
inspector,
testActor,
{ selector, before, changeStyle, after }
) {
await selectNode(selector, inspector);
@ -134,7 +133,7 @@ async function runTestData(
info("Listening for the display-change event");
const onDisplayChanged = inspector.markup.walker.once("display-change");
info("Making style changes");
await changeStyle(testActor);
await changeStyle();
const nodes = await onDisplayChanged;
info("Verifying that the list of changed nodes include our container");

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

@ -73,9 +73,11 @@ const TEST_DATA = [
},
{
selector: "#noevents",
beforeTest: async function(inspector, testActor) {
beforeTest: async function(inspector) {
const nodeMutated = inspector.once("markupmutation");
await testActor.eval("window.wrappedJSObject.addNoeventsClickHandler();");
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () =>
content.wrappedJSObject.addNoeventsClickHandler()
);
await nodeMutated;
},
expected: [
@ -92,10 +94,10 @@ const TEST_DATA = [
},
{
selector: "#noevents",
beforeTest: async function(inspector, testActor) {
beforeTest: async function(inspector) {
const nodeMutated = inspector.once("markupmutation");
await testActor.eval(
"window.wrappedJSObject.removeNoeventsClickHandler();"
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () =>
content.wrappedJSObject.removeNoeventsClickHandler()
);
await nodeMutated;
},

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

@ -22,7 +22,7 @@ add_task(async function() {
waitForExplicitFinish();
await pushPref("devtools.chrome.enabled", false);
const { tab, inspector, testActor } = await openInspectorForURL(TEST_URL);
const { tab, inspector } = await openInspectorForURL(TEST_URL);
const browser = tab.linkedBrowser;
const badgeEventAdded = inspector.markup.once("badge-added-event");
@ -41,6 +41,6 @@ add_task(async function() {
is(result, "timeout", "Ensure that no event badges were added");
for (const test of TEST_DATA) {
await checkEventsForNode(test, inspector, testActor);
await checkEventsForNode(test, inspector);
}
});

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

@ -33,7 +33,7 @@ add_task(async function() {
waitForExplicitFinish();
await pushPref("devtools.chrome.enabled", true);
const { tab, inspector, testActor } = await openInspectorForURL(TEST_URL);
const { tab, inspector } = await openInspectorForURL(TEST_URL);
const browser = tab.linkedBrowser;
const eventBadgeAdded = inspector.markup.once("badge-added-event");
@ -48,6 +48,6 @@ add_task(async function() {
await eventBadgeAdded;
for (const test of TEST_DATA) {
await checkEventsForNode(test, inspector, testActor);
await checkEventsForNode(test, inspector);
}
});

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

@ -32,9 +32,7 @@ add_task(async function() {
// Load some other URL before opening the toolbox, then navigate to
// the test URL. This ensures that source map service will see the
// sources as they are loaded, avoiding any races.
const { toolbox, inspector, testActor } = await openInspectorForURL(
INITIAL_URL
);
const { toolbox, inspector } = await openInspectorForURL(INITIAL_URL);
// Ensure the source map service is operating. This looks a bit
// funny, but sourceMapURLService is a getter, and we don't need the
@ -46,7 +44,7 @@ add_task(async function() {
await inspector.markup.expandAll();
for (const test of TEST_DATA) {
await checkEventsForNode(test, inspector, testActor);
await checkEventsForNode(test, inspector);
}
// Wait for promises to avoid leaks when running this as a single test.

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

@ -16,12 +16,15 @@ const TEST_DATA = [
validate: async function({ pageNodeFront, selectedNodeFront, testActor }) {
is(pageNodeFront, selectedNodeFront, "Original element is selected");
const textNodeName = await testActor.eval(`
document.querySelector("#badMarkup1").nextSibling.nodeName
`);
const textNodeData = await testActor.eval(`
document.querySelector("#badMarkup1").nextSibling.data
`);
const [textNodeName, textNodeData] = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => {
const node = content.document.querySelector("#badMarkup1")
.nextSibling;
return [node.nodeName, node.data];
}
);
is(textNodeName, "#text", "Sibling is a text element");
is(textNodeData, " hanging", "New text node has expected text content");
},
@ -35,12 +38,15 @@ const TEST_DATA = [
validate: async function({ pageNodeFront, selectedNodeFront, testActor }) {
is(pageNodeFront, selectedNodeFront, "Original element is selected");
const textNodeName = await testActor.eval(`
document.querySelector("#badMarkup2").nextSibling.nodeName
`);
const textNodeData = await testActor.eval(`
document.querySelector("#badMarkup2").nextSibling.data
`);
const [textNodeName, textNodeData] = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => {
const node = content.document.querySelector("#badMarkup2")
.nextSibling;
return [node.nodeName, node.data];
}
);
is(textNodeName, "#text", "Sibling is a text element");
is(textNodeData, " hanging", "New text node has expected text content");
},

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

@ -140,16 +140,8 @@ async function testHead(inspector, testActor) {
await onReselected;
await onUpdated;
is(
await testActor.eval("document.title"),
"New Title",
"New title has been added"
);
is(
await testActor.eval("window.foo"),
undefined,
"Script has not been executed"
);
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"),
headHTML,
@ -163,9 +155,7 @@ async function testHead(inspector, testActor) {
}
async function testDocumentElement(inspector, testActor) {
const currentDocElementOuterHMTL = await testActor.eval(
"document.documentElement.outerHMTL"
);
const currentDocElementOuterHMTL = await getDocumentOuterHTML();
const docElementHTML =
'<html id="updated" foo="bar"><head>' +
"<title>Updated from document element</title>" +
@ -182,15 +172,11 @@ async function testDocumentElement(inspector, testActor) {
await onReselected;
is(
await testActor.eval("document.title"),
await getDocumentTitle(),
"Updated from document element",
"New title has been added"
);
is(
await testActor.eval("window.foo"),
undefined,
"Script has not been executed"
);
is(await getWindowFoo(), undefined, "Script has not been executed");
is(
await getAttributeInBrowser(gBrowser.selectedBrowser, "html", "id"),
"updated",
@ -229,9 +215,7 @@ async function testDocumentElement(inspector, testActor) {
}
async function testDocumentElement2(inspector, testActor) {
const currentDocElementOuterHMTL = await testActor.eval(
"document.documentElement.outerHMTL"
);
const currentDocElementOuterHMTL = await getDocumentOuterHTML();
const docElementHTML =
'<html id="somethingelse" class="updated"><head>' +
"<title>Updated again from document element</title>" +
@ -248,15 +232,11 @@ async function testDocumentElement2(inspector, testActor) {
await onReselected;
is(
await testActor.eval("document.title"),
await getDocumentTitle(),
"Updated again from document element",
"New title has been added"
);
is(
await testActor.eval("window.foo"),
undefined,
"Script has not been executed"
);
is(await getWindowFoo(), undefined, "Script has not been executed");
is(
await getAttributeInBrowser(gBrowser.selectedBrowser, "html", "id"),
"somethingelse",
@ -293,3 +273,27 @@ async function testDocumentElement2(inspector, testActor) {
"document.body.textContent has been updated"
);
}
function getDocumentTitle() {
return SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.document.title
);
}
function getDocumentOuterHTML() {
return SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.document.documentElement.outerHTML
);
}
function getWindowFoo() {
return SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.wrappedJSObject.foo
);
}

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

@ -27,8 +27,10 @@ add_task(async function() {
});
async function testDocumentElement(inspector, testActor) {
const currentDocElementOuterHTML = await testActor.eval(
"document.documentElement.outerHTML"
const currentDocElementOuterHTML = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.document.documentElement.outerHTML
);
const docElementSVG =
'<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">' +
@ -62,8 +64,10 @@ async function testDocumentElement(inspector, testActor) {
}
async function testDocumentElement2(inspector, testActor) {
const currentDocElementOuterHTML = await testActor.eval(
"document.documentElement.outerHTML"
const currentDocElementOuterHTML = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.document.documentElement.outerHTML
);
const docElementSVG =
'<svg width="300" height="300" xmlns="http://www.w3.org/2000/svg">' +

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

@ -22,8 +22,8 @@ add_task(async function() {
inspector.markup._frame.focus();
info("Before test starts, #scroll-top is visible, #scroll-bottom is hidden");
await checkElementIsInViewport("#scroll-top", true, testActor);
await checkElementIsInViewport("#scroll-bottom", false, testActor);
await checkElementIsInViewport("#scroll-top", true);
await checkElementIsInViewport("#scroll-bottom", false);
info("Select the #scroll-bottom node");
await selectNode("#scroll-bottom", inspector);
@ -34,8 +34,8 @@ add_task(async function() {
ok(true, "Scroll event received");
info("#scroll-top should be scrolled out, #scroll-bottom should be visible");
await checkElementIsInViewport("#scroll-top", false, testActor);
await checkElementIsInViewport("#scroll-bottom", true, testActor);
await checkElementIsInViewport("#scroll-top", false);
await checkElementIsInViewport("#scroll-bottom", true);
info("Select the #scroll-top node");
await selectNode("#scroll-top", inspector);
@ -46,8 +46,8 @@ add_task(async function() {
ok(true, "Scroll event received");
info("#scroll-top should be visible, #scroll-bottom should be scrolled out");
await checkElementIsInViewport("#scroll-top", true, testActor);
await checkElementIsInViewport("#scroll-bottom", false, testActor);
await checkElementIsInViewport("#scroll-top", true);
await checkElementIsInViewport("#scroll-bottom", false);
info("Select #scroll-bottom node");
await selectNode("#scroll-bottom", inspector);
@ -55,8 +55,8 @@ add_task(async function() {
await EventUtils.synthesizeKey("S", { shiftKey: true }, inspector.panelWin);
info("Same state, #scroll-top is visible, #scroll-bottom is scrolled out");
await checkElementIsInViewport("#scroll-top", true, testActor);
await checkElementIsInViewport("#scroll-bottom", false, testActor);
await checkElementIsInViewport("#scroll-top", true);
await checkElementIsInViewport("#scroll-bottom", false);
});
/**
@ -68,17 +68,23 @@ add_task(async function() {
* css selector for the element to test
* @param {Boolean} expected
* true if the element is expected to be in the viewport, false otherwise
* @param {TestActor} testActor
* current test actor
* @return {Promise} promise
*/
async function checkElementIsInViewport(selector, expected, testActor) {
const isInViewport = await testActor.eval(`
let node = document.querySelector("${selector}");
let rect = node.getBoundingClientRect();
rect.bottom >= 0 && rect.right >= 0 &&
rect.top <= window.innerHeight && rect.left <= window.innerWidth;
`);
async function checkElementIsInViewport(selector, expected) {
const isInViewport = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[selector],
_selector => {
const node = content.document.querySelector(_selector);
const rect = node.getBoundingClientRect();
return (
rect.bottom >= 0 &&
rect.right >= 0 &&
rect.top <= content.innerHeight &&
rect.left <= content.innerWidth
);
}
);
is(
isInViewport,

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

@ -44,7 +44,8 @@ add_task(async function() {
ok(inspector.markup, "There is a markup view");
// Select an element while the tab is in the middle of a slow reload.
testActor.eval("location.reload()");
// Do not await here because we interact with the page during navigation.
const onToolboxNavigated = navigateTo(TEST_URL);
info("Wait for DOMContentLoaded");
await domContentLoaded;
@ -56,6 +57,9 @@ add_task(async function() {
info("Wait for load");
await pageLoaded;
info("Wait for toolbox navigation");
await onToolboxNavigated;
info("Wait for markup-loaded after element inspection");
await markupLoaded;
info("Wait for multiple children updates after element inspection");

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

@ -145,10 +145,10 @@ const TEST_DATA = [
desc: "Adding ::after element",
numMutations: 2,
test: async function(testActor) {
await testActor.eval(`
let node1 = document.querySelector("#node1");
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const node1 = content.document.querySelector("#node1");
node1.classList.add("pseudo");
`);
});
},
check: async function(inspector) {
const { children } = await getContainerForSelector("#node1", inspector);
@ -163,10 +163,10 @@ const TEST_DATA = [
desc: "Removing ::after element",
numMutations: 2,
test: async function(testActor) {
await testActor.eval(`
let node1 = document.querySelector("#node1");
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const node1 = content.document.querySelector("#node1");
node1.classList.remove("pseudo");
`);
});
},
check: async function(inspector) {
const container = await getContainerForSelector("#node1", inspector);
@ -193,11 +193,11 @@ const TEST_DATA = [
{
desc: "Adding a second text child",
test: async function(testActor) {
await testActor.eval(`
let node1 = document.querySelector("#node1");
let newText = node1.ownerDocument.createTextNode("more");
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const node1 = content.document.querySelector("#node1");
const newText = node1.ownerDocument.createTextNode("more");
node1.appendChild(newText);
`);
});
},
check: async function(inspector) {
const container = await getContainerForSelector("#node1", inspector);
@ -286,12 +286,12 @@ const TEST_DATA = [
{
desc: "Removing child nodes",
test: async function(testActor) {
await testActor.eval(`
let node4 = document.querySelector("#node4");
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const node4 = content.document.querySelector("#node4");
while (node4.firstChild) {
node4.removeChild(node4.firstChild);
node4.firstChild.remove();
}
`);
});
},
check: async function(inspector) {
const { children } = await getContainerForSelector("#node4", inspector);
@ -301,11 +301,11 @@ const TEST_DATA = [
{
desc: "Appending a child to a different parent",
test: async function(testActor) {
await testActor.eval(`
let node17 = document.querySelector("#node17");
let node2 = document.querySelector("#node2");
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const node17 = content.document.querySelector("#node17");
const node2 = content.document.querySelector("#node2");
node2.appendChild(node17);
`);
});
},
check: async function(inspector) {
const { children } = await getContainerForSelector("#node16", inspector);
@ -337,13 +337,13 @@ const TEST_DATA = [
// node18
// node19
test: async function(testActor) {
await testActor.eval(`
let node18 = document.querySelector("#node18");
let node20 = document.querySelector("#node20");
let node1 = document.querySelector("#node1");
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const node18 = content.document.querySelector("#node18");
const node20 = content.document.querySelector("#node20");
const node1 = content.document.querySelector("#node1");
node1.appendChild(node20);
node20.appendChild(node18);
`);
});
},
check: async function(inspector) {
await inspector.markup.expandAll();

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

@ -29,30 +29,30 @@ const TEST_DATA = [
{
desc: "Adding a new node should flash the new node",
mutate: async function(testActor) {
await testActor.eval(`
let newLi = document.createElement("LI");
newLi.textContent = "new list item";
document.querySelector(".list").appendChild(newLi);
`);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const newLi = content.document.createElement("LI");
newLi.textContent = "new list item";
content.document.querySelector(".list").appendChild(newLi);
});
},
flashedNode: ".list li:nth-child(3)",
},
{
desc: "Removing a node should flash its parent",
mutate: async function(testActor) {
await testActor.eval(`
let root = document.querySelector(".list");
root.removeChild(root.lastElementChild);
`);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const root = content.document.querySelector(".list");
root.removeChild(root.lastElementChild);
});
},
},
{
desc: "Re-appending an existing node should only flash this node",
mutate: async function(testActor) {
await testActor.eval(`
let root = document.querySelector(".list");
root.appendChild(root.firstElementChild);
`);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const root = content.document.querySelector(".list");
root.appendChild(root.firstElementChild);
});
},
flashedNode: ".list .item:last-child",
},
@ -98,24 +98,24 @@ const TEST_DATA = [
desc: "Multiple changes to an attribute should flash the attribute",
attribute: "class",
mutate: async function(testActor) {
await testActor.eval(`
let root = document.querySelector(".list");
root.removeAttribute("class");
root.setAttribute("class", "list value-" + Date.now());
root.setAttribute("class", "list value-" + Date.now());
root.removeAttribute("class");
root.setAttribute("class", "list value-" + Date.now());
root.setAttribute("class", "list value-" + Date.now());
`);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const root = content.document.querySelector(".list");
root.removeAttribute("class");
root.setAttribute("class", "list value-" + Date.now());
root.setAttribute("class", "list value-" + Date.now());
root.removeAttribute("class");
root.setAttribute("class", "list value-" + Date.now());
root.setAttribute("class", "list value-" + Date.now());
});
},
},
{
desc: "Removing an attribute should flash the node",
mutate: async function(testActor) {
await testActor.eval(`
let root = document.querySelector(".list");
root.removeAttribute("class");
`);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const root = content.document.querySelector(".list");
root.removeAttribute("class");
});
},
},
];
@ -128,7 +128,7 @@ add_task(async function() {
Preferences.set("privacy.reduceTimerPrecision", timerPrecision);
});
const { inspector, testActor } = await openInspectorForURL(TEST_URL);
const { inspector } = await openInspectorForURL(TEST_URL);
// Make sure mutated nodes flash for a very long time so we can more easily
// assert they do
@ -145,7 +145,7 @@ add_task(async function() {
info("Mutating the DOM and listening for markupmutation event");
const onMutation = inspector.once("markupmutation");
await mutate(testActor);
await mutate();
const mutations = await onMutation;
info("Wait for the breadcrumbs widget to update if it needs to");

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

@ -12,13 +12,11 @@ const TEST_DATA = [
desc: "Hiding a node by creating a new stylesheet",
selector: "#normal-div",
before: true,
changeStyle: async function(testActor) {
await testActor.eval(`
let div = document.createElement("div");
div.id = "new-style";
div.innerHTML = "<style>#normal-div {display:none;}</style>";
document.body.appendChild(div);
`);
changeStyle: () => {
const div = content.document.createElement("div");
div.id = "new-style";
div.innerHTML = "<style>#normal-div {display:none;}</style>";
content.document.body.appendChild(div);
},
after: false,
},
@ -26,22 +24,16 @@ const TEST_DATA = [
desc: "Showing a node by deleting an existing stylesheet",
selector: "#normal-div",
before: false,
changeStyle: async function(testActor) {
await testActor.eval(`
document.getElementById("new-style").remove();
`);
},
changeStyle: () => content.document.getElementById("new-style").remove(),
after: true,
},
{
desc: "Hiding a node by changing its style property",
selector: "#display-none",
before: false,
changeStyle: async function(testActor) {
await testActor.eval(`
let node = document.querySelector("#display-none");
node.style.display = "block";
`);
changeStyle: () => {
const node = content.document.querySelector("#display-none");
node.style.display = "block";
},
after: true,
},
@ -49,38 +41,29 @@ const TEST_DATA = [
desc: "Showing a node by removing its hidden attribute",
selector: "#hidden-true",
before: false,
changeStyle: async function(testActor) {
await testActor.eval(`
document.querySelector("#hidden-true")
.removeAttribute("hidden");
`);
},
changeStyle: () =>
content.document.querySelector("#hidden-true").removeAttribute("hidden"),
after: true,
},
{
desc: "Hiding a node by adding a hidden attribute",
selector: "#hidden-true",
before: true,
changeStyle: async function(testActor) {
await setAttributeInBrowser(
gBrowser.selectedBrowser,
"#hidden-true",
"hidden",
"true"
);
},
changeStyle: () =>
content.document
.querySelector("#hidden-true")
.setAttribute("hidden", true),
after: false,
},
{
desc: "Showing a node by changin a stylesheet's rule",
selector: "#hidden-via-stylesheet",
before: false,
changeStyle: async function(testActor) {
await testActor.eval(`
document.styleSheets[0]
.cssRules[0].style
.setProperty("display", "inline");
`);
changeStyle: () => {
content.document.styleSheets[0].cssRules[0].style.setProperty(
"display",
"inline"
);
},
after: true,
},
@ -88,11 +71,11 @@ const TEST_DATA = [
desc: "Hiding a node by adding a new rule to a stylesheet",
selector: "#hidden-via-stylesheet",
before: true,
changeStyle: async function(testActor) {
await testActor.eval(`
document.styleSheets[0].insertRule(
"#hidden-via-stylesheet {display: none;}", 1);
`);
changeStyle: () => {
content.document.styleSheets[0].insertRule(
"#hidden-via-stylesheet {display: none;}",
1
);
},
after: false,
},
@ -100,30 +83,30 @@ const TEST_DATA = [
desc: "Hiding a node by adding a class that matches an existing rule",
selector: "#normal-div",
before: true,
changeStyle: async function(testActor) {
await testActor.eval(`
document.styleSheets[0].insertRule(
".a-new-class {display: none;}", 2);
document.querySelector("#normal-div")
.classList.add("a-new-class");
`);
changeStyle: () => {
content.document.styleSheets[0].insertRule(
".a-new-class {display: none;}",
2
);
content.document
.querySelector("#normal-div")
.classList.add("a-new-class");
},
after: false,
},
];
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(TEST_URL);
const { inspector } = await openInspectorForURL(TEST_URL);
for (const data of TEST_DATA) {
info("Running test case: " + data.desc);
await runTestData(inspector, testActor, data);
await runTestData(inspector, data);
}
});
async function runTestData(
inspector,
testActor,
{ selector, before, changeStyle, after }
) {
info("Getting the " + selector + " test node");
@ -141,7 +124,7 @@ async function runTestData(
});
info("Making style changes");
await changeStyle(testActor);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], changeStyle);
const nodes = await onDisplayChanged;
info("Verifying that the list of changed nodes include our container");

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

@ -61,22 +61,18 @@ const TEST_DATA = [
];
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(TEST_URL);
const { inspector } = await openInspectorForURL(TEST_URL);
for (const data of TEST_DATA) {
await checkNode(inspector, testActor, data);
await checkNode(inspector, data);
}
});
async function checkNode(
inspector,
testActor,
{ desc, selector, inline, value }
) {
async function checkNode(inspector, { desc, selector, inline, value }) {
info(desc);
const container = await getContainerForSelector(selector, inspector);
const nodeValue = await getFirstChildNodeValue(selector, testActor);
const nodeValue = await getFirstChildNodeValue(selector);
is(nodeValue, value, "The test node's text content is correct");
is(

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

@ -11,19 +11,19 @@ const {
} = require("devtools/server/actors/inspector/walker");
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(TEST_URL);
const { inspector } = await openInspectorForURL(TEST_URL);
info("Expanding all nodes");
await inspector.markup.expandAll();
await waitForMultipleChildrenUpdates(inspector);
await editContainer(inspector, testActor, {
await editContainer(inspector, {
selector: ".node6",
newValue: "New text",
oldValue: "line6",
});
await editContainer(inspector, testActor, {
await editContainer(inspector, {
selector: "#node17",
newValue:
"LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT. " +
@ -33,7 +33,7 @@ add_task(async function() {
"Donec posuere placerat magna et imperdiet.",
});
await editContainer(inspector, testActor, {
await editContainer(inspector, {
selector: "#node17",
newValue: "New value",
oldValue:
@ -41,7 +41,7 @@ add_task(async function() {
"DONEC POSUERE PLACERAT MAGNA ET IMPERDIET.",
});
await editContainer(inspector, testActor, {
await editContainer(inspector, {
selector: "#node17",
newValue:
"LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT. " +
@ -50,12 +50,8 @@ add_task(async function() {
});
});
async function editContainer(
inspector,
testActor,
{ selector, newValue, oldValue }
) {
let nodeValue = await getFirstChildNodeValue(selector, testActor);
async function editContainer(inspector, { selector, newValue, oldValue }) {
let nodeValue = await getFirstChildNodeValue(selector);
is(nodeValue, oldValue, "The test node's text content is correct");
info("Changing the text content");
@ -85,7 +81,7 @@ async function editContainer(
info("Listening to the markupmutation event");
await onMutated;
nodeValue = await getFirstChildNodeValue(selector, testActor);
nodeValue = await getFirstChildNodeValue(selector);
is(nodeValue, newValue, "The test node's text content has changed");
const isNewValueInline = newValue.length <= DEFAULT_VALUE_SUMMARY_LENGTH;

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

@ -10,13 +10,13 @@ const TEST_URL = URL_ROOT + "doc_markup_edit.html";
const SELECTOR = ".node6";
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(TEST_URL);
const { inspector } = await openInspectorForURL(TEST_URL);
info("Expanding all nodes");
await inspector.markup.expandAll();
await waitForMultipleChildrenUpdates(inspector);
let nodeValue = await getFirstChildNodeValue(SELECTOR, testActor);
let nodeValue = await getFirstChildNodeValue(SELECTOR);
let expectedValue = "line6";
is(nodeValue, expectedValue, "The test node's text content is correct");
@ -83,7 +83,7 @@ add_task(async function() {
await sendKey("VK_RETURN", {}, editor, inspector.panelWin);
await onMutated;
nodeValue = await getFirstChildNodeValue(SELECTOR, testActor);
nodeValue = await getFirstChildNodeValue(SELECTOR);
is(nodeValue, expectedValue, "The test node's text content is correct");
});

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

@ -8,13 +8,16 @@ const URL_1 = URL_ROOT + "doc_markup_update-on-navigtion_1.html";
const URL_2 = URL_ROOT + "doc_markup_update-on-navigtion_2.html";
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(URL_1);
const { inspector } = await openInspectorForURL(URL_1);
assertMarkupViewIsLoaded();
await selectNode("#one", inspector);
const willNavigate = inspector.currentTarget.once("will-navigate");
await testActor.eval(`window.location = "${URL_2}"`);
// We should not await on navigateTo here, because the test will assert the
// various phases of the inspector during the navigation.
const onNavigated = navigateTo(URL_2);
info("Waiting for will-navigate");
await willNavigate;
@ -28,6 +31,7 @@ add_task(async function() {
info("Navigation to page 2 was done, the inspector should be back up");
assertMarkupViewIsLoaded();
await onNavigated;
await selectNode("#two", inspector);
function assertMarkupViewIsLoaded() {

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

@ -111,14 +111,16 @@ var getContainerForSelector = async function(
* Retrieve the nodeValue for the firstChild of a provided selector on the content page.
*
* @param {String} selector
* @param {TestActorFront} testActor The current TestActorFront instance.
* @return {String} the nodeValue of the first
*/
async function getFirstChildNodeValue(selector, testActor) {
const nodeValue = await testActor.eval(`
document.querySelector("${selector}").firstChild.nodeValue;
`);
return nodeValue;
function getFirstChildNodeValue(selector) {
return SpecialPowers.spawn(
gBrowser.selectedBrowser,
[selector],
_selector => {
return content.document.querySelector(_selector).firstChild.nodeValue;
}
);
}
/**

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

@ -15,12 +15,12 @@ loadHelperScript("helper_diff.js");
* TEST_DATA array.
*/
async function runEventPopupTests(url, tests) {
const { inspector, testActor } = await openInspectorForURL(url);
const { inspector } = await openInspectorForURL(url);
await inspector.markup.expandAll();
for (const test of tests) {
await checkEventsForNode(test, inspector, testActor);
await checkEventsForNode(test, inspector);
}
// Wait for promises to avoid leaks when running this as a single test.
@ -47,14 +47,13 @@ async function runEventPopupTests(url, tests) {
* is source-mapped, requiring some extra delay before the checks
* @param {InspectorPanel} inspector The instance of InspectorPanel currently
* opened
* @param {TestActorFront} testActor
*/
async function checkEventsForNode(test, inspector, testActor) {
async function checkEventsForNode(test, inspector) {
const { selector, expected, beforeTest, isSourceMapped } = test;
const container = await getContainerForSelector(selector, inspector);
if (typeof beforeTest === "function") {
await beforeTest(inspector, testActor);
await beforeTest(inspector);
}
const evHolder = container.elt.querySelector(

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

@ -17,7 +17,7 @@ const TEST_URI = `
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, view, testActor } = await openRuleView();
const { inspector, view } = await openRuleView();
const HIGHLIGHTER_TYPE = inspector.highlighters.TYPES.FLEXBOX;
const {
getNodeForActiveHighlighter,
@ -44,7 +44,9 @@ add_task(async function() {
info("Remove the #flex container in the content page.");
const onHighlighterHidden = waitForHighlighterTypeHidden(HIGHLIGHTER_TYPE);
testActor.eval(`document.querySelector("#flex").remove();`);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () =>
content.document.querySelector("#flex").remove()
);
await onHighlighterHidden;
ok(
!getNodeForActiveHighlighter(HIGHLIGHTER_TYPE),

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

@ -20,7 +20,7 @@ const TEST_URI = `
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, view, testActor } = await openRuleView();
const { inspector, view } = await openRuleView();
const highlighters = inspector.highlighters;
const HIGHLIGHTER_TYPE = inspector.highlighters.TYPES.GRID;
const {
@ -40,9 +40,9 @@ add_task(async function() {
const onHighlighterHidden = waitForHighlighterTypeHidden(HIGHLIGHTER_TYPE);
info("Remove the #grid container in the content page");
testActor.eval(`
document.querySelector("#grid").remove();
`);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () =>
content.document.querySelector("#grid").remove()
);
await onHighlighterHidden;
ok(!highlighters.gridHighlighters.size, "CSS grid highlighter is hidden.");
});

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

@ -19,7 +19,7 @@ const TEST_URI = `
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, view, testActor } = await openRuleView();
const { inspector, view } = await openRuleView();
const highlighters = view.highlighters;
info("Select a node with a shape value");
@ -35,9 +35,9 @@ add_task(async function() {
const onHighlighterHidden = highlighters.once("shapes-highlighter-hidden");
info("Remove the #shapes container in the content page");
testActor.eval(`
document.querySelector("#shape").remove();
`);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () =>
content.document.querySelector("#shape").remove()
);
await onHighlighterHidden;
ok(!highlighters.shapesHighlighterShown, "CSS shapes highlighter is hidden.");
});

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

@ -76,20 +76,19 @@ add_task(async function() {
});
async function testAllStylesheets(inspector, view, toolbox) {
const testActor = await getTestActor(toolbox);
await selectNode("div", inspector);
await testRuleViewLinkLabel(view);
await testDisabledStyleEditor(view, toolbox);
await testFirstInlineStyleSheet(view, toolbox, testActor);
await testSecondInlineStyleSheet(view, toolbox, testActor);
await testExternalStyleSheet(view, toolbox, testActor);
await testFirstInlineStyleSheet(view, toolbox);
await testSecondInlineStyleSheet(view, toolbox);
await testExternalStyleSheet(view, toolbox);
info("Switch back to the inspector panel");
await toolbox.selectTool("inspector");
await selectNode("body", inspector);
}
async function testFirstInlineStyleSheet(view, toolbox, testActor) {
async function testFirstInlineStyleSheet(view, toolbox) {
info("Testing inline stylesheet");
info("Listening for toolbox switch to the styleeditor");
@ -101,10 +100,10 @@ async function testFirstInlineStyleSheet(view, toolbox, testActor) {
ok(true, "Switched to the style-editor panel in the toolbox");
await validateStyleEditorSheet(toolbox, editor, 0, testActor);
await validateStyleEditorSheet(toolbox, editor, 0);
}
async function testSecondInlineStyleSheet(view, toolbox, testActor) {
async function testSecondInlineStyleSheet(view, toolbox) {
info("Testing second inline stylesheet");
const styleEditorPanel = toolbox.getCurrentPanel();
@ -126,10 +125,10 @@ async function testSecondInlineStyleSheet(view, toolbox, testActor) {
"styleeditor",
"The style editor is selected again"
);
await validateStyleEditorSheet(toolbox, editor, 1, testActor);
await validateStyleEditorSheet(toolbox, editor, 1);
}
async function testExternalStyleSheet(view, toolbox, testActor) {
async function testExternalStyleSheet(view, toolbox) {
info("Testing external stylesheet");
const styleEditorPanel = toolbox.getCurrentPanel();
const onEditorSelected = styleEditorPanel.UI.once("editor-selected");
@ -150,15 +149,10 @@ async function testExternalStyleSheet(view, toolbox, testActor) {
"styleeditor",
"The style editor is selected again"
);
await validateStyleEditorSheet(toolbox, editor, 2, testActor);
await validateStyleEditorSheet(toolbox, editor, 2);
}
async function validateStyleEditorSheet(
toolbox,
editor,
expectedSheetIndex,
testActor
) {
async function validateStyleEditorSheet(toolbox, editor, expectedSheetIndex) {
info("validating style editor stylesheet");
is(
editor.styleSheet.styleSheetIndex,
@ -168,9 +162,15 @@ async function validateStyleEditorSheet(
const href = editor.styleSheet.href || editor.styleSheet.nodeHref;
const expectedHref = await testActor.eval(
`document.styleSheets[${expectedSheetIndex}].href ||
document.location.href`
const expectedHref = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[expectedSheetIndex],
_expectedSheetIndex => {
return (
content.document.styleSheets[_expectedSheetIndex].href ||
content.document.location.href
);
}
);
is(href, expectedHref, "loaded stylesheet href matches document stylesheet");

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

@ -33,21 +33,6 @@ registerCleanupFunction(() => {
Services.prefs.clearUserPref("devtools.defaultColorUnit");
});
/**
* Get an element's inline style property value.
* @param {TestActor} testActor
* @param {String} selector
* The selector used to obtain the element.
* @param {String} name
* name of the property.
*/
function getStyle(testActor, selector, propName) {
return testActor.eval(`
document.querySelector("${selector}")
.style.getPropertyValue("${propName}");
`);
}
/**
* When a tooltip is closed, this ends up "commiting" the value changed within
* the tooltip (e.g. the color in case of a colorpicker) which, in turn, ends up

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

@ -53,7 +53,9 @@ add_task(async function() {
info("Scrolling the document");
await testActor.setProperty("iframe", "style", "margin-bottom: 2000px");
await testActor.eval("window.scrollBy(0, 40);");
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () =>
content.scrollBy(0, 40)
);
// target the body within the iframe
const iframeBodySelector = ["iframe", "body"];

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

@ -17,7 +17,7 @@ add_task(async function() {
const markupLoaded = inspector.once("markuploaded");
const y = await testActor.eval("window.pageYOffset");
const y = await getPageYOffset();
isnot(y, 0, "window scrolled vertically.");
info("Reloading page.");
@ -26,6 +26,14 @@ add_task(async function() {
info("Waiting for markupview to load after reload.");
await markupLoaded;
const newY = await testActor.eval("window.pageYOffset");
const newY = await getPageYOffset();
is(y, newY, "window remember the previous scroll position.");
});
async function getPageYOffset() {
return SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.pageYOffset
);
}

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

@ -108,10 +108,12 @@ add_task(async function() {
executeSoon(resolve);
});
ok(
await testActor.eval("!!document.documentElement"),
"Document element still alive."
const hasDocumentElement = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => !!content.document.documentElement
);
ok(hasDocumentElement, "Document element still alive.");
}
async function testShowDOMProperties() {

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

@ -20,7 +20,7 @@ const TEST_URL_4 =
"data:text/html;charset=utf-8," + encodeURIComponent("<h1>bar</h1>");
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(TEST_URL_1);
const { inspector } = await openInspectorForURL(TEST_URL_1);
await selectNode("#i1", inspector);
@ -34,7 +34,7 @@ add_task(async function() {
const onUpdated = inspector.once("inspector-updated");
info("Going back in history");
await testActor.eval("history.go(-1)");
gBrowser.goBack();
info("Waiting for markup view to load after going back in history.");
await markuploaded;
@ -43,13 +43,18 @@ add_task(async function() {
await onUpdated;
ok(true, "Old page loaded");
is(await testActor.eval("location.href;"), TEST_URL_1, "URL is correct.");
const url = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.location.href
);
is(url, TEST_URL_1, "URL is correct.");
await selectNode("#i1", inspector);
});
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(TEST_URL_3);
const { inspector } = await openInspectorForURL(TEST_URL_3);
await selectNode("img", inspector);
@ -63,7 +68,7 @@ add_task(async function() {
const onUpdated = inspector.once("inspector-updated");
info("Going back in history");
await testActor.eval("history.go(-1)");
gBrowser.goBack();
info("Waiting for markup view to load after going back in history.");
await markuploaded;
@ -72,7 +77,12 @@ add_task(async function() {
await onUpdated;
ok(true, "Old page loaded");
is(await testActor.eval("location.href;"), TEST_URL_3, "URL is correct.");
const url = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.location.href
);
is(url, TEST_URL_3, "URL is correct.");
await selectNode("img", inspector);
});

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

@ -14,10 +14,14 @@ add_task(async function() {
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TEST_URL_1);
await BrowserTestUtils.waitForErrorPage(gBrowser.selectedBrowser);
const { inspector, testActor } = await openInspector();
const { inspector } = await openInspector();
ok(true, "Inspector loaded on the already opened net error");
const documentURI = await testActor.eval("document.documentURI;");
const documentURI = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.document.documentURI
);
ok(
documentURI.startsWith("about:neterror"),
"content is really a net error page."

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

@ -11,13 +11,13 @@
const TEST_URI = "data:text/html,<p id='1'>p</p>";
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(TEST_URI);
const { inspector } = await openInspectorForURL(TEST_URI);
await selectNode("p", inspector);
const markupLoaded = inspector.once("markuploaded");
info("Reloading page.");
await testActor.eval("location.reload()");
await navigateTo(TEST_URI);
info("Waiting for markupview to load after reload.");
await markupLoaded;

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

@ -23,12 +23,12 @@ const TEST_URI =
"</svg>";
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(TEST_URI);
const { inspector } = await openInspectorForURL(TEST_URI);
const markupLoaded = inspector.once("markuploaded");
info("Reloading page.");
await testActor.eval("location.reload()");
await navigateTo(TEST_URI);
info("Waiting for markupview to load after reload.");
await markupLoaded;
@ -40,7 +40,7 @@ add_task(async function() {
await selectNode("rect", inspector);
info("Reloading page.");
await testActor.eval("location.reload");
await navigateTo(TEST_URI);
const rectFront = await getNodeFront("rect", inspector);
is(inspector.selection.nodeFront, rectFront, "<rect> selected after reload.");

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

@ -44,7 +44,7 @@ add_task(async function() {
const markupLoaded = inspector.once("markuploaded");
info("Reloading page.");
await testActor.eval("location.reload()");
await navigateTo(TEST_URI);
info("Waiting for markupview to load after reload.");
await markupLoaded;

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

@ -10,7 +10,7 @@
const TEST_URL = URL_ROOT + "doc_inspector_search.html";
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL(TEST_URL);
const { inspector } = await openInspectorForURL(TEST_URL);
info("Searching for test node #d1");
await focusSearchBoxUsingShortcut(inspector.panelWin);
@ -23,10 +23,8 @@ add_task(async function() {
// Expect an inspector-updated event here, because removing #d1 causes the
// breadcrumbs to update (since #d1 is displayed in it).
const onUpdated = inspector.once("inspector-updated");
await mutatePage(
inspector,
testActor,
'document.getElementById("d1").remove()'
await mutatePage(inspector, () =>
content.document.getElementById("d1").remove()
);
await onUpdated;
@ -54,11 +52,10 @@ add_task(async function() {
info("Create the #d3 node in the page");
// No need to expect an inspector-updated event here, Creating #d3 isn't going
// to update the breadcrumbs in any ways.
await mutatePage(
inspector,
testActor,
`document.getElementById("d2").insertAdjacentHTML(
"afterend", "<div id=d3></div>")`
await mutatePage(inspector, () =>
content.document
.getElementById("d2")
.insertAdjacentHTML("afterend", "<div id=d3></div>")
);
info("Pressing return button to search again for node #d3.");
@ -97,8 +94,8 @@ function assertHasResult(inspector, expectResult) {
);
}
async function mutatePage(inspector, testActor, expression) {
async function mutatePage(inspector, mutationFn) {
const onMutation = inspector.once("markupmutation");
await testActor.eval(expression);
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], mutationFn);
await onMutation;
}

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

@ -54,7 +54,7 @@ var TEST_DATA = [
];
add_task(async function() {
const { inspector, toolbox, testActor } = await openInspectorForURL(PAGE_1);
const { inspector, toolbox } = await openInspectorForURL(PAGE_1);
for (const { url, nodeToSelect, selectedNode } of TEST_DATA) {
if (nodeToSelect) {
@ -76,7 +76,11 @@ add_task(async function() {
async function navigateToAndWaitForNewRoot(url) {
info("Navigating and waiting for new-root event after navigation.");
const current = await testActor.eval("location.href");
const current = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.location.href
);
if (url == current) {
info("Reloading page.");
const markuploaded = inspector.once("markuploaded");