Bug 1235510 - Remove obsolete robocop tests for SelectionHandler routines, r=jchen

This commit is contained in:
Mark Capella 2016-02-01 16:42:12 -05:00
Родитель 2a64663d9c
Коммит dcf9e0e5e8
7 изменённых файлов: 0 добавлений и 1790 удалений

Просмотреть файл

@ -1,136 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
Cu.import("resource://gre/modules/Messaging.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import('resource://gre/modules/Geometry.jsm');
const TYPE_NAME = "Robocop:testSelectionHandler";
/* ============================== Utility functions ================================================
*
* Common functions available to all tests.
*
*/
function getSelectionHandler() {
return (!this._selectionHandler) ?
this._selectionHandler = Services.wm.getMostRecentWindow("navigator:browser").SelectionHandler :
this._selectionHandler;
}
function getClipboard() {
return Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
}
function getTextValue(aElement) {
return aElement.value || aElement.textContent;
}
function todo(result, msg) {
return Messaging.sendRequestForResult({
type: TYPE_NAME,
todo: result,
msg: msg
});
}
function ok(result, msg) {
return Messaging.sendRequestForResult({
type: TYPE_NAME,
result: result,
msg: msg
});
}
function is(one, two, msg) {
return Messaging.sendRequestForResult({
type: TYPE_NAME,
result: one === two,
msg: msg + " : " + one + " === " + two
});
}
function isNot(one, two, msg) {
return Messaging.sendRequestForResult({
type: TYPE_NAME,
result: one !== two,
msg: msg + " : " + one + " !== " + two
});
}
function lessThan(n1, n2, msg) {
return Messaging.sendRequestForResult({
type: TYPE_NAME,
result: n1 < n2,
msg: msg + " : " + n1 + " < " + n2
});
}
function greaterThan(n1, n2, msg) {
return Messaging.sendRequestForResult({
type: TYPE_NAME,
result: n1 > n2,
msg: msg + " : " + n1 + " > " + n2
});
}
// Use fuzzy logic to compare screen coords.
function truncPoint(point) {
return new Point(Math.trunc(point.x), Math.trunc(point.y));
}
function pointEquals(p1, p2, msg) {
return Messaging.sendRequestForResult({
type: TYPE_NAME,
result: truncPoint(p1).equals(truncPoint(p2)),
msg: msg + " : " + p1.toString() + " == " + p2.toString()
});
}
function pointNotEquals(p1, p2, msg) {
return Messaging.sendRequestForResult({
type: TYPE_NAME,
result: !truncPoint(p1).equals(truncPoint(p2)),
msg: msg + " : " + p1.toString() + " == " + p2.toString()
});
}
function selectionExists(selection, msg) {
return Messaging.sendRequestForResult({
type: TYPE_NAME,
result: !truncPoint(selection.anchorPt).equals(truncPoint(selection.focusPt)),
msg: msg + " : anchor:" + selection.anchorPt.toString() +
" focus:" + selection.focusPt.toString()
});
}
function selectionEquals(s1, s2, msg) {
return Messaging.sendRequestForResult({
type: TYPE_NAME,
result: truncPoint(s1.anchorPt).equals(truncPoint(s2.anchorPt)) &&
truncPoint(s1.focusPt).equals(truncPoint(s2.focusPt)),
msg: msg
});
}
/* =================================================================================================
*
* After finish of all selection tests, wrap up and go home.
*
*/
function finishTests() {
Messaging.sendRequest({
type: TYPE_NAME,
result: true,
msg: "Done!",
done: true
});
}

Просмотреть файл

@ -1,432 +0,0 @@
<html>
<head>
<title>Automated RTL/LTR Text Selection tests for Input elements</title>
<meta name="viewport" content="initial-scale=1.0"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="SelectionUtils.js"></script>
<script type="application/javascript;version=1.8">
// Used to create handle movement events for SelectionHandler.
const ANCHOR = "ANCHOR";
const FOCUS = "FOCUS";
// Types of DOM nodes that serve as Selection Anchor/Focus nodes.
const DIV_NODE = "DIV";
const TEXT_NODE = "#text";
// Used to specifiy midpoint selection text left/right of center.
const EST_SEL_TEXT_BOUND_CHARS = 5;
// Used to create test scenarios, and verify results.
const LTR_INPUT_TEXT_VALUE = "This input text is one character short of it's maxmimum.";
const RTL_INPUT_TEXT_VALUE = "טקסט קלט זה קצר תו אחד של זה גדול.";
/* =================================================================================
*
* Start of all text selection tests, check initialization state.
*/
function startTests() {
testLTR_selectAll().
then(testRTL_selectAll).
then(testLTR_dragFocusHandleToSelf).
then(testLTR_dragAnchorHandleToSelf).
then(testRTL_dragFocusHandleToSelf).
then(testRTL_dragAnchorHandleToSelf).
then(finishTests, function(err) {
ok(false, "Error in selection test " + err);
finishTests();
});
}
/* =================================================================================
*
* LTR selectAll() test selects the entire single-line <input> element and ensures:
* ) The Selection exists.
* ) The Selection text matches an expected value.
*
* ) Assumptions about the DOM Selection Anchor node are correct.
* ) Assumptions about the DOM Selection Focus node are correct.
*
* ) The UI Selection anchor handle is aligned vertically with the focus handle.
* ) The UI Selection anchor handle is left of the focus handle.
*/
function testLTR_selectAll() {
// Select entire LTR Input element.
let sh = getSelectionHandler();
let element = document.getElementById("LTRInput");
element.value = LTR_INPUT_TEXT_VALUE;
sh.startSelection(element);
let selection = sh._getSelection();
let anchorNode = selection.anchorNode;
let anchorOffset = selection.anchorOffset;
let focusNode = selection.focusNode;
let focusOffset = selection.focusOffset;
let anchorPt = new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y);
let focusPt = new Point(sh._cache.focusPt.x, sh._cache.focusPt.y);
return Promise.all([
ok(sh.isSelectionActive(),
"testLTR_selectAll starts, selection should be active."),
is(sh._targetElement, element,
"LTR SelectionHandler reference is the node we provided."),
is(sh._getSelectedText(), LTR_INPUT_TEXT_VALUE,
"LTR Selection text should match expected value."),
isNot(anchorNode, element,
"LTR Selection Anchor isn't the LTRInput node."),
is(anchorNode.nodeName, DIV_NODE, "LTR Anchor node is a DIV node."),
ok(!document.contains(anchorNode), "LTR Anchor node is an anonymous DIV node."),
is(anchorNode.parentNode, element, "LTR Anchor node is a child of the LTRInput node."),
is(anchorOffset, 0,
"LTR Selection starts at Anchor node with offset 0."),
isNot(focusNode, element,
"LTR Selection Focus isn't the LTRInput node."),
is(focusNode.nodeName, TEXT_NODE, "LTR Focus node is a TEXT node."),
ok(!document.contains(focusNode), "LTR Focus node is an anonymous TEXT node."),
is(focusNode.parentNode, anchorNode, "LTR Focus node is a child of the Anchor DIV node."),
is(focusOffset, LTR_INPUT_TEXT_VALUE.length,
"LTR Selection ends at Focus node with offset of the LTRInput node length."),
is(anchorPt.y, focusPt.y,
"LTR UI Selection anchor should match focus vertically."),
lessThan(anchorPt.x, focusPt.x,
"LTR UI Selection anchor should be to the left of focus."),
]).then(function() {
// Close selection and complete test.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(!sh.isSelectionActive(),
"testLTR_selectAll finishes, selection should not be active."),
]);
});
}
/* =================================================================================
*
* RTL selectAll() test selects the entire single-line <input> element and ensures:
* ) The Selection exists.
* ) The Selection text matches an expected value.
*
* ) Assumptions about the DOM Selection Anchor node are correct.
* ) Assumptions about the DOM Selection Focus node are correct.
*
* ) The UI Selection anchor handle is aligned vertically with the focus handle.
* ) The UI Selection anchor handle is right of the focus handle.
*/
function testRTL_selectAll() {
// Select entire RTL Input element.
let sh = getSelectionHandler();
let element = document.getElementById("RTLInput");
element.value = RTL_INPUT_TEXT_VALUE;
sh.startSelection(element);
let selection = sh._getSelection();
let anchorNode = selection.anchorNode;
let anchorOffset = selection.anchorOffset;
let focusNode = selection.focusNode;
let focusOffset = selection.focusOffset;
let anchorPt = new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y);
let focusPt = new Point(sh._cache.focusPt.x, sh._cache.focusPt.y);
return Promise.all([
ok(sh.isSelectionActive(),
"testRTL_selectAll starts, selection should be active."),
is(sh._targetElement, element,
"RTL SelectionHandler reference is the node we provided."),
is(sh._getSelectedText(), RTL_INPUT_TEXT_VALUE,
"RTL Selection text should match expected value."),
isNot(anchorNode, element,
"RTL Selection Anchor isn't the RTLInput node."),
is(anchorNode.nodeName, DIV_NODE, "RTL Anchor node is a DIV node."),
ok(!document.contains(anchorNode), "RTL Anchor node is an anonymous DIV node."),
is(anchorNode.parentNode, element, "RTL Anchor node is a child of the RTLInput node."),
is(anchorOffset, 0,
"RTL Selection starts at Anchor node with offset 0."),
isNot(focusNode, element,
"RTL Selection Focus isn't the RTLInput node."),
is(focusNode.nodeName, TEXT_NODE, "RTL Focus node is a TEXT node."),
ok(!document.contains(focusNode), "RTL Focus node is an anonymous TEXT node."),
is(focusNode.parentNode, anchorNode, "RTL Focus node is a child of the Anchor DIV node."),
is(focusOffset, RTL_INPUT_TEXT_VALUE.length,
"RTL Selection ends at Focus node with offset of the RTLInput node length."),
is(anchorPt.y, focusPt.y,
"RTL UI Selection anchor should match focus vertically."),
greaterThan(anchorPt.x, focusPt.x,
"RTL UI Selection anchor should be to the right of focus."),
]).then(function() {
// Close selection and complete test.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(!sh.isSelectionActive(),
"testRTL_selectAll finishes, selection should not be active."),
]);
});
}
/* =================================================================================
*
* If we selectAll() in a LTR <input>, then:
* ) drag the focus handle to itself, the selected text, and the
* selection anchor and focus points should all remain the same.
*/
function testLTR_dragFocusHandleToSelf() {
// Select entire LTR Input element.
let sh = getSelectionHandler();
let element = document.getElementById("LTRInput");
element.value = LTR_INPUT_TEXT_VALUE;
sh.startSelection(element);
// Note initial Selection handle points.
let initialSelection =
{ anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
let initialSelectionText = sh._getSelectedText();
// Drag focus handle and note results.
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : FOCUS,
x : initialSelection.focusPt.x,
y : initialSelection.focusPt.y
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : FOCUS })
);
let focusDraggedSelection =
{ anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
let focusDragSelectionText = sh._getSelectedText();
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testLTR_dragFocusHandleToSelf - Test Starts."),
is(initialSelectionText, LTR_INPUT_TEXT_VALUE,
"LTR Selection text initially should match expected value."),
selectionExists(initialSelection,
"LTR Selection initially existed at points"),
is(focusDragSelectionText, LTR_INPUT_TEXT_VALUE,
"LTR Selection text after focus drag should match expected value."),
selectionExists(focusDraggedSelection,
"LTR Selection after focus drag existed at points"),
selectionEquals(focusDraggedSelection, initialSelection,
"LTR Selection points after focus drag " +
"should match initial selection points."),
ok(true, "testLTR_dragFocusHandleToSelf - Test Finishes."),
]);
}
/* =================================================================================
*
* If we selectAll() in a LTR <input>, then:
* ) drag the anchor handle to itself, the selected text, and the
* selection anchor and focus points should all remain the same.
*/
function testLTR_dragAnchorHandleToSelf() {
// Select entire LTR Input element.
let sh = getSelectionHandler();
let element = document.getElementById("LTRInput");
element.value = LTR_INPUT_TEXT_VALUE;
sh.startSelection(element);
// Note initial Selection handle points.
let initialSelection =
{ anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
let initialSelectionText = sh._getSelectedText();
// Drag anchor handle and note results.
// Note, due to edge case with border boundaries, we actually
// move inside a pixel, to maintain Selection position.
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : ANCHOR,
x : initialSelection.anchorPt.x,
y : initialSelection.anchorPt.y - 1
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : ANCHOR })
);
let anchorDraggedSelection =
{ anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
let anchorDragSelectionText = sh._getSelectedText();
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testLTR_dragAnchorHandleToSelf - Test Starts."),
is(initialSelectionText, LTR_INPUT_TEXT_VALUE,
"LTR Selection text initially should match expected value."),
selectionExists(initialSelection,
"LTR Selection initially existed at points"),
is(anchorDragSelectionText, LTR_INPUT_TEXT_VALUE,
"LTR Selection text after anchor drag should match expected value."),
selectionExists(anchorDraggedSelection,
"LTR Selection after anchor drag existed at points"),
selectionEquals(anchorDraggedSelection, initialSelection,
"LTR Selection points after anchor drag " +
"should match initial selection points."),
ok(true, "testLTR_dragAnchorHandleToSelf - Test Finishes."),
]);
}
/* =================================================================================
*
* If we selectAll() in a RTL <input>, then:
* ) drag the focus handle to itself, the selected text, and the
* selection anchor and focus points should all remain the same.
*/
function testRTL_dragFocusHandleToSelf() {
// Select entire RTL Input element.
let sh = getSelectionHandler();
let element = document.getElementById("RTLInput");
element.value = RTL_INPUT_TEXT_VALUE;
sh.startSelection(element);
// Note initial Selection handle points.
let initialSelection =
{ anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
let initialSelectionText = sh._getSelectedText();
// Drag focus handle and note results.
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : FOCUS,
x : initialSelection.focusPt.x,
y : initialSelection.focusPt.y
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : FOCUS })
);
let focusDraggedSelection =
{ anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
let focusDragSelectionText = sh._getSelectedText();
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testRTL_dragFocusHandleToSelf - Test Starts."),
is(initialSelectionText, RTL_INPUT_TEXT_VALUE,
"RTL Selection text initially should match expected value."),
selectionExists(initialSelection,
"RTL Selection initially existed at points"),
is(focusDragSelectionText, RTL_INPUT_TEXT_VALUE,
"RTL Selection text after focus drag should match expected value."),
selectionExists(focusDraggedSelection,
"RTL Selection after focus drag existed at points"),
selectionEquals(focusDraggedSelection, initialSelection,
"RTL Selection points after focus drag " +
"should match initial selection points."),
ok(true, "testRTL_dragFocusHandleToSelf - Test Finishes."),
]);
}
/* =================================================================================
*
* If we selectAll() in a RTL <input>, then:
* ) drag the anchor handle to itself, the selected text, and the
* selection anchor and focus points should all remain the same.
*/
function testRTL_dragAnchorHandleToSelf() {
// Select entire RTL Input element.
let sh = getSelectionHandler();
let element = document.getElementById("RTLInput");
element.value = RTL_INPUT_TEXT_VALUE;
sh.startSelection(element);
// Note initial Selection handle points.
let initialSelection =
{ anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
let initialSelectionText = sh._getSelectedText();
// Drag anchor handle and note results.
// Note, due to edge case with border boundaries, we actually
// move inside a pixel, to maintain Selection position.
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : ANCHOR,
x : initialSelection.anchorPt.x,
y : initialSelection.anchorPt.y - 1
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : ANCHOR })
);
let anchorDraggedSelection =
{ anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
let anchorDragSelectionText = sh._getSelectedText();
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testRTL_dragAnchorHandleToSelf - Test Starts."),
is(initialSelectionText, RTL_INPUT_TEXT_VALUE,
"RTL Selection text initially should match expected value."),
selectionExists(initialSelection,
"RTL Selection initially existed at points"),
is(anchorDragSelectionText, RTL_INPUT_TEXT_VALUE,
"RTL Selection text after anchor drag should match expected value."),
selectionExists(anchorDraggedSelection,
"RTL Selection after anchor drag existed at points"),
selectionEquals(anchorDraggedSelection, initialSelection,
"RTL Selection points after anchor drag " +
"should match initial selection points."),
ok(true, "testRTL_dragAnchorHandleToSelf - Test Finishes."),
]);
}
</script>
</head>
<body onload="startTests();">
<input id="LTRInput" dir="ltr" type="text" maxlength="57" size="57" value="">
<br>
<input id="RTLInput" dir="rtl" type="text" maxlength="35" size="35" value="">
</body>
</html>

Просмотреть файл

@ -1,434 +0,0 @@
<html>
<head>
<title>Automated Text Selection tests for Mobile</title>
<meta name="viewport" content="initial-scale=1.0"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="SelectionUtils.js"></script>
<script type="application/javascript;version=1.8">
const DIV_POINT_TEXT = "Under";
const INPUT_TEXT = "Text for select all in an <input>";
const PASTE_TEXT = "Text for testing paste";
const READONLY_INPUT_TEXT = "readOnly text";
const TEXTAREA_TEXT = "Text for select all in a <textarea>";
/* =================================================================================
*
* Start of all text selection tests, check initialization state.
*
*/
function startTests() {
testSelectAllDivs().
then(testSelectDivAtPoint).
then(testSelectInput).
then(testSelectTextarea).
then(testReadonlyInput).
then(testCloseSelection).
then(testStartSelectionFail).
then(testPaste).
then(testAttachCaret).
then(testAttachCaretFail).
then(finishTests, function(err) {
ok(false, "Error in selection test " + err);
finishTests();
});
}
/* =================================================================================
*
* "Select all" text selection tests, for <div> (non-editable) fields.
*
*/
function testSelectAllDivs() {
let sh = getSelectionHandler();
let selDiv = document.getElementById("selDiv");
let nonSelDiv = document.getElementById("nonSelDiv");
// Check the initial state of the selection handler, and selectable/non-selectable <div>s.
return Promise.all([
ok(!sh.isSelectionActive(), "Selection should not be active at start of testSelectAllDivs"),
ok(sh.canSelect(selDiv), "Can select selectable <div>"),
ok(!sh.canSelect(nonSelDiv), "Can't select non-selectable <div>"),
]).then(function() {
// Select all on a non-editable text node selects all the text in the page.
let startSelectionResult = sh.startSelection(selDiv);
let selection = sh._getSelection();
return Promise.all([
is(startSelectionResult, sh.ERROR_NONE,
"startSelection() should have completed successfully"),
ok(sh.isSelectionActive(), "Selection should be active now"),
is(selection.anchorNode, document.documentElement, "Anchor Node should be start of document"),
is(selection.anchorOffset, 0, "Anchor offset should be 0"),
is(selection.focusNode, document.body.lastChild, "Focus node should be lastChild of document"),
is(selection.focusOffset, document.body.lastChild.textContent.length, "Focus offset should be it's length"),
]);
});
}
/* =================================================================================
*
* "Select word-at-point" text selection test, for <div> (non-editable) field.
* "collapseToStart" test closes selection (Bug 864589).
*
*/
function testSelectDivAtPoint() {
let sh = getSelectionHandler();
let selDiv = document.getElementById("selDiv");
// Select word at point in <div>
let rect = selDiv.getBoundingClientRect();
let startSelectionResult = sh.startSelection(selDiv, {
mode: sh.SELECT_AT_POINT,
x: rect.left + 1,
y: rect.top + 1
});
let selection = sh._getSelection();
// Check the state of the selection handler after selecting at a point.
return Promise.all([
ok(sh.isSelectionActive(), "Selection should be active at start of testSelectDivAtPoint"),
is(startSelectionResult, sh.ERROR_NONE,
"startSelection() should have completed successfully"),
is(selection.toString(), DIV_POINT_TEXT, "The first word in the <div> was selected"),
]).then(function() {
// Check the state of the selection handler after collapsing a selection.
selection.collapseToStart();
return Promise.all([
ok(selection.collapsed, "Selection should be collapsed"),
ok(!sh.isSelectionActive(), "Selection should not be active"),
]);
});
}
/* =================================================================================
*
* "Select all" text selection test, for <input> (editable) field.
*
*/
function testSelectInput() {
let sh = getSelectionHandler();
let inputNode = document.getElementById("inputNode");
inputNode.value = INPUT_TEXT;
// Test that calling startSelection with an input selects all the text in the input.
return Promise.all([
ok(!sh.isSelectionActive(), "Selection should not be active at start of testSelectInput"),
ok(sh.canSelect(inputNode), "Can select selectable <input>"),
]).then(function() {
// Check the state of the selection handler after calling startSelection on it.
let startSelectionResult = sh.startSelection(inputNode);
let selection = sh._getSelection();
return Promise.all([
is(startSelectionResult, sh.ERROR_NONE,
"startSelection() should have completed successfully"),
ok(sh.isSelectionActive(), "Selection should be active"),
ok((sh._targetElement instanceof Ci.nsIDOMNSEditableElement), "Selected element is editable"),
is(selection.toString(), INPUT_TEXT, "All text in the <input> was selected"),
]);
});
}
/* =================================================================================
*
* "Select all" text selection test, for <textarea> (editable) field.
*
*/
function testSelectTextarea() {
let sh = getSelectionHandler();
let textareaNode = document.getElementById("textareaNode");
textareaNode.value = TEXTAREA_TEXT;
// Change (still-active) selection from previous <input> field to <textarea>
let startSelectionResult = sh.startSelection(textareaNode);
let selection = sh._getSelection();
return Promise.all([
ok(sh.isSelectionActive(), "Selection should be active at start of testSelectTextarea"),
is(startSelectionResult, sh.ERROR_NONE,
"startSelection() should have completed successfully"),
ok((sh._targetElement instanceof Ci.nsIDOMHTMLTextAreaElement), "Selected element is editable, and a <textarea>"),
is(selection.toString(), TEXTAREA_TEXT, "All text in the <textarea> was selected"),
]).then(function() {
// Collpase the selection to close it again.
selection.collapseToStart();
return Promise.all([
ok(!sh.isSelectionActive(), "Selection should not be active"),
]);
});
}
/* =================================================================================
*
* Ensure that readonly inputs aren't editable, and not subject to
* SelectionHandler actions such as "cut".
*
*/
function testReadonlyInput() {
let sh = getSelectionHandler();
let readOnlyNode = document.getElementById("readOnlyTextInput");
readOnlyNode.value = READONLY_INPUT_TEXT;
return Promise.all([
ok(!sh.isSelectionActive(), "Selection should not be active at start of testReadonlyInput"),
]).then(function() {
return Promise.all([
ok(!sh.isElementEditableText(readOnlyNode), "Selected element should be readOnly (not editable)"),
]);
});
}
/* =================================================================================
*
* Various text selection tests to end active selections, including:
* 1.) Clicking outside the selection.
* 2.) SelectionEnd or Tab:Selected messages from java.
*
*/
function testCloseSelection() {
let sh = getSelectionHandler();
let inputNode = document.getElementById("inputNode");
let browserApp = Services.wm.getMostRecentWindow("navigator:browser").BrowserApp;
inputNode.value = INPUT_TEXT;
// Check the initial state of the selection handler.
return Promise.all([
ok(!sh.isSelectionActive(), "Selection should not be active at start of testCloseSelection"),
// Various ways to close an active selection.
]).then(function() {
sh.startSelection(inputNode);
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: -1}));
return ok(sh.isSelectionActive(), "unrelated TextSelection:End should not close active selection");
}).then(function() {
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return ok(!sh.isSelectionActive(), "TextSelection:End should close active selection");
}).then(function() {
sh.startSelection(inputNode);
Services.obs.notifyObservers(null, "Tab:Selected", browserApp.selectedTab.id);
return ok(!sh.isSelectionActive(), "Tab:Selected should close active selection");
}).then(function() {
sh.startSelection(inputNode);
sh.handleEvent({ type: "pagehide", originalTarget: {} });
return ok(sh.isSelectionActive(), "unrelated pagehide should not close active selection");
}).then(function() {
sh.handleEvent({ type: "pagehide", originalTarget: document });
return ok(!sh.isSelectionActive(), "pagehide should close active selection");
}).then(function() {
sh.startSelection(inputNode);
sh.handleEvent({ type: "blur" });
return ok(!sh.isSelectionActive(), "blur should close active selection");
});
}
/* =================================================================================
*
* Various text selection tests to ensure we fail certain startSelection() requests.
*
*/
function testStartSelectionFail() {
let sh = getSelectionHandler();
return Promise.all([
ok(!sh.isSelectionActive(),
"Selection should not be active at start of testStartSelectionFail"),
]).then(function() {
// We cannot perform an invalid selection request.
let element = document.getElementById("inputNode");
let rect = element.getBoundingClientRect();
let startSelectionResult = sh.startSelection(element, {
mode: "fooMode",
x: rect.left + 1,
y: rect.top + 1
});
return Promise.all([
is(startSelectionResult, sh.START_ERROR_INVALID_MODE,
"startSelection() should have failed predictably."),
ok(!sh.isSelectionActive(), "We cannot select text with a bad mode request."),
]);
}).then(function() {
// Select all on a Button should fail.
let element = document.getElementById("inputButton");
let startSelectionResult = sh.startSelection(element);
return Promise.all([
is(startSelectionResult, sh.START_ERROR_NONTEXT_INPUT,
"startSelection() should have failed predictably."),
ok(!sh.isSelectionActive(), "We cannot select text in an input Button."),
]);
}).then(function() {
// We cannot Select Word where no point exists.
let element = document.getElementById("inputNode");
let rect = element.getBoundingClientRect();
let startSelectionResult = sh.startSelection(element, {
mode: sh.SELECT_AT_POINT,
x: -1000,
y: -1000
});
return Promise.all([
is(startSelectionResult, sh.START_ERROR_SELECT_WORD_FAILED,
"startSelection() should have failed predictably."),
ok(!sh.isSelectionActive(), "We cannot select text at a bad location request."),
]);
});
}
/* =================================================================================
*
* Test to ensure we can attach a Caret to an input field.
*
*/
function testAttachCaret() {
let sh = getSelectionHandler();
return Promise.all([
ok(!sh.isSelectionActive(), "Selection should not be active at start of testAttachCaret"),
]).then(function() {
let element = document.getElementById("inputNode");
element.value = INPUT_TEXT;
let attachCaretResult = sh.attachCaret(element);
return Promise.all([
is(attachCaretResult, sh.ERROR_NONE,
"attachCaret() should have completed successfully"),
]);
}).then(function() {
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(!sh.isSelectionActive(), "Selection should not be active at end of testAttachCaret"),
]);
});
}
/* =================================================================================
*
* Test to ensure we fail certain attachCaret() requests.
*
*/
function testAttachCaretFail() {
let sh = getSelectionHandler();
return Promise.all([
is(sh._activeType, sh.TYPE_NONE,
"Selection should not be active at start of testAttachCaretFail."),
]).then(function() {
// We cannot attach Caret into disabled input.
let element = document.getElementById("inputDisabled");
element.value = INPUT_TEXT;
let attachCaretResult = sh.attachCaret(element);
return Promise.all([
is(attachCaretResult, sh.ATTACH_ERROR_INCOMPATIBLE,
"attachCaret() should have failed predictably."),
is(sh._activeType, sh.TYPE_NONE,
"Selection should not be active at end of testAttachCaretFail."),
]);
});
}
/* =================================================================================
*
* Tests to ensure we can paste text inside editable elements
*
*/
function testPaste() {
let sh = getSelectionHandler();
let clipboard = getClipboard();
clipboard.copyString(PASTE_TEXT);
// Add a contentEditable element to the document.
let div = document.createElement("div");
div.contentEditable = true;
div.dataset.editable = true;
document.body.appendChild(div);
let elements = document.querySelectorAll("div, input, textarea");
let promises = [];
for (var i = 0; i < elements.length; i++) {
sh.startSelection(elements[i]);
if (sh.isElementEditableText(elements[i]) && !elements[i].disabled) {
sh.actions.PASTE.action(elements[i]);
}
if (elements[i].dataset.editable) {
promises.push(is(getTextValue(elements[i]), PASTE_TEXT, "Pasted correctly"));
promises.push(ok(sh.isElementEditableText(elements[i]), "Element is editable"));
} else {
promises.push(isNot(getTextValue(elements[i]), PASTE_TEXT, "Paste failed correctly"));
}
}
document.body.removeChild(div);
div = null;
return Promise.all(promises);
}
</script>
</head>
<body onload="startTests();">
<div id="selDiv">Under sufficiently extreme conditions, quarks may become
deconfined and exist as free particles. In the course of asymptotic freedom,
the strong interaction becomes weaker at higher temperatures. Eventually,
color confinement would be lost and an extremely hot plasma of freely moving
quarks and gluons would be formed. This theoretical phase of matter is called
quark-gluon plasma.[81] The exact conditions needed to give rise to this state
are unknown and have been the subject of a great deal of speculation and
experimentation. A recent estimate puts the needed temperature at
(1.90±0.02)×1012 Kelvin. While a state of entirely free quarks and gluons has
never been achieved (despite numerous attempts by CERN in the 1980s and 1990s),
recent experiments at the Relativistic Heavy Ion Collider have yielded evidence
for liquid-like quark matter exhibiting "nearly perfect" fluid motion.</div><br>
<div id="nonSelDiv" style="-moz-user-select: none;">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Proin in blandit magna, non porttitor augue.
Nam in neque sagittis, varius augue at, ornare velit. Vestibulum eget nisl
congue odio molestie scelerisque. Pellentesque ut augue orci. In hac habitasse
platea dictumst. Sed placerat tellus quis lacus condimentum, quis luctus elit
pellentesque. Mauris cursus neque diam, sit amet gravida quam porta ac.
Aliquam aliquam feugiat vestibulum. Proin commodo nulla ligula, in bibendum
massa euismod a. Ut ac lobortis dui. Ut id augue id arcu ornare suscipit eu
ornare lorem. Pellentesque nec dictum ante. Nam quis ligula ultricies, auctor
nunc vel, fringilla turpis. Nulla lacinia, leo ut egestas hendrerit, risus
ligula interdum enim, vel varius libero sem ut ligula.</div><br>
<input data-editable="true" id="inputNode" type="text"><br>
<textarea data-editable="true" id="textareaNode"></textarea><br>
<input id="readOnlyTextInput" type="text" readonly><br>
<input id="inputButton" type="button" value="Click me"><br>
<input id="inputDisabled" type="text" disabled><br>
</body>
</html>

Просмотреть файл

@ -1,752 +0,0 @@
<html>
<head>
<title>Automated RTL/LTR Text Selection tests for Textareas</title>
<meta name="viewport" content="initial-scale=1.0"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="SelectionUtils.js"></script>
<script type="application/javascript;version=1.8">
// Used to create handle movement events for SelectionHandler.
const ANCHOR = "ANCHOR";
const FOCUS = "FOCUS";
// Used to specifiy midpoint selection text left/right of center.
const EST_SEL_TEXT_BOUND_CHARS = 5;
// Used to ensure calculated coords for handle movement events get us
// "into" the next/prev line vertically.
const EST_SEL_LINE_CHG_PTS = 10;
// Distance between text selection lines. Reality tested, and also
// Used to perform multi-line selection selections.
let selectionLineHeight = 0;
/* =================================================================================
*
* Start of all text selection tests, check initialization state.
*/
function startTests() {
testLTR_selectionPoints().
then(testRTL_selectionPoints).
then(test_selectionLineHeight).
then(testLTR_moveFocusHandleDown).
then(testLTR_moveFocusHandleUp).
then(testLTR_moveAnchorHandleUp).
then(testLTR_moveAnchorHandleDown).
then(testRTL_moveFocusHandleDown).
then(testRTL_moveFocusHandleUp).
then(testRTL_moveAnchorHandleUp).
then(testRTL_moveAnchorHandleDown).
then(finishTests, function(err) {
ok(false, "Error in selection test " + err);
finishTests();
});
}
/* =================================================================================
*
* LTR Textarea test will create a single line selection in the middle of the element
* and ensure that the anchor point is to the left of the focus point.
*/
function testLTR_selectionPoints() {
// Select entire LTRTextArea.
let sh = getSelectionHandler();
let element = document.getElementById("LTRTextarea");
sh.startSelection(element);
return Promise.all([
ok(sh.isSelectionActive(),
"testLTR_selectionPoints starts, selection should be active."),
]).then(function() {
// setSelectionRange() (in editable elements), gets us a single-line selection of
// midpoint character +- EST_SEL_TEXT_BOUND_CHARS chars on either side.
let midpointSelCharOffset = (element.selectionStart + element.selectionEnd) / 2;
element.setSelectionRange(midpointSelCharOffset - EST_SEL_TEXT_BOUND_CHARS,
midpointSelCharOffset + EST_SEL_TEXT_BOUND_CHARS);
// Grab values that are cleared by closing selection.
let selection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
let midpointSelText = sh._getSelectedText();
// Close selection and complete test.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
selectionExists(selection, "LTR Selection existed at points"),
is(midpointSelText, " plasma of", "LTR Selection should match expected text"),
is(selection.anchorPt.y, selection.focusPt.y,
"LTR Selection anchorPt should match focusPt vertically"),
lessThan(selection.anchorPt.x, selection.focusPt.x,
"LTR Selection anchorPt should be the left of focusPt"),
ok(!sh.isSelectionActive(),
"testLTR_selectionPoints finishes, selection should not be active."),
]);
});
}
/* =================================================================================
*
* RTL Textarea test will create a single line selection in the middle of the element
* and ensure that the anchor point is to the right of the focus point.
*/
function testRTL_selectionPoints() {
// Select entire RTLTextArea.
let sh = getSelectionHandler();
let element = document.getElementById("RTLTextarea");
sh.startSelection(element);
return Promise.all([
ok(sh.isSelectionActive(),
"testRTL_selectionPoints starts, selection should be active."),
]).then(function() {
// setSelectionRange() (in editable elements), gets us a single-line selection of
// midpoint character +- EST_SEL_TEXT_BOUND_CHARS chars on either side.
let midpointSelCharOffset = (element.selectionStart + element.selectionEnd) / 2;
element.setSelectionRange(midpointSelCharOffset - EST_SEL_TEXT_BOUND_CHARS,
midpointSelCharOffset + EST_SEL_TEXT_BOUND_CHARS);
// Grab values that are cleared by closing selection.
let selection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
let midpointSelText = sh._getSelectedText();
// Close selection and complete test.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
selectionExists(selection, "RTL Selection existed at points"),
is(midpointSelText, "ל גם את הב", "RTL Selection should match expected text"),
is(selection.anchorPt.y, selection.focusPt.y,
"RTL Selection anchorPt should match focusPt vertically"),
greaterThan(selection.anchorPt.x, selection.focusPt.x,
"RTL Selection anchorPt should be to the right of focusPt"),
ok(!sh.isSelectionActive(),
"testRTL_selectionPoints finishes, selection should not be active."),
]);
});
}
/* =================================================================================
*
* Textarea test will create (a) a single-line selection in the middle of the element,
* move the focus handle down a line creating (b) a two-line selection, and then
* ensure that the vertical distance between the bottom of (a) and (b) is > 0.
*
* The result is used later to ensure more-precise handle up/down movements.
*/
function test_selectionLineHeight() {
let sh = getSelectionHandler();
let element = document.getElementById("LTRTextarea");
let initialSelection = null;
let changedSelection = null;
// Select entire textarea, refine selection to midpoint string.
sh.startSelection(element);
let midpointSelCharOffset = (element.selectionStart + element.selectionEnd) / 2;
element.setSelectionRange(midpointSelCharOffset - EST_SEL_TEXT_BOUND_CHARS,
midpointSelCharOffset + EST_SEL_TEXT_BOUND_CHARS);
// Note initial selection points.
initialSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Force selection focus to next lower line (estimate distance required).
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : FOCUS,
x : initialSelection.focusPt.x,
y : initialSelection.focusPt.y + EST_SEL_LINE_CHG_PTS
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : FOCUS })
);
// Note changed selection points after handle movement.
changedSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Note selection line height for reality test,
// and later handle movement calculations.
selectionLineHeight = changedSelection.focusPt.y - initialSelection.focusPt.y;
return Promise.all([
ok(sh.isSelectionActive(),
"test_selectionLineHeight starts, selection should be active."),
]).then(function() {
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
greaterThan(selectionLineHeight, 0, "Distance from one line to another " +
"in a multi-line selection is greater than 0."),
ok(!sh.isSelectionActive(),
"test_selectionLineHeight finishes, selection should not be active."),
]);
});
}
/* =================================================================================
*
* LTR Textarea test will create a single-line selection in the middle of the element
* and ensure that handle reversals are detected as expected.
*
* This tests what happens during focus handle down movements.
*/
function testLTR_moveFocusHandleDown() {
let sh = getSelectionHandler();
let element = document.getElementById("LTRTextarea");
let initialSelection = null;
let changedSelection = null;
// Select entire textarea, refine selection to midpoint string.
sh.startSelection(element);
let midpointSelCharOffset = (element.selectionStart + element.selectionEnd) / 2;
element.setSelectionRange(midpointSelCharOffset - EST_SEL_TEXT_BOUND_CHARS,
midpointSelCharOffset + EST_SEL_TEXT_BOUND_CHARS);
// Note initial selection points.
initialSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Force selection focus to next lower line (estimate distance required).
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : FOCUS,
x : initialSelection.focusPt.x,
y : initialSelection.focusPt.y + EST_SEL_LINE_CHG_PTS
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : FOCUS })
);
// Note changed selection points after handle movement.
changedSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testLTR_moveFocusHandleDown - Test Starts."),
selectionExists(initialSelection, "LTR Initial selection existed at points"),
is(initialSelection.anchorPt.y, initialSelection.focusPt.y,
"LTR Initial selection anchorPt.y should match focusPt.y"),
lessThan(initialSelection.anchorPt.x, initialSelection.focusPt.x,
"LTR Initial selection anchorPt.x should be less than (left of) focusPt.x"),
selectionExists(changedSelection, "LTR Changed selection existed at points"),
pointEquals(changedSelection.anchorPt, initialSelection.anchorPt,
"LTR Changed selection focus handle moving down " +
"should not change anchor handle."),
greaterThan(changedSelection.focusPt.y, changedSelection.anchorPt.y,
"LTR Changed selection focusPt.y " +
"should be greater than (below) changed anchorPt.y"),
greaterThan(changedSelection.focusPt.y, initialSelection.focusPt.y,
"LTR Changed selection focusPt.y " +
"should be greater than (below) Initial selection focusPt.y"),
]);
}
/* =================================================================================
*
* LTR Textarea test will create a single-line selection in the middle of the element
* and ensure that handle reversals are detected as expected.
*
* This tests what happens during focus handle up movements.
*/
function testLTR_moveFocusHandleUp() {
let sh = getSelectionHandler();
let element = document.getElementById("LTRTextarea");
let initialSelection = null;
let changedSelection = null;
// Select entire textarea, refine selection to midpoint string.
sh.startSelection(element);
let midpointSelCharOffset = (element.selectionStart + element.selectionEnd) / 2;
element.setSelectionRange(midpointSelCharOffset - EST_SEL_TEXT_BOUND_CHARS,
midpointSelCharOffset + EST_SEL_TEXT_BOUND_CHARS);
// Note initial selection points.
initialSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Force selection focus to next upper line (estimate distance required).
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : FOCUS,
x : initialSelection.focusPt.x,
y : initialSelection.focusPt.y - selectionLineHeight - EST_SEL_LINE_CHG_PTS
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : FOCUS })
);
// Note changed selection points after handle movement.
changedSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testLTR_moveFocusHandleUp - Test Starts."),
selectionExists(initialSelection, "LTR Initial selection existed at points"),
is(initialSelection.anchorPt.y, initialSelection.focusPt.y,
"LTR Initial selection anchorPt.y should match focusPt.y"),
lessThan(initialSelection.anchorPt.x, initialSelection.focusPt.x,
"LTR Initial selection anchorPt.x should be less than (left of) focusPt.x"),
selectionExists(changedSelection, "LTR Changed selection existed at points"),
pointEquals(changedSelection.focusPt, initialSelection.anchorPt,
"LTR Reversed Changed selection focus handle moving up " +
"becomes new anchor handle, " +
"new focus handle is initial anchor handle."),
greaterThan(changedSelection.focusPt.y, changedSelection.anchorPt.y,
"LTR Reversed Changed selection focusPt.y " +
"should be greater than (below) changed anchorPt.y"),
is(changedSelection.focusPt.y, initialSelection.focusPt.y,
"LTR Reversed Changed selection focusPt.y " +
"should be equal-to Initial selection focusPt.y"),
lessThan(changedSelection.anchorPt.y, initialSelection.anchorPt.y,
"LTR Reversed Changed selection anchorPt.y " +
"should be less than (above) Initial selection anchorPt.y"),
]);
}
/* =================================================================================
*
* LTR Textarea test will create a single-line selection in the middle of the element
* and ensure that handle reversals are detected as expected.
*
* This tests what happens during anchor handle up movements.
*/
function testLTR_moveAnchorHandleUp() {
let sh = getSelectionHandler();
let element = document.getElementById("LTRTextarea");
let initialSelection = null;
let changedSelection = null;
// Select entire textarea, refine selection to midpoint string.
sh.startSelection(element);
let midpointSelCharOffset = (element.selectionStart + element.selectionEnd) / 2;
element.setSelectionRange(midpointSelCharOffset - EST_SEL_TEXT_BOUND_CHARS,
midpointSelCharOffset + EST_SEL_TEXT_BOUND_CHARS);
// Note initial selection points.
initialSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Force selection anchor to next upper line (estimate distance required).
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : ANCHOR,
x : initialSelection.anchorPt.x,
y : initialSelection.anchorPt.y - selectionLineHeight - EST_SEL_LINE_CHG_PTS
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : ANCHOR })
);
// Note changed selection points after handle movement.
changedSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testLTR_moveAnchorHandleUp - Test Starts."),
selectionExists(initialSelection, "LTR Initial selection existed at points"),
is(initialSelection.anchorPt.y, initialSelection.focusPt.y,
"LTR Initial selection anchorPt.y should match focusPt.y"),
lessThan(initialSelection.anchorPt.x, initialSelection.focusPt.x,
"LTR Initial selection anchorPt.x should be less than (left of) focusPt.x"),
selectionExists(changedSelection, "LTR Changed selection existed at points"),
pointEquals(changedSelection.focusPt, initialSelection.focusPt,
"LTR Changed selection anchor handle moving up " +
"should not change focus handle."),
greaterThan(changedSelection.focusPt.y, changedSelection.anchorPt.y,
"LTR Changed selection focusPt.y " +
"should be greater than (below) changed anchorPt.y"),
lessThan(changedSelection.anchorPt.y, initialSelection.anchorPt.y,
"LTR Changed selection anchorPt.y " +
"should be less than (above) Initial selection anchorPt.y"),
]);
}
/* =================================================================================
*
* LTR Textarea test will create a single-line selection in the middle of the element
* and ensure that handle reversals are detected as expected.
*
* This tests what happens during anchor handle down movements.
*/
function testLTR_moveAnchorHandleDown() {
let sh = getSelectionHandler();
let element = document.getElementById("LTRTextarea");
let initialSelection = null;
let changedSelection = null;
// Select entire textarea, refine selection to midpoint string.
sh.startSelection(element);
let midpointSelCharOffset = (element.selectionStart + element.selectionEnd) / 2;
element.setSelectionRange(midpointSelCharOffset - EST_SEL_TEXT_BOUND_CHARS,
midpointSelCharOffset + EST_SEL_TEXT_BOUND_CHARS);
// Note initial selection points.
initialSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Force selection anchor to next lower line (estimate distance required).
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : ANCHOR,
x : initialSelection.anchorPt.x,
y : initialSelection.anchorPt.y + EST_SEL_LINE_CHG_PTS
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : ANCHOR })
);
// Note changed selection points after handle movement.
changedSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testLTR_moveAnchorHandleDown - Test Starts."),
selectionExists(initialSelection, "LTR Initial selection existed at points"),
is(initialSelection.anchorPt.y, initialSelection.focusPt.y,
"LTR Initial selection anchorPt.y should match focusPt.y"),
lessThan(initialSelection.anchorPt.x, initialSelection.focusPt.x,
"LTR Initial selection anchorPt.x should be less than (left of) focusPt.x"),
selectionExists(changedSelection, "LTR Changed selection existed at points"),
pointEquals(changedSelection.anchorPt, initialSelection.focusPt,
"LTR Reversed Changed selection anchor handle moving down " +
"becomes new focus handle, " +
"new anchor handle is initial focus handle."),
greaterThan(changedSelection.focusPt.y, changedSelection.anchorPt.y,
"LTR Reversed Changed selection focusPt.y " +
"should be greater than (below) changed anchorPt.y"),
is(changedSelection.anchorPt.y, initialSelection.anchorPt.y,
"LTR Reversed Changed selection anchorPt.y " +
"should be equal to Initial selection anchorPt.y"),
greaterThan(changedSelection.focusPt.y, initialSelection.focusPt.y,
"LTR Reversed Changed selection focusPt.y " +
"should be greater than (below) Initial selection focusPt.y"),
]);
}
/* =================================================================================
*
* RTL Textarea test will create a single-line selection in the middle of the element
* and ensure that handle reversals are detected as expected.
*
* This tests what happens during focus handle down movements.
*/
function testRTL_moveFocusHandleDown() {
let sh = getSelectionHandler();
let element = document.getElementById("RTLTextarea");
let initialSelection = null;
let changedSelection = null;
// Select entire textarea, refine selection to midpoint string.
sh.startSelection(element);
let midpointSelCharOffset = (element.selectionStart + element.selectionEnd) / 2;
element.setSelectionRange(midpointSelCharOffset - EST_SEL_TEXT_BOUND_CHARS,
midpointSelCharOffset + EST_SEL_TEXT_BOUND_CHARS);
// Note initial selection points.
initialSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Force selection focus to next lower line (estimate distance required).
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : FOCUS,
x : initialSelection.focusPt.x,
y : initialSelection.focusPt.y + EST_SEL_LINE_CHG_PTS
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : FOCUS })
);
// Note changed selection points after handle movement.
changedSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testRTL_moveFocusHandleDown - Test Starts."),
selectionExists(initialSelection, "RTL Initial selection existed at points"),
is(initialSelection.anchorPt.y, initialSelection.focusPt.y,
"RTL Initial selection anchorPt.y should match focusPt.y"),
greaterThan(initialSelection.anchorPt.x, initialSelection.focusPt.x,
"RTL Initial selection anchorPt.x should be greater than (right of) focusPt.x"),
selectionExists(changedSelection, "RTL Changed selection existed at points"),
pointEquals(changedSelection.anchorPt, initialSelection.anchorPt,
"RTL Changed selection focus handle moving down " +
"should not change anchor handle position."),
greaterThan(changedSelection.focusPt.y, changedSelection.anchorPt.y,
"RTL Changed selection focusPt.y " +
"should be greater than (below) changed anchorPt.y"),
greaterThan(changedSelection.focusPt.y, initialSelection.focusPt.y,
"RTL Changed selection focusPt.y " +
"should be greater than (below) Initial selection focusPt.y"),
]);
}
/* =================================================================================
*
* RTL Textarea test will create a single-line selection in the middle of the element
* and ensure that handle reversals are detected as expected.
*
* This tests what happens during focus handle up movements.
*/
function testRTL_moveFocusHandleUp() {
let sh = getSelectionHandler();
let element = document.getElementById("RTLTextarea");
let initialSelection = null;
let changedSelection = null;
// Select entire textarea, refine selection to midpoint string.
sh.startSelection(element);
let midpointSelCharOffset = (element.selectionStart + element.selectionEnd) / 2;
element.setSelectionRange(midpointSelCharOffset - EST_SEL_TEXT_BOUND_CHARS,
midpointSelCharOffset + EST_SEL_TEXT_BOUND_CHARS);
// Note initial selection points.
initialSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Force selection focus to next upper line (estimate distance required).
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : FOCUS,
x : initialSelection.focusPt.x,
y : initialSelection.focusPt.y - selectionLineHeight - EST_SEL_LINE_CHG_PTS
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : FOCUS })
);
// Note changed selection points after handle movement.
changedSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testRTL_moveFocusHandleUp - Test Starts."),
selectionExists(initialSelection, "RTL Initial selection existed at points"),
is(initialSelection.anchorPt.y, initialSelection.focusPt.y,
"RTL Initial selection anchorPt.y should match focusPt.y"),
greaterThan(initialSelection.anchorPt.x, initialSelection.focusPt.x,
"RTL Initial selection anchorPt.x should be greater than (right of) focusPt.x"),
selectionExists(changedSelection, "RTL Changed selection existed at points"),
pointEquals(changedSelection.focusPt, initialSelection.anchorPt,
"RTL Reversed Changed selection focus handle moving up " +
"becomes new anchor handle, " +
"new focus handle is initial anchor handle."),
greaterThan(changedSelection.focusPt.y, changedSelection.anchorPt.y,
"RTL Reversed Changed selection focusPt.y " +
"should be greater than (below) changed anchorPt.y"),
is(changedSelection.focusPt.y, initialSelection.focusPt.y,
"RTL Reversed Changed selection focusPt.y " +
"should be equal to Initial selection focusPt.y"),
lessThan(changedSelection.anchorPt.y, initialSelection.anchorPt.y,
"RTL Reversed Changed selection anchorPt.y " +
"should be less than (above) Initial selection anchorPt.y"),
]);
}
/* =================================================================================
*
* RTL Textarea test will create a single-line selection in the middle of the element
* and ensure that handle reversals are detected as expected.
*
* This tests what happens during anchor handle up movements.
*/
function testRTL_moveAnchorHandleUp() {
let sh = getSelectionHandler();
let element = document.getElementById("RTLTextarea");
let initialSelection = null;
let changedSelection = null;
// Select entire textarea, refine selection to midpoint string.
sh.startSelection(element);
let midpointSelCharOffset = (element.selectionStart + element.selectionEnd) / 2;
element.setSelectionRange(midpointSelCharOffset - EST_SEL_TEXT_BOUND_CHARS,
midpointSelCharOffset + EST_SEL_TEXT_BOUND_CHARS);
// Note initial selection points.
initialSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Force selection anchor to next upper line (estimate distance required).
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : ANCHOR,
x : initialSelection.anchorPt.x,
y : initialSelection.anchorPt.y - selectionLineHeight - EST_SEL_LINE_CHG_PTS
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : ANCHOR })
);
// Note changed selection points after handle movement.
changedSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testRTL_moveAnchorHandleUp - Test Starts."),
selectionExists(initialSelection, "RTL Initial selection existed at points"),
is(initialSelection.anchorPt.y, initialSelection.focusPt.y,
"RTL Initial selection anchorPt.y should match focusPt.y"),
greaterThan(initialSelection.anchorPt.x, initialSelection.focusPt.x,
"RTL Initial selection anchorPt.x should be greater than (right of) focusPt.x"),
selectionExists(changedSelection, "RTL Changed selection existed at points"),
pointEquals(changedSelection.focusPt, initialSelection.focusPt,
"RTL Changed selection anchor handle moving up " +
"should not change focus handle position."),
greaterThan(changedSelection.focusPt.y, changedSelection.anchorPt.y,
"RTL Changed selection focusPt.y " +
"should be greater than (below) changed anchorPt.y"),
lessThan(changedSelection.anchorPt.y, initialSelection.anchorPt.y,
"RTL Changed selection anchorPt.y " +
"should be less than (above) Initial selection anchorPt.y"),
]);
}
/* =================================================================================
*
* RTL Textarea test will create a single-line selection in the middle of the element
* and ensure that handle reversals are detected as expected.
*
* This tests what happens during anchor handle down movements.
*/
function testRTL_moveAnchorHandleDown() {
let sh = getSelectionHandler();
let element = document.getElementById("RTLTextarea");
let initialSelection = null;
let changedSelection = null;
// Select entire textarea, refine selection to midpoint string.
sh.startSelection(element);
let midpointSelCharOffset = (element.selectionStart + element.selectionEnd) / 2;
element.setSelectionRange(midpointSelCharOffset - EST_SEL_TEXT_BOUND_CHARS,
midpointSelCharOffset + EST_SEL_TEXT_BOUND_CHARS);
// Note initial selection points.
initialSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Force selection anchor to next lower line (estimate distance required).
Services.obs.notifyObservers(null, "TextSelection:Move",
JSON.stringify({ handleType : ANCHOR,
x : initialSelection.anchorPt.x,
y : initialSelection.anchorPt.y + EST_SEL_LINE_CHG_PTS
})
);
Services.obs.notifyObservers(null, "TextSelection:Position",
JSON.stringify({ handleType : ANCHOR })
);
// Note changed selection points after handle movement.
changedSelection = { anchorPt : new Point(sh._cache.anchorPt.x, sh._cache.anchorPt.y),
focusPt : new Point(sh._cache.focusPt.x, sh._cache.focusPt.y) };
// Complete test, and report.
Services.obs.notifyObservers(null, "TextSelection:End",
JSON.stringify({selectionID: sh._selectionID}));
return Promise.all([
ok(true, "testRTL_moveAnchorHandleDown - Test Starts."),
selectionExists(initialSelection, "RTL Initial selection existed at points"),
is(initialSelection.anchorPt.y, initialSelection.focusPt.y,
"RTL Initial selection anchorPt.y should match focusPt.y"),
greaterThan(initialSelection.anchorPt.x, initialSelection.focusPt.x,
"RTL Initial selection anchorPt.x should be greater than (right of) focusPt.x"),
selectionExists(changedSelection, "RTL Changed selection existed at points"),
pointEquals(changedSelection.anchorPt, initialSelection.focusPt,
"RTL Reversed Changed selection anchor handle moving down " +
"becomes new focus handle, " +
"new anchor handle is initial focus handle."),
greaterThan(changedSelection.focusPt.y, changedSelection.anchorPt.y,
"RTL Reversed Changed selection focusPt.y " +
"should be greater than (below) changed anchorPt.y"),
is(changedSelection.anchorPt.y, initialSelection.anchorPt.y,
"RTL Reversed Changed selection anchorPt.y " +
"should be equal to Initial selection anchorPt.y"),
greaterThan(changedSelection.focusPt.y, initialSelection.focusPt.y,
"RTL Reversed Changed selection focusPt.y " +
"should be greater than (below) Initial selection focusPt.y"),
]);
}
</script>
</head>
<body onload="startTests();">
<textarea id="LTRTextarea" style="direction: ltr;" rows="10" cols="40"
readonly="true">Under sufficiently extreme conditions, quarks may become deconfined and exist as free particles. In the course of asymptotic freedom, the strong interaction becomes weaker at higher temperatures. Eventually, color confinement would be lost and an extremely hot plasma of freely moving quarks and gluons would be formed. This theoretical phase of matter is called quark-gluon plasma.[81] The exact conditions needed to give rise to this state are unknown and have been the subject of a great deal of speculation and experimentation.</textarea>
<textarea id="RTLTextarea" style="direction: rtl;" rows="10" cols="40"
readonly="true">טטיאנה קוזמינה, שהייתה 18, תלמיד תיכון בעפולה, עלה לישראל לפני כשנים עם האמא שלה, שהיה נשואה לאזרח ישראלי, כאשר אביה הביולוגי חתם על מסמך המאשר את המהלך שלה לישראל. האמא שלה היא בתהליך של התאזרחות חשב שזה כולל גם את הבת שלה, אבל ברגע שהיא הבינה כבר לפני כמה חודשים שהחברה המאוחדת לא נכללה בו, דחה את הבקשה לעבד גם לבת שלה. ואז הם קיבלו את הגור.וחד-קרן הגיעה, אבל הם לא הצליחו למצוא את קשת אז כולם אכלו ספגטי וכנפיים בופל חמים.</textarea>
</body>
</html>

Просмотреть файл

@ -1,12 +0,0 @@
package org.mozilla.gecko.tests;
public class testInputSelections extends SelectionHandlerTest {
public testInputSelections() {
super("chrome://roboextender/content/testInputSelections.html");
}
public void testInputSelections() {
super.testSelection();
}
}

Просмотреть файл

@ -1,12 +0,0 @@
package org.mozilla.gecko.tests;
public class testSelectionHandler extends SelectionHandlerTest {
public testSelectionHandler() {
super("chrome://roboextender/content/testSelectionHandler.html");
}
public void testSelectionHandler() {
super.testSelection();
}
}

Просмотреть файл

@ -1,12 +0,0 @@
package org.mozilla.gecko.tests;
public class testTextareaSelections extends SelectionHandlerTest {
public testTextareaSelections() {
super("chrome://roboextender/content/testTextareaSelections.html");
}
public void testTextareaSelections() {
super.testSelection();
}
}