summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/old-tests/submission/Microsoft/selection/selectionStartEnd.htm
blob: c5b69d5706003b6c42ab0d12ad936162f522860a (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE HTML>
<html>
    <head>
        <title id="desc">HTML5 Selection: Set selectionStart and selectionEnd on a text field</title>
        <script type="text/javascript">  
            var testPassed = true;
            
            function checkDefaultSelectionAttributes()
            {
                var selection = window.getSelection();
                if (null != selection.anchorNode)
                {
                    testPassed = false;
                }
                if (0 != selection.anchorOffset)
                {
                    testPassed = false;
                }
                if (null != selection.focusNode)
                {
                    testPassed = false;
                }
                if (0 != selection.focusOffset)
                {
                    testPassed = false;
                }
                if (!selection.isCollapsed)
                {
                    testPassed = false;
                }
                if (0 != selection.rangeCount)
                {
                    testPassed = false;
                }  
            }
            
            function RunTest()
            {
                try
                {
                    var input1 = document.getElementById("input1");
                    var expectedResult = "text";
                    
                    input1.selectionStart = 5;
                    input1.selectionEnd = 9;
                    
                    checkDefaultSelectionAttributes();
                    
                    var selectionText = input1.value.substring(input1.selectionStart, input1.selectionEnd);
                    if (expectedResult != selectionText)
                    {
                        testPassed = false;
                    }
                    
                    if (testPassed)
                    {
                        document.getElementById("testresult").firstChild.data = "PASS";
                    }
                }
                catch (ex)
                {
                    document.getElementById("testresult").firstChild.data = "FAIL";
                }
            }
        </script>
    </head>
    <body onload="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>
        <p>Test passes if the word "PASS" appears below.</p>
        <div>Test result: </div>
        <div id="testresult">FAIL</div>
    </body>
</html>