summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/close-watcher/resources
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/close-watcher/resources
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/close-watcher/resources')
-rw-r--r--testing/web-platform/tests/close-watcher/resources/helpers.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/testing/web-platform/tests/close-watcher/resources/helpers.js b/testing/web-platform/tests/close-watcher/resources/helpers.js
new file mode 100644
index 0000000000..97a62309cd
--- /dev/null
+++ b/testing/web-platform/tests/close-watcher/resources/helpers.js
@@ -0,0 +1,61 @@
+window.createRecordingCloseWatcher = (t, events, name, type, parentWatcher) => {
+ let watcher = null;
+ if (type === 'dialog') {
+ watcher = document.createElement('dialog');
+ watcher.textContent = 'hello world';
+ t.add_cleanup(() => watcher.remove());
+ if (parentWatcher?.appendChild) {
+ parentWatcher.appendChild(watcher);
+ } else {
+ document.body.appendChild(watcher);
+ }
+ watcher.showModal();
+ } else if (type === 'popover') {
+ watcher = document.createElement('div');
+ watcher.setAttribute('popover', 'auto');
+ watcher.textContent = 'hello world';
+ t.add_cleanup(() => watcher.remove());
+ if (parentWatcher?.appendChild) {
+ parentWatcher.appendChild(watcher);
+ } else {
+ document.body.appendChild(watcher);
+ }
+ watcher.showPopover();
+ } else {
+ watcher = new CloseWatcher();
+ t.add_cleanup(() => watcher.destroy());
+ }
+
+ const prefix = name === undefined ? "" : name + " ";
+ watcher.addEventListener('cancel', () => events.push(prefix + "cancel"));
+ watcher.addEventListener('close', () => events.push(prefix + "close"));
+
+ return watcher;
+};
+
+window.createBlessedRecordingCloseWatcher = async (t, events, name, type, parentWatcher) => {
+ await maybeTopLayerBless(parentWatcher);
+ return createRecordingCloseWatcher(t, events, name, type, parentWatcher);
+};
+
+window.sendEscKey = () => {
+ // Esc is \uE00C, *not* \uu001B; see https://w3c.github.io/webdriver/#keyboard-actions.
+ //
+ // It's important to target document.body, and not any element that might stop receiving events
+ // if a popover or dialog is making that element inert.
+ return test_driver.send_keys(document.body, '\uE00C');
+};
+
+// For now, we always use the Esc keypress as our close request. In
+// theory, in the future, we could add a WebDriver command or similar
+// for the close request, which would allow different tests on platforms
+// with different close requests. In that case, we'd update this
+// function, but not update the sendEscKey function above.
+window.sendCloseRequest = window.sendEscKey;
+
+window.maybeTopLayerBless = (watcher) => {
+ if (watcher instanceof HTMLElement) {
+ return blessTopLayer(watcher);
+ }
+ return test_driver.bless();
+};