tor-browser

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

browser_treeupdate_optgroup.js (2844B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /* import-globals-from ../../mochitest/role.js */
      8 loadScripts({ name: "role.js", dir: MOCHITESTS_DIR });
      9 
     10 addAccessibleTask(
     11  '<select id="select"></select>',
     12  async function (browser, accDoc) {
     13    let select = findAccessibleChildByID(accDoc, "select");
     14 
     15    let onEvent = waitForEvent(EVENT_REORDER, "select");
     16    // Create a combobox with grouping and 2 standalone options
     17    await invokeContentTask(browser, [], () => {
     18      let doc = content.document;
     19      let contentSelect = doc.getElementById("select");
     20      let optGroup = doc.createElement("optgroup");
     21 
     22      for (let i = 0; i < 2; i++) {
     23        let opt = doc.createElement("option");
     24        opt.value = i;
     25        opt.text = "Option: Value " + i;
     26        optGroup.appendChild(opt);
     27      }
     28      contentSelect.add(optGroup, null);
     29 
     30      for (let i = 0; i < 2; i++) {
     31        let opt = doc.createElement("option");
     32        contentSelect.add(opt, null);
     33      }
     34      contentSelect.firstChild.firstChild.id = "option1Node";
     35    });
     36    let event = await onEvent;
     37    let option1Node = findAccessibleChildByID(event.accessible, "option1Node");
     38 
     39    let tree = {
     40      COMBOBOX: [
     41        {
     42          COMBOBOX_LIST: [
     43            {
     44              GROUPING: [{ COMBOBOX_OPTION: [] }, { COMBOBOX_OPTION: [] }],
     45            },
     46            {
     47              COMBOBOX_OPTION: [],
     48            },
     49            {
     50              COMBOBOX_OPTION: [],
     51            },
     52          ],
     53        },
     54      ],
     55    };
     56    testAccessibleTree(select, tree);
     57    ok(!isDefunct(option1Node), "option shouldn't be defunct");
     58 
     59    onEvent = waitForEvent(EVENT_REORDER, "select");
     60    // Remove grouping from combobox
     61    await invokeContentTask(browser, [], () => {
     62      let contentSelect = content.document.getElementById("select");
     63      contentSelect.firstChild.remove();
     64    });
     65    await onEvent;
     66 
     67    tree = {
     68      COMBOBOX: [
     69        {
     70          COMBOBOX_LIST: [{ COMBOBOX_OPTION: [] }, { COMBOBOX_OPTION: [] }],
     71        },
     72      ],
     73    };
     74    testAccessibleTree(select, tree);
     75    ok(
     76      isDefunct(option1Node),
     77      "removed option shouldn't be accessible anymore!"
     78    );
     79 
     80    onEvent = waitForEvent(EVENT_REORDER, "select");
     81    // Remove all options from combobox
     82    await invokeContentTask(browser, [], () => {
     83      let contentSelect = content.document.getElementById("select");
     84      while (contentSelect.length) {
     85        contentSelect.remove(0);
     86      }
     87    });
     88    await onEvent;
     89 
     90    tree = {
     91      COMBOBOX: [
     92        {
     93          COMBOBOX_LIST: [],
     94        },
     95      ],
     96    };
     97    testAccessibleTree(select, tree);
     98  },
     99  { iframe: true, remoteIframe: true }
    100 );