test_bug460568.html (4814B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=460568 5 --> 6 <head> 7 <title>Test for Bug 460568</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="/tests/SimpleTest/EventUtils.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=460568">Mozilla Bug 460568</a> 14 <p id="display"><a href="" id="anchor">a[href]</a></p> 15 <div id="editor"> 16 <a href="" id="anchorInEditor">a[href] in editor</a> 17 </div> 18 <pre id="test"> 19 <script class="testbody" type="text/javascript"> 20 21 /** Test for Bug 460568 */ 22 23 function runTest() 24 { 25 var editor = document.getElementById("editor"); 26 var anchor = document.getElementById("anchor"); 27 var anchorInEditor = document.getElementById("anchorInEditor"); 28 29 var focused; 30 anchorInEditor.onfocus = function() { focused = true; }; 31 32 function isReallyEditable() 33 { 34 editor.focus(); 35 var range = document.createRange(); 36 range.selectNodeContents(editor); 37 var prevStr = range.toString(); 38 39 var docShell = SpecialPowers.wrap(window).docShell; 40 var controller = 41 docShell.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor) 42 .getInterface(SpecialPowers.Ci.nsISelectionDisplay) 43 .QueryInterface(SpecialPowers.Ci.nsISelectionController); 44 var sel = controller.getSelection(controller.SELECTION_NORMAL); 45 sel.collapse(anchorInEditor, 0); 46 sendString("a"); 47 range.selectNodeContents(editor); 48 return prevStr != range.toString(); 49 } 50 51 focused = false; 52 anchor.focus(); 53 editor.setAttribute("contenteditable", "true"); 54 anchorInEditor.focus(); 55 is(focused, false, "focus moved to element in contenteditable=true"); 56 is(isReallyEditable(), true, "cannot edit by a key event"); 57 58 // for bug 502273 59 focused = false; 60 anchor.focus(); 61 editor.setAttribute("dummy", "dummy"); 62 editor.removeAttribute("dummy"); 63 anchorInEditor.focus(); 64 is(focused, false, "focus moved to element in contenteditable=true (after dummy attribute was removed)"); 65 is(isReallyEditable(), true, "cannot edit by a key event"); 66 67 focused = false; 68 anchor.focus(); 69 editor.setAttribute("contenteditable", "false"); 70 anchorInEditor.focus(); 71 is(focused, true, "focus didn't move to element in contenteditable=false"); 72 is(isReallyEditable(), false, "can edit by a key event"); 73 74 // for bug 502273 75 focused = false; 76 anchor.focus(); 77 editor.setAttribute("dummy", "dummy"); 78 editor.removeAttribute("dummy"); 79 anchorInEditor.focus(); 80 is(focused, true, "focus moved to element in contenteditable=true (after dummy attribute was removed)"); 81 is(isReallyEditable(), false, "cannot edit by a key event"); 82 83 focused = false; 84 anchor.focus(); 85 editor.setAttribute("contenteditable", "true"); 86 anchorInEditor.focus(); 87 is(focused, false, "focus moved to element in contenteditable=true"); 88 is(isReallyEditable(), true, "cannot edit by a key event"); 89 90 // for bug 502273 91 focused = false; 92 anchor.focus(); 93 editor.setAttribute("dummy", "dummy"); 94 editor.removeAttribute("dummy"); 95 anchorInEditor.focus(); 96 is(focused, false, "focus moved to element in contenteditable=true (after dummy attribute was removed)"); 97 is(isReallyEditable(), true, "cannot edit by a key event"); 98 99 focused = false; 100 anchor.focus(); 101 editor.removeAttribute("contenteditable"); 102 anchorInEditor.focus(); 103 is(focused, true, "focus didn't move to element in contenteditable removed element"); 104 is(isReallyEditable(), false, "can edit by a key event"); 105 106 focused = false; 107 anchor.focus(); 108 editor.contentEditable = true; 109 anchorInEditor.focus(); 110 is(focused, false, "focus moved to element in contenteditable=true by property"); 111 is(isReallyEditable(), true, "cannot edit by a key event"); 112 113 focused = false; 114 anchor.focus(); 115 editor.contentEditable = false; 116 anchorInEditor.focus(); 117 is(focused, true, "focus didn't move to element in contenteditable=false by property"); 118 is(isReallyEditable(), false, "can edit by a key event"); 119 120 focused = false; 121 anchor.focus(); 122 editor.setAttribute("contenteditable", "true"); 123 anchorInEditor.focus(); 124 is(focused, false, "focus moved to element in contenteditable=true"); 125 is(isReallyEditable(), true, "cannot edit by a key event"); 126 127 // for bug 502273 128 focused = false; 129 anchor.focus(); 130 editor.setAttribute("dummy", "dummy"); 131 editor.removeAttribute("dummy"); 132 anchorInEditor.focus(); 133 is(focused, false, "focus moved to element in contenteditable=true (after dummy attribute was removed)"); 134 is(isReallyEditable(), true, "cannot edit by a key event"); 135 } 136 137 SimpleTest.waitForExplicitFinish(); 138 addLoadEvent(runTest); 139 addLoadEvent(SimpleTest.finish); 140 141 </script> 142 </pre> 143 </body> 144 </html>