diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /layout/reftests/bidi/dirAuto/setDir.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/reftests/bidi/dirAuto/setDir.js')
-rw-r--r-- | layout/reftests/bidi/dirAuto/setDir.js | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/layout/reftests/bidi/dirAuto/setDir.js b/layout/reftests/bidi/dirAuto/setDir.js new file mode 100644 index 0000000000..829935e564 --- /dev/null +++ b/layout/reftests/bidi/dirAuto/setDir.js @@ -0,0 +1,247 @@ +function setAllDir(value) +{ + for (var i = 0; ; ++i) { + try { + theElement = document.getElementById("set" + i); + theElement.dir = value; + } catch(e) { + break; + } + } +} + +function setAllDirAttribute(value) +{ + for (var i = 0; ; ++i) { + try { + theElement = document.getElementById("set" + i); + theElement.setAttribute("dir", value); + } catch(e) { + break; + } + } +} + +function removeAllDirAttribute() +{ + for (var i = 0; ; ++i) { + try { + theElement = document.getElementById("set" + i); + theElement.removeAttribute("dir"); + } catch(e) { + break; + } + } +} + +function addOneElement(innerHTML) +{ + var container = document.getElementById("container"); + var elem = document.createElement("div"); + elem.innerHTML = innerHTML; + container.appendChild(elem); +} + +function addLTRAutoElements() +{ + addOneElement('<input type="text" value="ABC אבג" id="set0" dir="auto">'); + addOneElement('<span id="set1" dir="auto">ABC אבג</span>'); + addOneElement('<textarea id="set2" dir="auto">ABC אבג</textarea>'); + addOneElement('<button id="set3" dir="auto">ABC אבג</button>'); + addOneElement('<bdi id="set4">ABC אבג</bdi>'); +} + +function addRTLAutoElements() +{ + addOneElement('<input type="text" value="אבג ABC" id="set0" dir="auto">'); + addOneElement('<span id="set1" dir="auto">אבג ABC</span>'); + addOneElement('<textarea id="set2" dir="auto">אבג ABC</textarea>'); + addOneElement('<button id="set3" dir="auto">אבג ABC</button>'); + addOneElement('<bdi id="set4">אבג ABC</bdi>'); +} + +function setAllTextValuesTo(newText) +{ + for (var i = 0; ; ++i) { + theElement = document.getElementById("set" + i); + if (!theElement) { + break; + } + if (theElement.tagName == "INPUT" || + theElement.tagName == "TEXTAREA") { + theElement.value = newText; + } else { + theElement.firstChild.textContent = newText; + } + } +} + +function setAllTextDefaultValuesTo(newText) +{ + for (var i = 0; ; ++i) { + theElement = document.getElementById("set" + i); + if (!theElement) { + break; + } + if (theElement.tagName == "INPUT" || + theElement.tagName == "TEXTAREA") { + theElement.defaultValue = newText; + } else { + theElement.firstChild.textContent = newText; + } + } +} + +function setAllTextChildrenTo(newText) +{ + for (var i = 0; ; ++i) { + theElement = document.getElementById("set" + i); + if (!theElement) { + break; + } + if (theElement.tagName == "INPUT") { + theElement.value = newText; + } else { + theElement.firstChild.textContent = newText; + } + } +} + +function appendTextFromArray(textArray) +{ + for (var i = 0; ; ++i) { + theElement = document.getElementById("set" + i); + if (!theElement) { + break; + } + for (var j = 0; j < textArray.length; ++j) { + if (theElement.tagName == "INPUT") { + theElement.value += textArray[j]; + } else { + var textNode = document.createTextNode(textArray[j]); + theElement.appendChild(textNode); + } + } + } +} + +// Add the members of the array to the text content of the elements in +// the document, not including the last member. Then delete the last but +// one and add the last one +// Useful for testing scenarios like bug 1169267 +function appendDeleteAppendTextFromArray(textArray) +{ + if (textArray.length < 2) { + return; + } + + for (var i = 0; ; ++i) { + theElement = document.getElementById("set" + i); + if (!theElement) { + break; + } + var isInput = (theElement.tagName == "INPUT"); + if (!isInput) { + var textNode = document.createTextNode(""); + theElement.appendChild(textNode); + } + + for (var j = 0; j < textArray.length - 1; ++j) { + if (isInput) { + theElement.value += textArray[j]; + } else { + textNode.appendData(textArray[j]); + } + } + + // delete the last element added + var deleteElt = textArray[textArray.length - 2]; + if (isInput) { + theElement.value = theElement.value.slice(0, -deleteElt.length); + } else { + textNode.deleteData(textNode.length - deleteElt.length, + deleteElt.length); + } + + // add the next element + var addElt = textArray[textArray.length - 1]; + if (isInput) { + theElement.value += addElt; + } else { + textNode.appendData(addElt); + } + } +} + +function appendSpansFromArray(textArray) +{ + for (var i = 0; ; ++i) { + theElement = document.getElementById("set" + i); + if (!theElement) { + break; + } + for (var j = 0; j < textArray.length; ++j) { + // fake the result for elements that can't have markup content + if (theElement.tagName == "INPUT") { + theElement.value += textArray[j]; + } else if (theElement.tagName == "TEXTAREA") { + theElement.innerHTML += textArray[j]; + } else { + var span = document.createElement("span"); + span.innerHTML = textArray[j]; + theElement.appendChild(span); + } + } + } +} + +function prependTextFromArray(textArray) +{ + for (var i = 0; ; ++i) { + theElement = document.getElementById("set" + i); + if (!theElement) { + break; + } + for (var j = 0; j < textArray.length; ++j) { + if (theElement.tagName == "INPUT") { + theElement.value = textArray[j] + theElement.value; + } else { + var textNode = document.createTextNode(textArray[j]); + theElement.insertBefore(textNode, theElement.firstChild); + } + } + } +} + +function prependSpansFromArray(textArray) +{ + for (var i = 0; ; ++i) { + theElement = document.getElementById("set" + i); + if (!theElement) { + break; + } + for (var j = 0; j < textArray.length; ++j) { + // fake the result for elements that can't have markup content + if (theElement.tagName == "INPUT") { + theElement.value = textArray[j] + theElement.value; + } else if (theElement.tagName == "TEXTAREA") { + theElement.innerHTML = textArray[j] + theElement.innerHTML; + } else { + var span = document.createElement("span"); + span.innerHTML = textArray[j]; + theElement.insertBefore(span, theElement.firstChild); + } + } + } +} + +function removeElements() +{ + for (var i = 0; ; ++i) { + theElement = document.getElementById("set" + i); + if (!theElement) { + break; + } + theElement.remove(); + } +} |