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