tor-browser

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

test_accesskey.html (5523B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <title>Test for Accesskey</title>
      6 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7 <script src="/tests/SimpleTest/EventUtils.js"></script>
      8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      9 </head>
     10 <body>
     11 <p id="display"></p>
     12 <button id="activation" accesskey="e">Should be activated</button>
     13 <!-- Tests for label -->
     14 <label id="label1" accesskey="a">Label 1</label><br>
     15 <label id="label2" accesskey="a" for="checkbox2">Label 2</label><input type="checkbox" id="checkbox2" disabled>Checkbox 2</input><br>
     16 <label id="label3" accesskey="a" for="checkbox3">Label 3</label><input type="checkbox" id="checkbox3">Checkbox 3</input><br>
     17 <!-- Tests for button -->
     18 <button id="button1" accesskey="b" style="display: none;">Button 1</button><br>
     19 <button id="button2" accesskey="b">Button 2</button><br>
     20 <button id="button3" accesskey="b" disabled>Button 3</button><br>
     21 <button id="button4" accesskey="b">Button 4</button><br>
     22 <!-- Tests for legend -->
     23 <fieldset>
     24 <legend accesskey="c">Legend 1</legend>
     25 <input type="radio" id="radio1" style="display: none;"><label for="radio1">Radio 1</label><br>
     26 <input type="radio" id="radio2" disabled><label for="radio2">Radio 2</label><br>
     27 <input type="radio" id="radio3"><label for="radio3">Radio 3</label><br>
     28 </fieldset>
     29 <!-- Tests for legend2 -->
     30 <fieldset>
     31 <legend accesskey="d">Legend 2</legend>
     32 <input type="radio" id="radio4" disabled><label for="radio4">Radio 4</label><br>
     33 </fieldset>
     34 <input type="text" id="text1" accesskey="d"><br>
     35 <!-- Tests for bug 1723010 -->
     36 <button id="button5" style="display:none" accesskey="1">Button 5</button>
     37 <button id="button6" style="display:none" accesskey="2">Button 6</button>
     38 <textarea id="textarea1" accesskey="2"></textarea>
     39 <!-- Test for file input -->
     40 <input type=file id="file" accesskey="f">
     41 <script>
     42 
     43 function performAccessKey(aKey) {
     44  synthesizeKey(aKey, (navigator.platform.includes("Mac")) ?
     45                        { altKey : true, ctrlKey : true } :
     46                     	  { altKey : true, shiftKey: true });
     47 }
     48 
     49 add_setup(async function() {
     50  // A workaround for bug 1726811.
     51  await SpecialPowers.pushPrefEnv({ set: [[ "accessibility.tabfocus", 7 ]] });
     52 });
     53 
     54 add_task(function activation() {
     55  ok(!SpecialPowers.wrap(document).hasValidTransientUserGestureActivation, "Shouldn't be activated yet");
     56  performAccessKey("e");
     57  is(document.activeElement, document.getElementById("activation"), "Focus moved");
     58  ok(SpecialPowers.wrap(document).hasValidTransientUserGestureActivation, "Accesskey triggers activation");
     59 });
     60 
     61 add_task(function label() {
     62  let checkbox3 = document.getElementById("checkbox3");
     63 
     64  performAccessKey("a");
     65  is(document.activeElement.id, checkbox3.id, `focus should move to ${checkbox3.id}`);
     66  ok(!checkbox3.checked, `${checkbox3.id} should be still unchecked`);
     67 });
     68 
     69 add_task(function button() {
     70  let button2 = document.getElementById("button2");
     71  let button4 = document.getElementById("button4");
     72 
     73  [button2, button4].forEach(function(element) {
     74    element.addEventListener("click", function() {
     75      ok(false, `${element.id} should not be clicked`);
     76    });
     77  });
     78 
     79  performAccessKey("b");
     80  is(document.activeElement.id, button2.id, `focus should move to ${button2.id}`);
     81 
     82  performAccessKey("b");
     83  is(document.activeElement.id, button4.id, `focus should move to ${button4.id}`);
     84 });
     85 
     86 add_task(function legend() {
     87  let radio3 = document.getElementById("radio3");
     88 
     89  performAccessKey("c");
     90  is(document.activeElement.id, radio3.id, `focus should move to ${radio3.id}`);
     91  ok(!radio3.checked, `${radio3.id} should be still unchecked`);
     92 });
     93 
     94 add_task(function legend2() {
     95  let text1 = document.getElementById("text1");
     96 
     97  performAccessKey("d");
     98  is(document.activeElement.id, text1.id, `focus should move to ${text1.id}`);
     99 });
    100 
    101 /** Test for Bug 1723010 */
    102 
    103 add_task(async function removeElement() {
    104  let button5 = document.getElementById("button5");
    105  let textarea1 = document.getElementById("textarea1");
    106  let promise = new Promise((resolve) => {
    107    button5.addEventListener("click", function() {
    108      textarea1.remove();
    109      SimpleTest.executeSoon(() => {
    110        ok(true, "should not crash");
    111        resolve();
    112      });
    113    }, { once: true });
    114  });
    115 
    116  performAccessKey("1");
    117  await promise;
    118 });
    119 
    120 add_task(async function modifyAccessKey() {
    121  let button5 = document.getElementById("button5");
    122  let button6 = document.getElementById("button6");
    123  let textarea1 = document.querySelector("textarea1");
    124  let promise = new Promise((resolve) => {
    125    button5.addEventListener("click", function() {
    126      button5.setAttribute("accesskey", "2");
    127      button6.setAttribute("accesskey", "1");
    128      SimpleTest.executeSoon(() => {
    129        ok(true, "Button 5 should be clicked");
    130        resolve();
    131      });
    132    }, { once: true });
    133 
    134    button6.addEventListener("click", function() {
    135      ok(false, "Button 6 should not be clicked");
    136    }, { once: true });
    137  });
    138 
    139  performAccessKey("1");
    140  await promise;
    141 });
    142 
    143 add_task(async function file_picker() {
    144  const file = document.getElementById("file");
    145  const MockFilePicker = SpecialPowers.MockFilePicker;
    146  MockFilePicker.init(SpecialPowers.wrap(window).browsingContext);
    147  MockFilePicker.returnValue = MockFilePicker.returnCancel;
    148 
    149  let clicked = false;
    150  file.addEventListener("click", function(e) { clicked = true; });
    151 
    152  performAccessKey("f");
    153  ok(clicked, "Should've activated the picker");
    154 
    155  MockFilePicker.reset();
    156 });
    157 
    158 </script>
    159 </body>
    160 </html>