tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit b5d1a06a6d144d0274b08fea918527668bbb46d7
parent ef2ef262e4ccc21be914a39da772e0e5faf6ee0c
Author: Andreas Pehrson <apehrson@mozilla.com>
Date:   Tue, 11 Nov 2025 08:20:23 +0000

Bug 1771789 - Break out some helpers from MST-resizeMode.https.html. r=jib

Differential Revision: https://phabricator.services.mozilla.com/D266397

Diffstat:
Mtesting/web-platform/mozilla/tests/mediacapture-streams/MediaStreamTrack-resizeMode.https.html | 70++--------------------------------------------------------------------
Atesting/web-platform/mozilla/tests/mediacapture-streams/settings-helper.js | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atesting/web-platform/mozilla/tests/mediacapture-streams/video-test-helper.js | 16++++++++++++++++
3 files changed, 72 insertions(+), 68 deletions(-)

diff --git a/testing/web-platform/mozilla/tests/mediacapture-streams/MediaStreamTrack-resizeMode.https.html b/testing/web-platform/mozilla/tests/mediacapture-streams/MediaStreamTrack-resizeMode.https.html @@ -6,77 +6,11 @@ <script src=/resources/testharnessreport.js></script> <script src=/resources/testdriver.js></script> <script src=/resources/testdriver-vendor.js></script> +<script src=settings-helper.js></script> +<script src=video-test-helper.js></script> <script> "use strict" - async function test_framerate_between_exclusive(t, track, lower, upper) { - const video = document.createElement("video"); - document.body.appendChild(video); - t.add_cleanup(async () => document.body.removeChild(video)); - - video.srcObject = new MediaStream([track]); - await video.play(); - - const numSeconds = 2; - await new Promise(r => setTimeout(r, numSeconds * 1000)); - const totalVideoFrames = video.mozPaintedFrames; - assert_between_exclusive(totalVideoFrames / numSeconds, lower, upper, "totalVideoFrames"); - } - - function createSettingsDicts(width, height, step = 1) { - const settingsDicts = [], aspect = width / height; - do { - settingsDicts.push({ width, height }); - if (width > height) { - height = Math.round((width - step) / aspect); - width -= step; - } else { - width = Math.round((height - step) * aspect); - height -= step; - } - } while (width > 2 && height > 2); - return settingsDicts; - } - - function integerFitness(actual, ideal) { - if (actual == ideal) { - return 0; - } - return Math.abs(actual - ideal) / Math.max(Math.abs(actual), Math.abs(ideal)); - } - - function findFittestResolutionSetting(width, height, constraints) { - const widthIsNumber = typeof constraints.width == "number"; - const heightIsNumber = typeof constraints.height == "number"; - const c = { - width: { - ideal: widthIsNumber ? constraints.width : constraints?.width?.ideal, - max: constraints?.width?.max ?? 1000000, - }, - height: { - ideal: heightIsNumber ? constraints.height : constraints?.height?.ideal, - max: constraints?.height?.max ?? 1000000, - }, - }; - const dicts = createSettingsDicts(width, height) - .filter(s => s.width <= c.width.max && s.height <= c.height.max); - for (const dict of dicts) { - dict.distance = - integerFitness(dict.width, c.width.ideal) + - integerFitness(dict.height, c.height.ideal); - } - - const filteredDicts = dicts.filter(s => { - return (!c.width.ideal || s.width <= c.width.ideal) && - (!c.height.ideal || s.height <= c.height.ideal); - }); - - return filteredDicts.reduce( - (a, b) => (a.distance < b.distance ? a : b), - filteredDicts[0], - ); - } - // Native capabilities supported by the fake camera. const nativeLow = {width: 640, height: 480, frameRate: 30, resizeMode: "none"}; const nativeHigh = {width: 1280, height: 720, frameRate: 10, resizeMode: "none"}; diff --git a/testing/web-platform/mozilla/tests/mediacapture-streams/settings-helper.js b/testing/web-platform/mozilla/tests/mediacapture-streams/settings-helper.js @@ -0,0 +1,54 @@ + +function createSettingsDicts(width, height, step = 1) { + const settingsDicts = [], aspect = width / height; + do { + settingsDicts.push({ width, height }); + if (width > height) { + height = Math.round((width - step) / aspect); + width -= step; + } else { + width = Math.round((height - step) * aspect); + height -= step; + } + } while (width > 2 && height > 2); + return settingsDicts; +} + +function integerFitness(actual, ideal) { + if (actual == ideal) { + return 0; + } + return Math.abs(actual - ideal) / Math.max(Math.abs(actual), Math.abs(ideal)); +} + +function findFittestResolutionSetting(width, height, constraints) { + const widthIsNumber = typeof constraints.width == "number"; + const heightIsNumber = typeof constraints.height == "number"; + const c = { + width: { + ideal: widthIsNumber ? constraints.width : constraints?.width?.ideal, + max: constraints?.width?.max ?? 1000000, + }, + height: { + ideal: heightIsNumber ? constraints.height : constraints?.height?.ideal, + max: constraints?.height?.max ?? 1000000, + }, + }; + const dicts = createSettingsDicts(width, height) + .filter(s => s.width <= c.width.max && s.height <= c.height.max); + for (const dict of dicts) { + dict.distance = + integerFitness(dict.width, c.width.ideal) + + integerFitness(dict.height, c.height.ideal); + } + + const filteredDicts = dicts.filter(s => { + return (!c.width.ideal || s.width <= c.width.ideal) && + (!c.height.ideal || s.height <= c.height.ideal); + }); + + return filteredDicts.reduce( + (a, b) => (a.distance < b.distance ? a : b), + filteredDicts[0], + ); +} diff --git a/testing/web-platform/mozilla/tests/mediacapture-streams/video-test-helper.js b/testing/web-platform/mozilla/tests/mediacapture-streams/video-test-helper.js @@ -0,0 +1,16 @@ +// Helper functions checking video flow using HTMLVideoElement. + +async function test_framerate_between_exclusive(t, track, lower, upper) { + const video = document.createElement("video"); + document.body.appendChild(video); + video.style = "width:320px;height:240px;" + t.add_cleanup(async () => document.body.removeChild(video)); + + video.srcObject = new MediaStream([track]); + await video.play(); + + const numSeconds = 2; + await new Promise(r => setTimeout(r, numSeconds * 1000)); + const totalVideoFrames = video.mozPaintedFrames; + assert_between_exclusive(totalVideoFrames / numSeconds, lower, upper, "totalVideoFrames"); +}