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