Add an API test to cover UIClient checkUserMediaPermissionForOrigin being nullptr
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Feb 2019 00:45:19 +0000 (00:45 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Feb 2019 00:45:19 +0000 (00:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194106
<rdar://problem/47676333>

Reviewed by Ryosuke Niwa.

* TestWebKitAPI/Tests/WebKit/UserMedia.cpp:
(TestWebKitAPI::didFinishNavigation):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit/getUserMedia.html:

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

Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit/UserMedia.cpp
Tools/TestWebKitAPI/Tests/WebKit/getUserMedia.html

index ea9a4e1..469a347 100644 (file)
@@ -1,3 +1,16 @@
+2019-01-31  Youenn Fablet  <youenn@apple.com>
+
+        Add an API test to cover UIClient checkUserMediaPermissionForOrigin being nullptr
+        https://bugs.webkit.org/show_bug.cgi?id=194106
+        <rdar://problem/47676333>
+
+        Reviewed by Ryosuke Niwa.
+
+        * TestWebKitAPI/Tests/WebKit/UserMedia.cpp:
+        (TestWebKitAPI::didFinishNavigation):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit/getUserMedia.html:
+
 2019-01-31  Chris Dumez  <cdumez@apple.com>
 
         Page zoom level is lost after a process swap or a crash
index 2b06b0b..a0c21d7 100644 (file)
@@ -157,6 +157,44 @@ TEST(WebKit, OnDeviceChangeCrash)
     EXPECT_TRUE(!didCrash);
 }
 
+static bool didReceiveMessage;
+static void didFinishNavigation(WKPageRef, WKNavigationRef, WKTypeRef, const void*)
+{
+    didReceiveMessage = true;
+}
+
+TEST(WebKit, EnumerateDevicesCrash)
+{
+    auto context = adoptWK(WKContextCreateWithConfiguration(nullptr));
+
+    WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(Util::toWK("GetUserMedia").get()));
+    WKPreferencesRef preferences = WKPageGroupGetPreferences(pageGroup.get());
+    WKPreferencesSetMediaDevicesEnabled(preferences, true);
+    WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true);
+    WKPreferencesSetMediaCaptureRequiresSecureConnection(preferences, false);
+    WKPreferencesSetMockCaptureDevicesEnabled(preferences, true);
+
+    WKPageUIClientV6 uiClient;
+    // We want uiClient.checkUserMediaPermissionForOrigin to be null.
+    memset(&uiClient, 0, sizeof(uiClient));
+    uiClient.base.version = 6;
+
+    WKPageNavigationClientV3 loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+    loaderClient.base.version = 3;
+    loaderClient.didFinishNavigation = didFinishNavigation;
+
+    PlatformWebView webView(context.get(), pageGroup.get());
+    WKPageSetPageUIClient(webView.page(), &uiClient.base);
+    WKPageSetPageNavigationClient(webView.page(), &loaderClient.base);
+
+    // Load a page doing enumerateDevices.
+    didReceiveMessage = false;
+    auto url = adoptWK(Util::createURLForResource("getUserMedia", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+    Util::run(&didReceiveMessage);
+}
+
 } // namespace TestWebKitAPI
 
 #endif // ENABLE(MEDIA_STREAM)
index 73f71b9..d72ce80 100644 (file)
@@ -5,15 +5,16 @@
 
             let stream = null;
 
-            function promptForCapture()
+            async function promptForCapture()
             {
-                navigator.mediaDevices.getUserMedia({ audio: false, video: true })
-                .then((s) => {
-                      stream = s;
-                      video.srcObject = stream;
-                      console.log("Got user media");
-                })
-                .catch((error) => console.log(`Failed with error: ${error}`));
+                try {
+                    await navigator.mediaDevices.enumerateDevices();
+                    const stream = await navigator.mediaDevices.getUserMedia({ audio: false, video: true })
+                    video.srcObject = stream;
+                    console.log("Got user media");
+                } catch(error) {
+                    console.log(`Failed with error: ${error}`);
+                }
             }
 
             function stop(kind)