Bug 1654415 - Replace testActor by SpecialPowers from browser_inspector_remove-iframe-during-load test r=nchevobbe

The test is currently a permafail with fission enabled.
TestActor gets destroyed when navigating from about:blank to the test page and can be replaced by SpecialPowers calls.

Differential Revision: https://phabricator.services.mozilla.com/D84478
This commit is contained in:
Julian Descottes 2020-07-22 13:07:01 +00:00
parent 6b7efe37ac
commit 64114183b0
2 changed files with 42 additions and 23 deletions

View File

@ -8,12 +8,25 @@
const TEST_URL = URL_ROOT + "doc_inspector_remove-iframe-during-load.html";
add_task(async function() {
const { inspector, testActor } = await openInspectorForURL("about:blank");
await pushPref("devtools.target-switching.enabled", true);
const { inspector, tab } = await openInspectorForURL("about:blank");
await selectNode("body", inspector);
// Note: here we don't want to use the `navigateTo` helper from shared-head.js
// because we want to modify the page as early as possible after the
// navigation, ideally before the inspector has fully initialized.
// See next comments.
const browser = tab.linkedBrowser;
const onBrowserLoaded = BrowserTestUtils.browserLoaded(browser);
await BrowserTestUtils.loadURI(browser, TEST_URL);
await onBrowserLoaded;
// We do not want to wait for the inspector to be fully ready before testing
// so we load TEST_URL and just wait for the content window to be done loading
await testActor.loadAndWaitForCustomEvent(TEST_URL);
await SpecialPowers.spawn(browser, [], async function() {
await content.wrappedJSObject.readyPromise;
});
// The content doc contains a script that creates iframes and deletes them
// immediately after. It does this before the load event, after
@ -21,33 +34,40 @@ add_task(async function() {
// blank when navigating to that page.
// At this stage, there should be no iframes in the page anymore.
ok(
!(await testActor.hasNode("iframe")),
!(await contentPageHasNode(browser, "iframe")),
"Iframes added by the content page should have been removed"
);
// Create/remove an extra one now, after the load event.
info("Creating and removing an iframe.");
testActor.eval(
"new " +
function() {
const iframe = document.createElement("iframe");
document.body.appendChild(iframe);
iframe.remove();
}
);
await SpecialPowers.spawn(browser, [], async function() {
const iframe = content.document.createElement("iframe");
content.document.body.appendChild(iframe);
iframe.remove();
});
ok(
!(await testActor.hasNode("iframe")),
!(await contentPageHasNode(browser, "iframe")),
"The after-load iframe should have been removed."
);
// Assert that the markup-view is displayed and works
ok(!(await testActor.hasNode("iframe")), "Iframe has been removed.");
is(
await testActor.getProperty("#yay", "textContent"),
"load",
"Load event fired."
);
ok(!(await contentPageHasNode(browser, "iframe")), "Iframe has been removed");
const expectedText = await SpecialPowers.spawn(browser, [], async function() {
return content.document.querySelector("#yay").textContent;
});
is(expectedText, "load", "Load event fired.");
// Smoke test to check that the inspector can still select nodes and hasn't
// gone blank.
await selectNode("#yay", inspector);
});
function contentPageHasNode(browser, selector) {
return SpecialPowers.spawn(browser, [selector], async function(
selectorChild
) {
return !!content.document.querySelector(selectorChild);
});
}

View File

@ -12,9 +12,9 @@
var yay = document.querySelector("#yay");
yay.textContent = "nothing";
// Create a custom event to let the test know when the window has finished
// loading.
var event = new Event("test-page-processing-done");
// Create a promise that the test can wait for.
let resolveReadyPromise;
window.readyPromise = new Promise(r => (resolveReadyPromise = r));
// Create/remove an iframe before load.
var iframe = document.createElement("iframe");
@ -37,8 +37,7 @@
newIframe.remove();
yay.textContent = "load";
// Dispatch the done event.
window.dispatchEvent(event);
resolveReadyPromise();
});
</script>
</body>