| <!DOCTYPE html> |
| <html> |
| <body> |
| </body> |
| <script> |
| function insertHeaderForTest(testContent, expected) |
| { |
| document.body.innerHTML = "<div id='testDiv' contentEditable='true'>foofoo</div>"; |
| var targetDiv = document.getElementById("testDiv"); |
| var targetText = targetDiv.firstChild; |
| window.getSelection().setPosition(targetText, 3); |
| document.execCommand("InsertHTML", false, testContent); |
| var actual = targetDiv.innerHTML; |
| if (actual == expected) |
| return "Success. " + testContent +" was inserted into <div>foo^foo<div> and the result was:" + actual + "\n"; |
| return "Failure. Result was: " + actual + ", should have been: " + expected + "\n"; |
| } |
| |
| if (window.testRunner) |
| window.testRunner.dumpAsText(); |
| |
| // Test 1: Verify that a header at the beginning of inserted content is preserved. |
| output = "Test 1: Verify that a header at the beginning of inserted content is preserved.\n"; |
| output += insertHeaderForTest("<h1>bar</h1><div>baz</div>", "foo<h1>bar</h1>bazfoo"); |
| output += insertHeaderForTest("<h2>bar</h2><div>baz</div>", "foo<h2>bar</h2>bazfoo"); |
| output += insertHeaderForTest("<h3>bar</h3><div>baz</div>", "foo<h3>bar</h3>bazfoo"); |
| output += insertHeaderForTest("<h4>bar</h4><div>baz</div>", "foo<h4>bar</h4>bazfoo"); |
| output += insertHeaderForTest("<h5>bar</h5><div>baz</div>", "foo<h5>bar</h5>bazfoo"); |
| output += insertHeaderForTest("<h6>bar</h6><div>baz</div>", "foo<h6>bar</h6>bazfoo"); |
| |
| // Test 2: Verify that a header at the end of inserted content is preserved. |
| output += "Test 2: Verify that a header at the end of inserted content is preserved.\n"; |
| output += insertHeaderForTest("<div>bar</div><h1>baz</h1>", "foobar<h1>baz</h1>foo"); |
| output += insertHeaderForTest("<div>bar</div><h2>baz</h2>", "foobar<h2>baz</h2>foo"); |
| output += insertHeaderForTest("<div>bar</div><h3>baz</h3>", "foobar<h3>baz</h3>foo"); |
| output += insertHeaderForTest("<div>bar</div><h4>baz</h4>", "foobar<h4>baz</h4>foo"); |
| output += insertHeaderForTest("<div>bar</div><h5>baz</h5>", "foobar<h5>baz</h5>foo"); |
| output += insertHeaderForTest("<div>bar</div><h6>baz</h6>", "foobar<h6>baz</h6>foo"); |
| |
| document.body.innerText = output; |
| </script> |
| </html> |