summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/html/interaction/focus/document-level-focus-apis
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/interaction/focus/document-level-focus-apis')
-rw-r--r--testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/document-has-system-focus.html44
-rw-r--r--testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/document-level-apis.html34
-rw-r--r--testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/support/popup.html18
-rw-r--r--testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/support/test.html5
4 files changed, 101 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/document-has-system-focus.html b/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/document-has-system-focus.html
new file mode 100644
index 0000000000..26f0bbbd09
--- /dev/null
+++ b/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/document-has-system-focus.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>HTML Test: focus - document has system focus</title>
+<link rel="help" href="https://html.spec.whatwg.org/#has-focus-steps">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<input id="input">
+<script>
+
+promise_test(async t => {
+ await new Promise(r => window.onload = r);
+ // This test requires the document to have focus as a starting condition.
+ // Whether a newly loaded page receives focus or not, seems to be somewhat
+ // browser-dependent and situation-dependent. For instance, Firefox appears to
+ // focus the page immediately if the page was loaded with the refresh button,
+ // but not if it was loaded from pressing ENTER in the URL bar. To ensure a
+ // reliable starting condition for this test, we give an extra push for focus.
+ if (!document.hasFocus()) {
+ const input = document.getElementById("input");
+ input.focus();
+ await new Promise(r => input.onfocus = r);
+ }
+ assert_true(document.hasFocus(), "Document has focus as starting condition.");
+
+ let gotBlur = false;
+ window.onblur = () => gotBlur = true;
+ const popup = window.open("support/popup.html", "otherwindow", "resizable");
+ assert_not_equals(popup, null, "Test requires popup be opened");
+ t.add_cleanup(() => popup.close());
+ const msg = await new Promise(r => window.onmessage = ({data}) => r(data));
+ assert_equals(msg, "focus = true",
+ "Test requires popups be focused (may require harness flags)");
+ assert_true(gotBlur, "Document received blur event when popup opened");
+ assert_false(document.hasFocus(), "Document lost focus when popup opened");
+
+ const p = new Promise(r => window.onfocus = r);
+ popup.close();
+ await p;
+ assert_true(true, "Document received focus event when popup closed");
+ assert_true(document.hasFocus(), "Document regained focus when popup closed");
+}, "Top-level document receives blur/focus events and loses system focus " +
+ "during opening/closing of a popup");
+
+</script>
diff --git a/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/document-level-apis.html b/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/document-level-apis.html
new file mode 100644
index 0000000000..4a8a9a291a
--- /dev/null
+++ b/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/document-level-apis.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>HTML Test: focus - document-level APIs</title>
+<link rel="author" title="Intel" href="http://www.intel.com/">
+<link rel="help" href="https://html.spec.whatwg.org/multipage/#document-level-focus-apis">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<input id="test">
+<script>
+
+test(function () {
+ assert_equals(document.activeElement, document.body, "The active element should be the body element.");
+}, "The body element must be the active element if no element is focused");
+
+test(function () {
+ document.getElementById("test").focus();
+ assert_equals(document.activeElement, document.getElementById("test"), "The active element should be the input element.");
+}, "The element must be the active element if it is focused");
+
+function frame_load () {
+ test(function () {
+ document.getElementById("fr").contentDocument.getElementById("ipt").focus();
+ assert_equals(document.activeElement, document.getElementById("fr"), "The active element should be the iframe element.");
+ }, "When a child browsing context is focused, its browsing context container is also focused");
+}
+
+test(function () {
+ var doc = document.implementation.createHTMLDocument("test");
+ assert_false(doc.hasFocus(), "The hasFocus() method should return false.");
+}, "The hasFocus() method must return false if the Document has no browsing context");
+
+</script>
+<iframe id="fr" src="support/test.html" onload="frame_load()"></iframe>
diff --git a/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/support/popup.html b/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/support/popup.html
new file mode 100644
index 0000000000..3a4419105a
--- /dev/null
+++ b/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/support/popup.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+Popup <input id="input">
+<script>
+window.onload = async () => {
+ try {
+ if (!document.hasFocus()) {
+ const input = document.getElementById("input");
+ input.focus();
+ await new Promise(r => input.onfocus = r);
+ }
+ opener.postMessage(`focus = ${document.hasFocus()}`, "*");
+ } catch(e) {
+ opener.postMessage(`${e.name}: $(e.message)`, "*");
+ }
+};
+</script>
+</html>
diff --git a/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/support/test.html b/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/support/test.html
new file mode 100644
index 0000000000..90d63e51e9
--- /dev/null
+++ b/testing/web-platform/tests/html/interaction/focus/document-level-focus-apis/support/test.html
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>HTML Test: focus - document-level APIs</title>
+<link rel="author" title="Intel" href="http://www.intel.com/">
+<input id="ipt">