Missing cursor/caret showing in search field on google.com
[WebKit-https.git] / LayoutTests / editing / selection / double-click-selection-with-dom-mutation.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4     <meta charset="utf-8">
5     <script src="../editing.js"></script>
6     <script src="../../resources/dump-as-markup.js"></script>
7 </head>
8 <body>
9 <p id="container">Double-click to select <span id="target">→this←</span> text.</p>
10
11 <script>
12     Markup.description('This test is for bug where selection vanishes when selection is created by Double-Click on text and then DOM is modified. Expected Output is that selected text should remain selected');
13     var target = document.getElementById("target");
14     Markup.dump("container", 'Before:');
15     doubleClick(target.offsetLeft + target.offsetWidth / 2, target.offsetTop + target.offsetHeight / 2);
16     var domRange = getSelection().getRangeAt(0);
17
18     function splitTextOnBoundary(container, offset, workaroundPreserveEnd) {
19         if (offset && offset < container.length) {
20             // WORKAROUND: doing the split manually avoids https://bugs.webkit.org/show_bug.cgi?id=114041
21             var newNode = document.createTextNode('');
22             if (workaroundPreserveEnd) {
23                 newNode.data = container.data.slice(0, offset);
24                 container.deleteData(0, offset);
25                 container.parentNode.insertBefore(newNode, container);
26             } else {
27                 newNode.data = container.data.slice(offset);
28                 container.deleteData(offset, container.data.length);
29                 container.parentNode.insertBefore(newNode, container.nextSibling);
30             }
31         }
32     }
33     splitTextOnBoundary(domRange.startContainer, domRange.startOffset, true);
34     splitTextOnBoundary(domRange.endContainer, domRange.endOffset, false);
35
36     Markup.dump("container", 'After:');
37 </script>
38 </body>
39 </html>