test_selection_tripleclick.html (2934B)
1 <!DOCTYPE> 2 <title>Selection test</title> 3 <script src="/tests/SimpleTest/SimpleTest.js"></script> 4 <script src="/tests/SimpleTest/EventUtils.js"></script> 5 <style> 6 body { margin: 0; font: 16px/1 sans-serif; } 7 code { display: inline-block } 8 #d code { overflow: auto } 9 </style> 10 <p id="a">Some <code>code</code> with <span>text</span> with <code>code</code> in it</p> 11 12 <p id="b">Here's <span>some</span> <code><span>code</span><br><span>broken</span></code> with <span>text</span> with <code><span>code</span><br><span>broken</span></code> in <span>it and such</span> and so on</p> 13 14 <pre id="c">Here's some text and 15 some <span>more</span> code <span>with</span> pre-formatted 16 whitespace <span>that</span> should be selected 17 line <span>by</span> line</pre> 18 19 <p id="d">Some <code>code</code> with <span>text</span> with <code>code</code> in <span>it</span></p> 20 21 <p id="e">Some <span style="display: table-caption">text in a caption</span> with more text</p> 22 23 <script> 24 SimpleTest.waitForExplicitFinish(); 25 26 function testTripleClick(elem, expectation) { 27 window.getSelection().removeAllRanges(); 28 synthesizeMouse(elem, 5, 5, { clickCount: 3 }); 29 is(window.getSelection().toString(), expectation); 30 } 31 32 SimpleTest.waitForFocus(function () { 33 for (let child of document.querySelectorAll(":is(#a, #d) :is(span, code)")) 34 testTripleClick(child, "Some code with text with code in it"); 35 36 { 37 let spans = document.querySelectorAll("#b span"); 38 let expectations = [ 39 "Here's some code", // First span, at the beginning of the text. 40 "Here's some code", // Top span in the inline-block, before break. 41 "broken with text with code", // Bottom span in inline-block, after break 42 "broken with text with code", // Center of the text. 43 "broken with text with code", // Top span in the second inline-block, before break. 44 "broken in it and such and so on", // Bottom span in the second inline-block, after break. 45 "broken in it and such and so on", // Last span, at the end of the text. 46 ]; 47 is(spans.length, expectations.length); 48 for (let i = 0; i < expectations.length; ++i) 49 testTripleClick(spans[i], expectations[i]); 50 } 51 52 { 53 testTripleClick(document.getElementById("c"), "Here's some text and"); 54 let spans = document.querySelectorAll("#c span"); 55 let expectations = [ 56 "some more code with pre-formatted", 57 "some more code with pre-formatted", 58 "whitespace that should be selected", 59 "line by line", 60 ]; 61 is(spans.length, expectations.length); 62 for (let i = 0; i < expectations.length; ++i) 63 testTripleClick(spans[i], expectations[i]); 64 } 65 66 testTripleClick(document.getElementById("e"), "Some "); // TODO: Maybe should get the whole paragraph. 67 testTripleClick(document.querySelector("#e span"), "text in a caption"); 68 69 SimpleTest.finish(); 70 }); 71 </script>