browser/metro/base/tests/mochitest/browser_selection_frame_textarea.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_frame_textarea.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,256 @@
     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 gFrame = null;
    1.13 +var gTextArea = null;
    1.14 +
    1.15 +const kCommonWaitMs = 5000;
    1.16 +const kCommonPollMs = 100;
    1.17 +
    1.18 +///////////////////////////////////////////////////
    1.19 +// form input tests
    1.20 +///////////////////////////////////////////////////
    1.21 +
    1.22 +function setUpAndTearDown() {
    1.23 +  emptyClipboard();
    1.24 +  if (gWindow)
    1.25 +    clearSelection(gWindow);
    1.26 +  if (gFrame)
    1.27 +    clearSelection(gFrame);
    1.28 +  if (gTextArea)
    1.29 +    clearSelection(gTextArea);
    1.30 +  yield waitForCondition(function () {
    1.31 +      return !SelectionHelperUI.isSelectionUIVisible;
    1.32 +    }, kCommonWaitMs, kCommonPollMs);
    1.33 +  InputSourceHelper.isPrecise = false;
    1.34 +  InputSourceHelper.fireUpdate();
    1.35 +}
    1.36 +
    1.37 +gTests.push({
    1.38 +  desc: "normalize browser",
    1.39 +  setUp: setUpAndTearDown,
    1.40 +  tearDown: setUpAndTearDown,
    1.41 +  run: function test() {
    1.42 +    info(chromeRoot + "browser_selection_frame_textarea.html");
    1.43 +    yield addTab(chromeRoot + "browser_selection_frame_textarea.html");
    1.44 +
    1.45 +    yield waitForCondition(function () {
    1.46 +      return !BrowserUI.isStartTabVisible;
    1.47 +      }, 10000, 100);
    1.48 +
    1.49 +    yield hideContextUI();
    1.50 +
    1.51 +    gWindow = Browser.selectedTab.browser.contentWindow;
    1.52 +    gFrame = gWindow.document.getElementById("frame1");
    1.53 +    gTextArea = gFrame.contentDocument.getElementById("textarea");
    1.54 +    ok(gWindow != null, "gWindow");
    1.55 +    ok(gFrame != null, "gFrame");
    1.56 +    ok(gTextArea != null, "gTextArea");
    1.57 +  },
    1.58 +});
    1.59 +
    1.60 +gTests.push({
    1.61 +  desc: "basic selection",
    1.62 +  setUp: setUpAndTearDown,
    1.63 +  tearDown: setUpAndTearDown,
    1.64 +  run: function test() {
    1.65 +    gTextArea.focus();
    1.66 +    gTextArea.selectionStart = gTextArea.selectionEnd = 0;
    1.67 +
    1.68 +    let promise = waitForEvent(document, "popupshown");
    1.69 +    sendContextMenuClickToElement(gWindow, gFrame, 220, 80);
    1.70 +    yield promise;
    1.71 +
    1.72 +    checkContextUIMenuItemVisibility(["context-select",
    1.73 +                                      "context-select-all"]);
    1.74 +
    1.75 +    let menuItem = document.getElementById("context-select");
    1.76 +    ok(menuItem, "menu item exists");
    1.77 +    ok(!menuItem.hidden, "menu item visible");
    1.78 +    let popupPromise = waitForEvent(document, "popuphidden");
    1.79 +    sendElementTap(gWindow, menuItem);
    1.80 +    yield popupPromise;
    1.81 +
    1.82 +    yield waitForCondition(function () {
    1.83 +        return SelectionHelperUI.isSelectionUIVisible;
    1.84 +      }, kCommonWaitMs, kCommonPollMs);
    1.85 +
    1.86 +    is(getTrimmedSelection(gTextArea).toString(), "wondered", "selection test");
    1.87 +
    1.88 +    checkMonoclePositionRange("start", 260, 280, 675, 690);
    1.89 +    checkMonoclePositionRange("end", 320, 340, 675, 690);
    1.90 +  },
    1.91 +});
    1.92 +
    1.93 +gTests.push({
    1.94 +  desc: "drag selection 1",
    1.95 +  setUp: setUpAndTearDown,
    1.96 +  tearDown: setUpAndTearDown,
    1.97 +  run: function test() {
    1.98 +    gTextArea.focus();
    1.99 +    gTextArea.selectionStart = gTextArea.selectionEnd = 0;
   1.100 +
   1.101 +    let promise = waitForEvent(document, "popupshown");
   1.102 +    sendContextMenuClickToElement(gWindow, gFrame, 220, 80);
   1.103 +    yield promise;
   1.104 +
   1.105 +    checkContextUIMenuItemVisibility(["context-select",
   1.106 +                                      "context-select-all"]);
   1.107 +
   1.108 +    let menuItem = document.getElementById("context-select");
   1.109 +    ok(menuItem, "menu item exists");
   1.110 +    ok(!menuItem.hidden, "menu item visible");
   1.111 +    let popupPromise = waitForEvent(document, "popuphidden");
   1.112 +    sendElementTap(gWindow, menuItem);
   1.113 +    yield popupPromise;
   1.114 +
   1.115 +    yield waitForCondition(function () {
   1.116 +        return SelectionHelperUI.isSelectionUIVisible;
   1.117 +      }, kCommonWaitMs, kCommonPollMs);
   1.118 +
   1.119 +    is(getTrimmedSelection(gTextArea).toString(), "wondered", "selection test");
   1.120 +
   1.121 +    // end marker to the right
   1.122 +    let xpos = SelectionHelperUI.endMark.xPos;
   1.123 +    let ypos = SelectionHelperUI.endMark.yPos + 10;
   1.124 +    var touchdrag = new TouchDragAndHold();
   1.125 +    yield touchdrag.start(gWindow, xpos, ypos, xpos + 150, ypos);
   1.126 +    yield waitForCondition(function () {
   1.127 +      return getTrimmedSelection(gTextArea).toString() == 
   1.128 +        "wondered at this,";
   1.129 +    }, 6000, 2000);
   1.130 +    touchdrag.end();
   1.131 +
   1.132 +    yield waitForCondition(function () {
   1.133 +        return !SelectionHelperUI.hasActiveDrag;
   1.134 +      }, kCommonWaitMs, kCommonPollMs);
   1.135 +    yield SelectionHelperUI.pingSelectionHandler();
   1.136 +
   1.137 +    // start marker up and to the left
   1.138 +    let xpos = SelectionHelperUI.startMark.xPos;
   1.139 +    let ypos = SelectionHelperUI.startMark.yPos + 10;
   1.140 +    var touchdrag = new TouchDragAndHold();
   1.141 +    yield touchdrag.start(gWindow, xpos, ypos, 40, 500);
   1.142 +    yield waitForCondition(function () {
   1.143 +      return getTrimmedSelection(gTextArea).toString().substring(0, 17) == 
   1.144 +        "There was nothing";
   1.145 +    }, 6000, 2000);
   1.146 +    touchdrag.end();
   1.147 +
   1.148 +    let promise = waitForEvent(document, "popupshown");
   1.149 +    sendContextMenuClick(250, 640);
   1.150 +    yield promise;
   1.151 +
   1.152 +    checkContextUIMenuItemVisibility(["context-cut",
   1.153 +                                      "context-copy"]);
   1.154 +
   1.155 +    let menuItem = document.getElementById("context-copy");
   1.156 +    ok(menuItem, "menu item exists");
   1.157 +    ok(!menuItem.hidden, "menu item visible");
   1.158 +    let popupPromise = waitForEvent(document, "popuphidden");
   1.159 +    sendElementTap(gWindow, menuItem);
   1.160 +    yield popupPromise;
   1.161 +
   1.162 +    let string = "";
   1.163 +    yield waitForCondition(function () {
   1.164 +      string = SpecialPowers.getClipboardData("text/unicode");
   1.165 +      return string.substring(0, 17) === "There was nothing";
   1.166 +    });
   1.167 +  },
   1.168 +});
   1.169 +
   1.170 +gTests.push({
   1.171 +  desc: "drag selection 2",
   1.172 +  setUp: setUpAndTearDown,
   1.173 +  tearDown: setUpAndTearDown,
   1.174 +  run: function test() {
   1.175 +    gTextArea.focus();
   1.176 +    gTextArea.selectionStart = gTextArea.selectionEnd = 0;
   1.177 +
   1.178 +    let scrollPromise = waitForEvent(gWindow, "scroll");
   1.179 +    gWindow.scrollBy(0, 200);
   1.180 +    yield scrollPromise;
   1.181 +
   1.182 +    let promise = waitForEvent(document, "popupshown");
   1.183 +    sendContextMenuClickToElement(gWindow, gFrame, 220, 80);
   1.184 +    yield promise;
   1.185 +
   1.186 +    checkContextUIMenuItemVisibility(["context-select",
   1.187 +                                      "context-select-all"]);
   1.188 +
   1.189 +    let menuItem = document.getElementById("context-select");
   1.190 +    ok(menuItem, "menu item exists");
   1.191 +    ok(!menuItem.hidden, "menu item visible");
   1.192 +    let popupPromise = waitForEvent(document, "popuphidden");
   1.193 +    sendElementTap(gWindow, menuItem);
   1.194 +    yield popupPromise;
   1.195 +
   1.196 +    yield waitForCondition(function () {
   1.197 +        return SelectionHelperUI.isSelectionUIVisible;
   1.198 +      }, kCommonWaitMs, kCommonPollMs);
   1.199 +
   1.200 +    is(getTrimmedSelection(gTextArea).toString(), "wondered", "selection test");
   1.201 +
   1.202 +    // end marker to the right
   1.203 +    let xpos = SelectionHelperUI.endMark.xPos;
   1.204 +    let ypos = SelectionHelperUI.endMark.yPos + 10;
   1.205 +    var touchdrag = new TouchDragAndHold();
   1.206 +    yield touchdrag.start(gWindow, xpos, ypos, xpos + 150, ypos);
   1.207 +    yield waitForCondition(function () {
   1.208 +      return getTrimmedSelection(gTextArea).toString() == 
   1.209 +        "wondered at this,";
   1.210 +    }, 6000, 2000);
   1.211 +    touchdrag.end();
   1.212 +
   1.213 +    yield waitForCondition(function () {
   1.214 +        return !SelectionHelperUI.hasActiveDrag;
   1.215 +      }, kCommonWaitMs, kCommonPollMs);
   1.216 +    yield SelectionHelperUI.pingSelectionHandler();
   1.217 +
   1.218 +    // start marker up and to the left
   1.219 +    let xpos = SelectionHelperUI.startMark.xPos;
   1.220 +    let ypos = SelectionHelperUI.startMark.yPos + 10;
   1.221 +    var touchdrag = new TouchDragAndHold();
   1.222 +    yield touchdrag.start(gWindow, xpos, ypos, 40, 300);
   1.223 +    yield waitForCondition(function () {
   1.224 +      return getTrimmedSelection(gTextArea).toString().substring(0, 17) == 
   1.225 +        "There was nothing";
   1.226 +    }, 6000, 2000);
   1.227 +    touchdrag.end();
   1.228 +
   1.229 +    let promise = waitForEvent(document, "popupshown");
   1.230 +    sendContextMenuClick(250, 440);
   1.231 +    yield promise;
   1.232 +
   1.233 +    checkContextUIMenuItemVisibility(["context-cut",
   1.234 +                                      "context-copy"]);
   1.235 +
   1.236 +    let menuItem = document.getElementById("context-copy");
   1.237 +    ok(menuItem, "menu item exists");
   1.238 +    ok(!menuItem.hidden, "menu item visible");
   1.239 +    let popupPromise = waitForEvent(document, "popuphidden");
   1.240 +    sendElementTap(gWindow, menuItem);
   1.241 +    yield popupPromise;
   1.242 +
   1.243 +    let string = "";
   1.244 +    yield waitForCondition(function () {
   1.245 +      string = SpecialPowers.getClipboardData("text/unicode");
   1.246 +      return string.substring(0, 17) === "There was nothing";
   1.247 +    });
   1.248 +  },
   1.249 +});
   1.250 +
   1.251 +function test() {
   1.252 +  if (!isLandscapeMode()) {
   1.253 +    todo(false, "browser_selection_tests need landscape mode to run.");
   1.254 +    return;
   1.255 +  }
   1.256 +  // XXX need this until bugs 886624 and 859742 are fully resolved
   1.257 +  setDevPixelEqualToPx();
   1.258 +  runTests();
   1.259 +}

mercurial