darin@apple.com | fd245ad | 2008-12-13 23:02:11 +0000 | [diff] [blame] | 1 | <html> |
| 2 | <head> |
mark.lam@apple.com | 93720da | 2013-09-07 23:31:07 +0000 | [diff] [blame] | 3 | <script src="../../resources/js-test-pre.js"></script> |
darin@apple.com | fd245ad | 2008-12-13 23:02:11 +0000 | [diff] [blame] | 4 | </head> |
| 5 | <body> |
| 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 | <p><textarea id="ta">abc123 |
| 9 | </textarea></p> |
| 10 | <script type="text/javascript"> |
| 11 | var ta = document.getElementById('ta'); |
| 12 | ta.selectionStart = 3; |
| 13 | ta.selectionEnd = 4; |
| 14 | shouldBe('ta.selectionStart', '3'); |
| 15 | shouldBe('ta.selectionEnd', '4'); |
| 16 | debug("- add background style"); |
| 17 | ta.setAttribute("style", "background-color: yellow"); |
| 18 | shouldBe('ta.selectionStart', '3'); |
| 19 | shouldBe('ta.selectionEnd', '4'); |
| 20 | debug("- set value to same value"); |
| 21 | ta.value = "abc123\n"; |
| 22 | shouldBe('ta.selectionStart', '3'); |
| 23 | shouldBe('ta.selectionEnd', '4'); |
| 24 | debug("- set value to a different value"); |
| 25 | ta.value = "abc123"; |
| 26 | shouldBe('ta.selectionStart', '6'); |
| 27 | shouldBe('ta.selectionEnd', '6'); |
| 28 | debug("- set selection so we can test again without a trailing newline"); |
| 29 | ta.selectionStart = 3; |
| 30 | ta.selectionEnd = 4; |
| 31 | ta.removeAttribute("style"); |
| 32 | shouldBe('ta.selectionStart', '3'); |
| 33 | shouldBe('ta.selectionEnd', '4'); |
| 34 | debug("- add background style"); |
| 35 | ta.setAttribute("style", "background-color: yellow"); |
| 36 | shouldBe('ta.selectionStart', '3'); |
| 37 | shouldBe('ta.selectionEnd', '4'); |
| 38 | debug("- set value to same value"); |
| 39 | ta.value = "abc123"; |
| 40 | shouldBe('ta.selectionStart', '3'); |
| 41 | shouldBe('ta.selectionEnd', '4'); |
darin@apple.com | fd245ad | 2008-12-13 23:02:11 +0000 | [diff] [blame] | 42 | </script> |
mark.lam@apple.com | 93720da | 2013-09-07 23:31:07 +0000 | [diff] [blame] | 43 | <script type="text/javascript" src="../../resources/js-test-post.js"></script> |
darin@apple.com | fd245ad | 2008-12-13 23:02:11 +0000 | [diff] [blame] | 44 | </body> |
| 45 | </html> |