tor-browser

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

browser_test_caret_move_granularity.js (3508B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const CLUSTER_AMOUNT = Ci.nsISelectionListener.CLUSTER_AMOUNT;
      8 const WORD_AMOUNT = Ci.nsISelectionListener.WORD_AMOUNT;
      9 const LINE_AMOUNT = Ci.nsISelectionListener.LINE_AMOUNT;
     10 const BEGINLINE_AMOUNT = Ci.nsISelectionListener.BEGINLINE_AMOUNT;
     11 const ENDLINE_AMOUNT = Ci.nsISelectionListener.ENDLINE_AMOUNT;
     12 
     13 const isMac = AppConstants.platform == "macosx";
     14 
     15 function matchCaretMoveEvent(id, caretOffset) {
     16  return evt => {
     17    evt.QueryInterface(nsIAccessibleCaretMoveEvent);
     18    return (
     19      getAccessibleDOMNodeID(evt.accessible) == id &&
     20      evt.caretOffset == caretOffset
     21    );
     22  };
     23 }
     24 
     25 addAccessibleTask(
     26  `<textarea id="textarea" style="scrollbar-width: none;" cols="15">` +
     27    `one two three four five six seven eight` +
     28    `</textarea>`,
     29  async function (browser, accDoc) {
     30    const textarea = findAccessibleChildByID(accDoc, "textarea");
     31    let caretMoved = waitForEvent(
     32      EVENT_TEXT_CARET_MOVED,
     33      matchCaretMoveEvent("textarea", 0)
     34    );
     35    textarea.takeFocus();
     36    let evt = await caretMoved;
     37    evt.QueryInterface(nsIAccessibleCaretMoveEvent);
     38    ok(!evt.isAtEndOfLine, "Caret is not at end of line");
     39 
     40    caretMoved = waitForEvent(
     41      EVENT_TEXT_CARET_MOVED,
     42      matchCaretMoveEvent("textarea", 1)
     43    );
     44    EventUtils.synthesizeKey("KEY_ArrowRight");
     45    evt = await caretMoved;
     46    evt.QueryInterface(nsIAccessibleCaretMoveEvent);
     47    ok(!evt.isAtEndOfLine, "Caret is not at end of line");
     48    is(evt.granularity, CLUSTER_AMOUNT, "Caret moved by cluster");
     49 
     50    caretMoved = waitForEvent(
     51      EVENT_TEXT_CARET_MOVED,
     52      matchCaretMoveEvent("textarea", 15)
     53    );
     54    EventUtils.synthesizeKey("KEY_ArrowDown");
     55    evt = await caretMoved;
     56    evt.QueryInterface(nsIAccessibleCaretMoveEvent);
     57    ok(!evt.isAtEndOfLine, "Caret is not at end of line");
     58    is(evt.granularity, LINE_AMOUNT, "Caret moved by line");
     59 
     60    caretMoved = waitForEvent(
     61      EVENT_TEXT_CARET_MOVED,
     62      matchCaretMoveEvent("textarea", 14)
     63    );
     64    if (isMac) {
     65      EventUtils.synthesizeKey("KEY_ArrowLeft", { metaKey: true });
     66    } else {
     67      EventUtils.synthesizeKey("KEY_Home");
     68    }
     69    evt = await caretMoved;
     70    evt.QueryInterface(nsIAccessibleCaretMoveEvent);
     71    ok(!evt.isAtEndOfLine, "Caret is not at end of line");
     72    is(evt.granularity, BEGINLINE_AMOUNT, "Caret moved to line start");
     73 
     74    caretMoved = waitForEvent(
     75      EVENT_TEXT_CARET_MOVED,
     76      matchCaretMoveEvent("textarea", 28)
     77    );
     78    if (isMac) {
     79      EventUtils.synthesizeKey("KEY_ArrowRight", { metaKey: true });
     80    } else {
     81      EventUtils.synthesizeKey("KEY_End");
     82    }
     83    evt = await caretMoved;
     84    evt.QueryInterface(nsIAccessibleCaretMoveEvent);
     85    ok(evt.isAtEndOfLine, "Caret is at end of line");
     86    is(evt.granularity, ENDLINE_AMOUNT, "Caret moved to line end");
     87 
     88    caretMoved = waitForEvent(
     89      EVENT_TEXT_CARET_MOVED,
     90      matchCaretMoveEvent("textarea", 24)
     91    );
     92    if (isMac) {
     93      EventUtils.synthesizeKey("KEY_ArrowLeft", { altKey: true });
     94    } else {
     95      EventUtils.synthesizeKey("KEY_ArrowLeft", { ctrlKey: true });
     96    }
     97    evt = await caretMoved;
     98    evt.QueryInterface(nsIAccessibleCaretMoveEvent);
     99    ok(!evt.isAtEndOfLine, "Caret is not at end of line");
    100    is(evt.granularity, WORD_AMOUNT, "Caret moved by word");
    101  }
    102 );