3 <script src=
"../../resources/js-test.js"></script>
6 <p>This tests for problems where we'd lose the selection in a textarea when making style and value changes.
</p>
7 <div id=
"console"></div>
8 <form id=
"form"><textarea id=
"ta">abc123
10 <script type=
"text/javascript">
11 var ta
= document
.getElementById('ta');
12 debug("- default value");
13 shouldBe('ta.selectionStart', '0');
14 shouldBe('ta.selectionEnd', '0');
15 debug("- set selectionStart/End");
16 ta
.selectionStart
= 3;
18 shouldBe('ta.selectionStart', '3');
19 shouldBe('ta.selectionEnd', '4');
20 debug("- add background style");
21 ta
.setAttribute("style", "background-color: yellow");
22 shouldBe('ta.selectionStart', '3');
23 shouldBe('ta.selectionEnd', '4');
24 debug("- set value to same value");
25 ta
.value
= "abc123\n";
26 shouldBe('ta.selectionStart', '3');
27 shouldBe('ta.selectionEnd', '4');
28 debug("- set value to a different value");
30 shouldBe('ta.selectionStart', '6');
31 shouldBe('ta.selectionEnd', '6');
32 debug("- set selection so we can test again without a trailing newline");
33 ta
.selectionStart
= 3;
35 ta
.removeAttribute("style");
36 shouldBe('ta.selectionStart', '3');
37 shouldBe('ta.selectionEnd', '4');
38 debug("- add background style");
39 ta
.setAttribute("style", "background-color: yellow");
40 shouldBe('ta.selectionStart', '3');
41 shouldBe('ta.selectionEnd', '4');
42 debug("- set value to same value");
44 shouldBe('ta.selectionStart', '3');
45 shouldBe('ta.selectionEnd', '4');
47 debug("- reset form");
49 shouldBe('ta.selectionStart', '7');
50 shouldBe('ta.selectionEnd', '7');
52 debug("- set new defaultValue");
53 ta
.defaultValue
= 'abc123456';
54 shouldBe('ta.selectionStart', '9');
55 shouldBe('ta.selectionEnd', '9');
57 debug("- set same defaultValue");
58 ta
.setSelectionRange(2, 3);
59 ta
.defaultValue
= 'abc123456';
60 shouldBe('ta.selectionStart', '9');
61 shouldBe('ta.selectionEnd', '9');
63 debug("- append a text node");
64 ta
.appendChild(document
.createTextNode('foo'));
65 shouldBe('ta.selectionStart', '12');
66 shouldBe('ta.selectionEnd', '12');
68 debug("- append a empty text node");
69 ta
.setSelectionRange(2, 3);
70 ta
.appendChild(document
.createTextNode(''));
71 shouldBe('ta.selectionStart', '12');
72 shouldBe('ta.selectionEnd', '12');