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: michael@0: const kMarkerOffsetY = 6; michael@0: const kCommonWaitMs = 5000; michael@0: const kCommonPollMs = 100; michael@0: michael@0: /////////////////////////////////////////////////// michael@0: // content (non-editable) 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: 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_basic.html"); michael@0: yield addTab(chromeRoot + "browser_selection_basic.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: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "tap-hold to select", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: sendContextMenuClick(30, 20); michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: michael@0: is(getTrimmedSelection(gWindow).toString(), "There", "selection test"); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "appbar interactions", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: sendContextMenuClick(100, 20); michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: michael@0: is(SelectionHelperUI.isActive, true, "selection active"); michael@0: is(getTrimmedSelection(gWindow).toString(), "nothing", "selection test"); michael@0: michael@0: yield fireAppBarDisplayEvent(); michael@0: michael@0: ok(ContextUI.isVisible, true, "appbar visible"); michael@0: michael@0: yield hideContextUI(); michael@0: michael@0: ok(!ContextUI.isVisible, true, "appbar hidden"); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "simple drag selection", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: yield waitForMs(100); michael@0: sendContextMenuClick(100, 20); michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: michael@0: is(SelectionHelperUI.isActive, true, "selection active"); michael@0: is(getTrimmedSelection(gWindow).toString(), "nothing", "selection test"); michael@0: michael@0: let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY; michael@0: michael@0: let touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 190, ypos); 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: is(SelectionHelperUI.isActive, true, "selection active"); michael@0: is(getTrimmedSelection(gWindow).toString(), "nothing so VERY", "selection test"); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "expand / collapse selection", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: sendContextMenuClick(30, 20); michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: michael@0: is(SelectionHelperUI.isActive, true, "initial active"); michael@0: is(getTrimmedSelection(gWindow).toString(), "There", "initial selection test"); michael@0: michael@0: for (let count = 0; count < 5; count++) { michael@0: let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY; michael@0: michael@0: let touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos); 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: is(getTrimmedSelection(gWindow).toString(), michael@0: "There was nothing so VERY remarkable in that; nor did Alice think it so", michael@0: "long selection test"); michael@0: michael@0: is(SelectionHelperUI.isActive, true, "selection active"); michael@0: michael@0: touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 40, ypos); 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: is(SelectionHelperUI.isActive, true, "selection active"); michael@0: is(getTrimmedSelection(gWindow).toString(), "There was", "short selection test"); michael@0: } michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "expand / collapse selection scolled content", michael@0: setUp: setUpAndTearDown, michael@0: run: function test() { michael@0: let scrollPromise = waitForEvent(gWindow, "scroll"); michael@0: gWindow.scrollBy(0, 200); michael@0: yield scrollPromise; michael@0: ok(scrollPromise && !(scrollPromise instanceof Error), "scrollPromise error"); michael@0: michael@0: sendContextMenuClick(106, 20); michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: michael@0: is(SelectionHelperUI.isActive, true, "selection active"); michael@0: is(getTrimmedSelection(gWindow).toString(), "moment", "selection test"); michael@0: michael@0: let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY; michael@0: michael@0: let touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos); 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: is(getTrimmedSelection(gWindow).toString(), michael@0: "moment down went Alice after it, never once considering how in", michael@0: "selection test"); michael@0: michael@0: is(SelectionHelperUI.isActive, true, "selection active"); michael@0: michael@0: touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 150, ypos); 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: is(getTrimmedSelection(gWindow).toString(), "moment down went", "selection test"); michael@0: michael@0: touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos); 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: is(getTrimmedSelection(gWindow).toString(), michael@0: "moment down went Alice after it, never once considering how in", michael@0: "selection test"); michael@0: michael@0: touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 160, ypos); 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: is(getTrimmedSelection(gWindow).toString(), michael@0: "moment down went", michael@0: "selection test"); michael@0: }, michael@0: tearDown: function tearDown() { michael@0: let scrollPromise = waitForEvent(gWindow, "scroll"); michael@0: gWindow.scrollBy(0, -200); michael@0: yield scrollPromise; michael@0: emptyClipboard(); michael@0: if (gWindow) michael@0: clearSelection(gWindow); michael@0: if (gFrame) michael@0: clearSelection(gFrame); michael@0: yield waitForCondition(function () { michael@0: return !SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: yield hideContextUI(); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "tap on selection clears selection in content", michael@0: setUp: setUpAndTearDown, michael@0: run: function test() { michael@0: michael@0: sendContextMenuClick(30, 20); michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: michael@0: sendTap(gWindow, 30, 20); michael@0: michael@0: yield waitForCondition(function () { michael@0: return !SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: }, michael@0: tearDown: setUpAndTearDown, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "tap off selection clears selection in content", michael@0: setUp: setUpAndTearDown, michael@0: run: function test() { michael@0: michael@0: sendContextMenuClick(30, 20); michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: michael@0: sendTap(gWindow, 30, 100); michael@0: michael@0: yield waitForCondition(function () { michael@0: return !SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: }, michael@0: tearDown: setUpAndTearDown, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "bug 903737 - right click targeting", michael@0: setUp: setUpAndTearDown, michael@0: run: function test() { michael@0: yield hideContextUI(); michael@0: let range = gWindow.document.createRange(); michael@0: range.selectNode(gWindow.document.getElementById("seldiv")); michael@0: gWindow.getSelection().addRange(range); michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClickToElement(gWindow, gWindow.document.getElementById("seldiv")); michael@0: yield promise; michael@0: promise = waitForEvent(document, "popuphidden"); michael@0: ContextMenuUI.hide(); michael@0: yield promise; michael@0: let emptydiv = gWindow.document.getElementById("emptydiv"); michael@0: let coords = logicalCoordsForElement(emptydiv); michael@0: InputSourceHelper.isPrecise = true; michael@0: sendContextMenuClick(coords.x, coords.y); michael@0: yield waitForCondition(function () { michael@0: return ContextUI.tabbarVisible; michael@0: }); michael@0: yield hideContextUI(); michael@0: }, michael@0: tearDown: setUpAndTearDown, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Bug 960886 - selection monocles being spilled over to other tabs " + michael@0: "when switching.", michael@0: setUp: setUpAndTearDown, michael@0: run: function test() { michael@0: let initialTab = Browser.selectedTab; michael@0: michael@0: // Create additional tab to which we will switch later michael@0: info(chromeRoot + "browser_selection_basic.html"); michael@0: let lastTab = yield addTab(chromeRoot + "browser_selection_basic.html"); michael@0: michael@0: // Switch back to the initial tab michael@0: let tabSelectPromise = waitForEvent(Elements.tabList, "TabSelect"); michael@0: Browser.selectedTab = initialTab; michael@0: yield tabSelectPromise; michael@0: yield hideContextUI(); michael@0: michael@0: // Make selection michael@0: sendContextMenuClick(30, 20); michael@0: yield waitForCondition(()=>SelectionHelperUI.isSelectionUIVisible); michael@0: michael@0: // Switch to another tab michael@0: tabSelectPromise = waitForEvent(Elements.tabList, "TabSelect"); michael@0: Browser.selectedTab = lastTab; michael@0: yield tabSelectPromise; michael@0: michael@0: yield waitForCondition(()=>!SelectionHelperUI.isSelectionUIVisible); michael@0: michael@0: Browser.closeTab(Browser.selectedTab, { forceClose: true }); michael@0: }, michael@0: tearDown: setUpAndTearDown 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: }