summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/old-tests/submission/Microsoft/selection/selectionStartEnd.htm
blob: 35687f4a5ad7a97d678b3880f75089b3527fb48f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE HTML>
<html>
    <head>
        <title id="desc">HTML5 Selection: Set selectionStart and selectionEnd on a text field</title>
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
        <script src="common.js"></script>
        <script type="text/javascript">
            function RunTest()
            {
                var selection = window.getSelection();
                var input1 = document.getElementById("input1");

                assert_equals(input1.selectionStart, 0);
                assert_equals(input1.selectionEnd, 0);
                checkDefaultSelectionAttributes();
                assert_equals(selection.toString(), "");

                // only setting selectionStart/End doesn't affect getSelection()

                input1.selectionStart = 5;
                input1.selectionEnd = 9;

                assert_equals(input1.selectionStart, 5);
                assert_equals(input1.selectionEnd, 9);
                checkDefaultSelectionAttributes();
                assert_equals(selection.toString(), "");

                // select() changes selectionStart/End and getSelection()

                input1.select();

                assert_equals(input1.selectionStart, 0);
                assert_equals(input1.selectionEnd, input1.value.length);
                checkSelectionAttributes(document.body, 1, document.body, 1, true, 1);
                assert_equals(selection.toString(), input1.value);

                // now setting selectionStart/End does affect getSelection()

                input1.selectionStart = 5;
                input1.selectionEnd = 9;

                assert_equals(input1.selectionStart, 5);
                assert_equals(input1.selectionEnd, 9);
                checkSelectionAttributes(document.body, 1, document.body, 1, true, 1);
                assert_equals(selection.toString(), "text");
            }
        </script>
    </head>
    <body onload="test(RunTest);">
        <input style="WIDTH: 500px" id="input1" value="Some text in an input control" type="text" />
        <p>Select some text in the input element by setting selectionStart and selectionEnd</p>
    </body>
</html>