test_bug1642588.html (2080B)
1 <!DOCTYPE html> 2 <title>Test for Bug 1642588</title> 3 <script src="/tests/SimpleTest/SimpleTest.js"></script> 4 <script src="/tests/SimpleTest/EventUtils.js"></script> 5 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 6 <style> 7 [contenteditable] { 8 padding: .5em 40%; 9 } 10 </style> 11 12 <div> 13 <p> 14 Intentionally not in WPT as triple click is not guaranteed to have same 15 behavior on every browser. 16 </p> 17 <span contenteditable></span><hr> 18 <div contenteditable style="display: inline;"></div><hr> 19 <div contenteditable style="display: inline-block;"></div><hr> 20 <!-- 21 FIXME: https://bugzilla.mozilla.org/show_bug.cgi?id=1654364 22 <table contenteditable style="display: inline-table;"><tr><td></table><hr> 23 --> 24 <div contenteditable style="display: inline-flex;"></div><hr> 25 <div contenteditable style="display: inline-grid;"></div> 26 </div> 27 28 <script> 29 function selectHostByClicks(host, number) { 30 for (let i = 1; i <= number; i++) { 31 synthesizeMouseAtCenter(host, { clickCount: i }); 32 } 33 } 34 35 function nonCollapsedDeletionTest(host, clickCount) { 36 host.textContent = "contenteditable"; 37 selectHostByClicks(host, clickCount); 38 const selection = getSelection(); 39 40 is(selection.isCollapsed, false, "Noncollapsed selection should occur"); 41 42 synthesizeKey("KEY_Backspace"); 43 is( 44 host.textContent, 45 "", 46 `Backspace should delete the content of the editing host (<div contenteditable style="${ 47 host.getAttribute("style") 48 }">)`); 49 } 50 51 function collapsedSelectionTest(host, clickCount) { 52 host.textContent = ""; 53 selectHostByClicks(host, clickCount); 54 const selection = getSelection(); 55 56 is(selection.isCollapsed, true, "Collapsed selection should occur"); 57 is(selection.anchorNode, host, "Caret should be in host"); 58 } 59 60 SimpleTest.waitForExplicitFinish(); 61 SimpleTest.waitForFocus(() => { 62 const hosts = document.querySelectorAll("[contenteditable]"); 63 for (const host of hosts) { 64 nonCollapsedDeletionTest(host, 2); 65 nonCollapsedDeletionTest(host, 3); 66 collapsedSelectionTest(host, 3); 67 } 68 SimpleTest.finish(); 69 }); 70 </script>