browser/metro/base/tests/mochitest/browser_selection_frame_textarea.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

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* Any copyright is dedicated to the Public Domain.
michael@0 4 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 5
michael@0 6 "use strict";
michael@0 7
michael@0 8 let gWindow = null;
michael@0 9 var gFrame = null;
michael@0 10 var gTextArea = null;
michael@0 11
michael@0 12 const kCommonWaitMs = 5000;
michael@0 13 const kCommonPollMs = 100;
michael@0 14
michael@0 15 ///////////////////////////////////////////////////
michael@0 16 // form input tests
michael@0 17 ///////////////////////////////////////////////////
michael@0 18
michael@0 19 function setUpAndTearDown() {
michael@0 20 emptyClipboard();
michael@0 21 if (gWindow)
michael@0 22 clearSelection(gWindow);
michael@0 23 if (gFrame)
michael@0 24 clearSelection(gFrame);
michael@0 25 if (gTextArea)
michael@0 26 clearSelection(gTextArea);
michael@0 27 yield waitForCondition(function () {
michael@0 28 return !SelectionHelperUI.isSelectionUIVisible;
michael@0 29 }, kCommonWaitMs, kCommonPollMs);
michael@0 30 InputSourceHelper.isPrecise = false;
michael@0 31 InputSourceHelper.fireUpdate();
michael@0 32 }
michael@0 33
michael@0 34 gTests.push({
michael@0 35 desc: "normalize browser",
michael@0 36 setUp: setUpAndTearDown,
michael@0 37 tearDown: setUpAndTearDown,
michael@0 38 run: function test() {
michael@0 39 info(chromeRoot + "browser_selection_frame_textarea.html");
michael@0 40 yield addTab(chromeRoot + "browser_selection_frame_textarea.html");
michael@0 41
michael@0 42 yield waitForCondition(function () {
michael@0 43 return !BrowserUI.isStartTabVisible;
michael@0 44 }, 10000, 100);
michael@0 45
michael@0 46 yield hideContextUI();
michael@0 47
michael@0 48 gWindow = Browser.selectedTab.browser.contentWindow;
michael@0 49 gFrame = gWindow.document.getElementById("frame1");
michael@0 50 gTextArea = gFrame.contentDocument.getElementById("textarea");
michael@0 51 ok(gWindow != null, "gWindow");
michael@0 52 ok(gFrame != null, "gFrame");
michael@0 53 ok(gTextArea != null, "gTextArea");
michael@0 54 },
michael@0 55 });
michael@0 56
michael@0 57 gTests.push({
michael@0 58 desc: "basic selection",
michael@0 59 setUp: setUpAndTearDown,
michael@0 60 tearDown: setUpAndTearDown,
michael@0 61 run: function test() {
michael@0 62 gTextArea.focus();
michael@0 63 gTextArea.selectionStart = gTextArea.selectionEnd = 0;
michael@0 64
michael@0 65 let promise = waitForEvent(document, "popupshown");
michael@0 66 sendContextMenuClickToElement(gWindow, gFrame, 220, 80);
michael@0 67 yield promise;
michael@0 68
michael@0 69 checkContextUIMenuItemVisibility(["context-select",
michael@0 70 "context-select-all"]);
michael@0 71
michael@0 72 let menuItem = document.getElementById("context-select");
michael@0 73 ok(menuItem, "menu item exists");
michael@0 74 ok(!menuItem.hidden, "menu item visible");
michael@0 75 let popupPromise = waitForEvent(document, "popuphidden");
michael@0 76 sendElementTap(gWindow, menuItem);
michael@0 77 yield popupPromise;
michael@0 78
michael@0 79 yield waitForCondition(function () {
michael@0 80 return SelectionHelperUI.isSelectionUIVisible;
michael@0 81 }, kCommonWaitMs, kCommonPollMs);
michael@0 82
michael@0 83 is(getTrimmedSelection(gTextArea).toString(), "wondered", "selection test");
michael@0 84
michael@0 85 checkMonoclePositionRange("start", 260, 280, 675, 690);
michael@0 86 checkMonoclePositionRange("end", 320, 340, 675, 690);
michael@0 87 },
michael@0 88 });
michael@0 89
michael@0 90 gTests.push({
michael@0 91 desc: "drag selection 1",
michael@0 92 setUp: setUpAndTearDown,
michael@0 93 tearDown: setUpAndTearDown,
michael@0 94 run: function test() {
michael@0 95 gTextArea.focus();
michael@0 96 gTextArea.selectionStart = gTextArea.selectionEnd = 0;
michael@0 97
michael@0 98 let promise = waitForEvent(document, "popupshown");
michael@0 99 sendContextMenuClickToElement(gWindow, gFrame, 220, 80);
michael@0 100 yield promise;
michael@0 101
michael@0 102 checkContextUIMenuItemVisibility(["context-select",
michael@0 103 "context-select-all"]);
michael@0 104
michael@0 105 let menuItem = document.getElementById("context-select");
michael@0 106 ok(menuItem, "menu item exists");
michael@0 107 ok(!menuItem.hidden, "menu item visible");
michael@0 108 let popupPromise = waitForEvent(document, "popuphidden");
michael@0 109 sendElementTap(gWindow, menuItem);
michael@0 110 yield popupPromise;
michael@0 111
michael@0 112 yield waitForCondition(function () {
michael@0 113 return SelectionHelperUI.isSelectionUIVisible;
michael@0 114 }, kCommonWaitMs, kCommonPollMs);
michael@0 115
michael@0 116 is(getTrimmedSelection(gTextArea).toString(), "wondered", "selection test");
michael@0 117
michael@0 118 // end marker to the right
michael@0 119 let xpos = SelectionHelperUI.endMark.xPos;
michael@0 120 let ypos = SelectionHelperUI.endMark.yPos + 10;
michael@0 121 var touchdrag = new TouchDragAndHold();
michael@0 122 yield touchdrag.start(gWindow, xpos, ypos, xpos + 150, ypos);
michael@0 123 yield waitForCondition(function () {
michael@0 124 return getTrimmedSelection(gTextArea).toString() ==
michael@0 125 "wondered at this,";
michael@0 126 }, 6000, 2000);
michael@0 127 touchdrag.end();
michael@0 128
michael@0 129 yield waitForCondition(function () {
michael@0 130 return !SelectionHelperUI.hasActiveDrag;
michael@0 131 }, kCommonWaitMs, kCommonPollMs);
michael@0 132 yield SelectionHelperUI.pingSelectionHandler();
michael@0 133
michael@0 134 // start marker up and to the left
michael@0 135 let xpos = SelectionHelperUI.startMark.xPos;
michael@0 136 let ypos = SelectionHelperUI.startMark.yPos + 10;
michael@0 137 var touchdrag = new TouchDragAndHold();
michael@0 138 yield touchdrag.start(gWindow, xpos, ypos, 40, 500);
michael@0 139 yield waitForCondition(function () {
michael@0 140 return getTrimmedSelection(gTextArea).toString().substring(0, 17) ==
michael@0 141 "There was nothing";
michael@0 142 }, 6000, 2000);
michael@0 143 touchdrag.end();
michael@0 144
michael@0 145 let promise = waitForEvent(document, "popupshown");
michael@0 146 sendContextMenuClick(250, 640);
michael@0 147 yield promise;
michael@0 148
michael@0 149 checkContextUIMenuItemVisibility(["context-cut",
michael@0 150 "context-copy"]);
michael@0 151
michael@0 152 let menuItem = document.getElementById("context-copy");
michael@0 153 ok(menuItem, "menu item exists");
michael@0 154 ok(!menuItem.hidden, "menu item visible");
michael@0 155 let popupPromise = waitForEvent(document, "popuphidden");
michael@0 156 sendElementTap(gWindow, menuItem);
michael@0 157 yield popupPromise;
michael@0 158
michael@0 159 let string = "";
michael@0 160 yield waitForCondition(function () {
michael@0 161 string = SpecialPowers.getClipboardData("text/unicode");
michael@0 162 return string.substring(0, 17) === "There was nothing";
michael@0 163 });
michael@0 164 },
michael@0 165 });
michael@0 166
michael@0 167 gTests.push({
michael@0 168 desc: "drag selection 2",
michael@0 169 setUp: setUpAndTearDown,
michael@0 170 tearDown: setUpAndTearDown,
michael@0 171 run: function test() {
michael@0 172 gTextArea.focus();
michael@0 173 gTextArea.selectionStart = gTextArea.selectionEnd = 0;
michael@0 174
michael@0 175 let scrollPromise = waitForEvent(gWindow, "scroll");
michael@0 176 gWindow.scrollBy(0, 200);
michael@0 177 yield scrollPromise;
michael@0 178
michael@0 179 let promise = waitForEvent(document, "popupshown");
michael@0 180 sendContextMenuClickToElement(gWindow, gFrame, 220, 80);
michael@0 181 yield promise;
michael@0 182
michael@0 183 checkContextUIMenuItemVisibility(["context-select",
michael@0 184 "context-select-all"]);
michael@0 185
michael@0 186 let menuItem = document.getElementById("context-select");
michael@0 187 ok(menuItem, "menu item exists");
michael@0 188 ok(!menuItem.hidden, "menu item visible");
michael@0 189 let popupPromise = waitForEvent(document, "popuphidden");
michael@0 190 sendElementTap(gWindow, menuItem);
michael@0 191 yield popupPromise;
michael@0 192
michael@0 193 yield waitForCondition(function () {
michael@0 194 return SelectionHelperUI.isSelectionUIVisible;
michael@0 195 }, kCommonWaitMs, kCommonPollMs);
michael@0 196
michael@0 197 is(getTrimmedSelection(gTextArea).toString(), "wondered", "selection test");
michael@0 198
michael@0 199 // end marker to the right
michael@0 200 let xpos = SelectionHelperUI.endMark.xPos;
michael@0 201 let ypos = SelectionHelperUI.endMark.yPos + 10;
michael@0 202 var touchdrag = new TouchDragAndHold();
michael@0 203 yield touchdrag.start(gWindow, xpos, ypos, xpos + 150, ypos);
michael@0 204 yield waitForCondition(function () {
michael@0 205 return getTrimmedSelection(gTextArea).toString() ==
michael@0 206 "wondered at this,";
michael@0 207 }, 6000, 2000);
michael@0 208 touchdrag.end();
michael@0 209
michael@0 210 yield waitForCondition(function () {
michael@0 211 return !SelectionHelperUI.hasActiveDrag;
michael@0 212 }, kCommonWaitMs, kCommonPollMs);
michael@0 213 yield SelectionHelperUI.pingSelectionHandler();
michael@0 214
michael@0 215 // start marker up and to the left
michael@0 216 let xpos = SelectionHelperUI.startMark.xPos;
michael@0 217 let ypos = SelectionHelperUI.startMark.yPos + 10;
michael@0 218 var touchdrag = new TouchDragAndHold();
michael@0 219 yield touchdrag.start(gWindow, xpos, ypos, 40, 300);
michael@0 220 yield waitForCondition(function () {
michael@0 221 return getTrimmedSelection(gTextArea).toString().substring(0, 17) ==
michael@0 222 "There was nothing";
michael@0 223 }, 6000, 2000);
michael@0 224 touchdrag.end();
michael@0 225
michael@0 226 let promise = waitForEvent(document, "popupshown");
michael@0 227 sendContextMenuClick(250, 440);
michael@0 228 yield promise;
michael@0 229
michael@0 230 checkContextUIMenuItemVisibility(["context-cut",
michael@0 231 "context-copy"]);
michael@0 232
michael@0 233 let menuItem = document.getElementById("context-copy");
michael@0 234 ok(menuItem, "menu item exists");
michael@0 235 ok(!menuItem.hidden, "menu item visible");
michael@0 236 let popupPromise = waitForEvent(document, "popuphidden");
michael@0 237 sendElementTap(gWindow, menuItem);
michael@0 238 yield popupPromise;
michael@0 239
michael@0 240 let string = "";
michael@0 241 yield waitForCondition(function () {
michael@0 242 string = SpecialPowers.getClipboardData("text/unicode");
michael@0 243 return string.substring(0, 17) === "There was nothing";
michael@0 244 });
michael@0 245 },
michael@0 246 });
michael@0 247
michael@0 248 function test() {
michael@0 249 if (!isLandscapeMode()) {
michael@0 250 todo(false, "browser_selection_tests need landscape mode to run.");
michael@0 251 return;
michael@0 252 }
michael@0 253 // XXX need this until bugs 886624 and 859742 are fully resolved
michael@0 254 setDevPixelEqualToPx();
michael@0 255 runTests();
michael@0 256 }

mercurial