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 gInput = 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 (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: 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_inputs.html"); michael@0: yield addTab(chromeRoot + "browser_selection_frame_inputs.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: gInput = gFrame.contentDocument.getElementById("textinput"); michael@0: michael@0: ok(gWindow != null, "gWindow"); michael@0: ok(gFrame != null, "gFrame"); michael@0: ok(gInput != null, "gInput"); 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: gInput.focus(); michael@0: gInput.selectionStart = gInput.selectionEnd = 0; michael@0: michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClickToElement(gWindow, gFrame, 135, 10); 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(), "straight", "selection test"); michael@0: michael@0: let rect = gFrame.getBoundingClientRect(); michael@0: checkMonoclePositionRange("start", rect.left + 125, rect.left + 135, rect.top + 20, rect.top + 30); michael@0: checkMonoclePositionRange("end", rect.left + 165, rect.left + 175, rect.top + 20, rect.top + 30); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "drag selection", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: gInput.focus(); michael@0: gInput.selectionStart = gInput.selectionEnd = 0; michael@0: michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClickToElement(gWindow, gFrame, 135, 10); 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(), "straight", "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 + 350, ypos); 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: }, 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 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 and then dipped suddenly down"; 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: }); 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: runTests(); michael@0: }