mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-06-06 08:29:08 +00:00
430 lines
16 KiB
HTML
430 lines
16 KiB
HTML
<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">
|
|
|
|
// Name of this test.
|
|
const TYPE_NAME = "Robocop:testInputSelections";
|
|
|
|
// 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", {});
|
|
|
|
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", {});
|
|
|
|
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", {});
|
|
|
|
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", {});
|
|
|
|
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", {});
|
|
|
|
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", {});
|
|
|
|
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>
|