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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/tests/mochitest/browser_selection_inputs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,296 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* Any copyright is dedicated to the Public Domain.
     1.7 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.8 +
     1.9 +"use strict";
    1.10 +
    1.11 +let gWindow = null;
    1.12 +var gInput = null;
    1.13 +
    1.14 +const kCommonWaitMs = 7000;
    1.15 +const kCommonPollMs = 200;
    1.16 +
    1.17 +///////////////////////////////////////////////////
    1.18 +// form input tests
    1.19 +///////////////////////////////////////////////////
    1.20 +
    1.21 +function setUpAndTearDown() {
    1.22 +  emptyClipboard();
    1.23 +  if (gWindow)
    1.24 +    clearSelection(gWindow);
    1.25 +  if (gInput)
    1.26 +    clearSelection(gInput);
    1.27 +  yield waitForCondition(function () {
    1.28 +      return !SelectionHelperUI.isSelectionUIVisible;
    1.29 +    }, kCommonWaitMs, kCommonPollMs);
    1.30 +  InputSourceHelper.isPrecise = false;
    1.31 +  InputSourceHelper.fireUpdate();
    1.32 +}
    1.33 +
    1.34 +/*
    1.35 +  5px top margin
    1.36 +  25px tall text input
    1.37 +  300px wide
    1.38 +*/
    1.39 +
    1.40 +gTests.push({
    1.41 +  desc: "normalize browser",
    1.42 +  setUp: setUpAndTearDown,
    1.43 +  tearDown: setUpAndTearDown,
    1.44 +  run: function test() {
    1.45 +    info(chromeRoot + "browser_selection_inputs.html");
    1.46 +    yield addTab(chromeRoot + "browser_selection_inputs.html");
    1.47 +
    1.48 +    yield waitForCondition(function () {
    1.49 +      return !BrowserUI.isStartTabVisible;
    1.50 +      });
    1.51 +
    1.52 +    yield hideContextUI();
    1.53 +
    1.54 +    gWindow = Browser.selectedTab.browser.contentWindow;
    1.55 +    gInput = gWindow.document.getElementById("a");
    1.56 +  },
    1.57 +});
    1.58 +
    1.59 +gTests.push({
    1.60 +  desc: "basic text input selection",
    1.61 +  setUp: setUpAndTearDown,
    1.62 +  tearDown: setUpAndTearDown,
    1.63 +  run: function test() {
    1.64 +    gInput.blur();
    1.65 +    gInput.selectionStart = gInput.selectionEnd = 0;
    1.66 +
    1.67 +    let promise = waitForEvent(document, "popupshown");
    1.68 +    sendContextMenuClick(200, 17);
    1.69 +    yield promise;
    1.70 +
    1.71 +    checkContextUIMenuItemVisibility(["context-select",
    1.72 +                                      "context-select-all"]);
    1.73 +
    1.74 +    let menuItem = document.getElementById("context-select");
    1.75 +    ok(menuItem, "menu item exists");
    1.76 +    ok(!menuItem.hidden, "menu item visible");
    1.77 +    let popupPromise = waitForEvent(document, "popuphidden");
    1.78 +    sendElementTap(gWindow, menuItem);
    1.79 +    yield popupPromise;
    1.80 +
    1.81 +    yield waitForCondition(function () {
    1.82 +        return SelectionHelperUI.isSelectionUIVisible;
    1.83 +      }, kCommonWaitMs, kCommonPollMs);
    1.84 +
    1.85 +    is(getTrimmedSelection(gInput).toString(), "went", "selection test");
    1.86 +    is(gWindow.document.activeElement, gInput, "input focused");
    1.87 +  },
    1.88 +});
    1.89 +
    1.90 +gTests.push({
    1.91 +  desc: "drag left to scroll",
    1.92 +  setUp: setUpAndTearDown,
    1.93 +  tearDown: setUpAndTearDown,
    1.94 +  run: function test() {
    1.95 +    gInput.selectionStart = gInput.selectionEnd = gInput.value.length;
    1.96 +    yield waitForEvent(window, "scroll");
    1.97 +
    1.98 +    let promise = waitForEvent(document, "popupshown");
    1.99 +    sendContextMenuClick(190, 17);
   1.100 +    yield promise;
   1.101 +
   1.102 +    checkContextUIMenuItemVisibility(["context-select",
   1.103 +                                      "context-select-all"]);
   1.104 +
   1.105 +    let menuItem = document.getElementById("context-select");
   1.106 +    ok(menuItem, "menu item exists");
   1.107 +    ok(!menuItem.hidden, "menu item visible");
   1.108 +    let popupPromise = waitForEvent(document, "popuphidden");
   1.109 +    sendElementTap(gWindow, menuItem);
   1.110 +    yield popupPromise;
   1.111 +
   1.112 +    yield waitForCondition(function () {
   1.113 +        return SelectionHelperUI.isSelectionUIVisible;
   1.114 +      }, kCommonWaitMs, kCommonPollMs);
   1.115 +
   1.116 +    // check text selection
   1.117 +    is(getTrimmedSelection(gInput).toString(), "way", "selection test");
   1.118 +
   1.119 +    // to the left
   1.120 +    let xpos = SelectionHelperUI.startMark.xPos;
   1.121 +    let ypos = SelectionHelperUI.startMark.yPos + 10;
   1.122 +    var touchdrag = new TouchDragAndHold();
   1.123 +    yield touchdrag.start(gWindow, xpos, ypos, 10, ypos);
   1.124 +    yield waitForCondition(function () {
   1.125 +      return getTrimmedSelection(gInput).toString() == 
   1.126 +        "The rabbit-hole went straight on like a tunnel for some way";
   1.127 +    }, kCommonWaitMs, kCommonPollMs);
   1.128 +    touchdrag.end();
   1.129 +
   1.130 +    yield waitForCondition(function () {
   1.131 +        return !SelectionHelperUI.hasActiveDrag;
   1.132 +      }, kCommonWaitMs, kCommonPollMs);
   1.133 +    yield SelectionHelperUI.pingSelectionHandler();
   1.134 +  },
   1.135 +});
   1.136 +
   1.137 +gTests.push({
   1.138 +  desc: "drag right to scroll and bug 862025",
   1.139 +  setUp: setUpAndTearDown,
   1.140 +  tearDown: setUpAndTearDown,
   1.141 +  run: function test() {
   1.142 +    gInput.selectionStart = gInput.selectionEnd = 0;
   1.143 +    yield waitForEvent(window, "scroll");
   1.144 +
   1.145 +    let promise = waitForEvent(document, "popupshown");
   1.146 +    sendContextMenuClick(230, 17);
   1.147 +    yield promise;
   1.148 +
   1.149 +    checkContextUIMenuItemVisibility(["context-select",
   1.150 +                                      "context-select-all"]);
   1.151 +
   1.152 +    let menuItem = document.getElementById("context-select");
   1.153 +    ok(menuItem, "menu item exists");
   1.154 +    ok(!menuItem.hidden, "menu item visible");
   1.155 +    let popupPromise = waitForEvent(document, "popuphidden");
   1.156 +    sendElementTap(gWindow, menuItem);
   1.157 +    yield popupPromise;
   1.158 +
   1.159 +    yield waitForCondition(function () {
   1.160 +        return SelectionHelperUI.isSelectionUIVisible;
   1.161 +      }, kCommonWaitMs, kCommonPollMs);
   1.162 +
   1.163 +    // check text selection
   1.164 +    is(getTrimmedSelection(gInput).toString(), "straight", "selection test");
   1.165 +
   1.166 +    // to the right with scroll
   1.167 +    let xpos = SelectionHelperUI.endMark.xPos;
   1.168 +    let ystartpos = SelectionHelperUI.endMark.yPos + 10;
   1.169 +    var touchdrag = new TouchDragAndHold();
   1.170 +    yield touchdrag.start(gWindow, xpos, ystartpos, 510, ystartpos);
   1.171 +    // hold the monocle in position outside the edit to trigger drag
   1.172 +    yield waitForCondition(function () {
   1.173 +      return getTrimmedSelection(gInput).toString() == 
   1.174 +        "straight on like a tunnel for some way and then dipped suddenly down";
   1.175 +    }, kCommonWaitMs, kCommonPollMs);
   1.176 +    touchdrag.end();
   1.177 +
   1.178 +    yield waitForCondition(function () {
   1.179 +        return !SelectionHelperUI.hasActiveDrag;
   1.180 +      }, kCommonWaitMs, kCommonPollMs);
   1.181 +    yield SelectionHelperUI.pingSelectionHandler();
   1.182 +
   1.183 +    // straight down - selection shouldn't change
   1.184 +    let xpos = SelectionHelperUI.endMark.xPos;
   1.185 +    let ypos = SelectionHelperUI.endMark.yPos + 10;
   1.186 +    yield touchdrag.start(gWindow, xpos, ypos, xpos, ypos + 150);
   1.187 +    // no touchend here, we want to continue the drag below
   1.188 +
   1.189 +    yield SelectionHelperUI.pingSelectionHandler();
   1.190 +    is(getTrimmedSelection(gInput).toString(), "straight on like a tunnel for some way and then dipped suddenly down", "selection test");
   1.191 +
   1.192 +    // left and up with no scrolling - selection should shrink
   1.193 +    yield touchdrag.move(135, ystartpos);
   1.194 +    touchdrag.end();
   1.195 +
   1.196 +    yield SelectionHelperUI.pingSelectionHandler();
   1.197 +    is(getTrimmedSelection(gInput).toString(), "straight on like a tunnel for", "selection test");
   1.198 +  },
   1.199 +});
   1.200 +
   1.201 +gTests.push({
   1.202 +  desc: "Bug 858206 - Drag selection monocles should not push other monocles " +
   1.203 +        "out of the way.",
   1.204 +  setUp: setUpAndTearDown,
   1.205 +  tearDown: setUpAndTearDown,
   1.206 +  run: function test() {
   1.207 +    let inputOriginalValue = gInput.value;
   1.208 +
   1.209 +    gInput.value = "The rabbit-hole went straight on";
   1.210 +
   1.211 +    let promise = waitForEvent(document, "popupshown");
   1.212 +    sendContextMenuClickToElement(gWindow, gInput, 150);
   1.213 +    yield promise;
   1.214 +
   1.215 +    // Make initial selection
   1.216 +    promise = waitForEvent(document, "popuphidden");
   1.217 +    sendElementTap(gWindow, document.getElementById("context-select"));
   1.218 +    yield promise;
   1.219 +
   1.220 +    yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible,
   1.221 +        kCommonWaitMs, kCommonPollMs);
   1.222 +    is(getTrimmedSelection(gInput).toString(), "straight");
   1.223 +
   1.224 +    // Swap monocles when dragging with end monocle
   1.225 +    let startXPos = SelectionHelperUI.endMark.xPos;
   1.226 +    let startYPos = SelectionHelperUI.endMark.yPos + 10;
   1.227 +    let touchDrag = new TouchDragAndHold();
   1.228 +    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 300,
   1.229 +        startYPos);
   1.230 +
   1.231 +    yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
   1.232 +        "The rabbit-hole went", kCommonWaitMs, kCommonPollMs);
   1.233 +    touchDrag.end();
   1.234 +    yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
   1.235 +        kCommonWaitMs, kCommonPollMs);
   1.236 +    yield SelectionHelperUI.pingSelectionHandler();
   1.237 +
   1.238 +     // Swap monocles when dragging with start monocle
   1.239 +    startXPos = SelectionHelperUI.startMark.xPos;
   1.240 +    startYPos = SelectionHelperUI.startMark.yPos + 10;
   1.241 +    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 300,
   1.242 +        startYPos);
   1.243 +    yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
   1.244 +        "straight on", kCommonWaitMs, kCommonPollMs);
   1.245 +    touchDrag.end();
   1.246 +    yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
   1.247 +        kCommonWaitMs, kCommonPollMs);
   1.248 +    yield SelectionHelperUI.pingSelectionHandler();
   1.249 +
   1.250 +    // Swap monocles right after caret-to-selection mode switch from start
   1.251 +    gInput.selectionStart = gInput.selectionEnd = 0;
   1.252 +    sendElementTap(gWindow, gInput, 0, 0);
   1.253 +
   1.254 +    yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
   1.255 +        SelectionHelperUI.isCaretUIVisible);
   1.256 +
   1.257 +    startXPos = SelectionHelperUI.caretMark.xPos;
   1.258 +    startYPos = SelectionHelperUI.caretMark.yPos + 10;
   1.259 +
   1.260 +    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 300,
   1.261 +        startYPos);
   1.262 +    yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
   1.263 +        "The rabbit-hole went straight on", kCommonWaitMs, kCommonPollMs);
   1.264 +    touchDrag.end();
   1.265 +
   1.266 +    sendTap(gWindow, 10, 10);
   1.267 +    yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible);
   1.268 +
   1.269 +    // Swap monocles right after caret-to-selection mode switch from end
   1.270 +    gInput.selectionStart = gInput.selectionEnd = gInput.value.length;
   1.271 +    let inputSelectionRectangle = gInput.QueryInterface(Ci.nsIDOMNSEditableElement).
   1.272 +        editor.selection.getRangeAt(0).getClientRects()[0];
   1.273 +    sendTap(gWindow, inputSelectionRectangle.right,
   1.274 +        inputSelectionRectangle.top);
   1.275 +
   1.276 +    yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible);
   1.277 +
   1.278 +    startXPos = SelectionHelperUI.caretMark.xPos;
   1.279 +    startYPos = SelectionHelperUI.caretMark.yPos + 10;
   1.280 +
   1.281 +    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 300,
   1.282 +        startYPos);
   1.283 +    yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
   1.284 +        "The rabbit-hole went straight on", kCommonWaitMs, kCommonPollMs);
   1.285 +    touchDrag.end();
   1.286 +
   1.287 +    gInput.value = inputOriginalValue;
   1.288 +  }
   1.289 +});
   1.290 +
   1.291 +function test() {
   1.292 +  if (!isLandscapeMode()) {
   1.293 +    todo(false, "browser_selection_tests need landscape mode to run.");
   1.294 +    return;
   1.295 +  }
   1.296 +  // XXX need this until bugs 886624 and 859742 are fully resolved
   1.297 +  setDevPixelEqualToPx();
   1.298 +  runTests();
   1.299 +}

mercurial