From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../tests/window-placement/resources/helpers.js | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 testing/web-platform/tests/window-placement/resources/helpers.js (limited to 'testing/web-platform/tests/window-placement/resources/helpers.js') diff --git a/testing/web-platform/tests/window-placement/resources/helpers.js b/testing/web-platform/tests/window-placement/resources/helpers.js new file mode 100644 index 0000000000..92442f9133 --- /dev/null +++ b/testing/web-platform/tests/window-placement/resources/helpers.js @@ -0,0 +1,68 @@ + +// Logs (appends) an HTML string to a logger element in a list format. +// An element in the document with id "logger" will be used as the log +// container. +function log(str) { + const entry = document.createElement('li'); + entry.innerHTML = str; + const loggerElement = document.getElementById('logger'); + loggerElement.appendChild(entry); + return entry; +} + +// Common setup for window management tests. Performs some basic assertions, and +// then waits for a click on the `setUpButton` element (for manual tests). +// Example usage: +// promise_test(async setUpTest => { +// await setUpWindowManagement(setUpTest, setUpButton); +// ... +// }); +async function setUpWindowManagement(setUpTest, setUpButton) { + assert_true( + 'getScreenDetails' in self && 'isExtended' in screen, + `API not supported; use Chromium (not content_shell) and enable + chrome://flags/#enable-experimental-web-platform-features`); + if (!screen.isExtended) + log(`WARNING: Use multiple screens for full test coverage`); + if (window.location.href.startsWith('file')) + log(`WARNING: Run via 'wpt serve'; file URLs lack permission support`); + + try { // Support manual testing where test_driver is not running. + await test_driver.set_permission({ name: 'window-management' }, 'granted'); + } catch { + } + const setUpWatcher = new EventWatcher(setUpTest, setUpButton, ['click']); + const setUpClick = setUpWatcher.wait_for('click'); + try { // Support manual testing where test_driver is not running. + await test_driver.click(setUpButton); + } catch { + } + await setUpClick; + setUpButton.disabled = true; +} + + +// Adds a button to the given `buttonContainer` element with the contents of +// `name`. Attaches an event watcher to the given test and waits for a signal +// from the test driver to click the button. If no test driver is available +// (manual testing) then awaits an actual click from the user instead. If +// `disableOnClick` is true, the button will also be disabled after it is +// clicked. +async function addTestTriggerButtonAndAwaitClick(buttonContainer, name, test) { + const button = document.createElement('button'); + button.innerHTML = name; + const entry = document.createElement('li'); + entry.appendChild(button); + buttonContainer.appendChild(entry); + const testWatcher = new EventWatcher(test, button, ['click']); + const buttonClick = testWatcher.wait_for('click'); + // Disable the button when it is clicked. + button.onclick = function() { + button.disabled = true; + }; + try { // Support manual testing where test_driver is not running. + await test_driver.click(button); + } catch { + } + await buttonClick; +} -- cgit v1.2.3