new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/editor/cloning_attributes.html
@@ -0,0 +1,728 @@
+<!doctype html>
+<html>
+<head>
+<meta charset=utf-8>
+<title>Cloning attributes</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+</head>
+<body>
+<script>
+"use strict";
+
+(function() {
+ // These tests assume that id attribute should be only in the left element.
+ // However, this is not standardized and other browsers may behave
+ // differently. So, it's okay to change the behavior for id attribute
+ // for compatibility with the other browsers.
+ const kTests = [
+ { description: "Should clone attributes of <p> element at splitting at middle of the <p>",
+ innerHTML: "<p foo=\"bar\" id=\"original\">foobar</p>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 3);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <p> element at splitting at end of the <p>",
+ innerHTML: "<p foo=\"bar\" id=\"original\">foobar</p>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 6);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <span> element in <p> to <span> in new <p>",
+ innerHTML: "<p>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span>ar</p>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 1);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <span> element at end of <p> to <span> in new <p>",
+ innerHTML: "<p>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span></p>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 2);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <li> element at splitting at middle of the <li>",
+ innerHTML: "<ul><li foo=\"bar\" id=\"original\">foobar</li></ul>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.firstChild, 3);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <li> element at splitting at end of the <li>",
+ innerHTML: "<ul><li foo=\"bar\" id=\"original\">foobar</li></ul>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.firstChild, 6);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <span> element in <li> to <span> in new <li>",
+ innerHTML: "<ul><li>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span>ar</li></ul>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.firstChild.nextSibling.firstChild, 1);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <span> element at end of <li> to <span> in new <li>",
+ innerHTML: "<ul><li>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span></li></ul>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.firstChild.nextSibling.firstChild, 2);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <dt> element to new <dt> element at splitting at middle of the <dt>",
+ innerHTML: "<dl><dt foo=\"bar\" id=\"original\">foobar</dt></dl>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.firstChild, 3);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <dt> element to new <dd> element at splitting at end of the <dt>",
+ innerHTML: "<dl><dt foo=\"bar\" id=\"original\">foobar</dt></dl>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.firstChild, 6);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <span> element in <dt> to <span> in new <dd>",
+ innerHTML: "<dl><dt>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span>ar</dt></dl>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.firstChild.nextSibling.firstChild, 1);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <span> element at end of <dt> to new <dd>",
+ innerHTML: "<dl><dt>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span></dt></dl>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.firstChild.nextSibling.firstChild, 2);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <dd> element to new <dd> element at splitting at middle of the <dd>",
+ innerHTML: "<dl><dd foo=\"bar\" id=\"original\">foobar</dd></dl>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.firstChild, 3);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <dd> element to new <dt> element at splitting at end of the <dd>",
+ innerHTML: "<dl><dd foo=\"bar\" id=\"original\">foobar</dd></dl>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.firstChild, 6);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <span> element in <dd> to <span> in new <dd>",
+ innerHTML: "<dl><dd>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span>ar</dd></dl>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.firstChild.nextSibling.firstChild, 1);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <span> element at end of <dd> to new <dt>",
+ innerHTML: "<dl><dd>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span></dd></dl>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.firstChild.nextSibling.firstChild, 2);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <h1> element to new <h1> at splitting it at middle of the <h1>",
+ innerHTML: "<h1 foo=\"bar\" id=\"original\">foobar</h1>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 3);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <h1> element to new <div> at splitting it at end of the <h1>",
+ innerHTML: "<h1 foo=\"bar\" id=\"original\">foobar</h1>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 6);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <span> element in <h1> to <span> in new <h1>",
+ innerHTML: "<h1>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span>ar</h1>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 1);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <span> element at end of <h1> to new <div>",
+ innerHTML: "<h1>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span></h1>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 2);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <h2> element to new <h2> at splitting it at middle of the <h2>",
+ innerHTML: "<h2 foo=\"bar\" id=\"original\">foobar</h2>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 3);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <h2> element to new <div> at splitting it at end of the <h2>",
+ innerHTML: "<h2 foo=\"bar\" id=\"original\">foobar</h2>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 6);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <span> element in <h2> to <span> in new <h2>",
+ innerHTML: "<h2>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span>ar</h2>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 1);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <span> element at end of <h2> to new <div>",
+ innerHTML: "<h2>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span></h2>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 2);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <h3> element to new <h3> at splitting it at middle of the <h3>",
+ innerHTML: "<h3 foo=\"bar\" id=\"original\">foobar</h3>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 3);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <h3> element to new <div> at splitting it at end of the <h3>",
+ innerHTML: "<h3 foo=\"bar\" id=\"original\">foobar</h3>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 6);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <span> element in <h3> to <span> in new <h3>",
+ innerHTML: "<h3>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span>ar</h3>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 1);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <span> element at end of <h3> to new <div>",
+ innerHTML: "<h3>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span></h3>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 2);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <h4> element to new <h4> at splitting it at middle of the <h4>",
+ innerHTML: "<h4 foo=\"bar\" id=\"original\">foobar</h4>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 3);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <h4> element to new <div> at splitting it at end of the <h4>",
+ innerHTML: "<h4 foo=\"bar\" id=\"original\">foobar</h4>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 6);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <span> element in <h4> to <span> in new <h4>",
+ innerHTML: "<h4>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span>ar</h4>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 1);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <span> element at end of <h4> to new <div>",
+ innerHTML: "<h4>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span></h4>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 2);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <h5> element to new <h5> at splitting it at middle of the <h5>",
+ innerHTML: "<h5 foo=\"bar\" id=\"original\">foobar</h5>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 3);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <h5> element to new <div> at splitting it at end of the <h5>",
+ innerHTML: "<h5 foo=\"bar\" id=\"original\">foobar</h5>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 6);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <span> element in <h5> to <span> in new <h5>",
+ innerHTML: "<h5>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span>ar</h5>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 1);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <span> element at end of <h5> to new <div>",
+ innerHTML: "<h5>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span></h5>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 2);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <h6> element to new <h6> at splitting it at middle of the <h6>",
+ innerHTML: "<h6 foo=\"bar\" id=\"original\">foobar</h6>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 3);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <h6> element to new <div> at splitting it at end of the <h6>",
+ innerHTML: "<h6 foo=\"bar\" id=\"original\">foobar</h6>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ foo: "bar",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild, 6);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should clone attributes of <span> element in <h6> to <span> in new <h6>",
+ innerHTML: "<h6>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span>ar</h6>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: true,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 1);
+ document.execCommand("insertParagraph", false);
+ }, },
+ { description: "Should NOT clone attributes of <span> element at end of <h6> to new <div>",
+ innerHTML: "<h6>fo<span id=\"original\" style=\"font-weight: bold;\">ob</span></h6>",
+ getLeftElement: function (aEditor) {
+ return aEditor.firstChild.firstChild.nextSibling;
+ },
+ getRightElement: function (aEditor) {
+ return aEditor.firstChild.nextSibling.firstChild;;
+ },
+ expectedToCloneAttributes: false,
+ expectedAttributes: {
+ style: "font-weight: bold;",
+ id: "original",
+ },
+ doIt: function (aEditor) {
+ window.getSelection().collapse(aEditor.firstChild.firstChild.nextSibling.firstChild, 2);
+ document.execCommand("insertParagraph", false);
+ }, },
+ ];
+
+ document.body.innerHTML = "<div id=\"editor\" contenteditable></div>";
+ let editor = document.getElementById("editor");
+ editor.focus();
+ let selection = document.getSelection();
+
+ for (const kTest of kTests) {
+ editor.innerHTML = kTest.innerHTML;
+ editor.focus();
+ kTest.doIt(editor);
+ let leftElement = kTest.getLeftElement(editor);
+ for (const kAttr in kTest.expectedAttributes) {
+ test(function () {
+ assert_equals(leftElement.getAttribute(kAttr),
+ kTest.expectedAttributes[kAttr]);
+ }, kTest.description + "left Element, " + kAttr + " attribute");
+ }
+ let rightElement = kTest.getRightElement(editor);
+ for (const kAttr in kTest.expectedAttributes) {
+ test(function () {
+ assert_equals(rightElement.getAttribute(kAttr),
+ !kTest.expectedToCloneAttributes || kAttr === "id" ? null : kTest.expectedAttributes[kAttr]);
+ }, kTest.description + ", right element, " + kAttr + " attribute");
+ }
+ }
+})();
+</script>
+</body>
+</html>