tor-browser

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

test_input_search.html (2954B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test for &lt;input type='search'&gt; clear search button</title>
      6  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      7  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
      8  <link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
      9 </head>
     10 <body>
     11 <p id="display"></p>
     12 <div id="content">
     13  <form>
     14    <input type="search" name="search" id="searchInput">
     15  </form>
     16 </div>
     17 <pre id="test">
     18 <script class="testbody" type="application/javascript">
     19  const { BrowserTestUtils } = ChromeUtils.importESModule(
     20    "resource://testing-common/BrowserTestUtils.sys.mjs");
     21  
     22  add_task(async function testClearSearchButton() {
     23    let input = document.getElementById("searchInput");
     24    let children = SpecialPowers.InspectorUtils.getChildrenForNode(input, true, false);
     25    let clearButton = children.find(e => e.localName == "button");
     26    is(searchInput.value, "",
     27      "Search input should be blank at the start of test");
     28    ok(!BrowserTestUtils.isVisible(clearButton),
     29      "Clear button is hidden when there is no value in the input");
     30    is(clearButton.getAttribute("tabindex"), "-1", "Clear button should not be focusable");
     31    is(clearButton.getAttribute("aria-hidden"), "true", "Clear button should be hidden from the accessibility tree");
     32 
     33    searchInput.value = "abc";
     34 
     35    ok(
     36      BrowserTestUtils.isVisible(clearButton),
     37      "Clear button should be visible when text is present"
     38    );
     39    is(
     40      clearButton.getAttribute("tabindex"),
     41      "-1",
     42      "Clear button should not be focusable when visible"
     43    );
     44    is(
     45      clearButton.getAttribute("aria-hidden"),
     46      "true",
     47      "Clear button should be hidden from accessibilty tree when visible"
     48    );
     49 
     50    // Clear text input by clicking the clear button
     51    synthesizeMouseAtCenter(clearButton, {});
     52 
     53    ok(
     54      !BrowserTestUtils.isVisible(clearButton),
     55      "Clear button should be hidden after clicking the clear button"
     56      );
     57    is(
     58      searchInput.value,
     59      "",
     60      "Search input should be blank after using the clear button"
     61    );
     62    is(
     63      clearButton.getAttribute("tabindex"),
     64      "-1",
     65      "Clear button should not be focusable when hidden again"
     66    );
     67    is(
     68      clearButton.getAttribute("aria-hidden"),
     69      "true",
     70      "Clear button should be hidden from accessibilty tree when button is hidden again"
     71    );
     72 
     73    searchInput.value = "foo";
     74 
     75    ok(
     76      BrowserTestUtils.isVisible(clearButton),
     77      "Clear button should be visible when text is present"
     78    );
     79    is(
     80      clearButton.getAttribute("tabindex"),
     81      "-1",
     82      "Clear button should not be focusable when visible"
     83    );
     84    is(
     85      clearButton.getAttribute("aria-hidden"),
     86      "true",
     87      "Clear button should be hidden from accessibilty tree when visible"
     88    );
     89  });
     90 
     91 </script>  
     92 </pre>
     93 </body>
     94 </html>