|
45 | 45 | #import <WebKit/_WKFeature.h>
|
46 | 46 | #import <WebKit/_WKProcessPoolConfiguration.h>
|
47 | 47 | #import <WebKit/_WKWebsiteDataStoreConfiguration.h>
|
| 48 | +#import <pal/spi/mac/MediaRemoteSPI.h> |
48 | 49 | #import <wtf/text/StringBuilder.h>
|
49 | 50 | #import <wtf/text/WTFString.h>
|
50 | 51 |
|
@@ -1269,6 +1270,83 @@ function capture()
|
1269 | 1270 | }
|
1270 | 1271 | #endif
|
1271 | 1272 |
|
| 1273 | +#if WK_HAVE_C_SPI |
| 1274 | +TEST(WebKit2, WebRTCAndRemoteCommands) |
| 1275 | +{ |
| 1276 | + auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); |
| 1277 | + auto context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); |
| 1278 | + configuration.get().processPool = (WKProcessPool *)context.get(); |
| 1279 | + configuration.get().processPool._configuration.shouldCaptureAudioInUIProcess = NO; |
| 1280 | + |
| 1281 | + initializeMediaCaptureConfiguration(configuration.get()); |
| 1282 | + |
| 1283 | + auto messageHandler = adoptNS([[GUMMessageHandler alloc] init]); |
| 1284 | + [[configuration.get() userContentController] addScriptMessageHandler:messageHandler.get() name:@"gum"]; |
| 1285 | + |
| 1286 | + auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration.get()]); |
| 1287 | + |
| 1288 | + auto delegate = adoptNS([[UserMediaCaptureUIDelegate alloc] init]); |
| 1289 | + [webView setUIDelegate:delegate.get()]; |
| 1290 | + [webView _setMediaCaptureReportingDelayForTesting:0]; |
| 1291 | + |
| 1292 | + auto observer = adoptNS([[MediaCaptureObserver alloc] init]); |
| 1293 | + [webView addObserver:observer.get() forKeyPath:@"microphoneCaptureState" options:NSKeyValueObservingOptionNew context:nil]; |
| 1294 | + [webView addObserver:observer.get() forKeyPath:@"cameraCaptureState" options:NSKeyValueObservingOptionNew context:nil]; |
| 1295 | + |
| 1296 | + cameraCaptureStateChange = false; |
| 1297 | + microphoneCaptureStateChange = false; |
| 1298 | + |
| 1299 | + done = false; |
| 1300 | + [webView loadTestPageNamed:@"webrtc-remote"]; |
| 1301 | + |
| 1302 | + EXPECT_TRUE(waitUntilCameraState(webView.get(), WKMediaCaptureStateActive)); |
| 1303 | + EXPECT_TRUE(waitUntilMicrophoneState(webView.get(), WKMediaCaptureStateActive)); |
| 1304 | + |
| 1305 | + done = false; |
| 1306 | + [webView stringByEvaluatingJavaScript:@"startTest()"]; |
| 1307 | + TestWebKitAPI::Util::run(&done); |
| 1308 | + done = false; |
| 1309 | + |
| 1310 | + cameraCaptureStateChange = false; |
| 1311 | + microphoneCaptureStateChange = false; |
| 1312 | + [webView stringByEvaluatingJavaScript:@"sendCommand('pause')"]; |
| 1313 | + EXPECT_TRUE(waitUntilCameraState(webView.get(), WKMediaCaptureStateMuted)); |
| 1314 | + EXPECT_TRUE(waitUntilMicrophoneState(webView.get(), WKMediaCaptureStateMuted)); |
| 1315 | + |
| 1316 | + [webView stringByEvaluatingJavaScript:@"sendCommand('play')"]; |
| 1317 | + EXPECT_TRUE(waitUntilCameraState(webView.get(), WKMediaCaptureStateActive)); |
| 1318 | + EXPECT_TRUE(waitUntilMicrophoneState(webView.get(), WKMediaCaptureStateActive)); |
| 1319 | + |
| 1320 | + [webView stringByEvaluatingJavaScript:@"sendCommand('toggleplaypause')"]; |
| 1321 | + EXPECT_TRUE(waitUntilCameraState(webView.get(), WKMediaCaptureStateMuted)); |
| 1322 | + EXPECT_TRUE(waitUntilMicrophoneState(webView.get(), WKMediaCaptureStateMuted)); |
| 1323 | + |
| 1324 | + [webView stringByEvaluatingJavaScript:@"sendCommand('toggleplaypause')"]; |
| 1325 | + EXPECT_TRUE(waitUntilCameraState(webView.get(), WKMediaCaptureStateActive)); |
| 1326 | + EXPECT_TRUE(waitUntilMicrophoneState(webView.get(), WKMediaCaptureStateActive)); |
| 1327 | + |
| 1328 | + done = false; |
| 1329 | + // register handlers will catch commands, so capture should not muted. |
| 1330 | + [webView stringByEvaluatingJavaScript:@"registerHandlers()"]; |
| 1331 | + TestWebKitAPI::Util::run(&done); |
| 1332 | + done = false; |
| 1333 | + |
| 1334 | + [webView stringByEvaluatingJavaScript:@"sendCommand('pause')"]; |
| 1335 | + TestWebKitAPI::Util::run(&done); |
| 1336 | + done = false; |
| 1337 | + |
| 1338 | + EXPECT_TRUE(waitUntilCameraState(webView.get(), WKMediaCaptureStateActive)); |
| 1339 | + EXPECT_TRUE(waitUntilMicrophoneState(webView.get(), WKMediaCaptureStateActive)); |
| 1340 | + |
| 1341 | + [webView stringByEvaluatingJavaScript:@"sendCommand('play')"]; |
| 1342 | + TestWebKitAPI::Util::run(&done); |
| 1343 | + done = false; |
| 1344 | + |
| 1345 | + EXPECT_TRUE(waitUntilCameraState(webView.get(), WKMediaCaptureStateActive)); |
| 1346 | + EXPECT_TRUE(waitUntilMicrophoneState(webView.get(), WKMediaCaptureStateActive)); |
| 1347 | +} |
| 1348 | +#endif // WK_HAVE_C_SPI |
| 1349 | + |
1272 | 1350 | } // namespace TestWebKitAPI
|
1273 | 1351 |
|
1274 | 1352 | #endif // ENABLE(MEDIA_STREAM)
|
0 commit comments