tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

focus_dialog.xhtml (1940B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      3 
      4 <window id="other-document"
      5        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
      6 <dialog buttons="accept">
      7 
      8 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
      9 
     10 <button id="button-1" label="Something"/>
     11 <button id="button-2" label="Something else"/>
     12 
     13 <script>
     14 <![CDATA[
     15 
     16 window.is = window.arguments[0].is;
     17 window.isnot = window.arguments[0].isnot;
     18 window.ok = window.arguments[0].ok;
     19 window.SimpleTest = window.arguments[0].SimpleTest;
     20 
     21 (async function() {
     22  await new Promise(resolve => {
     23    window.onload = resolve;
     24  });
     25 
     26  await new Promise(resolve => SimpleTest.waitForFocus(resolve, window));
     27 
     28  let dialog = document.querySelector("dialog");
     29  let shadow = dialog.shadowRoot;
     30 
     31  let button = document.getElementById("button-1");
     32  let button2 = document.getElementById("button-2");
     33  let forwardSequence = [];
     34 
     35  button.focus();
     36 
     37  is(document.activeElement, button, "Should've focused the button");
     38  forwardSequence.push(button);
     39 
     40  synthesizeKey("KEY_Tab");
     41 
     42  is(document.activeElement, button2, "Should've moved to the second button");
     43  forwardSequence.push(button2);
     44 
     45  synthesizeKey("KEY_Tab");
     46 
     47  isnot(shadow.activeElement, null, "Should've focused the shadow root button");
     48  is(document.activeElement, dialog, "document.focusedElement should be the dialog because retargeting");
     49  forwardSequence.push(shadow.activeElement);
     50 
     51  synthesizeKey("KEY_Tab");
     52 
     53  is(document.activeElement, button, "Should properly wrap around going forward");
     54 
     55  while (forwardSequence.length) {
     56    synthesizeKey("KEY_Tab", { shiftKey: true });
     57    is(
     58      shadow.activeElement || document.activeElement,
     59      forwardSequence.pop(),
     60      "Should travel backwards correctly: " + forwardSequence.length
     61    );
     62  }
     63 
     64  window.close();
     65  SimpleTest.finish();
     66 }());
     67 
     68 ]]>
     69 </script>
     70 </dialog>
     71 </window>