diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index decbfaf440a8..a3b63c2e46ff 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -7270,7 +7270,8 @@ void Document::SetScriptGlobalObject( // still test false at this point and no state change will happen) or we're // doing the initial document load and don't want to fire the event for this // change. - // + dom::VisibilityState oldState = mVisibilityState; + mVisibilityState = ComputeVisibilityState(); // When the visibility is changed, notify it to observers. // Some observers need the notification, for example HTMLMediaElement uses // it to update internal media resource allocation. @@ -7283,7 +7284,9 @@ void Document::SetScriptGlobalObject( // not yet necessary. But soon after Document::SetScriptGlobalObject() // call, the document becomes not hidden. At the time, MediaDecoder needs // to know it and needs to start updating decoding. - UpdateVisibilityState(DispatchVisibilityChange::No); + if (oldState != mVisibilityState) { + EnumerateActivityObservers(NotifyActivityChanged); + } // The global in the template contents owner document should be the same. if (mTemplateContentsOwner && mTemplateContentsOwner != this) { @@ -14852,15 +14855,13 @@ void Document::UnlockPointer(Document* aDoc) { asyncDispatcher->RunDOMEventWhenSafe(); } -void Document::UpdateVisibilityState(DispatchVisibilityChange aDispatchEvent) { +void Document::UpdateVisibilityState() { dom::VisibilityState oldState = mVisibilityState; mVisibilityState = ComputeVisibilityState(); if (oldState != mVisibilityState) { - if (aDispatchEvent == DispatchVisibilityChange::Yes) { - nsContentUtils::DispatchTrustedEvent(this, ToSupports(this), - u"visibilitychange"_ns, - CanBubble::eYes, Cancelable::eNo); - } + nsContentUtils::DispatchTrustedEvent(this, ToSupports(this), + u"visibilitychange"_ns, + CanBubble::eYes, Cancelable::eNo); EnumerateActivityObservers(NotifyActivityChanged); } @@ -14886,9 +14887,9 @@ VisibilityState Document::ComputeVisibilityState() const { } void Document::PostVisibilityUpdateEvent() { - nsCOMPtr event = NewRunnableMethod( - "Document::UpdateVisibilityState", this, &Document::UpdateVisibilityState, - DispatchVisibilityChange::Yes); + nsCOMPtr event = + NewRunnableMethod("Document::UpdateVisibilityState", this, + &Document::UpdateVisibilityState); Dispatch(TaskCategory::Other, event.forget()); } diff --git a/dom/base/Document.h b/dom/base/Document.h index fccb7d3c7042..f738f0267efa 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -3207,11 +3207,7 @@ class Document : public nsINode, // This method may fire a DOM event; if it does so it will happen // synchronously. - // - // Whether the event fires is controlled by the argument. - enum class DispatchVisibilityChange { No, Yes }; - void UpdateVisibilityState( - DispatchVisibilityChange = DispatchVisibilityChange::Yes); + void UpdateVisibilityState(); // Posts an event to call UpdateVisibilityState. void PostVisibilityUpdateEvent(); diff --git a/toolkit/content/tests/browser/browser.ini b/toolkit/content/tests/browser/browser.ini index 927178c3a972..f76f3ce7a919 100644 --- a/toolkit/content/tests/browser/browser.ini +++ b/toolkit/content/tests/browser/browser.ini @@ -47,10 +47,6 @@ skip-if = (os == "win" && processor == "aarch64") || (os == "mac") || (os == "li [browser_delay_autoplay_webAudio.js] tags = audiochannel skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1536573 -[browser_bug1572798.js] -tags = audiochannel -skip-if = (os == "win" && processor == "aarch64") # aarch64 due to 1536573 -support-files = file_document_open_audio.html [browser_bug1170531.js] skip-if = os == "linux" && !debug && !ccov # Bug 1647973 diff --git a/toolkit/content/tests/browser/browser_bug1572798.js b/toolkit/content/tests/browser/browser_bug1572798.js deleted file mode 100644 index 8b5dffd432de..000000000000 --- a/toolkit/content/tests/browser/browser_bug1572798.js +++ /dev/null @@ -1,29 +0,0 @@ -add_task(async function test_bug_1572798() { - let tab = BrowserTestUtils.addTab(window.gBrowser, "about:blank"); - BrowserTestUtils.loadURI( - tab.linkedBrowser, - "https://example.com/browser/toolkit/content/tests/browser/file_document_open_audio.html" - ); - await BrowserTestUtils.browserLoaded(tab.linkedBrowser); - let windowLoaded = BrowserTestUtils.waitForNewWindow(); - info("- clicking button to spawn a new window -"); - await ContentTask.spawn(tab.linkedBrowser, null, function() { - content.document.querySelector("button").click(); - }); - info("- waiting for the new window -"); - let newWin = await windowLoaded; - info("- checking that the new window plays the audio -"); - let documentOpenedBrowser = newWin.gBrowser.selectedBrowser; - await ContentTask.spawn(documentOpenedBrowser, null, async function() { - try { - await content.document.querySelector("audio").play(); - ok(true, "Could play the audio"); - } catch (e) { - ok(false, "Rejected audio promise" + e); - } - }); - - info("- Cleaning up -"); - await BrowserTestUtils.closeWindow(newWin); - await BrowserTestUtils.removeTab(tab); -}); diff --git a/toolkit/content/tests/browser/file_document_open_audio.html b/toolkit/content/tests/browser/file_document_open_audio.html deleted file mode 100644 index 1234299c673d..000000000000 --- a/toolkit/content/tests/browser/file_document_open_audio.html +++ /dev/null @@ -1,11 +0,0 @@ - -Test for bug 1572798 - -