test_htmleditor_toggle_text_direction.html (2245B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Text direction switch target of HTMLEditor</title> 6 <script src="/tests/SimpleTest/EventUtils.js"></script> 7 <script src="/tests/SimpleTest/SimpleTest.js"></script> 8 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 9 <script> 10 "use strict"; 11 12 SimpleTest.waitForExplicitFinish(); 13 SimpleTest.waitForFocus(async () => { 14 await (async function test_in_contenteditable() { 15 document.body.innerHTML = "<div><div contenteditable>editable text</div></div>"; 16 const editingHost = document.querySelector("div[contenteditable]"); 17 editingHost.focus(); 18 SpecialPowers.doCommand(window, "cmd_switchTextDirection"); 19 is( 20 editingHost.getAttribute("dir"), 21 "rtl", 22 "test_in_contenteditable: dir attr of the editing host should be set" 23 ); 24 is( 25 editingHost.parentElement.getAttribute("dir"), 26 null, 27 "test_in_contenteditable: dir attr of the parent div of the editing host should not be set" 28 ); 29 is( 30 document.body.getAttribute("dir"), 31 null, 32 "test_in_contenteditable: dir attr of the <body> should not be set", 33 ); 34 is( 35 document.documentElement.getAttribute("dir"), 36 null, 37 "test_in_contenteditable: dir attr of the <html> should not be set", 38 ); 39 })(); 40 41 await (async function test_in_designMode() { 42 document.body.innerHTML = "<div>abc</div>"; 43 document.designMode = "on"; 44 getSelection().collapse(document.querySelector("div").firstChild, 0); 45 SpecialPowers.doCommand(window, "cmd_switchTextDirection"); 46 is( 47 document.querySelector("div").getAttribute("dir"), 48 null, 49 "test_in_designMode: dir attr of the <div> should not be set", 50 ); 51 is( 52 document.body.getAttribute("dir"), 53 "rtl", 54 "test_in_designMode: dir attr of the <body> should be set", 55 ); 56 is( 57 document.documentElement.getAttribute("dir"), 58 null, 59 "test_in_designMode: dir attr of the <html> should not be set", 60 ); 61 document.designMode = "off"; 62 document.body.removeAttribute("dir"); 63 document.body.innerHTML = ""; 64 document.documentElement.removeAttribute("dir"); 65 })(); 66 67 SimpleTest.finish(); 68 }); 69 </script> 70 </head> 71 <body> 72 </body> 73 </html>