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: // sub frame content 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_frame_content.html"); michael@0: yield addTab(chromeRoot + "browser_selection_frame_content.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: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "iframe basic selection", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: gFrame.focus(); michael@0: michael@0: sendContextMenuClick(165, 35); michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: michael@0: // active state michael@0: is(SelectionHelperUI.isActive, true, "selection active"); michael@0: // check text selection michael@0: is(getTrimmedSelection(gFrame).toString(), "Alice", "selection test"); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "iframe expand / collapse selection", michael@0: setUp: setUpAndTearDown, michael@0: tearDown: setUpAndTearDown, michael@0: run: function test() { michael@0: gFrame.focus(); michael@0: michael@0: sendContextMenuClick(162, 180); michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: michael@0: // active state michael@0: is(SelectionHelperUI.isActive, true, "selection active"); michael@0: is(getTrimmedSelection(gFrame).toString(), "Alice", "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, 640, 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(gFrame).toString(), "Alice was beginning to get very tired of sitting by her sister on the bank", michael@0: "selection test"); michael@0: michael@0: touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 320, 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(gFrame).toString(), "Alice was beginning to get very", "selection test"); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "scrolled iframe selection", michael@0: setUp: setUpAndTearDown, michael@0: run: function test() { michael@0: gFrame.focus(); michael@0: michael@0: let scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll"); michael@0: gFrame.contentDocument.defaultView.scrollBy(0, 200); michael@0: yield scrollPromise; michael@0: michael@0: sendContextMenuClick(30, 240); 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(gFrame).toString(), "started", "selection test"); michael@0: michael@0: let promise = waitForEvent(document, "popupshown"); michael@0: sendContextMenuClickToSelection(gFrame.contentDocument.defaultView); michael@0: michael@0: yield promise; michael@0: ok(promise && !(promise instanceof Error), "promise error"); michael@0: ok(ContextMenuUI._menuPopup.visible, "is visible"); 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: ok(popupPromise && !(popupPromise instanceof Error), "promise error"); michael@0: michael@0: // The wait is needed to give time to populate the clipboard. michael@0: let string = ""; michael@0: yield waitForCondition(function () { michael@0: string = SpecialPowers.getClipboardData("text/unicode"); michael@0: return string === "started"; michael@0: }); michael@0: is(string, "started", "copy text"); michael@0: michael@0: }, michael@0: tearDown: function tearDown() { michael@0: emptyClipboard(); michael@0: let scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll"); michael@0: gFrame.contentDocument.defaultView.scrollBy(0, -200); michael@0: yield scrollPromise; michael@0: clearSelection(gWindow); 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: "iframe within scrolled page selection", michael@0: setUp: setUpAndTearDown, michael@0: run: function test() { michael@0: gFrame.focus(); michael@0: michael@0: let scrollPromise = waitForEvent(gWindow, "scroll"); michael@0: gWindow.scrollBy(0, 200); michael@0: yield scrollPromise; michael@0: michael@0: scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll"); michael@0: gFrame.contentDocument.defaultView.scrollBy(0, 200); michael@0: yield scrollPromise; michael@0: michael@0: sendContextMenuClick(114, 130); 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(gFrame).toString(), "moment", "selection test"); michael@0: }, michael@0: tearDown: function tearDown() { michael@0: emptyClipboard(); michael@0: clearSelection(gWindow); michael@0: clearSelection(gFrame); michael@0: let scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll"); michael@0: gFrame.contentDocument.defaultView.scrollBy(0, -200); michael@0: yield scrollPromise; michael@0: scrollPromise = waitForEvent(gWindow, "scroll"); michael@0: gWindow.scrollBy(0, -200); michael@0: yield scrollPromise; 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: 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: }