diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /layout/base/tests/browser_bug839103.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/base/tests/browser_bug839103.js')
-rw-r--r-- | layout/base/tests/browser_bug839103.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/layout/base/tests/browser_bug839103.js b/layout/base/tests/browser_bug839103.js new file mode 100644 index 0000000000..e0b7c3a963 --- /dev/null +++ b/layout/base/tests/browser_bug839103.js @@ -0,0 +1,82 @@ +const gTestRoot = getRootDirectory(gTestPath).replace( + "chrome://mochitests/content/", + "http://127.0.0.1:8888/" +); + +add_task(async function test() { + await BrowserTestUtils.withNewTab( + { gBrowser, url: gTestRoot + "file_bug839103.html" }, + async function(browser) { + await SpecialPowers.spawn(browser, [gTestRoot], testBody); + } + ); +}); + +// This function runs entirely in the content process. It doesn't have access +// any free variables in this file. +async function testBody(testRoot) { + const gStyleSheet = "bug839103.css"; + + function unexpectedContentEvent(event) { + ok(false, "Received a " + event.type + " event on content"); + } + + // 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; + doc.addEventListener( + "StyleSheetApplicableStateChanged", + unexpectedContentEvent + ); + doc.defaultView.addEventListener( + "StyleSheetApplicableStateChanged", + unexpectedContentEvent + ); + + let link = doc.createElement("link"); + link.setAttribute("rel", "stylesheet"); + link.setAttribute("type", "text/css"); + link.setAttribute("href", testRoot + gStyleSheet); + + let stateChanged = ContentTaskUtils.waitForEvent( + docShell.chromeEventHandler, + "StyleSheetApplicableStateChanged", + true + ); + doc.body.appendChild(link); + + info("waiting for applicable state change event"); + let evt = await stateChanged; + info("received dynamic style sheet applicable state change event"); + is( + evt.type, + "StyleSheetApplicableStateChanged", + "evt.type has expected value" + ); + is(evt.target, doc, "event targets correct document"); + is(evt.stylesheet, link.sheet, "evt.stylesheet has the right value"); + is(evt.applicable, true, "evt.applicable has the right value"); + + stateChanged = ContentTaskUtils.waitForEvent( + docShell.chromeEventHandler, + "StyleSheetApplicableStateChanged", + true + ); + link.sheet.disabled = true; + + evt = await stateChanged; + is( + evt.type, + "StyleSheetApplicableStateChanged", + "evt.type has expected value" + ); + info( + 'received dynamic style sheet applicable state change event after media="" changed' + ); + is(evt.target, doc, "event targets correct document"); + is(evt.stylesheet, link.sheet, "evt.stylesheet has the right value"); + is(evt.applicable, false, "evt.applicable has the right value"); + + doc.body.removeChild(link); +} |