accessible/tests/mochitest/hypertext/test_update.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/tests/mochitest/hypertext/test_update.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,173 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>nsIHyper>TextAccessible in dynamic tests</title>
     1.8 +  <link rel="stylesheet" type="text/css"
     1.9 +        href="chrome://mochikit/content/tests/SimpleTest/test.css" />
    1.10 +
    1.11 +  <script type="application/javascript"
    1.12 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +
    1.14 +  <script type="application/javascript"
    1.15 +          src="../common.js"></script>
    1.16 +  <script type="application/javascript"
    1.17 +          src="../events.js"></script>
    1.18 +
    1.19 +  <script type="application/javascript">
    1.20 +    const kLinksCount = 128;
    1.21 +    function addLinks(aContainerID)
    1.22 +    {
    1.23 +      this.containerNode = getNode(aContainerID);
    1.24 +
    1.25 +      this.eventSeq = [
    1.26 +        new invokerChecker(EVENT_REORDER, this.containerNode)
    1.27 +      ];
    1.28 +
    1.29 +      this.invoke = function addLinks_invoke()
    1.30 +      {
    1.31 +        for (var jdx = 0; jdx < kLinksCount; jdx++) {
    1.32 +          var a = document.createElement("a");
    1.33 +          a.setAttribute("href", "mozilla.org");
    1.34 +          a.textContent = "mozilla";
    1.35 +          this.containerNode.appendChild(a);
    1.36 +
    1.37 +          var span = document.createElement("span");
    1.38 +          span.textContent = " text ";
    1.39 +          this.containerNode.appendChild(span);
    1.40 +        }
    1.41 +      }
    1.42 +
    1.43 +      this.finalCheck = function addLinks_finalCheck()
    1.44 +      {
    1.45 +        // getLinkAt and getLinkIndex.
    1.46 +        var htAcc = getAccessible(this.containerNode, [nsIAccessibleHyperText]);
    1.47 +        for (var jdx = 0; jdx < kLinksCount; jdx++) {
    1.48 +          var link = htAcc.getLinkAt(jdx);
    1.49 +          ok(link, "No link at index " + jdx + " for '" + aContainerID + "'");
    1.50 +
    1.51 +          var linkIdx = htAcc.getLinkIndex(link);
    1.52 +          is(linkIdx, jdx, "Wrong link index for '" + aContainerID + "'!");
    1.53 +        }
    1.54 +      }
    1.55 +
    1.56 +      this.getID = function addLinks_getID()
    1.57 +      {
    1.58 +        return "Add links for '" + aContainerID + "'";
    1.59 +      }
    1.60 +    }
    1.61 +
    1.62 +    function updateText(aContainerID)
    1.63 +    {
    1.64 +      this.containerNode = getNode(aContainerID);
    1.65 +      this.container = getAccessible(this.containerNode, nsIAccessibleHyperText);
    1.66 +      this.text = this.container.firstChild;
    1.67 +      this.textNode = this.text.DOMNode;
    1.68 +      this.textLen = this.textNode.data.length;
    1.69 +
    1.70 +      this.eventSeq = [
    1.71 +        new invokerChecker(EVENT_TEXT_INSERTED, this.containerNode)
    1.72 +      ];
    1.73 +
    1.74 +      this.invoke = function updateText_invoke()
    1.75 +      {
    1.76 +        is(this.container.getLinkIndexAtOffset(this.textLen), 0,
    1.77 +           "Wrong intial text offsets!");
    1.78 +
    1.79 +        this.text.DOMNode.appendData(" my");
    1.80 +      }
    1.81 +
    1.82 +      this.finalCheck = function updateText_finalCheck()
    1.83 +      {
    1.84 +        is(this.container.getLinkIndexAtOffset(this.textLen), -1,
    1.85 +           "Text offsets weren't updated!");
    1.86 +      }
    1.87 +
    1.88 +      this.getID = function updateText_getID()
    1.89 +      {
    1.90 +        return "update text for '" + aContainerID + "'";
    1.91 +      }
    1.92 +    }
    1.93 +
    1.94 +    /**
    1.95 +     * Text offsets must be updated when hypertext child is removed.
    1.96 +     */
    1.97 +    function removeChild(aContainerID, aChildID, aInitialText, aFinalText)
    1.98 +    {
    1.99 +      this.containerNode = getNode(aContainerID);
   1.100 +      this.container = getAccessible(this.containerNode, nsIAccessibleText);
   1.101 +      this.childNode = getNode(aChildID);
   1.102 +
   1.103 +      // Call first to getText so offsets are cached
   1.104 +      is(this.container.getText(0, -1), aInitialText,
   1.105 +         "Wrong text before child removal");
   1.106 +
   1.107 +      this.eventSeq = [
   1.108 +        new invokerChecker(EVENT_REORDER, this.containerNode)
   1.109 +      ];
   1.110 +
   1.111 +      this.invoke = function removeChild_invoke()
   1.112 +      {
   1.113 +        this.containerNode.removeChild(this.childNode);
   1.114 +      }
   1.115 +
   1.116 +      this.finalCheck = function removeChild_finalCheck()
   1.117 +      {
   1.118 +        is(this.container.getText(0, -1), aFinalText,
   1.119 +           "Wrong text after child removal");
   1.120 +        is(this.container.characterCount, aFinalText.length,
   1.121 +           "Wrong text after child removal");
   1.122 +      }
   1.123 +
   1.124 +      this.getID = function removeChild_getID()
   1.125 +      {
   1.126 +        return "check text after removing child from '" + aContainerID + "'";
   1.127 +      }
   1.128 +    }
   1.129 +
   1.130 +
   1.131 +
   1.132 +    //gA11yEventDumpToConsole = true; // debug stuff
   1.133 +
   1.134 +    var gQueue = null;
   1.135 +    function doTest()
   1.136 +    {
   1.137 +      gQueue = new eventQueue();
   1.138 +      gQueue.push(new addLinks("p1"));
   1.139 +      gQueue.push(new updateText("p2"));
   1.140 +      gQueue.push(new removeChild("div1","div2",
   1.141 +                                  "hello my good friend", "hello friend"));
   1.142 +
   1.143 +      gQueue.invoke(); // Will call SimpleTest.finish();
   1.144 +    }
   1.145 +
   1.146 +    SimpleTest.waitForExplicitFinish();
   1.147 +    addA11yLoadEvent(doTest);
   1.148 +  </script>
   1.149 +</head>
   1.150 +<body>
   1.151 +
   1.152 +  <a target="_blank"
   1.153 +     title="Cache links within hypertext accessible"
   1.154 +     href="https://bugzilla.mozilla.org/show_bug.cgi?id=572394">
   1.155 +    Mozilla Bug 572394
   1.156 +  </a>
   1.157 +  <a target="_blank"
   1.158 +     title="Text offsets don't get updated when text of first child text accessible is changed"
   1.159 +     href="https://bugzilla.mozilla.org/show_bug.cgi?id=625009">
   1.160 +    Mozilla Bug 625009
   1.161 +  </a>
   1.162 +  <a target="_blank"
   1.163 +     title="Crash in nsHyperTextAccessible::GetText()"
   1.164 +     href="https://bugzilla.mozilla.org/show_bug.cgi?id=630841">
   1.165 +    Mozilla Bug 630841
   1.166 +  </a><br>
   1.167 +  <p id="display"></p>
   1.168 +  <div id="content" style="display: none"></div>
   1.169 +  <pre id="test">
   1.170 +  </pre>
   1.171 +
   1.172 +  <p id="p1"></p>
   1.173 +  <p id="p2"><b>hello</b><a>friend</a></p>
   1.174 +  <div id="div1">hello<span id="div2"> my<span id="div3"> good</span></span> friend</span></div>
   1.175 +</body>
   1.176 +</html>

mercurial