user-interaction-editing-contenteditable.html (2519B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Editing: contentEditable attribute test</title> 5 <link rel="author" title="Baidu" href="mailto: guopengcheng@baidu.com" /> 6 <link 7 rel="help" 8 href="https://html.spec.whatwg.org/multipage/#contenteditable" 9 /> 10 <script src="/resources/testharness.js"></script> 11 <script src="/resources/testharnessreport.js"></script> 12 <div id="log"></div> 13 </head> 14 <body> 15 <script> 16 function testContentEditable(variationFunc, title, expectIsContentEditable, expectContentEditable) { 17 test(() => { 18 const div = document.createElement("div"); 19 variationFunc(div); 20 assert_equals(div.isContentEditable, expectIsContentEditable, 'isContentEditable'); 21 assert_equals(div.contentEditable, expectContentEditable, 'contentEditable'); 22 }, title); 23 } 24 25 testContentEditable(el => { 26 }, "no contenteditable attribute", false, "inherit"); 27 28 testContentEditable(el => { 29 el.setAttribute("contenteditable", ""); 30 }, "empty contentEditable attribute", true, "true"); 31 32 testContentEditable(el => { 33 el.contentEditable = "true"; 34 }, 'set contentEditable = "true"', true, "true"); 35 36 testContentEditable(el => { 37 el.contentEditable = "false"; 38 }, 'set contentEditable = "false"', false, "false"); 39 40 testContentEditable(el => { 41 const parent = document.createElement("div"); 42 parent.appendChild(el); 43 parent.contentEditable = "true"; 44 }, 'set parent element contentEditable = "true"', true, "inherit"); 45 46 testContentEditable(el => { 47 const parent = document.createElement("div"); 48 parent.appendChild(el); 49 parent.contentEditable = "false"; 50 }, 'set parent element contentEditable = "false"', false, "inherit"); 51 52 testContentEditable(el => { 53 el.contentEditable = "true"; 54 el.removeAttribute("contenteditable"); 55 }, 'set contentEditable = "true" and then remove contenteditable attribute', false, "inherit"); 56 57 testContentEditable(el => { 58 el.setAttribute("contenteditable", "plaintext-only"); 59 }, "contentEditable=plaintext-only attribute", true, "plaintext-only"); 60 61 testContentEditable(el => { 62 const parent = document.createElement("div"); 63 parent.appendChild(el); 64 parent.contentEditable = "plaintext-only"; 65 }, 'set parent element contentEditable = "plaintext-only"', true, "inherit"); 66 </script> 67 </body> 68 </html>