Bug 858206 - Part 3: Add mochitests. r=jimm

This commit is contained in:
Aleh Zasypkin 2014-03-06 22:38:32 +01:00
parent 62bc8ec771
commit 650869912b
3 changed files with 178 additions and 2 deletions

View File

@ -37,7 +37,7 @@ gTests.push({
let div = gWindow.document.getElementById("testdiv");
ok(div, "have the div");
sendElementTap(gWindow, div, 287); // end of 'outlook.com'
sendElementTap(gWindow, div, 284); // end of 'outlook.com'
yield waitForCondition(function () {
return SelectionHelperUI.isCaretUIVisible;

View File

@ -195,6 +195,96 @@ gTests.push({
},
});
gTests.push({
desc: "Bug 858206 - Drag selection monocles should not push other monocles " +
"out of the way.",
setUp: setUpAndTearDown,
tearDown: setUpAndTearDown,
run: function test() {
let inputOriginalValue = gInput.value;
gInput.value = "The rabbit-hole went straight on";
let promise = waitForEvent(document, "popupshown");
sendContextMenuClickToElement(gWindow, gInput, 150);
yield promise;
// Make initial selection
promise = waitForEvent(document, "popuphidden");
sendElementTap(gWindow, document.getElementById("context-select"));
yield promise;
yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible,
kCommonWaitMs, kCommonPollMs);
is(getTrimmedSelection(gInput).toString(), "straight");
// Swap monocles when dragging with end monocle
let startXPos = SelectionHelperUI.endMark.xPos;
let startYPos = SelectionHelperUI.endMark.yPos + 10;
let touchDrag = new TouchDragAndHold();
yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 300,
startYPos);
yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
"The rabbit-hole went", kCommonWaitMs, kCommonPollMs);
touchDrag.end();
yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
kCommonWaitMs, kCommonPollMs);
yield SelectionHelperUI.pingSelectionHandler();
// Swap monocles when dragging with start monocle
startXPos = SelectionHelperUI.startMark.xPos;
startYPos = SelectionHelperUI.startMark.yPos + 10;
yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 300,
startYPos);
yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
"straight on", kCommonWaitMs, kCommonPollMs);
touchDrag.end();
yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
kCommonWaitMs, kCommonPollMs);
yield SelectionHelperUI.pingSelectionHandler();
// Swap monocles right after caret-to-selection mode switch from start
gInput.selectionStart = gInput.selectionEnd = 0;
sendElementTap(gWindow, gInput, 0, 0);
yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
SelectionHelperUI.isCaretUIVisible);
startXPos = SelectionHelperUI.caretMark.xPos;
startYPos = SelectionHelperUI.caretMark.yPos + 10;
yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 300,
startYPos);
yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
"The rabbit-hole went straight on", kCommonWaitMs, kCommonPollMs);
touchDrag.end();
sendTap(gWindow, 10, 10);
yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible);
// Swap monocles right after caret-to-selection mode switch from end
gInput.selectionStart = gInput.selectionEnd = gInput.value.length;
let inputSelectionRectangle = gInput.QueryInterface(Ci.nsIDOMNSEditableElement).
editor.selection.getRangeAt(0).getClientRects()[0];
sendTap(gWindow, inputSelectionRectangle.right,
inputSelectionRectangle.top);
yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible);
startXPos = SelectionHelperUI.caretMark.xPos;
startYPos = SelectionHelperUI.caretMark.yPos + 10;
yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 300,
startYPos);
yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
"The rabbit-hole went straight on", kCommonWaitMs, kCommonPollMs);
touchDrag.end();
gInput.value = inputOriginalValue;
}
});
function test() {
if (!isLandscapeMode()) {
todo(false, "browser_selection_tests need landscape mode to run.");

View File

@ -315,8 +315,94 @@ gTests.push({
sendTap(window, inputFieldRectangle.left + 10, inputFieldRectangle.top + 5);
yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible);
chromeHandlerSpy.restore();
inputField.blur();
}
});
gTests.push({
desc: "Bug 858206 - Drag selection monocles should not push other monocles " +
"out of the way.",
run: function test() {
yield showNavBar();
let edit = document.getElementById("urlbar-edit");
edit.value = "about:mozilla";
let editRectangle = edit.getBoundingClientRect();
sendTap(window, editRectangle.left, editRectangle.top);
yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible);
let selection = edit.QueryInterface(
Components.interfaces.nsIDOMXULTextBoxElement).editor.selection;
let selectionRectangle = selection.getRangeAt(0).getClientRects()[0];
// Place caret to the input start
sendTap(window, selectionRectangle.left + 2, selectionRectangle.top + 2);
yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
SelectionHelperUI.isCaretUIVisible);
let startXPos = SelectionHelperUI.caretMark.xPos;
let startYPos = SelectionHelperUI.caretMark.yPos + 10;
let touchDrag = new TouchDragAndHold();
yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200,
startYPos);
yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
"about:mozilla", kCommonWaitMs, kCommonPollMs);
touchDrag.end();
yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
kCommonWaitMs, kCommonPollMs);
// Place caret to the input end
sendTap(window, selectionRectangle.right - 2, selectionRectangle.top + 2);
yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
SelectionHelperUI.isCaretUIVisible);
startXPos = SelectionHelperUI.caretMark.xPos;
startYPos = SelectionHelperUI.caretMark.yPos + 10;
yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200,
startYPos);
yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
"about:mozilla", kCommonWaitMs, kCommonPollMs);
touchDrag.end();
yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
kCommonWaitMs, kCommonPollMs);
// Place caret in the middle
let midX = Math.ceil(((selectionRectangle.right - selectionRectangle.left) *
.5) + selectionRectangle.left);
let midY = Math.ceil(((selectionRectangle.bottom - selectionRectangle.top) *
.5) + selectionRectangle.top);
sendTap(window, midX, midY);
yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
SelectionHelperUI.isCaretUIVisible);
startXPos = SelectionHelperUI.caretMark.xPos;
startYPos = SelectionHelperUI.caretMark.yPos + 10;
yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200,
startYPos);
yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
"about:", kCommonWaitMs, kCommonPollMs);
touchDrag.end();
yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
kCommonWaitMs, kCommonPollMs);
// Now try to swap monocles
startXPos = SelectionHelperUI.startMark.xPos;
startYPos = SelectionHelperUI.startMark.yPos + 10;
yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200,
startYPos);
yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
"mozilla", kCommonWaitMs, kCommonPollMs);
touchDrag.end();
yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag &&
SelectionHelperUI.isSelectionUIVisible, kCommonWaitMs, kCommonPollMs);
}
});