browser/metro/base/tests/mochitest/browser_selection_inputs.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /* Any copyright is dedicated to the Public Domain.
     4    http://creativecommons.org/publicdomain/zero/1.0/ */
     6 "use strict";
     8 let gWindow = null;
     9 var gInput = null;
    11 const kCommonWaitMs = 7000;
    12 const kCommonPollMs = 200;
    14 ///////////////////////////////////////////////////
    15 // form input tests
    16 ///////////////////////////////////////////////////
    18 function setUpAndTearDown() {
    19   emptyClipboard();
    20   if (gWindow)
    21     clearSelection(gWindow);
    22   if (gInput)
    23     clearSelection(gInput);
    24   yield waitForCondition(function () {
    25       return !SelectionHelperUI.isSelectionUIVisible;
    26     }, kCommonWaitMs, kCommonPollMs);
    27   InputSourceHelper.isPrecise = false;
    28   InputSourceHelper.fireUpdate();
    29 }
    31 /*
    32   5px top margin
    33   25px tall text input
    34   300px wide
    35 */
    37 gTests.push({
    38   desc: "normalize browser",
    39   setUp: setUpAndTearDown,
    40   tearDown: setUpAndTearDown,
    41   run: function test() {
    42     info(chromeRoot + "browser_selection_inputs.html");
    43     yield addTab(chromeRoot + "browser_selection_inputs.html");
    45     yield waitForCondition(function () {
    46       return !BrowserUI.isStartTabVisible;
    47       });
    49     yield hideContextUI();
    51     gWindow = Browser.selectedTab.browser.contentWindow;
    52     gInput = gWindow.document.getElementById("a");
    53   },
    54 });
    56 gTests.push({
    57   desc: "basic text input selection",
    58   setUp: setUpAndTearDown,
    59   tearDown: setUpAndTearDown,
    60   run: function test() {
    61     gInput.blur();
    62     gInput.selectionStart = gInput.selectionEnd = 0;
    64     let promise = waitForEvent(document, "popupshown");
    65     sendContextMenuClick(200, 17);
    66     yield promise;
    68     checkContextUIMenuItemVisibility(["context-select",
    69                                       "context-select-all"]);
    71     let menuItem = document.getElementById("context-select");
    72     ok(menuItem, "menu item exists");
    73     ok(!menuItem.hidden, "menu item visible");
    74     let popupPromise = waitForEvent(document, "popuphidden");
    75     sendElementTap(gWindow, menuItem);
    76     yield popupPromise;
    78     yield waitForCondition(function () {
    79         return SelectionHelperUI.isSelectionUIVisible;
    80       }, kCommonWaitMs, kCommonPollMs);
    82     is(getTrimmedSelection(gInput).toString(), "went", "selection test");
    83     is(gWindow.document.activeElement, gInput, "input focused");
    84   },
    85 });
    87 gTests.push({
    88   desc: "drag left to scroll",
    89   setUp: setUpAndTearDown,
    90   tearDown: setUpAndTearDown,
    91   run: function test() {
    92     gInput.selectionStart = gInput.selectionEnd = gInput.value.length;
    93     yield waitForEvent(window, "scroll");
    95     let promise = waitForEvent(document, "popupshown");
    96     sendContextMenuClick(190, 17);
    97     yield promise;
    99     checkContextUIMenuItemVisibility(["context-select",
   100                                       "context-select-all"]);
   102     let menuItem = document.getElementById("context-select");
   103     ok(menuItem, "menu item exists");
   104     ok(!menuItem.hidden, "menu item visible");
   105     let popupPromise = waitForEvent(document, "popuphidden");
   106     sendElementTap(gWindow, menuItem);
   107     yield popupPromise;
   109     yield waitForCondition(function () {
   110         return SelectionHelperUI.isSelectionUIVisible;
   111       }, kCommonWaitMs, kCommonPollMs);
   113     // check text selection
   114     is(getTrimmedSelection(gInput).toString(), "way", "selection test");
   116     // to the left
   117     let xpos = SelectionHelperUI.startMark.xPos;
   118     let ypos = SelectionHelperUI.startMark.yPos + 10;
   119     var touchdrag = new TouchDragAndHold();
   120     yield touchdrag.start(gWindow, xpos, ypos, 10, ypos);
   121     yield waitForCondition(function () {
   122       return getTrimmedSelection(gInput).toString() == 
   123         "The rabbit-hole went straight on like a tunnel for some way";
   124     }, kCommonWaitMs, kCommonPollMs);
   125     touchdrag.end();
   127     yield waitForCondition(function () {
   128         return !SelectionHelperUI.hasActiveDrag;
   129       }, kCommonWaitMs, kCommonPollMs);
   130     yield SelectionHelperUI.pingSelectionHandler();
   131   },
   132 });
   134 gTests.push({
   135   desc: "drag right to scroll and bug 862025",
   136   setUp: setUpAndTearDown,
   137   tearDown: setUpAndTearDown,
   138   run: function test() {
   139     gInput.selectionStart = gInput.selectionEnd = 0;
   140     yield waitForEvent(window, "scroll");
   142     let promise = waitForEvent(document, "popupshown");
   143     sendContextMenuClick(230, 17);
   144     yield promise;
   146     checkContextUIMenuItemVisibility(["context-select",
   147                                       "context-select-all"]);
   149     let menuItem = document.getElementById("context-select");
   150     ok(menuItem, "menu item exists");
   151     ok(!menuItem.hidden, "menu item visible");
   152     let popupPromise = waitForEvent(document, "popuphidden");
   153     sendElementTap(gWindow, menuItem);
   154     yield popupPromise;
   156     yield waitForCondition(function () {
   157         return SelectionHelperUI.isSelectionUIVisible;
   158       }, kCommonWaitMs, kCommonPollMs);
   160     // check text selection
   161     is(getTrimmedSelection(gInput).toString(), "straight", "selection test");
   163     // to the right with scroll
   164     let xpos = SelectionHelperUI.endMark.xPos;
   165     let ystartpos = SelectionHelperUI.endMark.yPos + 10;
   166     var touchdrag = new TouchDragAndHold();
   167     yield touchdrag.start(gWindow, xpos, ystartpos, 510, ystartpos);
   168     // hold the monocle in position outside the edit to trigger drag
   169     yield waitForCondition(function () {
   170       return getTrimmedSelection(gInput).toString() == 
   171         "straight on like a tunnel for some way and then dipped suddenly down";
   172     }, kCommonWaitMs, kCommonPollMs);
   173     touchdrag.end();
   175     yield waitForCondition(function () {
   176         return !SelectionHelperUI.hasActiveDrag;
   177       }, kCommonWaitMs, kCommonPollMs);
   178     yield SelectionHelperUI.pingSelectionHandler();
   180     // straight down - selection shouldn't change
   181     let xpos = SelectionHelperUI.endMark.xPos;
   182     let ypos = SelectionHelperUI.endMark.yPos + 10;
   183     yield touchdrag.start(gWindow, xpos, ypos, xpos, ypos + 150);
   184     // no touchend here, we want to continue the drag below
   186     yield SelectionHelperUI.pingSelectionHandler();
   187     is(getTrimmedSelection(gInput).toString(), "straight on like a tunnel for some way and then dipped suddenly down", "selection test");
   189     // left and up with no scrolling - selection should shrink
   190     yield touchdrag.move(135, ystartpos);
   191     touchdrag.end();
   193     yield SelectionHelperUI.pingSelectionHandler();
   194     is(getTrimmedSelection(gInput).toString(), "straight on like a tunnel for", "selection test");
   195   },
   196 });
   198 gTests.push({
   199   desc: "Bug 858206 - Drag selection monocles should not push other monocles " +
   200         "out of the way.",
   201   setUp: setUpAndTearDown,
   202   tearDown: setUpAndTearDown,
   203   run: function test() {
   204     let inputOriginalValue = gInput.value;
   206     gInput.value = "The rabbit-hole went straight on";
   208     let promise = waitForEvent(document, "popupshown");
   209     sendContextMenuClickToElement(gWindow, gInput, 150);
   210     yield promise;
   212     // Make initial selection
   213     promise = waitForEvent(document, "popuphidden");
   214     sendElementTap(gWindow, document.getElementById("context-select"));
   215     yield promise;
   217     yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible,
   218         kCommonWaitMs, kCommonPollMs);
   219     is(getTrimmedSelection(gInput).toString(), "straight");
   221     // Swap monocles when dragging with end monocle
   222     let startXPos = SelectionHelperUI.endMark.xPos;
   223     let startYPos = SelectionHelperUI.endMark.yPos + 10;
   224     let touchDrag = new TouchDragAndHold();
   225     yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 300,
   226         startYPos);
   228     yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
   229         "The rabbit-hole went", kCommonWaitMs, kCommonPollMs);
   230     touchDrag.end();
   231     yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
   232         kCommonWaitMs, kCommonPollMs);
   233     yield SelectionHelperUI.pingSelectionHandler();
   235      // Swap monocles when dragging with start monocle
   236     startXPos = SelectionHelperUI.startMark.xPos;
   237     startYPos = SelectionHelperUI.startMark.yPos + 10;
   238     yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 300,
   239         startYPos);
   240     yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
   241         "straight on", kCommonWaitMs, kCommonPollMs);
   242     touchDrag.end();
   243     yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
   244         kCommonWaitMs, kCommonPollMs);
   245     yield SelectionHelperUI.pingSelectionHandler();
   247     // Swap monocles right after caret-to-selection mode switch from start
   248     gInput.selectionStart = gInput.selectionEnd = 0;
   249     sendElementTap(gWindow, gInput, 0, 0);
   251     yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
   252         SelectionHelperUI.isCaretUIVisible);
   254     startXPos = SelectionHelperUI.caretMark.xPos;
   255     startYPos = SelectionHelperUI.caretMark.yPos + 10;
   257     yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 300,
   258         startYPos);
   259     yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
   260         "The rabbit-hole went straight on", kCommonWaitMs, kCommonPollMs);
   261     touchDrag.end();
   263     sendTap(gWindow, 10, 10);
   264     yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible);
   266     // Swap monocles right after caret-to-selection mode switch from end
   267     gInput.selectionStart = gInput.selectionEnd = gInput.value.length;
   268     let inputSelectionRectangle = gInput.QueryInterface(Ci.nsIDOMNSEditableElement).
   269         editor.selection.getRangeAt(0).getClientRects()[0];
   270     sendTap(gWindow, inputSelectionRectangle.right,
   271         inputSelectionRectangle.top);
   273     yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible);
   275     startXPos = SelectionHelperUI.caretMark.xPos;
   276     startYPos = SelectionHelperUI.caretMark.yPos + 10;
   278     yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 300,
   279         startYPos);
   280     yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
   281         "The rabbit-hole went straight on", kCommonWaitMs, kCommonPollMs);
   282     touchDrag.end();
   284     gInput.value = inputOriginalValue;
   285   }
   286 });
   288 function test() {
   289   if (!isLandscapeMode()) {
   290     todo(false, "browser_selection_tests need landscape mode to run.");
   291     return;
   292   }
   293   // XXX need this until bugs 886624 and 859742 are fully resolved
   294   setDevPixelEqualToPx();
   295   runTests();
   296 }

mercurial