Wed, 31 Dec 2014 06:55:50 +0100
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 | |
michael@0 | 11 | const kMarkerOffsetY = 6; |
michael@0 | 12 | const kCommonWaitMs = 5000; |
michael@0 | 13 | const kCommonPollMs = 100; |
michael@0 | 14 | |
michael@0 | 15 | /////////////////////////////////////////////////// |
michael@0 | 16 | // content (non-editable) 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 | yield waitForCondition(function () { |
michael@0 | 26 | return !SelectionHelperUI.isSelectionUIVisible; |
michael@0 | 27 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 28 | InputSourceHelper.isPrecise = false; |
michael@0 | 29 | InputSourceHelper.fireUpdate(); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | gTests.push({ |
michael@0 | 33 | desc: "normalize browser", |
michael@0 | 34 | setUp: setUpAndTearDown, |
michael@0 | 35 | tearDown: setUpAndTearDown, |
michael@0 | 36 | run: function test() { |
michael@0 | 37 | info(chromeRoot + "browser_selection_basic.html"); |
michael@0 | 38 | yield addTab(chromeRoot + "browser_selection_basic.html"); |
michael@0 | 39 | |
michael@0 | 40 | yield waitForCondition(function () { |
michael@0 | 41 | return !BrowserUI.isStartTabVisible; |
michael@0 | 42 | }, 10000, 100); |
michael@0 | 43 | |
michael@0 | 44 | yield hideContextUI(); |
michael@0 | 45 | |
michael@0 | 46 | gWindow = Browser.selectedTab.browser.contentWindow; |
michael@0 | 47 | }, |
michael@0 | 48 | }); |
michael@0 | 49 | |
michael@0 | 50 | gTests.push({ |
michael@0 | 51 | desc: "tap-hold to select", |
michael@0 | 52 | setUp: setUpAndTearDown, |
michael@0 | 53 | tearDown: setUpAndTearDown, |
michael@0 | 54 | run: function test() { |
michael@0 | 55 | sendContextMenuClick(30, 20); |
michael@0 | 56 | |
michael@0 | 57 | yield waitForCondition(function () { |
michael@0 | 58 | return SelectionHelperUI.isSelectionUIVisible; |
michael@0 | 59 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 60 | |
michael@0 | 61 | is(getTrimmedSelection(gWindow).toString(), "There", "selection test"); |
michael@0 | 62 | }, |
michael@0 | 63 | }); |
michael@0 | 64 | |
michael@0 | 65 | gTests.push({ |
michael@0 | 66 | desc: "appbar interactions", |
michael@0 | 67 | setUp: setUpAndTearDown, |
michael@0 | 68 | tearDown: setUpAndTearDown, |
michael@0 | 69 | run: function test() { |
michael@0 | 70 | sendContextMenuClick(100, 20); |
michael@0 | 71 | |
michael@0 | 72 | yield waitForCondition(function () { |
michael@0 | 73 | return SelectionHelperUI.isSelectionUIVisible; |
michael@0 | 74 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 75 | |
michael@0 | 76 | is(SelectionHelperUI.isActive, true, "selection active"); |
michael@0 | 77 | is(getTrimmedSelection(gWindow).toString(), "nothing", "selection test"); |
michael@0 | 78 | |
michael@0 | 79 | yield fireAppBarDisplayEvent(); |
michael@0 | 80 | |
michael@0 | 81 | ok(ContextUI.isVisible, true, "appbar visible"); |
michael@0 | 82 | |
michael@0 | 83 | yield hideContextUI(); |
michael@0 | 84 | |
michael@0 | 85 | ok(!ContextUI.isVisible, true, "appbar hidden"); |
michael@0 | 86 | }, |
michael@0 | 87 | }); |
michael@0 | 88 | |
michael@0 | 89 | gTests.push({ |
michael@0 | 90 | desc: "simple drag selection", |
michael@0 | 91 | setUp: setUpAndTearDown, |
michael@0 | 92 | tearDown: setUpAndTearDown, |
michael@0 | 93 | run: function test() { |
michael@0 | 94 | yield waitForMs(100); |
michael@0 | 95 | sendContextMenuClick(100, 20); |
michael@0 | 96 | |
michael@0 | 97 | yield waitForCondition(function () { |
michael@0 | 98 | return SelectionHelperUI.isSelectionUIVisible; |
michael@0 | 99 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 100 | |
michael@0 | 101 | is(SelectionHelperUI.isActive, true, "selection active"); |
michael@0 | 102 | is(getTrimmedSelection(gWindow).toString(), "nothing", "selection test"); |
michael@0 | 103 | |
michael@0 | 104 | let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY; |
michael@0 | 105 | |
michael@0 | 106 | let touchdrag = new TouchDragAndHold(); |
michael@0 | 107 | yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 190, ypos); |
michael@0 | 108 | touchdrag.end(); |
michael@0 | 109 | |
michael@0 | 110 | yield waitForCondition(function () { |
michael@0 | 111 | return !SelectionHelperUI.hasActiveDrag; |
michael@0 | 112 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 113 | yield SelectionHelperUI.pingSelectionHandler(); |
michael@0 | 114 | |
michael@0 | 115 | is(SelectionHelperUI.isActive, true, "selection active"); |
michael@0 | 116 | is(getTrimmedSelection(gWindow).toString(), "nothing so VERY", "selection test"); |
michael@0 | 117 | }, |
michael@0 | 118 | }); |
michael@0 | 119 | |
michael@0 | 120 | gTests.push({ |
michael@0 | 121 | desc: "expand / collapse selection", |
michael@0 | 122 | setUp: setUpAndTearDown, |
michael@0 | 123 | tearDown: setUpAndTearDown, |
michael@0 | 124 | run: function test() { |
michael@0 | 125 | sendContextMenuClick(30, 20); |
michael@0 | 126 | |
michael@0 | 127 | yield waitForCondition(function () { |
michael@0 | 128 | return SelectionHelperUI.isSelectionUIVisible; |
michael@0 | 129 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 130 | |
michael@0 | 131 | is(SelectionHelperUI.isActive, true, "initial active"); |
michael@0 | 132 | is(getTrimmedSelection(gWindow).toString(), "There", "initial selection test"); |
michael@0 | 133 | |
michael@0 | 134 | for (let count = 0; count < 5; count++) { |
michael@0 | 135 | let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY; |
michael@0 | 136 | |
michael@0 | 137 | let touchdrag = new TouchDragAndHold(); |
michael@0 | 138 | yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos); |
michael@0 | 139 | touchdrag.end(); |
michael@0 | 140 | |
michael@0 | 141 | yield waitForCondition(function () { |
michael@0 | 142 | return !SelectionHelperUI.hasActiveDrag; |
michael@0 | 143 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 144 | yield SelectionHelperUI.pingSelectionHandler(); |
michael@0 | 145 | |
michael@0 | 146 | is(getTrimmedSelection(gWindow).toString(), |
michael@0 | 147 | "There was nothing so VERY remarkable in that; nor did Alice think it so", |
michael@0 | 148 | "long selection test"); |
michael@0 | 149 | |
michael@0 | 150 | is(SelectionHelperUI.isActive, true, "selection active"); |
michael@0 | 151 | |
michael@0 | 152 | touchdrag = new TouchDragAndHold(); |
michael@0 | 153 | yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 40, ypos); |
michael@0 | 154 | touchdrag.end(); |
michael@0 | 155 | |
michael@0 | 156 | yield waitForCondition(function () { |
michael@0 | 157 | return !SelectionHelperUI.hasActiveDrag; |
michael@0 | 158 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 159 | yield SelectionHelperUI.pingSelectionHandler(); |
michael@0 | 160 | |
michael@0 | 161 | is(SelectionHelperUI.isActive, true, "selection active"); |
michael@0 | 162 | is(getTrimmedSelection(gWindow).toString(), "There was", "short selection test"); |
michael@0 | 163 | } |
michael@0 | 164 | }, |
michael@0 | 165 | }); |
michael@0 | 166 | |
michael@0 | 167 | gTests.push({ |
michael@0 | 168 | desc: "expand / collapse selection scolled content", |
michael@0 | 169 | setUp: setUpAndTearDown, |
michael@0 | 170 | run: function test() { |
michael@0 | 171 | let scrollPromise = waitForEvent(gWindow, "scroll"); |
michael@0 | 172 | gWindow.scrollBy(0, 200); |
michael@0 | 173 | yield scrollPromise; |
michael@0 | 174 | ok(scrollPromise && !(scrollPromise instanceof Error), "scrollPromise error"); |
michael@0 | 175 | |
michael@0 | 176 | sendContextMenuClick(106, 20); |
michael@0 | 177 | |
michael@0 | 178 | yield waitForCondition(function () { |
michael@0 | 179 | return SelectionHelperUI.isSelectionUIVisible; |
michael@0 | 180 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 181 | |
michael@0 | 182 | is(SelectionHelperUI.isActive, true, "selection active"); |
michael@0 | 183 | is(getTrimmedSelection(gWindow).toString(), "moment", "selection test"); |
michael@0 | 184 | |
michael@0 | 185 | let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY; |
michael@0 | 186 | |
michael@0 | 187 | let touchdrag = new TouchDragAndHold(); |
michael@0 | 188 | yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos); |
michael@0 | 189 | touchdrag.end(); |
michael@0 | 190 | |
michael@0 | 191 | yield waitForCondition(function () { |
michael@0 | 192 | return !SelectionHelperUI.hasActiveDrag; |
michael@0 | 193 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 194 | yield SelectionHelperUI.pingSelectionHandler(); |
michael@0 | 195 | |
michael@0 | 196 | is(getTrimmedSelection(gWindow).toString(), |
michael@0 | 197 | "moment down went Alice after it, never once considering how in", |
michael@0 | 198 | "selection test"); |
michael@0 | 199 | |
michael@0 | 200 | is(SelectionHelperUI.isActive, true, "selection active"); |
michael@0 | 201 | |
michael@0 | 202 | touchdrag = new TouchDragAndHold(); |
michael@0 | 203 | yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 150, ypos); |
michael@0 | 204 | touchdrag.end(); |
michael@0 | 205 | |
michael@0 | 206 | yield waitForCondition(function () { |
michael@0 | 207 | return !SelectionHelperUI.hasActiveDrag; |
michael@0 | 208 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 209 | yield SelectionHelperUI.pingSelectionHandler(); |
michael@0 | 210 | |
michael@0 | 211 | is(getTrimmedSelection(gWindow).toString(), "moment down went", "selection test"); |
michael@0 | 212 | |
michael@0 | 213 | touchdrag = new TouchDragAndHold(); |
michael@0 | 214 | yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos); |
michael@0 | 215 | touchdrag.end(); |
michael@0 | 216 | |
michael@0 | 217 | yield waitForCondition(function () { |
michael@0 | 218 | return !SelectionHelperUI.hasActiveDrag; |
michael@0 | 219 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 220 | yield SelectionHelperUI.pingSelectionHandler(); |
michael@0 | 221 | |
michael@0 | 222 | is(getTrimmedSelection(gWindow).toString(), |
michael@0 | 223 | "moment down went Alice after it, never once considering how in", |
michael@0 | 224 | "selection test"); |
michael@0 | 225 | |
michael@0 | 226 | touchdrag = new TouchDragAndHold(); |
michael@0 | 227 | yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 160, ypos); |
michael@0 | 228 | touchdrag.end(); |
michael@0 | 229 | |
michael@0 | 230 | yield waitForCondition(function () { |
michael@0 | 231 | return !SelectionHelperUI.hasActiveDrag; |
michael@0 | 232 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 233 | yield SelectionHelperUI.pingSelectionHandler(); |
michael@0 | 234 | |
michael@0 | 235 | is(getTrimmedSelection(gWindow).toString(), |
michael@0 | 236 | "moment down went", |
michael@0 | 237 | "selection test"); |
michael@0 | 238 | }, |
michael@0 | 239 | tearDown: function tearDown() { |
michael@0 | 240 | let scrollPromise = waitForEvent(gWindow, "scroll"); |
michael@0 | 241 | gWindow.scrollBy(0, -200); |
michael@0 | 242 | yield scrollPromise; |
michael@0 | 243 | emptyClipboard(); |
michael@0 | 244 | if (gWindow) |
michael@0 | 245 | clearSelection(gWindow); |
michael@0 | 246 | if (gFrame) |
michael@0 | 247 | clearSelection(gFrame); |
michael@0 | 248 | yield waitForCondition(function () { |
michael@0 | 249 | return !SelectionHelperUI.isSelectionUIVisible; |
michael@0 | 250 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 251 | yield hideContextUI(); |
michael@0 | 252 | }, |
michael@0 | 253 | }); |
michael@0 | 254 | |
michael@0 | 255 | gTests.push({ |
michael@0 | 256 | desc: "tap on selection clears selection in content", |
michael@0 | 257 | setUp: setUpAndTearDown, |
michael@0 | 258 | run: function test() { |
michael@0 | 259 | |
michael@0 | 260 | sendContextMenuClick(30, 20); |
michael@0 | 261 | |
michael@0 | 262 | yield waitForCondition(function () { |
michael@0 | 263 | return SelectionHelperUI.isSelectionUIVisible; |
michael@0 | 264 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 265 | |
michael@0 | 266 | sendTap(gWindow, 30, 20); |
michael@0 | 267 | |
michael@0 | 268 | yield waitForCondition(function () { |
michael@0 | 269 | return !SelectionHelperUI.isSelectionUIVisible; |
michael@0 | 270 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 271 | }, |
michael@0 | 272 | tearDown: setUpAndTearDown, |
michael@0 | 273 | }); |
michael@0 | 274 | |
michael@0 | 275 | gTests.push({ |
michael@0 | 276 | desc: "tap off selection clears selection in content", |
michael@0 | 277 | setUp: setUpAndTearDown, |
michael@0 | 278 | run: function test() { |
michael@0 | 279 | |
michael@0 | 280 | sendContextMenuClick(30, 20); |
michael@0 | 281 | |
michael@0 | 282 | yield waitForCondition(function () { |
michael@0 | 283 | return SelectionHelperUI.isSelectionUIVisible; |
michael@0 | 284 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 285 | |
michael@0 | 286 | sendTap(gWindow, 30, 100); |
michael@0 | 287 | |
michael@0 | 288 | yield waitForCondition(function () { |
michael@0 | 289 | return !SelectionHelperUI.isSelectionUIVisible; |
michael@0 | 290 | }, kCommonWaitMs, kCommonPollMs); |
michael@0 | 291 | }, |
michael@0 | 292 | tearDown: setUpAndTearDown, |
michael@0 | 293 | }); |
michael@0 | 294 | |
michael@0 | 295 | gTests.push({ |
michael@0 | 296 | desc: "bug 903737 - right click targeting", |
michael@0 | 297 | setUp: setUpAndTearDown, |
michael@0 | 298 | run: function test() { |
michael@0 | 299 | yield hideContextUI(); |
michael@0 | 300 | let range = gWindow.document.createRange(); |
michael@0 | 301 | range.selectNode(gWindow.document.getElementById("seldiv")); |
michael@0 | 302 | gWindow.getSelection().addRange(range); |
michael@0 | 303 | let promise = waitForEvent(document, "popupshown"); |
michael@0 | 304 | sendContextMenuClickToElement(gWindow, gWindow.document.getElementById("seldiv")); |
michael@0 | 305 | yield promise; |
michael@0 | 306 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 307 | ContextMenuUI.hide(); |
michael@0 | 308 | yield promise; |
michael@0 | 309 | let emptydiv = gWindow.document.getElementById("emptydiv"); |
michael@0 | 310 | let coords = logicalCoordsForElement(emptydiv); |
michael@0 | 311 | InputSourceHelper.isPrecise = true; |
michael@0 | 312 | sendContextMenuClick(coords.x, coords.y); |
michael@0 | 313 | yield waitForCondition(function () { |
michael@0 | 314 | return ContextUI.tabbarVisible; |
michael@0 | 315 | }); |
michael@0 | 316 | yield hideContextUI(); |
michael@0 | 317 | }, |
michael@0 | 318 | tearDown: setUpAndTearDown, |
michael@0 | 319 | }); |
michael@0 | 320 | |
michael@0 | 321 | gTests.push({ |
michael@0 | 322 | desc: "Bug 960886 - selection monocles being spilled over to other tabs " + |
michael@0 | 323 | "when switching.", |
michael@0 | 324 | setUp: setUpAndTearDown, |
michael@0 | 325 | run: function test() { |
michael@0 | 326 | let initialTab = Browser.selectedTab; |
michael@0 | 327 | |
michael@0 | 328 | // Create additional tab to which we will switch later |
michael@0 | 329 | info(chromeRoot + "browser_selection_basic.html"); |
michael@0 | 330 | let lastTab = yield addTab(chromeRoot + "browser_selection_basic.html"); |
michael@0 | 331 | |
michael@0 | 332 | // Switch back to the initial tab |
michael@0 | 333 | let tabSelectPromise = waitForEvent(Elements.tabList, "TabSelect"); |
michael@0 | 334 | Browser.selectedTab = initialTab; |
michael@0 | 335 | yield tabSelectPromise; |
michael@0 | 336 | yield hideContextUI(); |
michael@0 | 337 | |
michael@0 | 338 | // Make selection |
michael@0 | 339 | sendContextMenuClick(30, 20); |
michael@0 | 340 | yield waitForCondition(()=>SelectionHelperUI.isSelectionUIVisible); |
michael@0 | 341 | |
michael@0 | 342 | // Switch to another tab |
michael@0 | 343 | tabSelectPromise = waitForEvent(Elements.tabList, "TabSelect"); |
michael@0 | 344 | Browser.selectedTab = lastTab; |
michael@0 | 345 | yield tabSelectPromise; |
michael@0 | 346 | |
michael@0 | 347 | yield waitForCondition(()=>!SelectionHelperUI.isSelectionUIVisible); |
michael@0 | 348 | |
michael@0 | 349 | Browser.closeTab(Browser.selectedTab, { forceClose: true }); |
michael@0 | 350 | }, |
michael@0 | 351 | tearDown: setUpAndTearDown |
michael@0 | 352 | }); |
michael@0 | 353 | |
michael@0 | 354 | function test() { |
michael@0 | 355 | if (!isLandscapeMode()) { |
michael@0 | 356 | todo(false, "browser_selection_tests need landscape mode to run."); |
michael@0 | 357 | return; |
michael@0 | 358 | } |
michael@0 | 359 | runTests(); |
michael@0 | 360 | } |