summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/chrome/window_focus_docnav.xhtml
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 /dom/tests/mochitest/chrome/window_focus_docnav.xhtml
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/tests/mochitest/chrome/window_focus_docnav.xhtml')
-rw-r--r--dom/tests/mochitest/chrome/window_focus_docnav.xhtml124
1 files changed, 124 insertions, 0 deletions
diff --git a/dom/tests/mochitest/chrome/window_focus_docnav.xhtml b/dom/tests/mochitest/chrome/window_focus_docnav.xhtml
new file mode 100644
index 0000000000..33bff7ec0a
--- /dev/null
+++ b/dom/tests/mochitest/chrome/window_focus_docnav.xhtml
@@ -0,0 +1,124 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+
+<window onload="start()"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+<input xmlns="http://www.w3.org/1999/xhtml" id="textbox1"/>
+<input xmlns="http://www.w3.org/1999/xhtml" id="textbox2"/>
+
+<panel id="panel" onpopupshown="runTests(this, 1);"
+ onpopuphidden="noChildrenTest()">
+ <input xmlns="http://www.w3.org/1999/xhtml" id="p1textbox" value="Popup1"/>
+</panel>
+<panel id="panel2" onpopupshown="runTests(this, 2);" onpopuphidden="document.getElementById('panel').hidePopup()">
+ <input xmlns="http://www.w3.org/1999/xhtml" id="p2textbox" value="Popup2"/>
+</panel>
+
+<browser id="browser" type="content" src="focus_frameset.html" style="width: 500px; height: 400px"/>
+
+<script type="application/javascript">
+<![CDATA[
+
+var fm = Cc["@mozilla.org/focus-manager;1"].
+ getService(Ci.nsIFocusManager);
+
+function is(l, r, n) { window.arguments[0].SimpleTest.is(l,r,n); }
+function ok(v, n) { window.arguments[0].SimpleTest.ok(v,n); }
+
+function noChildrenTest()
+{
+ // Remove the browser element and test navigation when there are no other documents.
+ // The focus should move or stay on the first focusable element.
+ let browser = document.getElementById("browser");
+ browser.remove();
+
+ let textbox1 = document.getElementById("textbox1");
+ let textbox2 = document.getElementById("textbox2");
+
+ textbox2.focus();
+ next(window, textbox1, "Focus forward when no child documents");
+ next(window, textbox1, "Focus forward again when no child documents");
+
+ textbox2.focus();
+ previous(window, textbox1, "Focus backward when no child documents");
+ previous(window, textbox1, "Focus backward again when no child documents");
+
+ done();
+}
+
+function done()
+{
+ window.close();
+ window.arguments[0].SimpleTest.finish();
+}
+
+function previous(expectedWindow, expectedElement, desc)
+{
+ synthesizeKey("KEY_F6", {shiftKey: true});
+ is(fm.focusedWindow, expectedWindow, desc);
+ is(fm.focusedElement, expectedElement, desc + " element");
+}
+
+function next(expectedWindow, expectedElement, desc)
+{
+ synthesizeKey("KEY_F6");
+ is(fm.focusedWindow, expectedWindow, desc);
+ is(fm.focusedElement, expectedElement, desc + " element" + "::" + (fm.focusedElement ? fm.focusedElement.parentNode.id : "<none>"));
+}
+
+// This test runs through three cases. Document navigation forward and
+// backward using the F6 key when no popups are open, with one popup open and
+// with two popups open.
+function runTests(panel, popupCount)
+{
+ if (!popupCount || popupCount > 2)
+ popupCount = 0;
+
+ fm.clearFocus(window);
+
+ var childwin = document.getElementById("browser").contentWindow;
+
+ if (popupCount) {
+ next(window, document.getElementById("p1textbox"), "First into popup 1 with " + popupCount);
+
+ if (popupCount == 2) {
+ next(window, document.getElementById("p2textbox"), "First into popup 2 with " + popupCount);
+ }
+ }
+
+ next(childwin.frames[0], childwin.frames[0].document.documentElement, "First with " + popupCount);
+ next(childwin.frames[1], childwin.frames[1].document.documentElement, "Second with " + popupCount);
+ previous(childwin.frames[0], childwin.frames[0].document.documentElement, "Second back with " + popupCount);
+
+ if (popupCount) {
+ if (popupCount == 2) {
+ previous(window, document.getElementById("p2textbox"), "First back from popup 2 with " + popupCount);
+ }
+
+ previous(window, document.getElementById("p1textbox"), "First back from popup 1 with " + popupCount);
+ }
+
+ previous(window, document.getElementById("textbox1"), "First back with " + popupCount);
+
+ if (panel == document.getElementById("panel"))
+ document.getElementById("panel2").openPopup(null, "after_start", 100, 20);
+ else if (panel == document.getElementById("panel2"))
+ panel.hidePopup();
+ else
+ document.getElementById("panel").openPopup(null, "after_start");
+}
+
+function start()
+{
+ window.arguments[0].SimpleTest.waitForExplicitFinish();
+ window.arguments[0].SimpleTest.waitForFocus(
+ function() { runTests(null, 0); },
+ document.getElementById("browser").contentWindow);
+}
+
+]]></script>
+
+</window>