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 kCommonWaitMs = 5000; michael@0: const kCommonPollMs = 100; michael@0: michael@0: /////////////////////////////////////////////////// michael@0: // text area tests michael@0: /////////////////////////////////////////////////// michael@0: michael@0: gTests.push({ michael@0: desc: "normalize browser", michael@0: run: function test() { michael@0: info(chromeRoot + "res/textblock01.html"); michael@0: yield addTab(chromeRoot + "res/textblock01.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: InputSourceHelper.isPrecise = false; michael@0: InputSourceHelper.fireUpdate(); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "nav bar display", michael@0: run: function test() { michael@0: gWindow = window; michael@0: michael@0: yield showNavBar(); michael@0: michael@0: let edit = document.getElementById("urlbar-edit"); michael@0: michael@0: sendElementTap(window, edit, 100, 10); michael@0: michael@0: ok(SelectionHelperUI.isSelectionUIVisible, "selection ui active"); michael@0: michael@0: sendElementTap(window, edit, 70, 10); michael@0: michael@0: ok(SelectionHelperUI.isCaretUIVisible, "caret ui active"); michael@0: michael@0: // to the right michael@0: let xpos = SelectionHelperUI.caretMark.xPos; michael@0: let ypos = SelectionHelperUI.caretMark.yPos + 10; michael@0: var touchdrag = new TouchDragAndHold(); michael@0: yield touchdrag.start(gWindow, xpos, ypos, 900, ypos); michael@0: yield waitForCondition(function () { michael@0: return getTrimmedSelection(edit).toString() == michael@0: "mochitests/content/metro/browser/metro/base/tests/mochitest/res/textblock01.html"; michael@0: }, kCommonWaitMs, kCommonPollMs); michael@0: touchdrag.end(); michael@0: yield waitForMs(100); michael@0: michael@0: ok(SelectionHelperUI.isSelectionUIVisible, "selection ui active"); michael@0: }, michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "bug 887120 - tap & hold to paste into urlbar", michael@0: run: function() { michael@0: gWindow = window; michael@0: michael@0: yield showNavBar(); michael@0: let edit = document.getElementById("urlbar-edit"); michael@0: michael@0: SpecialPowers.clipboardCopyString("mozilla"); michael@0: sendContextMenuClickToElement(window, edit); michael@0: yield waitForEvent(document, "popupshown"); michael@0: michael@0: ok(ContextMenuUI._menuPopup.visible, "is visible"); michael@0: let paste = document.getElementById("context-paste"); michael@0: ok(!paste.hidden, "paste item is visible"); michael@0: michael@0: sendElementTap(window, paste); michael@0: ok(edit.popup.popupOpen, "bug: popup should be showing"); michael@0: michael@0: clearSelection(edit); michael@0: yield waitForCondition(function () { michael@0: return !SelectionHelperUI.isSelectionUIVisible; michael@0: }); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "bug 895284 - tap selection", michael@0: run: function() { michael@0: gWindow = window; michael@0: michael@0: yield showNavBar(); michael@0: let edit = document.getElementById("urlbar-edit"); michael@0: edit.value = "wikipedia.org"; michael@0: edit.select(); michael@0: michael@0: let editCoords = logicalCoordsForElement(edit); michael@0: michael@0: // wait for popup animation to complete, it interferes with edit selection testing michael@0: let autocompletePopup = document.getElementById("urlbar-autocomplete-scroll"); michael@0: yield waitForEvent(autocompletePopup, "transitionend"); michael@0: michael@0: SelectionHelperUI.attachEditSession(ChromeSelectionHandler, editCoords.x, michael@0: editCoords.y, edit); michael@0: ok(SelectionHelperUI.isSelectionUIVisible, "selection enabled"); michael@0: michael@0: let selection = edit.QueryInterface(Components.interfaces.nsIDOMXULTextBoxElement) michael@0: .editor.selection; michael@0: let rects = selection.getRangeAt(0).getClientRects(); michael@0: let midX = Math.ceil(((rects[0].right - rects[0].left) * .5) + rects[0].left); michael@0: let midY = Math.ceil(((rects[0].bottom - rects[0].top) * .5) + rects[0].top); michael@0: michael@0: sendTap(window, midX, midY); michael@0: michael@0: ok(SelectionHelperUI.isCaretUIVisible, "caret browsing enabled"); michael@0: michael@0: clearSelection(edit); michael@0: yield waitForCondition(function () { michael@0: return !SelectionHelperUI.isSelectionUIVisible; michael@0: }); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "bug 894713 - blur shuts down selection handling", michael@0: run: function() { michael@0: gWindow = window; michael@0: yield showNavBar(); michael@0: let edit = document.getElementById("urlbar-edit"); michael@0: edit.value = "wikipedia.org"; michael@0: edit.select(); michael@0: let editCoords = logicalCoordsForElement(edit); michael@0: SelectionHelperUI.attachEditSession(ChromeSelectionHandler, editCoords.x, michael@0: editCoords.y, edit); michael@0: edit.blur(); michael@0: ok(!SelectionHelperUI.isSelectionUIVisible, "selection no longer enabled"); michael@0: clearSelection(edit); michael@0: yield waitForCondition(function () { michael@0: return !SelectionHelperUI.isSelectionUIVisible; michael@0: }); michael@0: } michael@0: }); michael@0: michael@0: function getClipboardCondition(aExpected) { michael@0: return () => aExpected == SpecialPowers.getClipboardData("text/unicode"); michael@0: } michael@0: michael@0: gTests.push({ michael@0: desc: "bug 894715 - URLs selected by touch are copied with trimming", michael@0: run: function () { michael@0: gWindow = window; michael@0: yield showNavBar(); michael@0: michael@0: let edit = document.getElementById("urlbar-edit"); michael@0: edit.value = "http://www.wikipedia.org/"; michael@0: michael@0: sendElementTap(window, edit); michael@0: edit.select(); michael@0: michael@0: let panel = ContextMenuUI._menuPopup._panel; michael@0: let promise = waitForEvent(panel, "popupshown") michael@0: sendContextMenuClickToElement(window, edit); michael@0: ok((yield promise), "show context menu"); michael@0: michael@0: let copy = document.getElementById("context-copy"); michael@0: ok(!copy.hidden, "copy menu item is visible") michael@0: michael@0: let condition = getClipboardCondition("http://www.wikipedia.org/"); michael@0: let promise = waitForCondition(condition); michael@0: sendElementTap(window, copy); michael@0: ok((yield promise), "copy text onto clipboard") michael@0: michael@0: clearSelection(edit); michael@0: edit.blur(); michael@0: } michael@0: }) michael@0: michael@0: gTests.push({ michael@0: desc: "bug 965832 - selection monocles move with the nav bar", michael@0: run: function() { michael@0: yield showNavBar(); michael@0: michael@0: let originalUtils = Services.metro; michael@0: Services.metro = { michael@0: keyboardHeight: 0, michael@0: keyboardVisible: false michael@0: }; michael@0: registerCleanupFunction(function() { michael@0: Services.metro = originalUtils; michael@0: }); michael@0: michael@0: let edit = document.getElementById("urlbar-edit"); michael@0: edit.value = "http://www.wikipedia.org/"; michael@0: michael@0: sendElementTap(window, edit); michael@0: michael@0: let promise = waitForEvent(window, "MozDeckOffsetChanged"); michael@0: Services.metro.keyboardHeight = 300; michael@0: Services.metro.keyboardVisible = true; michael@0: Services.obs.notifyObservers(null, "metro_softkeyboard_shown", null); michael@0: yield promise; michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }); michael@0: michael@0: promise = waitForEvent(window, "MozDeckOffsetChanged"); michael@0: Services.metro.keyboardHeight = 0; michael@0: Services.metro.keyboardVisible = false; michael@0: Services.obs.notifyObservers(null, "metro_softkeyboard_hidden", null); michael@0: yield promise; michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }); michael@0: michael@0: clearSelection(edit); michael@0: edit.blur(); michael@0: michael@0: yield waitForCondition(function () { michael@0: return !SelectionHelperUI.isSelectionUIVisible; michael@0: }); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Bug 957646 - Selection monocles sometimes don't display when tapping" + michael@0: " text in the nav bar.", michael@0: run: function() { michael@0: yield showNavBar(); michael@0: michael@0: let edit = document.getElementById("urlbar-edit"); michael@0: edit.value = "about:mozilla"; michael@0: michael@0: let editRectangle = edit.getBoundingClientRect(); michael@0: michael@0: // Tap outside the input but close enough for fluffing to take effect. michael@0: sendTap(window, editRectangle.left + 50, editRectangle.top - 2); michael@0: michael@0: yield waitForCondition(function () { michael@0: return SelectionHelperUI.isSelectionUIVisible; michael@0: }); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Bug 972574 - Monocles not matching selection after double tap" + michael@0: " in URL text field.", michael@0: run: function() { michael@0: yield showNavBar(); michael@0: michael@0: let MARGIN_OF_ERROR = 15; michael@0: let EST_URLTEXT_WIDTH = 125; michael@0: michael@0: let edit = document.getElementById("urlbar-edit"); michael@0: edit.value = "http://www.wikipedia.org/"; michael@0: michael@0: // Determine a tap point centered on URL. michael@0: let editRectangle = edit.getBoundingClientRect(); michael@0: let midX = editRectangle.left + Math.ceil(EST_URLTEXT_WIDTH / 2); michael@0: let midY = editRectangle.top + Math.ceil(editRectangle.height / 2); michael@0: michael@0: // Tap inside the input for fluffing to take effect. michael@0: sendTap(window, midX, midY); michael@0: michael@0: // Double-tap inside the input to selectALL. michael@0: sendDoubleTap(window, midX, midY); michael@0: michael@0: // Check for start/end monocles positioned within accepted margins. michael@0: checkMonoclePositionRange("start", michael@0: Math.ceil(editRectangle.left - MARGIN_OF_ERROR), michael@0: Math.ceil(editRectangle.left + MARGIN_OF_ERROR), michael@0: Math.ceil(editRectangle.top + editRectangle.height - MARGIN_OF_ERROR), michael@0: Math.ceil(editRectangle.top + editRectangle.height + MARGIN_OF_ERROR)); michael@0: checkMonoclePositionRange("end", michael@0: Math.ceil(editRectangle.left + EST_URLTEXT_WIDTH - MARGIN_OF_ERROR), michael@0: Math.ceil(editRectangle.left + EST_URLTEXT_WIDTH + MARGIN_OF_ERROR), michael@0: Math.ceil(editRectangle.top + editRectangle.height - MARGIN_OF_ERROR), michael@0: Math.ceil(editRectangle.top + editRectangle.height + MARGIN_OF_ERROR)); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Bug 972428 - grippers not appearing under the URL field when adding " + michael@0: "text.", michael@0: run: function() { michael@0: let inputField = document.getElementById("urlbar-edit").inputField; michael@0: let inputFieldRectangle = inputField.getBoundingClientRect(); michael@0: michael@0: let chromeHandlerSpy = spyOnMethod(ChromeSelectionHandler, "msgHandler"); michael@0: michael@0: // Reset URL to empty string michael@0: inputField.value = ""; michael@0: inputField.blur(); michael@0: michael@0: // Activate URL input michael@0: sendTap(window, inputFieldRectangle.left + 50, inputFieldRectangle.top + 5); michael@0: michael@0: // Wait until ChromeSelectionHandler tries to attach selection michael@0: yield waitForCondition(() => chromeHandlerSpy.argsForCall.some( michael@0: (args) => args[0] == "Browser:SelectionAttach")); michael@0: michael@0: ok(!SelectHelperUI.isSelectionUIVisible && !SelectHelperUI.isCaretUIVisible, michael@0: "Neither CaretUI nor SelectionUI is visible on empty input."); michael@0: michael@0: inputField.value = "Test text"; michael@0: michael@0: sendTap(window, inputFieldRectangle.left + 10, inputFieldRectangle.top + 5); michael@0: michael@0: yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible); michael@0: chromeHandlerSpy.restore(); michael@0: inputField.blur(); 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: run: function test() { michael@0: yield showNavBar(); michael@0: michael@0: let edit = document.getElementById("urlbar-edit"); michael@0: edit.value = "about:mozilla"; michael@0: michael@0: let editRectangle = edit.getBoundingClientRect(); michael@0: michael@0: sendTap(window, editRectangle.left, editRectangle.top); michael@0: michael@0: yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible); michael@0: michael@0: let selection = edit.QueryInterface( michael@0: Components.interfaces.nsIDOMXULTextBoxElement).editor.selection; michael@0: let selectionRectangle = selection.getRangeAt(0).getClientRects()[0]; michael@0: michael@0: // Place caret to the input start michael@0: sendTap(window, selectionRectangle.left + 2, selectionRectangle.top + 2); michael@0: yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible && michael@0: SelectionHelperUI.isCaretUIVisible); michael@0: michael@0: let startXPos = SelectionHelperUI.caretMark.xPos; michael@0: let startYPos = SelectionHelperUI.caretMark.yPos + 10; michael@0: let touchDrag = new TouchDragAndHold(); michael@0: yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200, michael@0: startYPos); michael@0: yield waitForCondition(() => getTrimmedSelection(edit).toString() == michael@0: "about:mozilla", kCommonWaitMs, kCommonPollMs); michael@0: michael@0: touchDrag.end(); michael@0: yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag, michael@0: kCommonWaitMs, kCommonPollMs); michael@0: michael@0: // Place caret to the input end michael@0: sendTap(window, selectionRectangle.right - 2, selectionRectangle.top + 2); 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: yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200, michael@0: startYPos); michael@0: yield waitForCondition(() => getTrimmedSelection(edit).toString() == michael@0: "about:mozilla", kCommonWaitMs, kCommonPollMs); michael@0: michael@0: touchDrag.end(); michael@0: yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag, michael@0: kCommonWaitMs, kCommonPollMs); michael@0: michael@0: // Place caret in the middle michael@0: let midX = Math.ceil(((selectionRectangle.right - selectionRectangle.left) * michael@0: .5) + selectionRectangle.left); michael@0: let midY = Math.ceil(((selectionRectangle.bottom - selectionRectangle.top) * michael@0: .5) + selectionRectangle.top); michael@0: michael@0: sendTap(window, midX, midY); 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: yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200, michael@0: startYPos); michael@0: yield waitForCondition(() => getTrimmedSelection(edit).toString() == michael@0: "about:", kCommonWaitMs, kCommonPollMs); michael@0: michael@0: touchDrag.end(); michael@0: yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag, michael@0: kCommonWaitMs, kCommonPollMs); michael@0: michael@0: // Now try to swap monocles michael@0: startXPos = SelectionHelperUI.startMark.xPos; michael@0: startYPos = SelectionHelperUI.startMark.yPos + 10; michael@0: yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200, michael@0: startYPos); michael@0: yield waitForCondition(() => getTrimmedSelection(edit).toString() == michael@0: "mozilla", kCommonWaitMs, kCommonPollMs); michael@0: touchDrag.end(); michael@0: yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag && michael@0: SelectionHelperUI.isSelectionUIVisible, kCommonWaitMs, kCommonPollMs); 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: }