Bug 863739 - Add text input selection related mochitests. r=rsilveira

This commit is contained in:
Jim Mathies 2013-04-23 08:51:03 -05:00
parent 0bb372a266
commit f0692427e0
4 changed files with 217 additions and 0 deletions

View File

@ -42,6 +42,8 @@ BROWSER_TESTS += \
browser_selection_textarea.html \
browser_selection_frame_content.js \
browser_selection_frame_content.html \
browser_selection_inputs.js \
browser_selection_inputs.html \
$(NULL)
endif

View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body style="margin: 5px 5px 5px 85px;">
<input id="a" style="width:300px; height:25px;" value="The rabbit-hole went straight on like a tunnel for some way and then dipped suddenly down" type="text">
</body>
</html>

View File

@ -0,0 +1,204 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
let gWindow = null;
var gInput = null;
const kMarkerOffsetY = 12;
const kCommonWaitMs = 5000;
const kCommonPollMs = 100;
///////////////////////////////////////////////////
// form input tests
///////////////////////////////////////////////////
function setUpAndTearDown() {
emptyClipboard();
if (gWindow)
clearSelection(gWindow);
if (gInput)
clearSelection(gInput);
yield waitForCondition(function () {
return !SelectionHelperUI.isSelectionUIVisible;
}, kCommonWaitMs, kCommonPollMs);
yield hideContextUI();
}
/*
5px top margin
25px tall text input
300px wide
*/
gTests.push({
desc: "normalize browser",
setUp: setUpAndTearDown,
tearDown: setUpAndTearDown,
run: function test() {
info(chromeRoot + "browser_selection_inputs.html");
yield addTab(chromeRoot + "browser_selection_inputs.html");
yield waitForCondition(function () {
return !StartUI.isStartPageVisible;
}, 10000, 100);
gWindow = Browser.selectedTab.browser.contentWindow;
gInput = gWindow.document.getElementById("a");
InputSourceHelper.isPrecise = false;
},
});
gTests.push({
desc: "basic text input selection",
setUp: setUpAndTearDown,
tearDown: setUpAndTearDown,
run: function test() {
gInput.focus();
gInput.selectionStart = gInput.selectionEnd = 0;
let promise = waitForEvent(document, "popupshown");
sendContextMenuClick(200, 17);
yield promise;
checkContextUIMenuItemVisibility(["context-select",
"context-select-all"]);
let menuItem = document.getElementById("context-select");
ok(menuItem, "menu item exists");
ok(!menuItem.hidden, "menu item visible");
let popupPromise = waitForEvent(document, "popuphidden");
EventUtils.synthesizeMouse(menuItem, 10, 10, {}, gWindow);
yield popupPromise;
yield waitForCondition(function () {
return SelectionHelperUI.isSelectionUIVisible;
}, kCommonWaitMs, kCommonPollMs);
is(getTrimmedSelection(gInput).toString(), "went", "selection test");
},
});
gTests.push({
desc: "drag left to scroll",
setUp: setUpAndTearDown,
tearDown: setUpAndTearDown,
run: function test() {
gInput.selectionStart = gInput.selectionEnd = gInput.value.length;
let promise = waitForEvent(document, "popupshown");
sendContextMenuClick(190, 17);
yield promise;
checkContextUIMenuItemVisibility(["context-select",
"context-select-all"]);
let menuItem = document.getElementById("context-select");
ok(menuItem, "menu item exists");
ok(!menuItem.hidden, "menu item visible");
let popupPromise = waitForEvent(document, "popuphidden");
EventUtils.synthesizeMouse(menuItem, 10, 10, {}, gWindow);
yield popupPromise;
yield waitForCondition(function () {
return SelectionHelperUI.isSelectionUIVisible;
}, kCommonWaitMs, kCommonPollMs);
// check text selection
is(getTrimmedSelection(gInput).toString(), "way", "selection test");
// to the left
let xpos = SelectionHelperUI.startMark.xPos;
let ypos = SelectionHelperUI.startMark.yPos + 10;
var touchdrag = new TouchDragAndHold();
yield touchdrag.start(gWindow, xpos, ypos, 10, ypos);
yield waitForCondition(function () {
return getTrimmedSelection(gInput).toString() ==
"The rabbit-hole went straight on like a tunnel for some way";
}, 6000, 2000);
touchdrag.end();
yield waitForCondition(function () {
return !SelectionHelperUI.hasActiveDrag;
}, kCommonWaitMs, kCommonPollMs);
yield SelectionHelperUI.pingSelectionHandler();
},
});
gTests.push({
desc: "drag right to scroll and bug 862025",
setUp: setUpAndTearDown,
tearDown: setUpAndTearDown,
run: function test() {
gInput.selectionStart = gInput.selectionEnd = 0;
let promise = waitForEvent(document, "popupshown");
sendContextMenuClick(230, 17);
yield promise;
checkContextUIMenuItemVisibility(["context-select",
"context-select-all"]);
let menuItem = document.getElementById("context-select");
ok(menuItem, "menu item exists");
ok(!menuItem.hidden, "menu item visible");
let popupPromise = waitForEvent(document, "popuphidden");
EventUtils.synthesizeMouse(menuItem, 10, 10, {}, gWindow);
yield popupPromise;
yield waitForCondition(function () {
return SelectionHelperUI.isSelectionUIVisible;
}, kCommonWaitMs, kCommonPollMs);
// check text selection
is(getTrimmedSelection(gInput).toString(), "straight", "selection test");
// to the right
let xpos = SelectionHelperUI.endMark.xPos;
let ypos = SelectionHelperUI.endMark.yPos + 10;
var touchdrag = new TouchDragAndHold();
yield touchdrag.start(gWindow, xpos, ypos, 510, ypos);
yield waitForCondition(function () {
return getTrimmedSelection(gInput).toString() ==
"straight on like a tunnel for some way and then dipped suddenly down";
}, 6000, 2000);
touchdrag.end();
yield waitForCondition(function () {
return !SelectionHelperUI.hasActiveDrag;
}, kCommonWaitMs, kCommonPollMs);
yield SelectionHelperUI.pingSelectionHandler();
// down - selection shouldn't change
let xpos = SelectionHelperUI.endMark.xPos;
let ypos = SelectionHelperUI.endMark.yPos + 10;
yield touchdrag.start(gWindow, xpos, ypos, xpos, ypos + 150);
yield waitForMs(2000);
touchdrag.end();
is(getTrimmedSelection(gInput).toString(), "straight on like a tunnel for some way and then dipped suddenly down", "selection test");
// left and up - selection should shrink
let xpos = SelectionHelperUI.endMark.xPos;
let ypos = SelectionHelperUI.endMark.yPos + 10;
yield touchdrag.start(gWindow, xpos, ypos, 105, 25);
yield waitForCondition(function () {
return getTrimmedSelection(gInput).toString() ==
"straight on like a tunnel for";
}, 6000, 2000);
touchdrag.end();
},
});
function test() {
if (!isLandscapeMode()) {
todo(false, "browser_selection_tests need landscape mode to run.");
return;
}
requestLongerTimeout(3);
runTests();
}

View File

@ -547,8 +547,11 @@ TouchDragAndHold.prototype = {
_timeoutStep: 2,
_numSteps: 50,
_debug: false,
_win: null,
callback: function callback() {
if (this._win == null)
return;
if (++this._step.steps >= this._numSteps) {
EventUtils.synthesizeTouchAtPoint(this._endPoint.xPos, this._endPoint.yPos,
{ type: "touchmove" }, this._win);