summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/editing/selection/toString.html
blob: e176d1cd4fd81d71a02709e9d7e3c2e51bcd1af3 (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
<script>
if (window.testRunner)
     testRunner.dumpEditingCallbacks();
</script>
<script>
function log(str) {
    var li = document.createElement("li");
    li.appendChild(document.createTextNode(str));
    var console = document.getElementById("console");
    console.appendChild(li);
}

function runTest() {
    try {
        if (window.testRunner)
            window.testRunner.dumpAsText();
            
        var selection = window.getSelection();
        var element = document.getElementById("test");
        
        if (selection.setBaseAndExtent)
            selection.setBaseAndExtent(element, 0, element, 1);
        else if (selection.selectAllChildren)
            selection.selectAllChildren(element);
        else
            throw("Couldn't set a selection.");
        
        if (selection.toString) {
            var string = selection.toString();
            if (string != selection)
                throw("Implicit toString call did not match explicit call");
            if (string != "hello world")
                throw("Selection::toString() returned incorrect results.");
            log("Success");
        } else
            throw("Selection::toString() not supported");
    } catch(e) {
        log("Test Failed.  Error was: " + e);
    }
}
</script>
<body>
<p>This tests Selection::toString(): that it exists, that it returns the same result as the implicit toString call, and that it returns the correct results.</p>
<div id="test" style="border: 1px solid black;">hello world</div>
<ul id="console"></ul>
<script>runTest();</script>
</body>