Skip to content

Commit

Permalink
[Region Capture] add cropTo WPT test
Browse files Browse the repository at this point in the history
This patch adds a web platform test for the
BrowserCaptureMediaStreamTrack cropTo function.

Change-Id: I719ca4eda9c635166ef9261a116a4644d66ea199
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5381258
Reviewed-by: Mark Foltz <mfoltz@chromium.org>
Commit-Queue: Jordan Bayles <jophba@chromium.org>
Reviewed-by: Elad Alon <eladalon@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1275764}
  • Loading branch information
baylesj authored and chromium-wpt-export-bot committed Mar 20, 2024
1 parent b8fda6f commit e690f9c
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!doctype html>
<html>

<head>
<title>BrowserCaptureMediaStreamTrack cropTo()</title>
<link rel="help" href="https://github.com/w3c/mediacapture-region/">
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>

<body>
<p class="instructions">
When prompted, accept to give permission to use your audio, video devices.
</p>
<h1 class="instructions">Description</h1>
<p class="instructions">
This test checks that BrowserCaptureMediaStreamTrack cropping works as
expected.
</p>

<button id="button">Start test</button>
<div id='test-div' width="500px" height="600px"></div>

<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
<script src=/resources/testdriver-vendor.js></script>
<script src=permission-helper.js></script>

<script>
"use strict";

async function getDisplayMedia() {
const p = new Promise(r => button.onclick = r);
await test_driver.click(button);
await p;
return navigator.mediaDevices.getDisplayMedia(
{video:{displaySurface:"browser"}, selfBrowserSurface:"include"});
}

promise_test(async t => {
const stream = await getDisplayMedia();
assert_true(stream.active, "stream should be active.");

assert_equals(stream.getVideoTracks().length, 1);
const [videoTrack] = stream.getVideoTracks();
assert_true(videoTrack instanceof MediaStreamTrack,
"track should be either MediaStreamTrack or a subclass thereof.");
assert_equals(videoTrack.readyState, "live");

const div = document.getElementById('test-div');
const cropTarget = await CropTarget.fromElement(div);
assert_true(!!videoTrack.cropTo, "cropTo exposed.");
assert_true(typeof videoTrack.cropTo === 'function',
"cropTo is a function.");
await videoTrack.cropTo(cropTarget);

assert_true(stream.active, "stream should be active.");
assert_false(videoTrack.muted, "track should not be muted.");
}, "Tests that cropping MediaStreamTrack objects works as expected");

</script>
</body>

</html>

0 comments on commit e690f9c

Please sign in to comment.