inspector/page/overrideSetting-MockCaptureDevicesEnabled.html is failing after remova...
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Dec 2019 15:24:13 +0000 (15:24 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Dec 2019 15:24:13 +0000 (15:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=204849

Reviewed by Eric Carlson.

Source/WebCore:

Add API and internals to check which center is used in WebProcess.
Covered by updated test.

* platform/mock/MockRealtimeMediaSourceCenter.cpp:
(WebCore::MockRealtimeMediaSourceCenter::setMockRealtimeMediaSourceCenterEnabled):
(WebCore::MockRealtimeMediaSourceCenter::mockRealtimeMediaSourceCenterEnabled):
* platform/mock/MockRealtimeMediaSourceCenter.h:
* testing/Internals.cpp:
(WebCore::Internals::isMockRealtimeMediaSourceCenterEnabled):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

Synchronize the center with the preferences when the value might be updated.
Add API to check which center is used in UIProcess.

* UIProcess/API/C/WKPage.cpp:
(WKPageIsMockRealtimeMediaSourceCenterEnabled):
* UIProcess/API/C/WKPagePrivate.h:
* UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
(WebKit::UserMediaPermissionRequestManagerProxy::UserMediaPermissionRequestManagerProxy):
(WebKit::UserMediaPermissionRequestManagerProxy::setMockCaptureDevicesEnabledOverride):
* UIProcess/UserMediaPermissionRequestManagerProxy.h:
(WebKit::UserMediaPermissionRequestManagerProxy::setMockCaptureDevicesEnabledOverride): Deleted.

Tools:

Add test runner API to check which center (mock or not) is used in UIProcess side.

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::isMockRealtimeMediaSourceCenterEnabled):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::isMockRealtimeMediaSourceCenterEnabled const):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

LayoutTests:

Update test to use center state getters.

* inspector/page/overrideSetting-MockCaptureDevicesEnabled-expected.txt:
* inspector/page/overrideSetting-MockCaptureDevicesEnabled.html:

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

21 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/page/overrideSetting-MockCaptureDevicesEnabled-expected.txt
LayoutTests/inspector/page/overrideSetting-MockCaptureDevicesEnabled.html
Source/WebCore/ChangeLog
Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp
Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/C/WKPage.cpp
Source/WebKit/UIProcess/API/C/WKPagePrivate.h
Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp
Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.h
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestController.h
Tools/WebKitTestRunner/TestInvocation.cpp

index cf0bff9..0b11b7d 100644 (file)
@@ -1,3 +1,15 @@
+2019-12-05  youenn fablet  <youenn@apple.com>
+
+        inspector/page/overrideSetting-MockCaptureDevicesEnabled.html is failing after removal of internals.setMockMediaCaptureDevicesEnabled API
+        https://bugs.webkit.org/show_bug.cgi?id=204849
+
+        Reviewed by Eric Carlson.
+
+        Update test to use center state getters.
+
+        * inspector/page/overrideSetting-MockCaptureDevicesEnabled-expected.txt:
+        * inspector/page/overrideSetting-MockCaptureDevicesEnabled.html:
+
 2019-12-05  Eric Carlson  <eric.carlson@apple.com>
 
         WPT test MediaStream-MediaElement-srcObject.https.html times out
index 0f88bf0..2417d90 100644 (file)
@@ -3,9 +3,10 @@ Tests for the Page.overrideSetting command.
 
 == Running test suite: Page.overrideSetting
 -- Running test case: Page.overrideSetting.MockCaptureDevicesEnabled
-Expected Error: The I/O read operation failed.
+Overriding MockCaptureDevicesEnabled to false...
+Mock use check: PASS
 Overriding MockCaptureDevicesEnabled to true...
-PASS: getUserMedia should not fail when no devices are available
+Mock use check: PASS
 Removing MockCaptureDevicesEnabled override...
-Expected Error: The I/O read operation failed.
+Mock use check: PASS
 
index 4278733..ef0bbbb 100644 (file)
@@ -4,13 +4,18 @@
 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
 <script>
 
-if (window.internals)
-    window.internals.setMockMediaCaptureDevicesEnabled(false);
+function checkMockUsage(expectToUseMock)
+{
+    if (window.testRunner && testRunner.isMockRealtimeMediaSourceCenterEnabled && testRunner.isMockRealtimeMediaSourceCenterEnabled() !== expectToUseMock)
+        return "FAIL: testRunner mismatch";
+    if (window.internals && internals.isMockRealtimeMediaSourceCenterEnabled && internals.isMockRealtimeMediaSourceCenterEnabled() !== expectToUseMock)
+        return "FAIL: internals mismatch";
+    return "PASS";
+}
 
-function requestGetUserMedia() {
-    navigator.mediaDevices.getUserMedia({audio: {}, video: {}})
-        .then(() => TestPage.dispatchEventToFrontend("GetUserMedia", {success: true}))
-        .catch((error) => TestPage.dispatchEventToFrontend("GetUserMedia", {error: error.message}));
+function validateMockUsage(expectToUseMock)
+{
+    TestPage.dispatchEventToFrontend("ValidateMock", checkMockUsage(expectToUseMock));
 }
 
 function test()
@@ -21,29 +26,28 @@ function test()
         name: "Page.overrideSetting.MockCaptureDevicesEnabled",
         description: "Test that changing whether mock capture devices are enabled has an effect.",
         async test() {
-            let [defaultResult] = await Promise.all([
-                InspectorTest.awaitEvent("GetUserMedia"),
-                InspectorTest.evaluateInPage(`requestGetUserMedia()`),
-            ]);
-            InspectorTest.log("Expected Error: " + defaultResult.data.error);
+            InspectorTest.log("Overriding MockCaptureDevicesEnabled to false...");
+            await PageAgent.overrideSetting(InspectorBackend.Enum.Page.Setting.MockCaptureDevicesEnabled, false);
+
+            InspectorTest.evaluateInPage(`validateMockUsage(false)`);
+            result = await InspectorTest.awaitEvent("ValidateMock");
+            InspectorTest.log("Mock use check: " + result.data);
+
 
             InspectorTest.log("Overriding MockCaptureDevicesEnabled to true...");
             await PageAgent.overrideSetting(InspectorBackend.Enum.Page.Setting.MockCaptureDevicesEnabled, true);
 
-            let [overriddenResult] = await Promise.all([
-                InspectorTest.awaitEvent("GetUserMedia"),
-                InspectorTest.evaluateInPage(`requestGetUserMedia()`),
-            ])
-            InspectorTest.expectTrue(overriddenResult.data.success, "getUserMedia should not fail when no devices are available");
+            InspectorTest.evaluateInPage(`validateMockUsage(true)`);
+            result = await InspectorTest.awaitEvent("ValidateMock");
+            InspectorTest.log("Mock use check: " + result.data);
+
 
             InspectorTest.log("Removing MockCaptureDevicesEnabled override...");
             await PageAgent.overrideSetting(InspectorBackend.Enum.Page.Setting.MockCaptureDevicesEnabled);
 
-            let [originalResult] = await Promise.all([
-                InspectorTest.awaitEvent("GetUserMedia"),
-                InspectorTest.evaluateInPage(`requestGetUserMedia()`),
-            ])
-            InspectorTest.log("Expected Error: " + originalResult.data.error);
+            InspectorTest.evaluateInPage(`validateMockUsage(true)`);
+            result = await InspectorTest.awaitEvent("ValidateMock");
+            InspectorTest.log("Mock use check: " + result.data);
         },
     });
 
index 426bcae..652f8b7 100644 (file)
@@ -1,3 +1,22 @@
+2019-12-05  youenn fablet  <youenn@apple.com>
+
+        inspector/page/overrideSetting-MockCaptureDevicesEnabled.html is failing after removal of internals.setMockMediaCaptureDevicesEnabled API
+        https://bugs.webkit.org/show_bug.cgi?id=204849
+
+        Reviewed by Eric Carlson.
+
+        Add API and internals to check which center is used in WebProcess.
+        Covered by updated test.
+
+        * platform/mock/MockRealtimeMediaSourceCenter.cpp:
+        (WebCore::MockRealtimeMediaSourceCenter::setMockRealtimeMediaSourceCenterEnabled):
+        (WebCore::MockRealtimeMediaSourceCenter::mockRealtimeMediaSourceCenterEnabled):
+        * platform/mock/MockRealtimeMediaSourceCenter.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::isMockRealtimeMediaSourceCenterEnabled):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2019-12-05  Eric Carlson  <eric.carlson@apple.com>
 
         WPT test MediaStream-MediaElement-srcObject.https.html times out
index e6b8426..f77da7a 100644 (file)
@@ -191,16 +191,15 @@ MockRealtimeMediaSourceCenter& MockRealtimeMediaSourceCenter::singleton()
 
 void MockRealtimeMediaSourceCenter::setMockRealtimeMediaSourceCenterEnabled(bool enabled)
 {
-    static bool active = false;
-    if (active == enabled)
-        return;
+    MockRealtimeMediaSourceCenter& mock = singleton();
 
-    active = enabled;
+    if (mock.m_isEnabled == enabled)
+        return;
 
+    mock.m_isEnabled = enabled;
     RealtimeMediaSourceCenter& center = RealtimeMediaSourceCenter::singleton();
-    MockRealtimeMediaSourceCenter& mock = singleton();
 
-    if (active) {
+    if (mock.m_isEnabled) {
         if (mock.m_isMockAudioCaptureEnabled)
             center.setAudioCaptureFactory(mock.audioCaptureFactory());
         if (mock.m_isMockVideoCaptureEnabled)
@@ -220,10 +219,7 @@ void MockRealtimeMediaSourceCenter::setMockRealtimeMediaSourceCenterEnabled(bool
 
 bool MockRealtimeMediaSourceCenter::mockRealtimeMediaSourceCenterEnabled()
 {
-    MockRealtimeMediaSourceCenter& mock = singleton();
-    RealtimeMediaSourceCenter& center = RealtimeMediaSourceCenter::singleton();
-
-    return &center.audioCaptureFactory() == &mock.audioCaptureFactory() || &center.videoCaptureFactory() == &mock.videoCaptureFactory() || &center.displayCaptureFactory() == &mock.displayCaptureFactory();
+    return singleton().m_isEnabled;
 }
 
 static void createCaptureDevice(const MockMediaDevice& device)
index 6d16fe7..1c5aa66 100644 (file)
@@ -94,6 +94,7 @@ private:
     bool m_isMockAudioCaptureEnabled { true };
     bool m_isMockVideoCaptureEnabled { true };
     bool m_isMockDisplayCaptureEnabled { true };
+    bool m_isEnabled { false };
 };
 
 }
index f623afd..b84bfff 100644 (file)
@@ -4884,6 +4884,11 @@ void Internals::setMediaStreamSourceInterrupted(MediaStreamTrack& track, bool in
 {
     track.source().setInterruptedForTesting(interrupted);
 }
+
+bool Internals::isMockRealtimeMediaSourceCenterEnabled()
+{
+    return MockRealtimeMediaSourceCenter::mockRealtimeMediaSourceCenterEnabled();
+}
 #endif
 
 bool Internals::supportsAudioSession() const
index 78b9b28..ec32617 100644 (file)
@@ -744,6 +744,7 @@ public:
     void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
     void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
     void setMediaStreamSourceInterrupted(MediaStreamTrack&, bool);
+    bool isMockRealtimeMediaSourceCenterEnabled();
 #endif
 
     bool supportsAudioSession() const;
index 936c2a7..3af7dbe 100644 (file)
@@ -725,6 +725,7 @@ enum CompositingPolicy {
     [Conditional=MEDIA_STREAM] void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack track);
     [Conditional=MEDIA_STREAM] void setMediaStreamTrackIdentifier(MediaStreamTrack track, DOMString identifier);
     [Conditional=MEDIA_STREAM] void setMediaStreamSourceInterrupted(MediaStreamTrack track, boolean interrupted);
+    [Conditional=MEDIA_STREAM] boolean isMockRealtimeMediaSourceCenterEnabled();
 
     unsigned long long documentIdentifier(Document document);
     boolean isDocumentAlive(unsigned long long documentIdentifier);
index 0f32a53..314d7fc 100644 (file)
@@ -1,3 +1,22 @@
+2019-12-05  youenn fablet  <youenn@apple.com>
+
+        inspector/page/overrideSetting-MockCaptureDevicesEnabled.html is failing after removal of internals.setMockMediaCaptureDevicesEnabled API
+        https://bugs.webkit.org/show_bug.cgi?id=204849
+
+        Reviewed by Eric Carlson.
+
+        Synchronize the center with the preferences when the value might be updated.
+        Add API to check which center is used in UIProcess.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageIsMockRealtimeMediaSourceCenterEnabled):
+        * UIProcess/API/C/WKPagePrivate.h:
+        * UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
+        (WebKit::UserMediaPermissionRequestManagerProxy::UserMediaPermissionRequestManagerProxy):
+        (WebKit::UserMediaPermissionRequestManagerProxy::setMockCaptureDevicesEnabledOverride):
+        * UIProcess/UserMediaPermissionRequestManagerProxy.h:
+        (WebKit::UserMediaPermissionRequestManagerProxy::setMockCaptureDevicesEnabledOverride): Deleted.
+
 2019-12-04  Joonghun Park  <jh718.park@samsung.com>
 
         Unreviewed. Remove build warnings below since r253025.
index e6dd375..4d8f6cf 100644 (file)
@@ -76,6 +76,7 @@
 #include "WebProcessProxy.h"
 #include "WebProtectionSpace.h"
 #include <WebCore/ContentRuleListResults.h>
+#include <WebCore/MockRealtimeMediaSourceCenter.h>
 #include <WebCore/Page.h>
 #include <WebCore/SSLKeyGenerator.h>
 #include <WebCore/SecurityOriginData.h>
@@ -2937,3 +2938,12 @@ void WKPageSetMockCameraOrientation(WKPageRef page, uint64_t orientation)
     toImpl(page)->setOrientationForMediaCapture(orientation);
 #endif
 }
+
+WK_EXPORT bool WKPageIsMockRealtimeMediaSourceCenterEnabled(WKPageRef)
+{
+#if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
+    return MockRealtimeMediaSourceCenter::mockRealtimeMediaSourceCenterEnabled();
+#else
+    return false;
+#endif
+}
index 1ed824c..0e62f61 100644 (file)
@@ -192,6 +192,7 @@ typedef void (*WKPageMarkAdClickAttributionsAsExpiredForTestingFunction)(void* f
 WK_EXPORT void WKPageMarkAdClickAttributionsAsExpiredForTesting(WKPageRef page, WKPageMarkAdClickAttributionsAsExpiredForTestingFunction callback, void* callbackContext);
 
 WK_EXPORT void WKPageSetMockCameraOrientation(WKPageRef page, uint64_t orientation);
+WK_EXPORT bool WKPageIsMockRealtimeMediaSourceCenterEnabled(WKPageRef page);
 
 #ifdef __cplusplus
 }
index 403fd2d..7f3bd12 100644 (file)
@@ -79,6 +79,7 @@ UserMediaPermissionRequestManagerProxy::UserMediaPermissionRequestManagerProxy(W
 #if ENABLE(MEDIA_STREAM)
     proxies().add(this);
 #endif
+    syncWithWebCorePrefs();
 }
 
 UserMediaPermissionRequestManagerProxy::~UserMediaPermissionRequestManagerProxy()
@@ -683,6 +684,12 @@ void UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame(Frame
 #endif
 }
 
+void UserMediaPermissionRequestManagerProxy::setMockCaptureDevicesEnabledOverride(Optional<bool> enabled)
+{
+    m_mockDevicesEnabledOverride = enabled;
+    syncWithWebCorePrefs();
+}
+
 void UserMediaPermissionRequestManagerProxy::syncWithWebCorePrefs() const
 {
 #if ENABLE(MEDIA_STREAM)
index 2498392..6f01a1f 100644 (file)
@@ -86,7 +86,7 @@ public:
         Prompt
     };
 
-    void setMockCaptureDevicesEnabledOverride(Optional<bool> enabled) { m_mockDevicesEnabledOverride = enabled; }
+    void setMockCaptureDevicesEnabledOverride(Optional<bool>);
     bool hasPendingCapture() const { return m_hasPendingCapture; }
 
 private:
index e728723..563f846 100644 (file)
@@ -1,3 +1,22 @@
+2019-12-05  youenn fablet  <youenn@apple.com>
+
+        inspector/page/overrideSetting-MockCaptureDevicesEnabled.html is failing after removal of internals.setMockMediaCaptureDevicesEnabled API
+        https://bugs.webkit.org/show_bug.cgi?id=204849
+
+        Reviewed by Eric Carlson.
+
+        Add test runner API to check which center (mock or not) is used in UIProcess side.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::isMockRealtimeMediaSourceCenterEnabled):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::isMockRealtimeMediaSourceCenterEnabled const):
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+
 2019-12-05  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][IFC] Move trailing trimming logic to LineBuilder::TrimmableContent
index 9fdc205..9e53b5b 100644 (file)
@@ -388,6 +388,7 @@ interface TestRunner {
     void removeMockMediaDevice(DOMString persistentId);
     void resetMockMediaDevices();
     void setMockCameraOrientation(unsigned long orientation);
+    boolean isMockRealtimeMediaSourceCenterEnabled();
 
     void injectUserScript(DOMString string);
     readonly attribute unsigned long userScriptInjectedCount;
index 182c2c6..fe9e2fe 100644 (file)
@@ -2424,6 +2424,15 @@ void TestRunner::setMockCameraOrientation(unsigned orientation)
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
 }
 
+bool TestRunner::isMockRealtimeMediaSourceCenterEnabled()
+{
+    auto messageName = adoptWK(WKStringCreateWithUTF8CString("IsMockRealtimeMediaSourceCenterEnabled"));
+    WKTypeRef returnData = nullptr;
+    WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), nullptr, &returnData);
+    ASSERT(WKGetTypeID(returnData) == WKBooleanGetTypeID());
+    return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get());
+}
+
 #if PLATFORM(MAC)
 void TestRunner::connectMockGamepad(unsigned index)
 {
index 76f6676..955dd0f 100644 (file)
@@ -492,6 +492,7 @@ public:
     void removeMockMediaDevice(JSStringRef persistentId);
     void resetMockMediaDevices();
     void setMockCameraOrientation(unsigned);
+    bool isMockRealtimeMediaSourceCenterEnabled();
 
     size_t userScriptInjectedCount() const;
     void injectUserScript(JSStringRef);
index f56d0c9..88a65ab 100644 (file)
@@ -3640,6 +3640,11 @@ void TestController::setMockCameraOrientation(uint64_t orientation)
     WKPageSetMockCameraOrientation(m_mainWebView->page(), orientation);
 }
 
+bool TestController::isMockRealtimeMediaSourceCenterEnabled() const
+{
+    return WKPageIsMockRealtimeMediaSourceCenterEnabled(m_mainWebView->page());
+}
+
 #if !PLATFORM(COCOA)
 void TestController::platformAddTestOptions(TestOptions&) const
 {
index 004e535..24ef4cb 100644 (file)
@@ -295,6 +295,7 @@ public:
     void removeMockMediaDevice(WKStringRef persistentID);
     void resetMockMediaDevices();
     void setMockCameraOrientation(uint64_t);
+    bool isMockRealtimeMediaSourceCenterEnabled() const;
 
     void injectUserScript(WKStringRef);
     
index 674605d..098f5ba 100644 (file)
@@ -985,6 +985,11 @@ WKRetainPtr<WKTypeRef> TestInvocation::didReceiveSynchronousMessageFromInjectedB
         return nullptr;
     }
 
+    if (WKStringIsEqualToUTF8CString(messageName, "IsMockRealtimeMediaSourceCenterEnabled")) {
+        bool isMockRealtimeMediaSourceCenterEnabled = TestController::singleton().isMockRealtimeMediaSourceCenterEnabled();
+        return adoptWK(WKBooleanCreate(isMockRealtimeMediaSourceCenterEnabled));
+    }
+
 #if PLATFORM(MAC)
     if (WKStringIsEqualToUTF8CString(messageName, "ConnectMockGamepad")) {
         ASSERT(WKGetTypeID(messageBody) == WKUInt64GetTypeID());