accessible/tests/mochitest/events/test_text_alg.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <html>
     3 <head>
     4   <title>Accessible text update algorithm testing</title>
     6   <link rel="stylesheet" type="text/css"
     7         href="chrome://mochikit/content/tests/SimpleTest/test.css" />
     9   <script type="application/javascript"
    10           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    11   <script type="application/javascript"
    12           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    14   <script type="application/javascript"
    15           src="../common.js"></script>
    16   <script type="application/javascript"
    17           src="../events.js"></script>
    19   <script type="application/javascript">
    20     ////////////////////////////////////////////////////////////////////////////
    21     // Invokers
    23     const kRemoval = 0;
    24     const kInsertion = 1;
    25     const kUnexpected = true;
    27     function changeText(aContainerID, aValue, aEventList)
    28     {
    29       this.containerNode = getNode(aContainerID);
    30       this.textNode = this.containerNode.firstChild;
    31       this.textData = this.textNode.data;
    33       this.eventSeq = [ ];
    34       this.unexpectedEventSeq = [ ];
    36       for (var i = 0; i < aEventList.length; i++) {
    37         var event = aEventList[i];
    39         var isInserted = event[0];
    40         var str = event[1];
    41         var offset = event[2];
    42         var checker = new textChangeChecker(this.containerNode, offset,
    43                                             offset + str.length, str,
    44                                             isInserted);
    46         if (event[3] == kUnexpected)
    47           this.unexpectedEventSeq.push(checker);
    48         else
    49           this.eventSeq.push(checker);
    50       }
    52       this.invoke = function changeText_invoke()
    53       {
    54         this.textNode.data = aValue;
    55       }
    57       this.getID = function changeText_getID()
    58       {
    59         return "change text '" + shortenString(this.textData) + "' -> '" +
    60           shortenString(this.textNode.data) + "' for " +
    61           prettyName(this.containerNode);
    62       }
    63     }
    65     function expStr(x, doublings)
    66     {
    67       for (var i = 0; i < doublings; ++i)
    68         x = x + x;
    69       return x;
    70     }
    72     ////////////////////////////////////////////////////////////////////////////
    73     // Do tests
    75     //gA11yEventDumpID = "eventdump"; // debug stuff
    76     //gA11yEventDumpToConsole = true;
    78     var gQueue = null;
    79     function doTests()
    80     {
    81       gQueue = new eventQueue();
    83       //////////////////////////////////////////////////////////////////////////
    84       // wqrema -> tqb: substitution coalesced with removal
    86       var events = [
    87         [ kRemoval, "w", 0 ], // wqrema -> qrema
    88         [ kInsertion, "t", 0], // qrema -> tqrema
    89         [ kRemoval, "rema", 2 ], // tqrema -> tq
    90         [ kInsertion, "b", 2] // tq -> tqb
    91       ];
    92       gQueue.push(new changeText("p1", "tqb", events));
    94       //////////////////////////////////////////////////////////////////////////
    95       // b -> insa: substitution coalesced with insertion (complex substitution)
    97       events = [
    98         [ kRemoval, "b", 0 ], // b ->
    99         [ kInsertion, "insa", 0] //  -> insa
   100       ];
   101       gQueue.push(new changeText("p2", "insa", events));
   103       //////////////////////////////////////////////////////////////////////////
   104       // abc -> def: coalesced substitutions
   106       events = [
   107         [ kRemoval, "abc", 0 ], // abc ->
   108         [ kInsertion, "def", 0] //  -> def
   109       ];
   110       gQueue.push(new changeText("p3", "def", events));
   112       //////////////////////////////////////////////////////////////////////////
   113       // abcabc -> abcDEFabc: coalesced insertions
   115       events = [
   116         [ kInsertion, "DEF", 3] // abcabc -> abcDEFabc
   117       ];
   118       gQueue.push(new changeText("p4", "abcDEFabc", events));
   120       //////////////////////////////////////////////////////////////////////////
   121       // abc -> defabc: insertion into begin
   123       events = [
   124         [ kInsertion, "def", 0] // abc -> defabc
   125       ];
   126       gQueue.push(new changeText("p5", "defabc", events));
   128       //////////////////////////////////////////////////////////////////////////
   129       // abc -> abcdef: insertion into end
   131       events = [
   132         [ kInsertion, "def", 3] // abc -> abcdef
   133       ];
   134       gQueue.push(new changeText("p6", "abcdef", events));
   136       //////////////////////////////////////////////////////////////////////////
   137       // defabc -> abc: removal from begin
   139       events = [
   140         [ kRemoval, "def", 0] // defabc -> abc
   141       ];
   142       gQueue.push(new changeText("p7", "abc", events));
   144       //////////////////////////////////////////////////////////////////////////
   145       // abcdef -> abc: removal from the end
   147       events = [
   148         [ kRemoval, "def", 3] // abcdef -> abc
   149       ];
   150       gQueue.push(new changeText("p8", "abc", events));
   152       //////////////////////////////////////////////////////////////////////////
   153       // abcDEFabc -> abcabc: coalesced removals
   155       events = [
   156         [ kRemoval, "DEF", 3] // abcDEFabc -> abcabc
   157       ];
   158       gQueue.push(new changeText("p9", "abcabc", events));
   160       //////////////////////////////////////////////////////////////////////////
   161       // !abcdef@ -> @axbcef!: insertion, deletion and substitutions
   163       events = [
   164         [ kRemoval, "!", 0 ], // !abcdef@ -> abcdef@
   165         [ kInsertion, "@", 0], // abcdef@ -> @abcdef@
   166         [ kInsertion, "x", 2 ], // @abcdef@ -> @axbcdef@
   167         [ kRemoval, "d", 5], // @axbcdef@ -> @axbcef@
   168         [ kRemoval, "@", 7 ], // @axbcef@ -> @axbcef
   169         [ kInsertion, "!", 7 ], // @axbcef -> @axbcef!
   170       ];
   171       gQueue.push(new changeText("p10", "@axbcef!", events));
   173       //////////////////////////////////////////////////////////////////////////
   174       // meilenstein -> levenshtein: insertion, complex and simple substitutions
   176       events = [
   177         [ kRemoval, "m", 0 ], // meilenstein -> eilenstein
   178         [ kInsertion, "l", 0], // eilenstein -> leilenstein
   179         [ kRemoval, "il", 2 ], // leilenstein -> leenstein
   180         [ kInsertion, "v", 2], // leenstein -> levenstein
   181         [ kInsertion, "h", 6 ], // levenstein -> levenshtein
   182       ];
   183       gQueue.push(new changeText("p11", "levenshtein", events));
   185       //////////////////////////////////////////////////////////////////////////
   186       // long strings, remove/insert pair as the old string was replaced on
   187       // new one
   189       var longStr1 = expStr("x", 16);
   190       var longStr2 = expStr("X", 16);
   192       var newStr = "a" + longStr1 + "b", insStr = longStr1, rmStr = "";
   193       events = [
   194         [ kRemoval, rmStr, 1, kUnexpected ],
   195         [ kInsertion, insStr, 1 ]
   196       ];
   197       gQueue.push(new changeText("p12", newStr, events));
   199       newStr = "a" + longStr2 + "b", insStr = longStr2, rmStr = longStr1;
   200       events = [
   201         [ kRemoval, rmStr, 1 ],
   202         [ kInsertion, insStr, 1]
   203       ];
   204       gQueue.push(new changeText("p12", newStr, events));
   206       newStr = "ab", insStr = "", rmStr = longStr2;
   207       events = [
   208         [ kRemoval, rmStr, 1 ],
   209         [ kInsertion, insStr, 1, kUnexpected ]
   210       ];
   211       gQueue.push(new changeText("p12", newStr, events));
   213       gQueue.invoke(); // Will call SimpleTest.finish();
   214     }
   216     SimpleTest.waitForExplicitFinish();
   217     addA11yLoadEvent(doTests);
   218   </script>
   219 </head>
   221 <body>
   223   <a target="_blank"
   224      href="https://bugzilla.mozilla.org/show_bug.cgi?id=626660"
   225      title="Cache rendered text on a11y side">
   226     Mozilla Bug 626660
   227   </a>
   228   <br>
   230   <p id="display"></p>
   231   <div id="content" style="display: none"></div>
   232   <pre id="test">
   233   </pre>
   234   <div id="eventdump"></div>
   236   <p id="p1">wqrema</p>
   237   <p id="p2">b</p>
   238   <p id="p3">abc</p>
   239   <p id="p4">abcabc</p>
   240   <p id="p5">abc</p>
   241   <p id="p6">abc</p>
   242   <p id="p7">defabc</p>
   243   <p id="p8">abcdef</p>
   244   <p id="p9">abcDEFabc</p>
   245   <p id="p10">!abcdef@</p>
   246   <p id="p11">meilenstein</p>
   247   <p id="p12">ab</p>
   248 </body>
   249 </html>

mercurial