// This function runs entirely in the content process. It doesn't have access // any free variables in this file.
async function testApplicableStateChangeEvent(testRoot) { // We've seen the original stylesheet in the document. // Now add a stylesheet on the fly and make sure we see it.
let doc = content.document;
doc.styleSheetChangeEventsEnabled = true;
function shouldIgnoreEvent(e) { // accessiblecaret.css might be reported, interfering with the test // assertions, so let's ignore it return (
e.stylesheet?.href === "resource://content-accessible/accessiblecaret.css"
);
}
function waitForStyleApplicableStateChanged() { return ContentTaskUtils.waitForEvent(
docShell.chromeEventHandler, "StyleSheetApplicableStateChanged", true,
e => !shouldIgnoreEvent(e)
);
}
function waitForStyleSheetRemovedEvent() { return ContentTaskUtils.waitForEvent(
docShell.chromeEventHandler, "StyleSheetRemoved", true,
e => !shouldIgnoreEvent(e)
);
}
function checkApplicableStateChangeEvent(event, { applicable, stylesheet }) {
is(
event.type, "StyleSheetApplicableStateChanged", "event.type has expected value"
);
is(event.target, doc, "event targets correct document");
is(event.stylesheet, stylesheet, "event.stylesheet has the expected value");
is(event.applicable, applicable, "event.applicable has the expected value");
}
function checkStyleSheetRemovedEvent(event, { stylesheet }) {
is(event.type, "StyleSheetRemoved", "event.type has expected value");
is(event.target, doc, "event targets correct document");
is(event.stylesheet, stylesheet, "event.stylesheet has the expected value");
}
// Updating the text content will actually create a new StyleSheet instance, // and so we should get one event for the new instance, and another one for // the removal of the "previous"one. function waitForTextContentChange() { return Promise.all([
waitForStyleSheetRemovedEvent(),
waitForStyleApplicableStateChanged(),
]);
}
info("Add and wait for applicable state change event");
let linkEl = doc.createElement("link");
linkEl.setAttribute("rel", "stylesheet");
linkEl.setAttribute("type", "text/css");
linkEl.setAttribute("href", testRoot + gStyleSheet);