tor-browser

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

test_label.xhtml (5140B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
      4                 type="text/css"?>
      5 
      6 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      7        title="Tests: accessible XUL label/description events">
      8 
      9  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
     10 
     11  <script type="application/javascript"
     12          src="../common.js" />
     13  <script type="application/javascript"
     14          src="../role.js" />
     15  <script type="application/javascript"
     16          src="../events.js" />
     17 
     18  <script type="application/javascript">
     19  <![CDATA[
     20    ////////////////////////////////////////////////////////////////////////////
     21    // Invokers
     22 
     23    const kRecreated = 0;
     24    const kTextRemoved = 1;
     25    const kTextChanged = 2;
     26 
     27    const kNoValue = 0;
     28 
     29    /**
     30     * Set/remove @value attribute.
     31     */
     32    function setValue(aID, aValue, aResult, aOldValue)
     33    {
     34      this.labelNode = getNode(aID);
     35 
     36      this.eventSeq = [];
     37 
     38      switch (aResult) {
     39        case kRecreated:
     40          this.eventSeq.push(new invokerChecker(EVENT_HIDE, this.labelNode));
     41          this.eventSeq.push(new invokerChecker(EVENT_SHOW, this.labelNode));
     42          break;
     43        case kTextRemoved:
     44          this.eventSeq.push(
     45            new textChangeChecker(this.labelNode, 0, aOldValue.length,
     46                                  aOldValue, false));
     47          break;
     48        case kTextChanged:
     49          this.eventSeq.push(
     50            new textChangeChecker(this.labelNode, 0, aOldValue.length,
     51                                  aOldValue, false));
     52           this.eventSeq.push(
     53             new textChangeChecker(this.labelNode, 0, aValue.length,
     54                                   aValue, true));
     55          break;
     56      }
     57 
     58      this.invoke = function setValue_invoke()
     59      {
     60        if (aValue === kNoValue)
     61          this.labelNode.removeAttribute("value");
     62        else
     63          this.labelNode.setAttribute("value", aValue);
     64      }
     65 
     66      this.finalCheck = function setValue_finalCheck()
     67      {
     68        let tree =
     69          { LABEL: [] };
     70 
     71        const expectChild = (() => {
     72          if (aValue === kNoValue) {
     73            return false;
     74          }
     75          if (aValue === "") {
     76            return this.labelNode.nodeName == "label";
     77          }
     78          return true;
     79        })();
     80 
     81        if (expectChild) {
     82          tree.LABEL.push({ STATICTEXT: [ ] });
     83        }
     84        testAccessibleTree(aID, tree);
     85      }
     86 
     87      this.getID = function setValue_getID()
     88      {
     89        return "set @value='" + aValue + "' for label " + prettyName(aID);
     90      }
     91    }
     92 
     93    /**
     94     * Change @crop attribute.
     95     */
     96    function setCrop(aID, aCropValue)
     97    {
     98      this.labelNode = getNode(aID);
     99      this.width = this.labelNode.getBoundingClientRect().width;
    100      this.charWidth = this.width / this.labelNode.value.length;
    101 
    102      this.eventSeq = [
    103        new invokerChecker(EVENT_HIDE, this.labelNode),
    104        new invokerChecker(EVENT_SHOW, this.labelNode),
    105      ];
    106 
    107      this.invoke = function setCrop_invoke()
    108      {
    109        if (!this.labelNode.hasAttribute("crop"))
    110          this.labelNode.style.width = Math.floor(this.width - 2 * this.charWidth) + "px";
    111 
    112        this.labelNode.setAttribute("crop", aCropValue);
    113      }
    114 
    115      this.getID = function setCrop_finalCheck()
    116      {
    117        return "set crop " + aCropValue;
    118      }
    119    }
    120 
    121    ////////////////////////////////////////////////////////////////////////////
    122    // Test
    123 
    124    gA11yEventDumpToConsole = true;
    125 
    126    var gQueue = null;
    127    function doTest()
    128    {
    129      gQueue = new eventQueue();
    130 
    131      gQueue.push(new setValue("label", "shiroka strana", kRecreated));
    132      gQueue.push(new setValue("label", "?<>!+_", kTextChanged, "shiroka strana"));
    133      gQueue.push(new setValue("label", "", kRecreated));
    134      gQueue.push(new setValue("label", kNoValue, kRecreated));
    135 
    136      gQueue.push(new setValue("descr", "hello world", kRecreated));
    137      gQueue.push(new setValue("descr", "si_ya", kTextChanged, "hello world"));
    138      gQueue.push(new setValue("descr", "", kTextRemoved, "si_ya"));
    139      gQueue.push(new setValue("descr", kNoValue, kRecreated));
    140 
    141      gQueue.push(new setCrop("croplabel", "center"));
    142 
    143      gQueue.invoke(); // Will call SimpleTest.finish();
    144    }
    145 
    146    SimpleTest.waitForExplicitFinish();
    147    addA11yLoadEvent(doTest);
    148  ]]>
    149  </script>
    150 
    151  <hbox flex="1" style="overflow: auto;">
    152    <body xmlns="http://www.w3.org/1999/xhtml">
    153      <a target="_blank"
    154         href="https://bugzilla.mozilla.org/show_bug.cgi?id=396166"
    155         title="xul:label@value accessible should implement nsIAccessibleText">
    156        Bug 396166
    157      </a>
    158      <br/>
    159      <p id="display"></p>
    160      <div id="content" style="display: none">
    161      </div>
    162      <pre id="test">
    163      </pre>
    164    </body>
    165 
    166    <vbox flex="1">
    167      <label id="label"/>
    168      <description id="descr"/>
    169 
    170      <hbox>
    171      <label id="croplabel" value="valuetocro"
    172             style="font-family: monospace;"/>
    173      </hbox>
    174    </vbox>
    175  </hbox>
    176 
    177 </window>