DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (93bdbca5399c)

VCS Links

Line Code
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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
<!DOCTYPE>
<html>
<head>
  <title>Test for nsIHTMLEditor.removeInlineProperty()</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body>
<div id="display">
</div>
<div id="content" contenteditable></div>
<pre id="test">
</pre>

<script class="testbody" type="application/javascript">
"use strict";

SimpleTest.waitForExplicitFinish();

SimpleTest.waitForFocus(async () => {
  await SpecialPowers.pushPrefEnv({
    set: [["dom.input_events.beforeinput.enabled", true]],
  });

  let editor = document.getElementById("content");
  let selection = window.getSelection();
  let description, condition;
  let beforeInputEvents = [];
  let inputEvents = [];
  let selectionRanges = [];
  function onBeforeInput(aEvent) {
    beforeInputEvents.push(aEvent);
    selectionRanges = [];
    for (let i = 0; i < selection.rangeCount; i++) {
      let range = selection.getRangeAt(i);
      selectionRanges.push({startContainer: range.startContainer, startOffset: range.startOffset,
                            endContainer: range.endContainer, endOffset: range.endOffset});
    }
  }
  function onInput(aEvent) {
    inputEvents.push(aEvent);
  }
  editor.addEventListener("beforeinput", onBeforeInput);
  editor.addEventListener("input", onInput);

  function checkInputEvent(aEvent, aInputType, aDescription) {
    if (aEvent.type !== "input" && aEvent.type !== "beforeinput") {
      return;
    }
    ok(aEvent instanceof InputEvent, `${aDescription}"${aEvent.type}" event should be dispatched with InputEvent interface`);
    // If it were cancelable whose inputType is empty string, web apps would
    // block any Firefox specific modification whose inputType are not declared
    // by the spec.
    let expectedCancelable = aEvent.type === "beforeinput" && aInputType !== "";
    is(aEvent.cancelable, expectedCancelable,
       `${aDescription}"${aEvent.type}" event should ${expectedCancelable ? "be" : "be never"} cancelable`);
    is(aEvent.bubbles, true, `${aDescription}"${aEvent.type}" event should always bubble`);
    is(aEvent.inputType, aInputType, `${aDescription}inputType of "${aEvent.type}" event should be ${aInputType}`);
    is(aEvent.data, null, `${aDescription}data of "${aEvent.type}" event should be null`);
    is(aEvent.dataTransfer, null, `${aDescription}dataTransfer of "${aEvent.type}" event should be null`);
    let targetRanges = aEvent.getTargetRanges();
    if (aEvent.type === "beforeinput") {
      is(targetRanges.length, selectionRanges.length,
         `${aDescription}getTargetRanges() of "${aEvent.type}" event should return selection ranges`);
      if (targetRanges.length === selectionRanges.length) {
        for (let i = 0; i < selectionRanges.length; i++) {
          is(targetRanges[i].startContainer, selectionRanges[i].startContainer,
             `${aDescription}startContainer of getTargetRanges()[${i}] of "beforeinput" event does not match`);
          is(targetRanges[i].startOffset, selectionRanges[i].startOffset,
             `${aDescription}startOffset of getTargetRanges()[${i}] of "beforeinput" event does not match`);
          is(targetRanges[i].endContainer, selectionRanges[i].endContainer,
             `${aDescription}endContainer of getTargetRanges()[${i}] of "beforeinput" event does not match`);
          is(targetRanges[i].endOffset, selectionRanges[i].endOffset,
             `${aDescription}endOffset of getTargetRanges()[${i}] of "beforeinput" event does not match`);
        }
      }
    } else {
      is(targetRanges.length, 0, `${aDescription}getTargetRanges() of "${aEvent.type}" event should return empty array`);
    }
  }

  function selectFromTextSiblings(aNode) {
    condition = "selecting the node from end of previous text to start of next text node";
    selection.setBaseAndExtent(aNode.previousSibling, aNode.previousSibling.length,
                               aNode.nextSibling, 0);
  }
  function selectNode(aNode) {
    condition = "selecting the node";
    let range = document.createRange();
    range.selectNode(aNode);
    selection.removeAllRanges();
    selection.addRange(range);
  }
  function selectAllChildren(aNode) {
    condition = "selecting all children of the node";
    selection.selectAllChildren(aNode);
  }
  function selectChildContents(aNode) {
    condition = "selecting all contents of its child";
    let range = document.createRange();
    range.selectNodeContents(aNode.firstChild);
    selection.removeAllRanges();
    selection.addRange(range);
  }

  description = "When there is a <b> element and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = "<p>test: <b>here</b> is bolden text</p>";
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("b", "");
    is(editor.innerHTML, "<p>test: here is bolden text</p>",
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should remove the <b> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should cause a "beforeinput" event');
    checkInputEvent(beforeInputEvents[0], "formatBold", description + condition + ': nsIHTMLEditor.removeInlineProperty("b", ""): ');
    is(inputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should cause an "input" event');
    checkInputEvent(inputEvents[0], "formatBold", description + condition + ': nsIHTMLEditor.removeInlineProperty("b", ""): ');
  }

  description = "When there is a <b> element which has style attribute and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = '<p>test: <b style="font-style: italic">here</b> is bolden text</p>';
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("b", "");
    is(editor.innerHTML, '<p>test: <span style="font-style: italic">here</span> is bolden text</p>',
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should replace the <b> element with <span> element to keep the style');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should cause a "beforeinput" event');
    checkInputEvent(beforeInputEvents[0], "formatBold", description + condition + ': nsIHTMLEditor.removeInlineProperty("b", ""): ');
    is(inputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should cause an "input" event');
    checkInputEvent(inputEvents[0], "formatBold", description + condition + ': nsIHTMLEditor.removeInlineProperty("b", ""): ');
  }

  description = "When there is a <b> element which has class attribute and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = '<p>test: <b class="foo">here</b> is bolden text</p>';
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("b", "");
    is(editor.innerHTML, '<p>test: <span class="foo">here</span> is bolden text</p>',
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should replace the <b> element with <span> element to keep the class');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should cause a "beforeinput" event');
    checkInputEvent(beforeInputEvents[0], "formatBold", description + condition + ': nsIHTMLEditor.removeInlineProperty("b", ""): ');
    is(inputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should cause an "input" event');
    checkInputEvent(inputEvents[0], "formatBold", description + condition + ': nsIHTMLEditor.removeInlineProperty("b", ""): ');
  }

  description = "When there is a <b> element which has an <i> element and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = "<p>test: <b><i>here</i></b> is bolden and italic text</p>";
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("b", "");
    is(editor.innerHTML, "<p>test: <i>here</i> is bolden and italic text</p>",
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should remove only the <b> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should cause a "beforeinput" event');
    checkInputEvent(beforeInputEvents[0], "formatBold", description + condition + ': nsIHTMLEditor.removeInlineProperty("b", ""): ');
    is(inputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should cause an "input" event');
    checkInputEvent(inputEvents[0], "formatBold", description + condition + ': nsIHTMLEditor.removeInlineProperty("b", ""): ');
  }

  description = "When there is a <b> element which has an <i> element and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = "<p>test: <b><i>here</i></b> is bolden and italic text</p>";
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("i", "");
    is(editor.innerHTML, "<p>test: <b>here</b> is bolden and italic text</p>",
      description + condition + ': nsIHTMLEditor.removeInlineProperty("i", "") should remove only the <i> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("i", "") should cause a "beforeinput" event');
    checkInputEvent(beforeInputEvents[0], "formatItalic", description + condition + ': nsIHTMLEditor.removeInlineProperty("i", ""): ');
    is(inputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("i", "") should cause an "input" event');
    checkInputEvent(inputEvents[0], "formatItalic", description + condition + ': nsIHTMLEditor.removeInlineProperty("i", ""): ');
  }

  description = "When there is an <i> element in a <b> element and ";
  for (let prepare of [selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = "<p>test: <b><i>here</i></b> is bolden and italic text</p>";
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling.firstChild);
    getHTMLEditor().removeInlineProperty("b", "");
    is(editor.innerHTML, "<p>test: <i>here</i> is bolden and italic text</p>",
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should remove only the <b> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should cause a "beforeinput" event');
    checkInputEvent(beforeInputEvents[0], "formatBold", description + condition + ': nsIHTMLEditor.removeInlineProperty("b", ""): ');
    is(inputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should cause an "input" event');
    checkInputEvent(inputEvents[0], "formatBold", description + condition + ': nsIHTMLEditor.removeInlineProperty("b", ""): ');
  }

  description = "When there is an <i> element in a <b> element and ";
  for (let prepare of [selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = "<p>test: <b><i>here</i></b> is bolden and italic text</p>";
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling.firstChild);
    getHTMLEditor().removeInlineProperty("i", "");
    is(editor.innerHTML, "<p>test: <b>here</b> is bolden and italic text</p>",
      description + condition + ': nsIHTMLEditor.removeInlineProperty("i", "") should remove only the <i> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("i", "") should cause a "beforeinput" event');
    checkInputEvent(beforeInputEvents[0], "formatItalic", description + condition + ': nsIHTMLEditor.removeInlineProperty("i", ""): ');
    is(inputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("i", "") should cause an "input" event');
    checkInputEvent(inputEvents[0], "formatItalic", description + condition + ': nsIHTMLEditor.removeInlineProperty("i", ""): ');
  }

  description = "When there is an <i> element between text nodes in a <b> element and ";
  for (let prepare of [selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = "<p>test: <b>h<i>e</i>re</b> is bolden and italic text</p>";
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("i", "");
    is(editor.innerHTML, "<p>test: <b>here</b> is bolden and italic text</p>",
      description + condition + ': nsIHTMLEditor.removeInlineProperty("i", "") should remove only the <i> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("i", "") should cause a "beforeinput" event');
    checkInputEvent(beforeInputEvents[0], "formatItalic", description + condition + ': nsIHTMLEditor.removeInlineProperty("i", ""): ');
    is(inputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("i", "") should cause an "input" event');
    checkInputEvent(inputEvents[0], "formatItalic", description + condition + ': nsIHTMLEditor.removeInlineProperty("i", ""): ');
  }

  description = "When there is an <i> element between text nodes in a <b> element and ";
  for (let prepare of [selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = "<p>test: <b>h<i>e</i>re</b> is bolden and italic text</p>";
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("b", "");
    is(editor.innerHTML, "<p>test: <b>h</b><i>e</i><b>re</b> is bolden and italic text</p>",
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should split the <b> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should cause a "beforeinput" event');
    checkInputEvent(beforeInputEvents[0], "formatBold", description + condition + ': nsIHTMLEditor.removeInlineProperty("b", ""): ');
    is(inputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("b", "") should cause an "input" event');
    checkInputEvent(inputEvents[0], "formatBold", description + condition + ': nsIHTMLEditor.removeInlineProperty("b", ""): ');
  }

  description = "When there is an <a> element whose href attribute is not empty and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = '<p>test: <a href="about:blank">here</a> is a link</p>';
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("href", "");
    is(editor.innerHTML, "<p>test: here is a link</p>",
      description + condition + ': nsIHTMLEditor.removeInlineProperty("href", "") should remove the <a> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("href", "") should cause a "beforeinput" event');
    checkInputEvent(beforeInputEvents[0], "", description + condition + ': nsIHTMLEditor.removeInlineProperty("href", ""): ');
    is(inputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("href", "") should cause an "input" event');
    checkInputEvent(inputEvents[0], "", description + condition + ': nsIHTMLEditor.removeInlineProperty("href", ""): ');
  }

  // XXX In the case of "name", removeInlineProperty() does not the <a> element when name attribute is empty.
  description = "When there is an <a> element whose href attribute is empty and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = '<p>test: <a href="">here</a> is a link</p>';
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("href", "");
    is(editor.innerHTML, "<p>test: here is a link</p>",
      description + condition + ': nsIHTMLEditor.removeInlineProperty("href", "") should remove the <a> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("href", "") should cause a "beforeinput" event');
    checkInputEvent(beforeInputEvents[0], "", description + condition + ': nsIHTMLEditor.removeInlineProperty("href", ""): ');
    is(inputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("href", "") should cause an "input" event');
    checkInputEvent(inputEvents[0], "", description + condition + ': nsIHTMLEditor.removeInlineProperty("href", ""): ');
  }

  description = "When there is an <a> element which does not have href attribute and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = "<p>test: <a>here</a> is an anchor</p>";
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("href", "");
    is(editor.innerHTML, "<p>test: <a>here</a> is an anchor</p>",
      description + condition + ': nsIHTMLEditor.removeInlineProperty("href", "") should NOT remove the <a> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("href", "") should cause a "beforeinput" event even though HTMLEditor will do nothing');
    checkInputEvent(beforeInputEvents[0], "", description + condition + ': nsIHTMLEditor.removeInlineProperty("href", ""): ');
    is(inputEvents.length, 0,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("href", "") should NOT cause an "input" event');
  }

  description = "When there is an <a> element whose name attribute is not empty and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = '<p>test: <a name="foo">here</a> is a named anchor</p>';
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("href", "");
    is(editor.innerHTML, '<p>test: <a name="foo">here</a> is a named anchor</p>',
      description + condition + ': nsIHTMLEditor.removeInlineProperty("href", "") should NOT remove the <a> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("href", "") should cause a "beforeinput" event even though HTMLEditor will do nothing');
    checkInputEvent(beforeInputEvents[0], "", description + condition + ': nsIHTMLEditor.removeInlineProperty("href", ""): ');
    is(inputEvents.length, 0,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("href", "") should NOT cause an "input" event');
  }

  description = "When there is an <a> element whose name attribute is not empty and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = '<p>test: <a name="foo">here</a> is a named anchor</p>';
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("name", "");
    is(editor.innerHTML, "<p>test: here is a named anchor</p>",
      description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "") should remove the <a> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "") should cause a "beforeinput" event');
    checkInputEvent(beforeInputEvents[0], "", description + condition + ': nsIHTMLEditor.removeInlineProperty("name", ""): ');
    is(inputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "") should cause an "input" event');
    checkInputEvent(inputEvents[0], "", description + condition + ': nsIHTMLEditor.removeInlineProperty("name", ""): ');
  }

  // XXX In the case of "href", removeInlineProperty() removes the <a> element when href attribute is empty.
  description = "When there is an <a> element whose name attribute is empty and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = '<p>test: <a name="">here</a> is a named anchor</p>';
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("name", "");
    is(editor.innerHTML, '<p>test: <a name="">here</a> is a named anchor</p>',
      description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "") should NOT remove the <a> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "") should cause a "beforeinput" event even though HTMLEditor will do nothing');
    checkInputEvent(beforeInputEvents[0], "", description + condition + ': nsIHTMLEditor.removeInlineProperty("name", ""): ');
    is(inputEvents.length, 0,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "") should NOT cause an "input" event');
  }

  description = "When there is an <a> element which does not have name attribute and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = "<p>test: <a>here</a> is an anchor</p>";
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("name", "");
    is(editor.innerHTML, "<p>test: <a>here</a> is an anchor</p>",
      description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "") should NOT remove the <a> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "") should cause a "beforeinput" event even though HTMLEditor will do nothing');
    checkInputEvent(beforeInputEvents[0], "", description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "")');
    is(inputEvents.length, 0,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "") should NOT cause an "input" event');
  }

  description = "When there is an <a> element whose href attribute is not empty and ";
  for (let prepare of [selectFromTextSiblings, selectNode, selectAllChildren, selectChildContents]) {
    editor.innerHTML = '<p>test: <a href="about:blank">here</a> is a link</p>';
    editor.focus();
    beforeInputEvents = [];
    inputEvents = [];
    prepare(editor.firstChild.firstChild.nextSibling);
    getHTMLEditor().removeInlineProperty("name", "");
    is(editor.innerHTML, '<p>test: <a href="about:blank">here</a> is a link</p>',
      description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "") should NOT remove the <a> element');
    is(beforeInputEvents.length, 1,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "") should cause a "beforeinput" event even though HTMLEditor will do nothing');
    checkInputEvent(beforeInputEvents[0], "", description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "")');
    is(inputEvents.length, 0,
      description + condition + ': nsIHTMLEditor.removeInlineProperty("name", "") should NOT cause an "input" event');
  }

  editor.removeEventListener("beforeinput", onBeforeInput);
  editor.removeEventListener("input", onInput);

  SimpleTest.finish();
});

function getHTMLEditor() {
  var Ci = SpecialPowers.Ci;
  var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
  return editingSession.getEditorForWindow(window).QueryInterface(Ci.nsIHTMLEditor);
}

</script>
</body>

</html>