Skip to content

Commit

Permalink
[Conditional Focus] Add CaptureController to getDisplayMedia options
Browse files Browse the repository at this point in the history
This CL adds a new CaptureController object that can be passed to
navigator.mediaDevices.getDisplayMedia() so that web developers
can control whether the captured surface (tab or window only) will be
focused or not.

Spec: w3c/mediacapture-screen-share#230
Demo: https://capture-controller.glitch.me/
Bug: 1215480
Change-Id: Ib826b702fc853542a0c5bae5ddac3286216e2d63
  • Loading branch information
beaufortfrancois authored and chromium-wpt-export-bot committed Sep 29, 2022
1 parent 9320d46 commit c17b9d9
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions screen-capture/getdisplaymedia-capture-controller.https.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// META: script=/resources/testharness.js
// META: script=/resources/testharnessreport.js
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js

'use strict';

test(() => {
assert_own_property(window, 'CaptureController');
}, 'CaptureController in window');

const stopTracks = stream => stream.getTracks().forEach(track => track.stop());

promise_test(async t => {
const controller = new CaptureController();
await test_driver.bless('getDisplayMedia()');
const stream = await navigator.mediaDevices.getDisplayMedia({controller});
t.add_cleanup(() => stopTracks(stream));
assert_equals(stream.getTracks().length, 1);
assert_equals(stream.getVideoTracks().length, 1);
assert_equals(stream.getAudioTracks().length, 0);
}, 'getDisplayMedia(controller) must succeed');

promise_test(async t => {
const controller = new CaptureController();

await test_driver.bless('getDisplayMedia()');
const stream = await navigator.mediaDevices.getDisplayMedia({controller});
t.add_cleanup(() => stopTracks(stream));

await test_driver.bless('getDisplayMedia()');
const p = navigator.mediaDevices.getDisplayMedia({controller});
t.add_cleanup(async () => {
try {
stopTracks(await p)
} catch {
}
});
await promise_rejects_dom(
t, 'InvalidStateError', Promise.race([p, Promise.resolve()]),
'getDisplayMedia should have returned an already-rejected promise.');
}, 'getDisplayMedia(controller) must fail with InvalidStateError if controller is bound');

0 comments on commit c17b9d9

Please sign in to comment.