summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/old-tests/submission/Microsoft/selection/deleteFromDocument.htm
blob: 2373939cc49b9c9ffe359760aece06ef0dbe32f1 (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
75
76
77
78
79
80
<!DOCTYPE HTML>
<html>
    <head>
        <title id="desc">HTML5 Selection: Delete some text from the document while it is part of a selection</title>
        <script type="text/javascript">
            var testPassed = true;
            
            function checkSelectionAttributes(anchorNode, anchorOffset, focusNode, focusOffset, collapsed, rangeCount)
            {
                var selection = window.getSelection();
                if (anchorNode != selection.anchorNode)
                {
                    testPassed = false;
                }
                if (anchorOffset != selection.anchorOffset)
                {
                    testPassed = false;
                }
                if (focusNode != selection.focusNode)
                {
                    testPassed = false;
                }
                if (focusOffset != selection.focusOffset)
                {
                    testPassed = false;
                }
                if (collapsed != selection.isCollapsed)
                {
                    testPassed = false;
                }
                if (rangeCount != selection.rangeCount)
                {
                    testPassed = false;
                }
            }
            
            function RunTest()
            {
                try
                {
                    var selection = window.getSelection();
                    var p2 = document.getElementById("p2");
                    var expectedResult = "abcdeuvwxyz";
                    
                    var range = document.createRange();
                    range.setStart(p2.firstChild, 5);
                    range.setEnd(p2.firstChild, 20);
                    selection.addRange(range);
                    selection.deleteFromDocument();
                    p2.normalize();
                    
                    range.collapse(true);
                    
                    checkSelectionAttributes(range.startContainer, range.startOffset, range.endContainer, range.endOffset, true, 1);
                    
                    if (expectedResult != p2.firstChild.data)
                    {
                        testPassed = false;
                    }
                    
                    if (testPassed)
                    {
                        document.getElementById("testresult").firstChild.data = "PASS";
                    }
                }
                catch (ex)
                {
                    document.getElementById("testresult").firstChild.data = "FAIL";
                }
            }
        </script>
    </head>
    <body onload="RunTest();">
        <p id="p1">Delete some text from the document while it is part of a selection</p>
        <p id="p2">abcdefghijklmnopqrstuvwxyz</p>
        <p>Test passes if the word "PASS" appears below.</p>
        <div>Test result: </div>
        <div id="testresult">FAIL</div>
    </body>
</html>