AudioBufferSourceNode start method causes OfflineAudioContext to start running
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Apr 2018 15:40:20 +0000 (15:40 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Apr 2018 15:40:20 +0000 (15:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181939
<rdar://problem/36755393>

Reviewed by Eric Carlson.

Source/WebCore:

Test: webaudio/offlineaudiocontext-restriction.html

Don't respect playback restrictions for offline AudioContexts.

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::constructCommon):
* Modules/webaudio/AudioContext.h:
(WebCore::AudioContext::isOfflineContext const):
(WebCore::AudioContext::userGestureRequiredForAudioStart const):
(WebCore::AudioContext::pageConsentRequiredForAudioStart const):
(WebCore::AudioContext::isOfflineContext): Deleted.

LayoutTests:

* webaudio/offlineaudiocontext-restriction-expected.txt: Added.
* webaudio/offlineaudiocontext-restriction.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230158 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/webaudio/offlineaudiocontext-restriction-expected.txt [new file with mode: 0644]
LayoutTests/webaudio/offlineaudiocontext-restriction.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/webaudio/AudioContext.cpp
Source/WebCore/Modules/webaudio/AudioContext.h

index 0c08b1e..2dbde75 100644 (file)
@@ -1,3 +1,14 @@
+2018-04-02  Jer Noble  <jer.noble@apple.com>
+
+        AudioBufferSourceNode start method causes OfflineAudioContext to start running
+        https://bugs.webkit.org/show_bug.cgi?id=181939
+        <rdar://problem/36755393>
+
+        Reviewed by Eric Carlson.
+
+        * webaudio/offlineaudiocontext-restriction-expected.txt: Added.
+        * webaudio/offlineaudiocontext-restriction.html: Added.
+
 2018-03-31  Brent Fulgham  <bfulgham@apple.com>
 
         Show punycode if URL contains hyphen character
diff --git a/LayoutTests/webaudio/offlineaudiocontext-restriction-expected.txt b/LayoutTests/webaudio/offlineaudiocontext-restriction-expected.txt
new file mode 100644 (file)
index 0000000..c9ccf4e
--- /dev/null
@@ -0,0 +1,14 @@
+OfflineAudioContexts should not have behavior restrictions.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS context.state is "suspended"
+node.connect(context.destination)
+node.start()
+PASS context.state is "suspended"
+Calling context.startRendering() without a user gesture
+PASS context.state is "running"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/webaudio/offlineaudiocontext-restriction.html b/LayoutTests/webaudio/offlineaudiocontext-restriction.html
new file mode 100644 (file)
index 0000000..f9d6a6f
--- /dev/null
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+<script src="../resources/js-test.js"></script>
+<script type="text/javascript" src="resources/audio-testing.js"></script>
+</head>
+
+<body>
+<div id="description"></div>
+<div id="console"></div>
+
+<script>
+description('OfflineAudioContexts should not have behavior restrictions.');
+
+var context = null;
+var node = null;
+var calledResumeWithUserGesture = false;
+
+function runTest() {
+    window.jsTestIsAsync = true;
+
+    context = new webkitOfflineAudioContext(2, 1000, 44100);
+
+    if (window.internals)
+        internals.setAudioContextRestrictions(context, 'RequireUserGestureForAudioStart');
+
+    shouldBe('context.state', '"suspended"');
+
+    node = context.createBufferSource();
+    evalAndLog('node.connect(context.destination)');
+    evalAndLog('node.start()');
+    shouldBe('context.state', '"suspended"');
+
+    debug('Calling context.startRendering() without a user gesture');
+    context.startRendering();
+    shouldBe('context.state', '"running"');
+    finishJSTest();
+}
+
+runTest();
+
+</script>
+</body>
+</html>
index 20222cb..9d203ae 100644 (file)
@@ -1,3 +1,23 @@
+2018-04-02  Jer Noble  <jer.noble@apple.com>
+
+        AudioBufferSourceNode start method causes OfflineAudioContext to start running
+        https://bugs.webkit.org/show_bug.cgi?id=181939
+        <rdar://problem/36755393>
+
+        Reviewed by Eric Carlson.
+
+        Test: webaudio/offlineaudiocontext-restriction.html
+
+        Don't respect playback restrictions for offline AudioContexts.
+
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::constructCommon):
+        * Modules/webaudio/AudioContext.h:
+        (WebCore::AudioContext::isOfflineContext const):
+        (WebCore::AudioContext::userGestureRequiredForAudioStart const):
+        (WebCore::AudioContext::pageConsentRequiredForAudioStart const):
+        (WebCore::AudioContext::isOfflineContext): Deleted.
+
 2018-04-02  Alejandro G. Castro  <alex@igalia.com>
 
         [GTK] Make libwebrtc backend buildable for GTK  port
index dc6462b..5bb2b03 100644 (file)
@@ -166,12 +166,10 @@ void AudioContext::constructCommon()
     
     m_listener = AudioListener::create();
 
-#if PLATFORM(IOS)
-    if (document()->settings().audioPlaybackRequiresUserGesture())
+    if (document()->audioPlaybackRequiresUserGesture())
         addBehaviorRestriction(RequireUserGestureForAudioStartRestriction);
     else
         m_restrictions = NoRestrictions;
-#endif
 
 #if PLATFORM(COCOA)
     addBehaviorRestriction(RequirePageConsentForAudioStartRestriction);
index 0cc077f..2b8a2b1 100644 (file)
@@ -85,7 +85,7 @@ public:
 
     bool isInitialized() const;
     
-    bool isOfflineContext() { return m_isOfflineContext; }
+    bool isOfflineContext() const { return m_isOfflineContext; }
 
     Document* document() const; // ASSERTs if document no longer exists.
 
@@ -276,8 +276,8 @@ private:
     bool willBeginPlayback();
     bool willPausePlayback();
 
-    bool userGestureRequiredForAudioStart() const { return m_restrictions & RequireUserGestureForAudioStartRestriction; }
-    bool pageConsentRequiredForAudioStart() const { return m_restrictions & RequirePageConsentForAudioStartRestriction; }
+    bool userGestureRequiredForAudioStart() const { return !isOfflineContext() && m_restrictions & RequireUserGestureForAudioStartRestriction; }
+    bool pageConsentRequiredForAudioStart() const { return !isOfflineContext() && m_restrictions & RequirePageConsentForAudioStartRestriction; }
 
     void setState(State);