michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: let gWindow = null; michael@0: var gInput = null; michael@0: michael@0: const kCommonWaitMs = 7000; michael@0: const kCommonPollMs = 200; michael@0: michael@0: /////////////////////////////////////////////////// michael@0: // form input tests michael@0: /////////////////////////////////////////////////// michael@0: michael@0: function setUpAndTearDown() { michael@0: emptyClipboard(); michael@0: if (gWindow) michael@0: clearSelection(gWindow); michael@0: if (gInput) michael@0: clearSelection(gInput); michael@0: yield waitForCondition(function () { michael@0: return !SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: InputSourceHelper.isPrecise = false; michael@0: InputSourceHelper.fireUpdate(); michael@0: } michael@0: michael@0: /* michael@0: 5px top margin michael@0: 25px tall text input michael@0: 300px wide michael@0: */ michael@0: michael@0: gTests.push({ michael@0: desc: "normalize browser", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: info(chromeRoot + "browser_selection_inputs.html"); michael@0: yield addTab(chromeRoot + "browser_selection_inputs.html"); michael@0: michael@0: yield waitForCondition(function () { michael@0: return !BrowserUI.isStartTabVisible; michael@0: }); michael@0: michael@0: yield hideContextUI(); michael@0: michael@0: gWindow = Browser.selectedTab.browser.contentWindow; michael@0: gInput = gWindow.document.getElementById("a"); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "basic text input selection", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: gInput.blur(); michael@0: gInput.selectionStart = gInput.selectionEnd = 0; michael@0: michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClick(200, 17); michael@0: yield promise; michael@0: michael@0: checkContextUIMenuItemVisibility(["context-select", michael@0: "context-select-all"]); michael@0: michael@0: let menuItem = document.getElementById("context-select"); michael@0: ok(menuItem, "menu item exists"); michael@0: ok(!menuItem.hidden, "menu item visible"); michael@0: let popupPromise = waitForEvent(document, "popuphidden"); michael@0: sendElementTap(gWindow, menuItem); michael@0: yield popupPromise; michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: michael@0: is(getTrimmedSelection(gInput).toString(), "went", "selection test"); michael@0: is(gWindow.document.activeElement, gInput, "input focused"); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "drag left to scroll", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: gInput.selectionStart = gInput.selectionEnd = gInput.value.length; michael@0: yield waitForEvent(window, "scroll"); michael@0: michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClick(190, 17); michael@0: yield promise; michael@0: michael@0: checkContextUIMenuItemVisibility(["context-select", michael@0: "context-select-all"]); michael@0: michael@0: let menuItem = document.getElementById("context-select"); michael@0: ok(menuItem, "menu item exists"); michael@0: ok(!menuItem.hidden, "menu item visible"); michael@0: let popupPromise = waitForEvent(document, "popuphidden"); michael@0: sendElementTap(gWindow, menuItem); michael@0: yield popupPromise; michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: michael@0: // check text selection michael@0: is(getTrimmedSelection(gInput).toString(), "way", "selection test"); michael@0: michael@0: // to the left michael@0: let xpos = SelectionHelperUI.startMark.xPos; michael@0: let ypos = SelectionHelperUI.startMark.yPos + 10; michael@0: var touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, xpos, ypos, 10, ypos); michael@0: yield waitForCondition(function () { michael@0: return getTrimmedSelection(gInput).toString() == michael@0: "The rabbit-hole went straight on like a tunnel for some way"; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: touchdrag.end(); michael@0: michael@0: yield waitForCondition(function () { michael@0: return !SelectionHelperUI.hasActiveDrag; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: yield SelectionHelperUI.pingSelectionHandler(); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "drag right to scroll and bug 862025", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: gInput.selectionStart = gInput.selectionEnd = 0; michael@0: yield waitForEvent(window, "scroll"); michael@0: michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClick(230, 17); michael@0: yield promise; michael@0: michael@0: checkContextUIMenuItemVisibility(["context-select", michael@0: "context-select-all"]); michael@0: michael@0: let menuItem = document.getElementById("context-select"); michael@0: ok(menuItem, "menu item exists"); michael@0: ok(!menuItem.hidden, "menu item visible"); michael@0: let popupPromise = waitForEvent(document, "popuphidden"); michael@0: sendElementTap(gWindow, menuItem); michael@0: yield popupPromise; michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: michael@0: // check text selection michael@0: is(getTrimmedSelection(gInput).toString(), "straight", "selection test"); michael@0: michael@0: // to the right with scroll michael@0: let xpos = SelectionHelperUI.endMark.xPos; michael@0: let ystartpos = SelectionHelperUI.endMark.yPos + 10; michael@0: var touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, xpos, ystartpos, 510, ystartpos); michael@0: // hold the monocle in position outside the edit to trigger drag michael@0: yield waitForCondition(function () { michael@0: return getTrimmedSelection(gInput).toString() == michael@0: "straight on like a tunnel for some way and then dipped suddenly down"; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: touchdrag.end(); michael@0: michael@0: yield waitForCondition(function () { michael@0: return !SelectionHelperUI.hasActiveDrag; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: yield SelectionHelperUI.pingSelectionHandler(); michael@0: michael@0: // straight down - selection shouldn't change michael@0: let xpos = SelectionHelperUI.endMark.xPos; michael@0: let ypos = SelectionHelperUI.endMark.yPos + 10; michael@0: yield touchdrag.start(gWindow, xpos, ypos, xpos, ypos + 150); michael@0: // no touchend here, we want to continue the drag below michael@0: michael@0: yield SelectionHelperUI.pingSelectionHandler(); michael@0: is(getTrimmedSelection(gInput).toString(), "straight on like a tunnel for some way and then dipped suddenly down", "selection test"); michael@0: michael@0: // left and up with no scrolling - selection should shrink michael@0: yield touchdrag.move(135, ystartpos); michael@0: touchdrag.end(); michael@0: michael@0: yield SelectionHelperUI.pingSelectionHandler(); michael@0: is(getTrimmedSelection(gInput).toString(), "straight on like a tunnel for", "selection test"); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Bug 858206 - Drag selection monocles should not push other monocles " + michael@0: "out of the way.", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: let inputOriginalValue = gInput.value; michael@0: michael@0: gInput.value = "The rabbit-hole went straight on"; michael@0: michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClickToElement(gWindow, gInput, 150); michael@0: yield promise; michael@0: michael@0: // Make initial selection michael@0: promise = waitForEvent(document, "popuphidden"); michael@0: sendElementTap(gWindow, document.getElementById("context-select")); michael@0: yield promise; michael@0: michael@0: yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible, michael@0: kCommonWaitMs, kCommonPollMs); michael@0: is(getTrimmedSelection(gInput).toString(), "straight"); michael@0: michael@0: // Swap monocles when dragging with end monocle michael@0: let startXPos = SelectionHelperUI.endMark.xPos; michael@0: let startYPos = SelectionHelperUI.endMark.yPos + 10; michael@0: let touchDrag = new TouchDragAndHold(); michael@0: yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 300, michael@0: startYPos); michael@0: michael@0: yield waitForCondition(() => getTrimmedSelection(gInput).toString() == michael@0: "The rabbit-hole went", kCommonWaitMs, kCommonPollMs); michael@0: touchDrag.end(); michael@0: yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag, michael@0: kCommonWaitMs, kCommonPollMs); michael@0: yield SelectionHelperUI.pingSelectionHandler(); michael@0: michael@0: // Swap monocles when dragging with start monocle michael@0: startXPos = SelectionHelperUI.startMark.xPos; michael@0: startYPos = SelectionHelperUI.startMark.yPos + 10; michael@0: yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 300, michael@0: startYPos); michael@0: yield waitForCondition(() => getTrimmedSelection(gInput).toString() == michael@0: "straight on", kCommonWaitMs, kCommonPollMs); michael@0: touchDrag.end(); michael@0: yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag, michael@0: kCommonWaitMs, kCommonPollMs); michael@0: yield SelectionHelperUI.pingSelectionHandler(); michael@0: michael@0: // Swap monocles right after caret-to-selection mode switch from start michael@0: gInput.selectionStart = gInput.selectionEnd = 0; michael@0: sendElementTap(gWindow, gInput, 0, 0); michael@0: michael@0: yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible && michael@0: SelectionHelperUI.isCaretUIVisible); michael@0: michael@0: startXPos = SelectionHelperUI.caretMark.xPos; michael@0: startYPos = SelectionHelperUI.caretMark.yPos + 10; michael@0: michael@0: yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 300, michael@0: startYPos); michael@0: yield waitForCondition(() => getTrimmedSelection(gInput).toString() == michael@0: "The rabbit-hole went straight on", kCommonWaitMs, kCommonPollMs); michael@0: touchDrag.end(); michael@0: michael@0: sendTap(gWindow, 10, 10); michael@0: yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible); michael@0: michael@0: // Swap monocles right after caret-to-selection mode switch from end michael@0: gInput.selectionStart = gInput.selectionEnd = gInput.value.length; michael@0: let inputSelectionRectangle = gInput.QueryInterface(Ci.nsIDOMNSEditableElement). michael@0: editor.selection.getRangeAt(0).getClientRects()[0]; michael@0: sendTap(gWindow, inputSelectionRectangle.right, michael@0: inputSelectionRectangle.top); michael@0: michael@0: yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible); michael@0: michael@0: startXPos = SelectionHelperUI.caretMark.xPos; michael@0: startYPos = SelectionHelperUI.caretMark.yPos + 10; michael@0: michael@0: yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 300, michael@0: startYPos); michael@0: yield waitForCondition(() => getTrimmedSelection(gInput).toString() == michael@0: "The rabbit-hole went straight on", kCommonWaitMs, kCommonPollMs); michael@0: touchDrag.end(); michael@0: michael@0: gInput.value = inputOriginalValue; michael@0: } michael@0: }); michael@0: michael@0: function test() { michael@0: if (!isLandscapeMode()) { michael@0: todo(false, "browser_selection_tests need landscape mode to run."); michael@0: return; michael@0: } michael@0: // XXX need this until bugs 886624 and 859742 are fully resolved michael@0: setDevPixelEqualToPx(); michael@0: runTests(); michael@0: }