<html>
<body>
<p>This tests inserting a new paragraph preserves the background color.</p>
<div>
<div id="test" contenteditable="true">
test
</div>
</div>
<div id="console"></div>

<script type="text/javascript">

function pressKey( key ) {
    if (window.KeyEvent) {
        var ev = document.createEvent("KeyboardEvent");
        ev.initKeyEvent("keypress", true, true, window,  0,0,0,0, 0, key.charCodeAt(0));
        document.body.dispatchEvent(ev);
    }
    else {
        var ev = document.createEvent("TextEvent");
        ev.initTextEvent('textInput', true, true, null, key.charAt(0));
        document.body.dispatchEvent(ev);
    }
}

if (window.testRunner)
    testRunner.dumpAsText();

var e = document.getElementById('test');
var s = window.getSelection();

r = document.createRange();
r.setStart(e.firstChild,0);
r.setEnd(e.firstChild,5);
s.removeAllRanges();
s.addRange(r);
document.execCommand("hiliteColor",false,"#99f");

r = document.createRange();
r.setStart(e.firstChild.firstChild,5);
r.setEnd(e.firstChild.firstChild,5);
s.removeAllRanges();
s.addRange(r);
pressKey('\n');
pressKey('e');

document.getElementById('console').appendChild(document.createTextNode(e.innerHTML));

</script>
