Skip to content

Commit

Permalink
Bug 834370 - Text area selection tests. r=rsilveira
Browse files Browse the repository at this point in the history
  • Loading branch information
jmathies committed Apr 19, 2013
1 parent 89514ff commit 80fd937
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 0 deletions.
2 changes: 2 additions & 0 deletions browser/metro/base/tests/mochitest/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ ifndef MOZ_DEBUG
BROWSER_TESTS += \
browser_selection_basic.js \
browser_selection_basic.html \
browser_selection_textarea.js \
browser_selection_textarea.html \
$(NULL)
endif

Expand Down
21 changes: 21 additions & 0 deletions browser/metro/base/tests/mochitest/browser_selection_textarea.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="texarea.html">
<div style="margin-left: 250px;">
<textarea wrap="on" style="width:800px; height:100px; overflow:scroll;" id="inputtext">
Alice was beginning to get very tired of sitting by her sister on the bank, and of having
nothing to do: once or twice she had peeped into the book her sister was reading, but it
had no pictures or conversations in it, `and what is the use of a book,' thought Alice
`without pictures or conversation?'

Either the well was very deep, or she fell very slowly, for she had plenty of time as she
went down to look about her and to wonder what was going to happen next. First, she tried
to look down and make out what she was coming to, but it was too dark to see anything;
then she looked at the sides of the well, and noticed that they were filled with cupboards
and book-shelves;(end)</textarea>
</div>
</body>
</html>
158 changes: 158 additions & 0 deletions browser/metro/base/tests/mochitest/browser_selection_textarea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/* -*- 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 gFrame = null;

const kMarkerOffsetY = 12;
const kCommonWaitMs = 5000;
const kCommonPollMs = 100;

///////////////////////////////////////////////////
// text area tests
///////////////////////////////////////////////////

function setUpAndTearDown() {
emptyClipboard();
if (gWindow)
clearSelection(gWindow);
if (gFrame)
clearSelection(gFrame);
yield waitForCondition(function () {
return !SelectionHelperUI.isSelectionUIVisible;
}, kCommonWaitMs, kCommonPollMs);
yield hideContextUI();
}

gTests.push({
desc: "normalize browser",
setUp: setUpAndTearDown,
tearDown: setUpAndTearDown,
run: function test() {
info(chromeRoot + "browser_selection_textarea.html");
yield addTab(chromeRoot + "browser_selection_textarea.html");

yield waitForCondition(function () {
return !StartUI.isStartPageVisible;
}, 10000, 100);

gWindow = Browser.selectedTab.browser.contentWindow;
InputSourceHelper.isPrecise = false;
},
});

gTests.push({
desc: "textarea basic selection",
setUp: setUpAndTearDown,
tearDown: setUpAndTearDown,
run: function test() {
let textarea = gWindow.document.getElementById("inputtext");
textarea.focus();

let promise = waitForEvent(document, "popupshown");
sendContextMenuClick(355, 50);
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;
ok(popupPromise && !(popupPromise instanceof Error), "promise error");

yield waitForCondition(function () {
return SelectionHelperUI.isSelectionUIVisible;
}, kCommonWaitMs, kCommonPollMs);

// check text selection
is(getTrimmedSelection(textarea).toString(), "pictures", "selection test");

clearSelection(textarea);
},
});

gTests.push({
desc: "textarea complex drag selection",
setUp: setUpAndTearDown,
tearDown: setUpAndTearDown,
run: function test() {
// work around for buggy context menu display
yield waitForMs(100);

let textarea = gWindow.document.getElementById("inputtext");

let promise = waitForEvent(document, "popupshown");
sendContextMenuClick(355, 50);
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;
ok(popupPromise && !(popupPromise instanceof Error), "promise error");

yield waitForCondition(function () {
return SelectionHelperUI.isSelectionUIVisible;
}, kCommonWaitMs, kCommonPollMs);

is(SelectionHelperUI.isActive, true, "selection active");
is(getTrimmedSelection(textarea).toString(), "pictures", "selection test");

let xpos = SelectionHelperUI.endMark.xPos;
let ypos = SelectionHelperUI.endMark.yPos + 10;

var touchdrag = new TouchDragAndHold();

// end marker and off the text area to the right
yield touchdrag.start(gWindow, xpos, ypos, 1200, 400);
let textLength = getTrimmedSelection(textarea).toString().length;
yield waitForCondition(function () {
let newTextLength = getTrimmedSelection(textarea).toString().length;
if (textLength != newTextLength) {
textLength = newTextLength;
return false;
}
return true;
}, 45000, 1000);

touchdrag.end();
touchdrag = null;

yield waitForCondition(function () {
return !SelectionHelperUI.hasActiveDrag;
}, kCommonWaitMs, kCommonPollMs);
yield SelectionHelperUI.pingSelectionHandler();

let text = getTrimmedSelection(textarea).toString();
let end = text.substring(text.length - "(end)".length);
is(end, "(end)", "selection test");
},
});

function test() {
if (isDebugBuild()) {
todo(false, "selection tests can't run in debug builds.");
return;
}

if (!isLandscapeMode()) {
todo(false, "browser_selection_tests need landscape mode to run.");
return;
}

requestLongerTimeout(3);
runTests();
}

0 comments on commit 80fd937

Please sign in to comment.