accessible/tests/mochitest/textselection/test_general.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <html>
     3 <head>
     4   <title>Text selection 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>
    12   <script type="application/javascript"
    13           src="../common.js"></script>
    14   <script type="application/javascript"
    15           src="../events.js"></script>
    17   <script type="application/javascript">
    18     /**
    19      * Invokers
    20      */
    21     function addSelection(aID, aStartOffset, aEndOffset)
    22     {
    23       this.hyperTextNode = getNode(aID);
    24       this.hyperText = getAccessible(aID, [ nsIAccessibleText ]);
    26       this.eventSeq = [
    27         new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID)
    28       ];
    30       this.invoke = function addSelection_invoke()
    31       {
    32         this.hyperText.addSelection(aStartOffset, aEndOffset);
    33       }
    35       this.finalCheck = function addSelection_finalCheck()
    36       {
    37         is(this.hyperText.selectionCount, 1,
    38            "addSelection: Wrong selection count for " + aID);
    39         var startOffset = {}, endOffset = {};
    40         this.hyperText.getSelectionBounds(0, startOffset, endOffset);
    42         is(startOffset.value, aStartOffset,
    43            "addSelection: Wrong start offset for " + aID);
    44         is(endOffset.value, aEndOffset,
    45            "addSelection: Wrong end offset for " + aID);
    46       }
    48       this.getID = function addSelection_getID()
    49       {
    50         return "nsIAccessibleText::addSelection test for " + aID;
    51       }
    52     }
    54     function changeSelection(aID, aStartOffset, aEndOffset)
    55     {
    56       this.hyperTextNode = getNode(aID);
    57       this.hyperText = getAccessible(aID, [ nsIAccessibleText ]);
    59       this.eventSeq = [
    60         new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID)
    61       ];
    63       this.invoke = function changeSelection_invoke()
    64       {
    65         this.hyperText.setSelectionBounds(0, aStartOffset, aEndOffset);
    66       }
    68       this.finalCheck = function changeSelection_finalCheck()
    69       {
    70         is(this.hyperText.selectionCount, 1,
    71            "setSelectionBounds: Wrong selection count for " + aID);
    72         var startOffset = {}, endOffset = {};
    73         this.hyperText.getSelectionBounds(0, startOffset, endOffset);
    75         is(startOffset.value, aStartOffset,
    76            "setSelectionBounds: Wrong start offset for " + aID);
    77         is(endOffset.value, aEndOffset,
    78            "setSelectionBounds: Wrong end offset for " + aID);
    79       }
    81       this.getID = function changeSelection_getID()
    82       {
    83         return "nsIAccessibleText::setSelectionBounds test for " + aID;
    84       }
    85     }
    87     function removeSelection(aID)
    88     {
    89       this.hyperText = getAccessible(aID, [ nsIAccessibleText ]);
    91       this.eventSeq = [
    92         new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, document)
    93       ];
    95       this.invoke = function removeSelection_invoke()
    96       {
    97         this.hyperText.removeSelection(0);
    98       }
   100       this.finalCheck = function removeSelection_finalCheck()
   101       {
   102         is(this.hyperText.selectionCount, 0,
   103            "removeSelection: Wrong selection count for " + aID);
   104       }
   106       this.getID = function removeSelection_getID()
   107       {
   108         return "nsIAccessibleText::removeSelection test for " + aID;
   109       }
   110     }
   112     function changeDOMSelection(aID, aNodeID1, aNodeOffset1,
   113                                 aNodeID2, aNodeOffset2,
   114                                 aStartOffset, aEndOffset)
   115     {
   116       this.hyperText = getAccessible(aID, [ nsIAccessibleText ]);
   118       this.eventSeq = [
   119         new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID)
   120       ];
   122       this.invoke = function changeDOMSelection_invoke()
   123       {
   124         var sel = window.getSelection();
   125         var range = document.createRange();
   126         range.setStart(getNode(aNodeID1), aNodeOffset1);
   127         range.setEnd(getNode(aNodeID2), aNodeOffset2);
   128         sel.addRange(range);
   129       }
   131       this.finalCheck = function changeDOMSelection_finalCheck()
   132       {
   133         is(this.hyperText.selectionCount, 1,
   134            "setSelectionBounds: Wrong selection count for " + aID);
   135         var startOffset = {}, endOffset = {};
   136         this.hyperText.getSelectionBounds(0, startOffset, endOffset);
   138         is(startOffset.value, aStartOffset,
   139            "setSelectionBounds: Wrong start offset for " + aID);
   140         is(endOffset.value, aEndOffset,
   141            "setSelectionBounds: Wrong end offset for " + aID);
   142       }
   144       this.getID = function changeDOMSelection_getID()
   145       {
   146         return "DOM selection change for " + aID;
   147       }
   148     }
   150     function onfocusEventSeq(aID)
   151     {
   152       var caretMovedChecker =
   153         new invokerChecker(EVENT_TEXT_CARET_MOVED, aID);
   154       var selChangedChecker =
   155         new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID);
   156       selChangedChecker.unexpected = true;
   158       return [ caretMovedChecker, selChangedChecker ];
   159     }
   161     /**
   162      * Do tests
   163      */
   165     //gA11yEventDumpToConsole = true; // debug stuff
   167     var gQueue = null;
   168     function doTests()
   169     {
   170       gQueue = new eventQueue();
   172       gQueue.push(new addSelection("paragraph", 1, 3));
   173       gQueue.push(new changeSelection("paragraph", 2, 4));
   174       gQueue.push(new removeSelection("paragraph"));
   176       gQueue.push(new synthFocus("textbox", onfocusEventSeq("textbox")));
   177       gQueue.push(new changeSelection("textbox", 1, 3));
   179       gQueue.push(new synthFocus("textarea", onfocusEventSeq("textarea")));
   180       gQueue.push(new changeSelection("textarea", 1, 3));
   182       gQueue.push(new changeDOMSelection("c1", "c1_span1", 0, "c1_span2", 0, 2, 2));
   183       gQueue.invoke(); // Will call SimpleTest.finish();
   184     }
   186     SimpleTest.waitForExplicitFinish();
   187     addA11yLoadEvent(doTests);
   188   </script>
   189 </head>
   191 <body>
   193   <a target="_blank"
   194      href="https://bugzilla.mozilla.org/show_bug.cgi?id=688126"
   195      title="nsIAccessibleText::setSelectionBounds doesn't fire text selection changed events in some cases">
   196     Bug 688126
   197   </a>
   198   <a target="_blank"
   199      href="https://bugzilla.mozilla.org/show_bug.cgi?id=688124"
   200      title="no text selection changed event when selection is removed">
   201     Bug 688124
   202   </a>
   203   <p id="display"></p>
   204   <div id="content" style="display: none"></div>
   205   <pre id="test">
   206   </pre>
   208   <p id="paragraph">hello</p>
   209   <input id="textbox" value="hello"/>
   210   <textarea id="textarea">hello</textarea>
   211   <div id="c1">hi<span id="c1_span1"></span><span id="c1_span2"></span>hi</div>
   213 </body>
   214 </html>

mercurial