1 | /* |
2 | * Copyright (C) 2016 Apple Inc. All rights reserved. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | |
19 | #include "config.h" |
20 | |
21 | #if WK_HAVE_C_SPI |
22 | |
23 | #if ENABLE(MEDIA_STREAM) |
24 | #include "PlatformUtilities.h" |
25 | #include "PlatformWebView.h" |
26 | #include "Test.h" |
27 | #include <WebKit/WKPreferencesRef.h> |
28 | #include <WebKit/WKPreferencesRefPrivate.h> |
29 | #include <WebKit/WKRetainPtr.h> |
30 | #include <WebKit/WKUserMediaPermissionCheck.h> |
31 | #include <string.h> |
32 | #include <vector> |
33 | |
34 | namespace TestWebKitAPI { |
35 | |
36 | static bool loadedFirstTime; |
37 | static bool loadedSecondTime; |
38 | |
39 | void checkUserMediaPermissionCallback(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKSecurityOriginRef, WKUserMediaPermissionCheckRef permissionRequest, const void*) |
40 | { |
41 | WKUserMediaPermissionCheckSetUserMediaAccessInfo(permissionRequest, WKStringCreateWithUTF8CString("0x123456789" ), true); |
42 | if (!loadedFirstTime) { |
43 | loadedFirstTime = true; |
44 | return; |
45 | } |
46 | |
47 | loadedSecondTime = true; |
48 | } |
49 | |
50 | TEST(WebKit, EnumerateDevices) |
51 | { |
52 | auto context = adoptWK(WKContextCreateWithConfiguration(nullptr)); |
53 | |
54 | WKRetainPtr<WKPageGroupRef> pageGroup = adoptWK(WKPageGroupCreateWithIdentifier(Util::toWK("EnumerateDevices" ).get())); |
55 | WKPreferencesRef preferences = WKPageGroupGetPreferences(pageGroup.get()); |
56 | WKPreferencesSetMediaDevicesEnabled(preferences, true); |
57 | WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true); |
58 | WKPreferencesSetMediaCaptureRequiresSecureConnection(preferences, false); |
59 | |
60 | WKPageUIClientV6 uiClient; |
61 | memset(&uiClient, 0, sizeof(uiClient)); |
62 | uiClient.base.version = 6; |
63 | uiClient.checkUserMediaPermissionForOrigin = checkUserMediaPermissionCallback; |
64 | |
65 | PlatformWebView webView(context.get(), pageGroup.get()); |
66 | WKPageSetPageUIClient(webView.page(), &uiClient.base); |
67 | |
68 | auto url = adoptWK(Util::createURLForResource("enumerateMediaDevices" , "html" )); |
69 | |
70 | // Load and kill the page. |
71 | WKPageLoadURL(webView.page(), url.get()); |
72 | Util::run(&loadedFirstTime); |
73 | WKPageTerminate(webView.page()); |
74 | |
75 | // Load it again to make sure the user media process manager doesn't assert. |
76 | WKPageLoadURL(webView.page(), url.get()); |
77 | Util::run(&loadedSecondTime); |
78 | } |
79 | |
80 | } // namespace TestWebKitAPI |
81 | |
82 | #endif // ENABLE(MEDIA_STREAM) |
83 | |
84 | #endif // WK_HAVE_C_SPI |
85 | |