accessible/tests/mochitest/events/test_label.xul

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial