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 gFrame = null; michael@0: var gTextArea = null; michael@0: michael@0: const kCommonWaitMs = 5000; michael@0: const kCommonPollMs = 100; 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 (gFrame) michael@0: clearSelection(gFrame); michael@0: if (gTextArea) michael@0: clearSelection(gTextArea); 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: 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_frame_textarea.html"); michael@0: yield addTab(chromeRoot + "browser_selection_frame_textarea.html"); michael@0: michael@0: yield waitForCondition(function () { michael@0: return !BrowserUI.isStartTabVisible; michael@0: }, 10000, 100); michael@0: michael@0: yield hideContextUI(); michael@0: michael@0: gWindow = Browser.selectedTab.browser.contentWindow; michael@0: gFrame = gWindow.document.getElementById("frame1"); michael@0: gTextArea = gFrame.contentDocument.getElementById("textarea"); michael@0: ok(gWindow != null, "gWindow"); michael@0: ok(gFrame != null, "gFrame"); michael@0: ok(gTextArea != null, "gTextArea"); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "basic selection", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: gTextArea.focus(); michael@0: gTextArea.selectionStart = gTextArea.selectionEnd = 0; michael@0: michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClickToElement(gWindow, gFrame, 220, 80); 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(gTextArea).toString(), "wondered", "selection test"); michael@0: michael@0: checkMonoclePositionRange("start", 260, 280, 675, 690); michael@0: checkMonoclePositionRange("end", 320, 340, 675, 690); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "drag selection 1", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: gTextArea.focus(); michael@0: gTextArea.selectionStart = gTextArea.selectionEnd = 0; michael@0: michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClickToElement(gWindow, gFrame, 220, 80); 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(gTextArea).toString(), "wondered", "selection test"); michael@0: michael@0: // end marker to the right michael@0: let xpos = SelectionHelperUI.endMark.xPos; michael@0: let ypos = SelectionHelperUI.endMark.yPos + 10; michael@0: var touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, xpos, ypos, xpos + 150, ypos); michael@0: yield waitForCondition(function () { michael@0: return getTrimmedSelection(gTextArea).toString() == michael@0: "wondered at this,"; michael@0: }, 6000, 2000); 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: // start marker up and 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, 40, 500); michael@0: yield waitForCondition(function () { michael@0: return getTrimmedSelection(gTextArea).toString().substring(0, 17) == michael@0: "There was nothing"; michael@0: }, 6000, 2000); michael@0: touchdrag.end(); michael@0: michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClick(250, 640); michael@0: yield promise; michael@0: michael@0: checkContextUIMenuItemVisibility(["context-cut", michael@0: "context-copy"]); michael@0: michael@0: let menuItem = document.getElementById("context-copy"); 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: let string = ""; michael@0: yield waitForCondition(function () { michael@0: string = SpecialPowers.getClipboardData("text/unicode"); michael@0: return string.substring(0, 17) === "There was nothing"; michael@0: }); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "drag selection 2", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: gTextArea.focus(); michael@0: gTextArea.selectionStart = gTextArea.selectionEnd = 0; michael@0: michael@0: let scrollPromise = waitForEvent(gWindow, "scroll"); michael@0: gWindow.scrollBy(0, 200); michael@0: yield scrollPromise; michael@0: michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClickToElement(gWindow, gFrame, 220, 80); 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(gTextArea).toString(), "wondered", "selection test"); michael@0: michael@0: // end marker to the right michael@0: let xpos = SelectionHelperUI.endMark.xPos; michael@0: let ypos = SelectionHelperUI.endMark.yPos + 10; michael@0: var touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, xpos, ypos, xpos + 150, ypos); michael@0: yield waitForCondition(function () { michael@0: return getTrimmedSelection(gTextArea).toString() == michael@0: "wondered at this,"; michael@0: }, 6000, 2000); 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: // start marker up and 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, 40, 300); michael@0: yield waitForCondition(function () { michael@0: return getTrimmedSelection(gTextArea).toString().substring(0, 17) == michael@0: "There was nothing"; michael@0: }, 6000, 2000); michael@0: touchdrag.end(); michael@0: michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClick(250, 440); michael@0: yield promise; michael@0: michael@0: checkContextUIMenuItemVisibility(["context-cut", michael@0: "context-copy"]); michael@0: michael@0: let menuItem = document.getElementById("context-copy"); 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: let string = ""; michael@0: yield waitForCondition(function () { michael@0: string = SpecialPowers.getClipboardData("text/unicode"); michael@0: return string.substring(0, 17) === "There was nothing"; michael@0: }); 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: }