<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<div id=editor contenteditable><x-x>aa</x-x></div>
<script>
'use strict';
promise_test(function () {
let constructCount = 0;
customElements.define('x-x', class extends HTMLElement {
constructor() {
super();
constructCount++;
}
});
assert_equals(constructCount, 1, 'define() should run constructor');
let element = editor.firstElementChild;
element.focus();
let selection = getSelection();
selection.collapse(element.firstChild, 1);
eventSender.keyDown('\r');
// Backup queue runs in a microtask, so schedule the assertions after that.
return new Promise(resolve => {
resolve();
}).then(() => {
assert_equals(document.getElementsByTagName('x-x').length, 2, 'Enter key should clone the element');
assert_equals(constructCount, 2, 'clone should run constructor');
});
}, 'clone-a-node in contenteditable');
</script>