diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/mozilla/tests/media | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
3 files changed, 125 insertions, 0 deletions
diff --git a/testing/web-platform/mozilla/tests/media/2x2-green.ogv b/testing/web-platform/mozilla/tests/media/2x2-green.ogv Binary files differnew file mode 100644 index 0000000000..29903c0a81 --- /dev/null +++ b/testing/web-platform/mozilla/tests/media/2x2-green.ogv diff --git a/testing/web-platform/mozilla/tests/mediacapture-streams/enumerateDevices-in-background.https.html b/testing/web-platform/mozilla/tests/mediacapture-streams/enumerateDevices-in-background.https.html new file mode 100644 index 0000000000..55d1d24dce --- /dev/null +++ b/testing/web-platform/mozilla/tests/mediacapture-streams/enumerateDevices-in-background.https.html @@ -0,0 +1,67 @@ +<!doctype html> +<title>enumerateDevices() in background tab with focus in chrome</title> +<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> +<body></body> +<script> +'use strict'; +// This test is not in cross-browser wpt because it uses Gecko-specific API +// for focusing browser chrome and it assumes a specific tab browser design. +// It assumes that +// * browser chrome widget focus is associated with a single current document +// presentation (tab), +// https://github.com/w3c/mediacapture-main/issues/752#issuecomment-742036800 +// * window.open() focuses the new tab and makes the current tab hidden, and +// * the opener tab becomes the current and visible tab again when the new tab +// is closed. +const blank_url = '/common/blank.html'; + +function promise_event(target, name) { + return new Promise(resolve => target[`on${name}`] = resolve); +} + +promise_test(async t => { + // Open a new tab, which is expected to receive focus and hide the first tab. + await test_driver.bless('window.open()'); + assert_true(document.hasFocus(), 'This test needs focus on the browser.'); + const promise_hidden = promise_event(document, 'visibilitychange'); + const proxy = window.open(blank_url); + t.add_cleanup(() => proxy.close()); + await Promise.all([ + promise_hidden, + promise_event(proxy, 'focus'), + promise_event(proxy, 'load'), + ]); + assert_true(proxy.document.hasFocus(), 'proxy.document.hasFocus()'); + + await Promise.all([ + promise_event(proxy, 'blur'), + SpecialPowers.spawnChrome([], function focus_url_bar() { + this.browsingContext.topChromeWindow.gURLBar.focus(); + }), + ]); + assert_false(proxy.document.hasFocus(), 'proxy.document.hasFocus()'); + assert_false(document.hasFocus(), 'document.hasFocus()'); + assert_equals(document.visibilityState, 'hidden', 'visibilityState'); + + // Enumeration should remain pending while the first tab is background. + const promise_enumerate = navigator.mediaDevices.enumerateDevices(); + // Enumerate in the foreground tab to confirm that URL bar focus is + // sufficient, and to provide enough time to check that the Promise from the + // background tab does not settle. + await proxy.navigator.mediaDevices.enumerateDevices(); + // Race a settled Promise to check that the enumeration in the background tab + // has not settled. + const result = await Promise.race([promise_enumerate, 'pending']); + assert_equals(result, 'pending', 'pending Promise while background.'); + + // The enumeration Promise should resolve after the first tab returns to the + // foreground. + proxy.close(); + await promise_event(document, 'visibilitychange'); + assert_equals(document.visibilityState, 'visible', 'visibilityState'); + await promise_enumerate; +}, 'enumerateDevices in background'); +</script> diff --git a/testing/web-platform/mozilla/tests/mediacapture-streams/enumerateDevices-without-focus.https.html b/testing/web-platform/mozilla/tests/mediacapture-streams/enumerateDevices-without-focus.https.html new file mode 100644 index 0000000000..6516a514c5 --- /dev/null +++ b/testing/web-platform/mozilla/tests/mediacapture-streams/enumerateDevices-without-focus.https.html @@ -0,0 +1,58 @@ +<!doctype html> +<title>enumerateDevices() without focus</title> +<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> +<body></body> +<script> +'use strict'; +const blank_url = '/common/blank.html'; + +function promise_event(target, name) { + return new Promise(resolve => target[`on${name}`] = resolve); +} +// When testdriver.js supports switch-to-window, it can replace this function +// and this test can be upstreamed. +// https://github.com/web-platform-tests/wpt/issues/10666 +function switch_toplevel_focus_for_window(win) { + return win.SpecialPowers.spawnChrome([], function activate_browser_window() { + this.browsingContext.topChromeWindow.focus(); + }); +} + +promise_test(async t => { + await test_driver.bless('window.open()'); + assert_true(document.hasFocus(), 'This test needs focus on the document.'); + const promise_blur = promise_event(window, 'blur'); + // 'resizable' is requested for a separate OS window on relevant platforms + // so that this test tests OS focus changes rather than document visibility. + const proxy = window.open(blank_url, '', 'resizable'); + t.add_cleanup(() => proxy.close()); + await Promise.all([ + promise_blur, + switch_toplevel_focus_for_window(proxy), + promise_event(proxy, 'load'), + ]); + assert_false(document.hasFocus(), 'document.hasFocus() after blur'); + + // Enumeration should remain pending without focus. + const promise_enumerate = navigator.mediaDevices.enumerateDevices(); + // Enumerate in the focused window to provide enough time to check that + // the Promise from the unfocused window does not settle. + await proxy.navigator.mediaDevices.enumerateDevices(); + // Race a settled Promise to check that the enumeration in the first window + // has not settled. + const result = await Promise.race([promise_enumerate, 'pending']); + assert_equals(result, 'pending', 'pending Promise without focus.'); + + // The enumeration Promise should resolve after focus returns to the window. + proxy.close(); + await Promise.all([ + promise_event(window, 'focus'), + switch_toplevel_focus_for_window(window), + ]); + assert_true(document.hasFocus(), 'document.hasFocus() after focus'); + await promise_enumerate; +}, 'enumerateDevices without focus'); +</script> |