blob: 06915a81a8b634be928a035537988518a36836ea [file] [log] [blame]
<!DOCTYPE HTML>
<title>Test of text field setSelectionRange</title>
<link rel="author" title="Takeharu.Oshida" href="mailto:georgeosddev@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-textarea/input-setselectionrange">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<div id="hide" style="display: block">
<input id="a" type="text" value="abcde">
<textarea id="b">abcde</textarea>
</div>
<script>
test(function() {
var input = document.getElementById("a");
test(function() {
assert_equals(typeof(input.setSelectionRange), "function", "element must have 'setSelectionRange' function");
},"input typeof(input.setSelectionRange)'");
test(function() {
assert_equals(input.setSelectionRange(0,1,"forward"),undefined,"setSelectionRange is void functuon");
},"input setSelectionRange return void");
test(function() {
input.setSelectionRange(0,1)
assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
},'input setSelectionRange(0,1)');
test(function() {
input.setSelectionRange(0,input.value.length+1)
assert_equals(input.selectionEnd, input.value.length, "Arguments greater than the length of the value of the text field must be treated as pointing at the end of the text field");
},'input setSelectionRange(0,input.value.length+1)');
test(function() {
input.setSelectionRange(2,2)
assert_equals(input.selectionStart, 2, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
assert_equals(input.selectionEnd, 2, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
},'input setSelectionRange(2,2)');
test(function() {
input.setSelectionRange(2,1)
assert_equals(input.selectionStart, 1, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
assert_equals(input.selectionEnd, 1, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
},'input setSelectionRange(2,1)');
test(function() {
input.setSelectionRange(0,1,"backward")
assert_equals(input.selectionDirection, "backward", 'The direction of the selection must be set to backward if direction is a case-sensitive match for the string "backward"');
},'input direction of setSelectionRange(0,1,"backward")');
test(function() {
input.setSelectionRange(0,1,"forward")
assert_equals(input.selectionDirection, "forward", 'The direction of the selection must be set to forward if direction is a case-sensitive match for the string "forward"');
},'input direction of setSelectionRange(0,1,"forward")');
test(function() {
input.setSelectionRange(0,1,"none")
assert_equals(input.selectionDirection, "none", 'The direction of the selection must be set to forward if direction is a case-sensitive match for the string "none"');
},'input direction of setSelectionRange(0,1,"none")');
test(function() {
input.setSelectionRange(0,1,"hoge")
assert_equals(input.selectionDirection, "none", "otherwise");
},'input direction of setSelectionRange(0,1,"hoge")');
test(function() {
input.setSelectionRange(0,1,"BACKWARD")
assert_equals(input.selectionDirection, "none", "selectionDirection should be 'none'");
},'input direction of setSelectionRange(0,1,"BACKWARD")');
test(function() {
input.setSelectionRange(0,1)
assert_equals(input.selectionDirection, "none", "if the argument is omitted");
},'input direction of setSelectionRange(0,1)');
test(function() {
input.setSelectionRange("string",1);
assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
},'input setSelectionRange("string",1)');
test(function() {
input.setSelectionRange(true,1);
assert_equals(input.selectionStart, 1, "element.selectionStart should be 1");
assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
},'input setSelectionRange(true,1)');
test(function() {
input.setSelectionRange([],1);
assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
},'input setSelectionRange([],1)');
test(function() {
input.setSelectionRange({},1);
assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
},'input setSelectionRange({},1)');
test(function() {
input.setSelectionRange(NaN,1);
assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
},'input setSelectionRange(NaN,1)');
test(function() {
input.setSelectionRange(null,1);
assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
},'input setSelectionRange(null,1)');
test(function() {
input.setSelectionRange(undefined,1);
assert_equals(input.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(input.selectionEnd, 1, "element.selectionEnd should be 1");
},'input setSelectionRange(undefined,1)');
},"test of input.setSelectionRange");
test(function() {
var textarea = document.getElementById("b");
test(function() {
assert_equals(typeof(textarea.setSelectionRange), "function", "element must have 'setSelectionRange' function");
},"textarea typeof(input.setSelectionRange)'");
test(function() {
assert_equals(textarea.setSelectionRange(0,1,"forward"),undefined,"setSelectionRange is void functuon");
},"textarea setSelectionRange return void");
test(function() {
textarea.setSelectionRange(0,1)
assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(textarea.selectionEnd, 1, "element.selectionEnd should be 1");
},'textarea setSelectionRange(0,1)');
test(function() {
textarea.setSelectionRange(0,textarea.value.length+1)
assert_equals(textarea.selectionEnd, textarea.value.length, "Arguments greater than the length of the value of the text field must be treated as pointing at the end of the text field");
},'textarea setSelectionRange(0,textarea.value.length+1)');
test(function() {
textarea.setSelectionRange(2,2)
assert_equals(textarea.selectionStart, 2, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
assert_equals(textarea.selectionEnd, 2, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
},'textarea setSelectionRange(2,2)');
test(function() {
textarea.setSelectionRange(2,1)
assert_equals(textarea.selectionStart, 1, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
assert_equals(textarea.selectionEnd, 1, "If end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end");
},'textarea setSelectionRange(2,1)');
test(function() {
textarea.setSelectionRange(0,1,"backward")
assert_equals(textarea.selectionDirection, "backward", 'The direction of the selection must be set to backward if direction is a case-sensitive match for the string "backward"');
},'textarea direction of setSelectionRange(0,1,"backward")');
test(function() {
textarea.setSelectionRange(0,1,"forward")
assert_equals(textarea.selectionDirection, "forward", 'The direction of the selection must be set to forward if direction is a case-sensitive match for the string "forward"');
},'textarea direction of setSelectionRange(0,1,"forward")');
test(function() {
textarea.setSelectionRange(0,1,"none")
assert_equals(textarea.selectionDirection, "none", 'The direction of the selection must be set to forward if direction is a case-sensitive match for the string "none"');
},'textarea direction of setSelectionRange(0,1,"none")');
test(function() {
textarea.setSelectionRange(0,1,"hoge")
assert_equals(textarea.selectionDirection, "none", "otherwise");
},'textarea direction of setSelectionRange(0,1,"hoge")');
test(function() {
textarea.setSelectionRange(0,1,"BACKWARD")
assert_equals(textarea.selectionDirection, "none", "selectionDirection should be 'none'");
},'textarea direction of setSelectionRange(0,1,"BACKWARD")');
test(function() {
textarea.setSelectionRange(0,1)
assert_equals(textarea.selectionDirection, "none", "if the argument is omitted");
},'textarea direction of setSelectionRange(0,1)');
test(function() {
textarea.setSelectionRange("string",1);
assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
},'textarea setSelectionRange("string",1)');
test(function() {
textarea.setSelectionRange(true,1);
assert_equals(textarea.selectionStart, 1, "element.selectionStart should be 1");
assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
},'textarea setSelectionRange(true,1)');
test(function() {
textarea.setSelectionRange([],1);
assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
},'textarea setSelectionRange([],1)');
test(function() {
textarea.setSelectionRange({},1);
assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
},'textarea setSelectionRange({},1)');
test(function() {
textarea.setSelectionRange(NaN,1);
assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
},'textarea setSelectionRange(NaN,1)');
test(function() {
textarea.setSelectionRange(null,1);
assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
},'textarea setSelectionRange(null,1)');
test(function() {
textarea.setSelectionRange(undefined,1);
assert_equals(textarea.selectionStart, 0, "element.selectionStart should be 0");
assert_equals(textarea.selectionEnd, 1, "element.selectionStart should be 1");
},'textarea setSelectionRange(undefined,1)');
},"test of textarea.setSelectionRange");
</script>