Title: [291390] trunk
Revision
291390
Author
[email protected]
Date
2022-03-17 00:21:46 -0700 (Thu, 17 Mar 2022)

Log Message

AudioContext is suspended on iOS when page is backgrounded
https://bugs.webkit.org/show_bug.cgi?id=237878

Reviewed by Eric Carlson.

Source/WebCore:

On iOS, when the application goes in the background, AudioContext gets suspended.
This is problematic when AudioContext is used to generate audio samples but not play audio samples.
To allow those silent AudioContexts to run even in background, the following is done:
- Override background interruptions in case the audio context default destination is not connected.
- Monitor whether the default destination is connected or not.
- If the default destination gets connected while application is in the background, trigger an interruption to prevent playing audio.

To prevent potential audio burst, we interrupt just before the destination gets connected and not just after.
For that reason, we add m_canOverrideBackgroundPlaybackRestriction to enforce interruption when we now the connection will be connected.

This approach keeps the existing iOS behavior in terms of rendered audio while allowing for not-playing audio contexts to continue in the background.

Tests: webaudio/suspend-context-while-backgrounded.html and API test.

* Modules/webaudio/AudioContext.cpp:
* Modules/webaudio/AudioContext.h:
* Modules/webaudio/AudioNode.cpp:
* Modules/webaudio/AudioSummingJunction.h:
* Modules/webaudio/DefaultAudioDestinationNode.cpp:
* Modules/webaudio/DefaultAudioDestinationNode.h:
* platform/audio/PlatformMediaSessionManager.h:

Source/WebKit:

Expose private SPI for testing purposes.

* UIProcess/API/Cocoa/WKProcessPool.mm:
* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
* UIProcess/WebProcessPool.h:

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/GPUProcess.mm:
* TestWebKitAPI/Tests/WebKitCocoa/audio-context-playing.html:

LayoutTests:

* webaudio/suspend-context-while-backgrounded-expected.txt: Added.
* webaudio/suspend-context-while-backgrounded.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (291389 => 291390)


--- trunk/LayoutTests/ChangeLog	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/LayoutTests/ChangeLog	2022-03-17 07:21:46 UTC (rev 291390)
@@ -1,3 +1,13 @@
+2022-03-17  Youenn Fablet  <[email protected]>
+
+        AudioContext is suspended on iOS when page is backgrounded
+        https://bugs.webkit.org/show_bug.cgi?id=237878
+
+        Reviewed by Eric Carlson.
+
+        * webaudio/suspend-context-while-backgrounded-expected.txt: Added.
+        * webaudio/suspend-context-while-backgrounded.html: Added.
+
 2022-03-16  Matteo Flores  <[email protected]>
 
         [ iOS EWS ] imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-not-application-textarea.html is a flaky text failure

Added: trunk/LayoutTests/webaudio/suspend-context-while-backgrounded-expected.txt (0 => 291390)


--- trunk/LayoutTests/webaudio/suspend-context-while-backgrounded-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webaudio/suspend-context-while-backgrounded-expected.txt	2022-03-17 07:21:46 UTC (rev 291390)
@@ -0,0 +1,3 @@
+
+PASS Tests that media session interruption does not cause AudioContext interruption for AudioContext that do not output audio
+

Added: trunk/LayoutTests/webaudio/suspend-context-while-backgrounded.html (0 => 291390)


--- trunk/LayoutTests/webaudio/suspend-context-while-backgrounded.html	                        (rev 0)
+++ trunk/LayoutTests/webaudio/suspend-context-while-backgrounded.html	2022-03-17 07:21:46 UTC (rev 291390)
@@ -0,0 +1,115 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script src=""
+<script>
+promise_test(async (t) => {
+    if (!window.internals)
+        return;
+    internals.setMediaSessionRestrictions("WebAudio", "backgroundprocessplaybackrestricted");
+
+    // Regular context who is setting its destination upfront, it should be interrupted/uninterrupted following background interruptions.
+    var context1 = new AudioContext;
+    // Context who is setting its destination to a media stream track then to the default destination. It should not be interrupted until its destination changes.
+    var context2 = new AudioContext;
+    // Context who is setting its destination to a media stream track. It should not be interrupted.
+    var context3 = new AudioContext;
+    // Context who is created while in the background, its destination as a media stream track then the default destination. It should not be interrupted until its destination changes.
+    var context4 = new AudioContext;
+
+    t.add_cleanup(() => {
+        context1.close();
+        context2.close();
+        context3.close();
+        context4.close();
+    });
+
+    var source1 = context1.createConstantSource();
+    source1.connect(context1.destination);
+
+    var source2 = context2.createConstantSource();
+    var destination2 = context2.createMediaStreamDestination();
+    source2.connect(destination2);
+
+    var source3 = context3.createConstantSource();
+    var destination3 = context3.createMediaStreamDestination();
+    source3.connect(destination3);
+
+    let stateChangePromise = new Promise((resolve, reject) => {
+        context1._onstatechange_ = resolve;
+        setTimeout(() => reject("start promise timed out"), 5000);
+    });
+
+    source1.start();
+    source2.start();
+    source3.start();
+
+    await stateChangePromise;
+    await new Promise(resolve => setTimeout(resolve, 10));
+
+    assert_equals(context1.state, "running", "test1a");
+    assert_equals(context2.state, "running", "test1b");
+    assert_equals(context3.state, "running", "test1c");
+
+    stateChangePromise = new Promise((resolve, reject) => {
+        context1._onstatechange_ = resolve;
+        setTimeout(() => reject("context1 interruption promise timed out"), 5000);
+    })
+    internals.applicationDidEnterBackground(false);
+
+    await stateChangePromise;
+    await new Promise(resolve => setTimeout(resolve, 10));
+
+    assert_equals(context1.state, "interrupted", "test2a");
+    assert_equals(context2.state, "running", "test2b");
+    assert_equals(context3.state, "running", "test2c");
+
+    var source4 = context4.createConstantSource();
+    var destination4 = context4.createMediaStreamDestination();
+    source4.connect(destination4);
+
+    stateChangePromise = new Promise((resolve, reject) => {
+        context2._onstatechange_ = resolve;
+        setTimeout(() => reject("context2 interruption promise timed out"), 5000);
+    });
+    source2.connect(context2.destination);
+
+    await stateChangePromise;
+    await new Promise(resolve => setTimeout(resolve, 10));
+
+    assert_equals(context1.state, "interrupted", "test3a");
+    assert_equals(context2.state, "interrupted", "test3b");
+    assert_equals(context3.state, "running", "test3c");
+    assert_equals(context4.state, "running", "test3d");
+
+    stateChangePromise = new Promise((resolve, reject) => {
+        context4._onstatechange_ = resolve;
+        setTimeout(() => reject("context4 interruption promise timed out"), 5000);
+    });
+    source4.connect(context4.destination);
+
+    await stateChangePromise;
+    await new Promise(resolve => setTimeout(resolve, 10));
+
+    assert_equals(context1.state, "interrupted", "test4q");
+    assert_equals(context2.state, "interrupted", "test4b");
+    assert_equals(context3.state, "running", "test4c");
+    assert_equals(context4.state, "interrupted", "test4d");
+
+    stateChangePromise = new Promise((resolve, reject) => {
+        context2._onstatechange_ = resolve;
+        setTimeout(() => reject("context2 uninterruption promise timed out"), 5000);
+    });
+    internals.applicationWillEnterForeground(false);
+
+    await stateChangePromise;
+    await new Promise(resolve => setTimeout(resolve, 10));
+
+    assert_equals(context1.state, "running", "test5a");
+    assert_equals(context2.state, "running", "test5b");
+    assert_equals(context3.state, "running", "test5c");
+    assert_equals(context4.state, "running", "test5d");
+}, "Tests that media session interruption does not cause AudioContext interruption for AudioContext that do not output audio");
+</script>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (291389 => 291390)


--- trunk/Source/WebCore/ChangeLog	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Source/WebCore/ChangeLog	2022-03-17 07:21:46 UTC (rev 291390)
@@ -1,3 +1,32 @@
+2022-03-17  Youenn Fablet  <[email protected]>
+
+        AudioContext is suspended on iOS when page is backgrounded
+        https://bugs.webkit.org/show_bug.cgi?id=237878
+
+        Reviewed by Eric Carlson.
+
+        On iOS, when the application goes in the background, AudioContext gets suspended.
+        This is problematic when AudioContext is used to generate audio samples but not play audio samples.
+        To allow those silent AudioContexts to run even in background, the following is done:
+        - Override background interruptions in case the audio context default destination is not connected.
+        - Monitor whether the default destination is connected or not.
+        - If the default destination gets connected while application is in the background, trigger an interruption to prevent playing audio.
+
+        To prevent potential audio burst, we interrupt just before the destination gets connected and not just after.
+        For that reason, we add m_canOverrideBackgroundPlaybackRestriction to enforce interruption when we now the connection will be connected.
+
+        This approach keeps the existing iOS behavior in terms of rendered audio while allowing for not-playing audio contexts to continue in the background.
+
+        Tests: webaudio/suspend-context-while-backgrounded.html and API test.
+
+        * Modules/webaudio/AudioContext.cpp:
+        * Modules/webaudio/AudioContext.h:
+        * Modules/webaudio/AudioNode.cpp:
+        * Modules/webaudio/AudioSummingJunction.h:
+        * Modules/webaudio/DefaultAudioDestinationNode.cpp:
+        * Modules/webaudio/DefaultAudioDestinationNode.h:
+        * platform/audio/PlatformMediaSessionManager.h:
+
 2022-03-16  Devin Rousso  <[email protected]>
 
         [Apple Pay] version values are incorrect, causing incorrect feature detection

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp (291389 => 291390)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2022-03-17 07:21:46 UTC (rev 291390)
@@ -485,6 +485,25 @@
     });
 }
 
+bool AudioContext::shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType interruption) const
+{
+    return m_canOverrideBackgroundPlaybackRestriction && interruption == PlatformMediaSession::InterruptionType::EnteringBackground && !destination().isConnected();
+}
+
+void AudioContext::defaultDestinationWillBecomeConnected()
+{
+    // We might need to interrupt if we previously overrode a background interruption.
+    if (!PlatformMediaSessionManager::sharedManager().isApplicationInBackground() || m_mediaSession->state() == PlatformMediaSession::Interrupted)
+        return;
+
+    // We end the overriden interruption (if any) to get the right count of interruptions and start a new interruption.
+    m_mediaSession->endInterruption(PlatformMediaSession::EndInterruptionFlags::NoFlags);
+
+    m_canOverrideBackgroundPlaybackRestriction = false;
+    m_mediaSession->beginInterruption(PlatformMediaSession::EnteringBackground);
+    m_canOverrideBackgroundPlaybackRestriction = true;
+}
+
 #if !RELEASE_LOG_DISABLED
 const Logger& AudioContext::logger() const
 {

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.h (291389 => 291390)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2022-03-17 07:21:46 UTC (rev 291390)
@@ -94,6 +94,8 @@
     void addBehaviorRestriction(BehaviorRestrictions restriction) { m_restrictions |= restriction; }
     void removeBehaviorRestriction(BehaviorRestrictions restriction) { m_restrictions &= ~restriction; }
 
+    void defaultDestinationWillBecomeConnected();
+
 private:
     AudioContext(Document&, const AudioContextOptions&);
 
@@ -125,7 +127,7 @@
     bool canReceiveRemoteControlCommands() const final { return false; }
     void didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType, const PlatformMediaSession::RemoteCommandArgument&) final { }
     bool supportsSeeking() const final { return false; }
-    bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const final { return false; }
+    bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const final;
     bool canProduceAudio() const final { return true; }
     bool isSuspended() const final;
     bool isPlaying() const final;
@@ -148,6 +150,8 @@
     // [[suspended by user]] flag in the specification:
     // https://www.w3.org/TR/webaudio/#dom-audiocontext-suspended-by-user-slot
     bool m_wasSuspendedByScript { false };
+
+    bool m_canOverrideBackgroundPlaybackRestriction { true };
 };
 
 } // WebCore

Modified: trunk/Source/WebCore/Modules/webaudio/AudioNode.cpp (291389 => 291390)


--- trunk/Source/WebCore/Modules/webaudio/AudioNode.cpp	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Source/WebCore/Modules/webaudio/AudioNode.cpp	2022-03-17 07:21:46 UTC (rev 291390)
@@ -193,7 +193,8 @@
     if (inputIndex >= destination.numberOfInputs())
         return Exception { IndexSizeError, "Input index exceeds number of inputs"_s };
 
-    if (&context() != &destination.context())
+    auto& context = this->context();
+    if (&context != &destination.context())
         return Exception { InvalidAccessError, "Source and destination nodes belong to different audio contexts"_s };
 
     auto* input = destination.input(inputIndex);
@@ -202,6 +203,9 @@
     if (!output->numberOfChannels())
         return Exception { InvalidAccessError, "Node has zero output channels"_s };
 
+    if (is<AudioContext>(context) && &destination == &context.destination() && !downcast<AudioContext>(context).destination().isConnected())
+        downcast<AudioContext>(context).defaultDestinationWillBecomeConnected();
+
     input->connect(output);
 
     updatePullStatus();

Modified: trunk/Source/WebCore/Modules/webaudio/AudioSummingJunction.h (291389 => 291390)


--- trunk/Source/WebCore/Modules/webaudio/AudioSummingJunction.h	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Source/WebCore/Modules/webaudio/AudioSummingJunction.h	2022-03-17 07:21:46 UTC (rev 291390)
@@ -63,13 +63,13 @@
 
     void markRenderingStateAsDirty();
 
-protected:
-    WeakPtr<BaseAudioContext> m_context;
-
     // numberOfConnections() should never be called from the audio rendering thread.
     // Instead numberOfRenderingConnections() and renderingOutput() should be used.
     unsigned numberOfConnections() const { return m_outputs.size(); }
 
+protected:
+    WeakPtr<BaseAudioContext> m_context;
+
     unsigned maximumNumberOfChannels() const;
 
     // m_renderingOutputs is a copy of m_outputs which will never be modified during the graph rendering on the audio thread.

Modified: trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.cpp (291389 => 291390)


--- trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.cpp	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.cpp	2022-03-17 07:21:46 UTC (rev 291390)
@@ -64,6 +64,12 @@
     return downcast<AudioContext>(AudioDestinationNode::context());
 }
 
+bool DefaultAudioDestinationNode::isConnected() const
+{
+    auto* input = const_cast<DefaultAudioDestinationNode*>(this)->input(0);
+    return input ? !!input->numberOfConnections() : false;
+}
+
 const AudioContext& DefaultAudioDestinationNode::context() const
 {
     return downcast<AudioContext>(AudioDestinationNode::context());

Modified: trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.h (291389 => 291390)


--- trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.h	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Source/WebCore/Modules/webaudio/DefaultAudioDestinationNode.h	2022-03-17 07:21:46 UTC (rev 291390)
@@ -51,6 +51,7 @@
 
     void setMuted(bool muted) { m_muted = muted; }
     bool isPlayingAudio() const { return m_isEffectivelyPlayingAudio; }
+    bool isConnected() const;
 
 private:
     void createDestination();

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h (291389 => 291390)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2022-03-17 07:21:46 UTC (rev 291390)
@@ -169,6 +169,8 @@
 
     virtual void resetHaveEverRegisteredAsNowPlayingApplicationForTesting() { };
 
+    bool isApplicationInBackground() const { return m_isApplicationInBackground; }
+
 protected:
     friend class PlatformMediaSession;
     static std::unique_ptr<PlatformMediaSessionManager> create();
@@ -181,7 +183,6 @@
     void forEachSessionInGroup(MediaSessionGroupIdentifier, const Function<void(PlatformMediaSession&)>&);
     bool anyOfSessions(const Function<bool(const PlatformMediaSession&)>&) const;
 
-    bool isApplicationInBackground() const { return m_isApplicationInBackground; }
     void maybeDeactivateAudioSession();
     bool maybeActivateAudioSession();
 

Modified: trunk/Source/WebKit/ChangeLog (291389 => 291390)


--- trunk/Source/WebKit/ChangeLog	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Source/WebKit/ChangeLog	2022-03-17 07:21:46 UTC (rev 291390)
@@ -1,3 +1,16 @@
+2022-03-17  Youenn Fablet  <[email protected]>
+
+        AudioContext is suspended on iOS when page is backgrounded
+        https://bugs.webkit.org/show_bug.cgi?id=237878
+
+        Reviewed by Eric Carlson.
+
+        Expose private SPI for testing purposes.
+
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+        * UIProcess/WebProcessPool.h:
+
 2022-03-16  Sihui Liu  <[email protected]>
 
         Always update assertion state for existing default network process

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm (291389 => 291390)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2022-03-17 07:21:46 UTC (rev 291390)
@@ -402,6 +402,11 @@
 #endif
 }
 
+- (BOOL)_hasAudibleMediaActivity
+{
+    return _processPool->hasAudibleMediaActivity() ? YES : NO;
+}
+
 - (BOOL)_requestWebProcessTermination:(pid_t)pid
 {
     for (auto& process : _processPool->processes()) {

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h (291389 => 291390)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2022-03-17 07:21:46 UTC (rev 291390)
@@ -118,6 +118,7 @@
 - (void)_clearWebProcessCache WK_API_AVAILABLE(macos(10.15.4), ios(13.4));
 - (void)_setUseSeparateServiceWorkerProcess:(BOOL)forceServiceWorkerProcess WK_API_AVAILABLE(macos(10.15.4), ios(13.4));
 - (pid_t)_gpuProcessIdentifier WK_API_AVAILABLE(macos(12.0), ios(15.0));
+- (BOOL)_hasAudibleMediaActivity WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (BOOL)_requestWebProcessTermination:(pid_t)pid WK_API_AVAILABLE(macos(12.0), ios(15.0));
 
 // Test only. Returns web processes running web pages (does not include web processes running service workers)

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (291389 => 291390)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2022-03-17 07:21:46 UTC (rev 291390)
@@ -525,6 +525,8 @@
 
     Ref<WebProcessProxy> createNewWebProcess(WebsiteDataStore*, WebProcessProxy::CaptivePortalMode, WebProcessProxy::IsPrewarmed = WebProcessProxy::IsPrewarmed::No, WebCore::CrossOriginMode = WebCore::CrossOriginMode::Shared);
 
+    bool hasAudibleMediaActivity() const { return !!m_audibleMediaActivity; }
+
 private:
     void platformInitialize();
 

Modified: trunk/Tools/ChangeLog (291389 => 291390)


--- trunk/Tools/ChangeLog	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Tools/ChangeLog	2022-03-17 07:21:46 UTC (rev 291390)
@@ -1,3 +1,13 @@
+2022-03-17  Youenn Fablet  <[email protected]>
+
+        AudioContext is suspended on iOS when page is backgrounded
+        https://bugs.webkit.org/show_bug.cgi?id=237878
+
+        Reviewed by Eric Carlson.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/GPUProcess.mm:
+        * TestWebKitAPI/Tests/WebKitCocoa/audio-context-playing.html:
+
 2022-03-16  Jonathan Bedard  <[email protected]>
 
         [Merge-Queue] Add step to make comment on pull requests

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/GPUProcess.mm (291389 => 291390)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/GPUProcess.mm	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/GPUProcess.mm	2022-03-17 07:21:46 UTC (rev 291390)
@@ -764,3 +764,41 @@
     TestWebKitAPI::Util::sleep(0.5);
     EXPECT_EQ(0, [configuration.get().processPool _gpuProcessIdentifier]);
 }
+
+TEST(GPUProcess, ValidateWebAudioMediaProcessingAssertion)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    WKPreferencesSetBoolValueForKeyForTesting((__bridge WKPreferencesRef)[configuration preferences], true, WKStringCreateWithUTF8CString("UseGPUProcessForMediaEnabled"));
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 400, 400) configuration:configuration.get()]);
+    [webView synchronouslyLoadTestPageNamed:@"audio-context-playing"];
+
+    // evaluateJavaScript gives us the user gesture we need to reliably start audio playback on all platforms.
+    __block bool done = false;
+    [webView evaluateJavaScript:@"generateAudioInMediaStreamTrack()" completionHandler:^(id result, NSError *error) {
+        EXPECT_TRUE(!error);
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+
+    // A GPUProcess should get launched.
+    while (![configuration.get().processPool _gpuProcessIdentifier])
+        TestWebKitAPI::Util::sleep(0.1);
+
+    // There should be no audible activity.
+    EXPECT_FALSE([configuration.get().processPool _hasAudibleMediaActivity]);
+
+    done = false;
+    [webView evaluateJavaScript:@"transitionAudioToSpeakers()" completionHandler:^(id result, NSError *error) {
+        EXPECT_TRUE(!error);
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+
+    // There should be audible activity.
+    int counter = 20;
+    while (--counter && ![configuration.get().processPool _hasAudibleMediaActivity])
+        TestWebKitAPI::Util::sleep(0.1);
+
+    EXPECT_TRUE([configuration.get().processPool _hasAudibleMediaActivity]);
+}

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/audio-context-playing.html (291389 => 291390)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/audio-context-playing.html	2022-03-17 07:17:53 UTC (rev 291389)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/audio-context-playing.html	2022-03-17 07:21:46 UTC (rev 291390)
@@ -2,13 +2,38 @@
 <html>
 <body>
 <script>
+var context;
+var oscillator;
 function startPlaying()
 {
+    if (context)
+        context.close();
+
     context = new AudioContext();
-    let oscillator = new OscillatorNode(context);
+    oscillator = new OscillatorNode(context);
     oscillator.connect(context.destination);
     oscillator.start();
 }
+
+function generateAudioInMediaStreamTrack()
+{
+    if (context)
+        context.close();
+
+    context = new AudioContext();
+    oscillator = new OscillatorNode(context);
+
+    const mediaStreamDestination = context.createMediaStreamDestination();
+    oscillator.connect(mediaStreamDestination);
+    oscillator.start();
+}
+
+function transitionAudioToSpeakers()
+{
+    if (context)
+        oscillator.connect(context.destination);
+}
+
 </script>
 </body>
 </html>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to