6 function insertHeaderForTest(testContent
, expected
)
8 document
.body
.innerHTML
= "<div id='testDiv' contentEditable='true'>foofoo</div>";
9 var targetDiv
= document
.getElementById("testDiv");
10 var targetText
= targetDiv
.firstChild
;
11 window
.getSelection().collapse(targetText
, 3);
12 document
.execCommand("InsertHTML", false, testContent
);
13 var actual
= targetDiv
.innerHTML
;
14 if (actual
== expected
)
15 return "Success. " + testContent
+" was inserted into <div>foo^foo<div> and the result was:" + actual
+ "\n";
16 return "Failure. Result was: " + actual
+ ", should have been: " + expected
+ "\n";
19 if (window
.testRunner
)
20 window
.testRunner
.dumpAsText();
22 // Test 1: Verify that a header at the beginning of inserted content is preserved.
23 output
= "Test 1: Verify that a header at the beginning of inserted content is preserved.\n";
24 output
+= insertHeaderForTest("<h1>bar</h1><div>baz</div>", "foo<h1>bar</h1>bazfoo");
25 output
+= insertHeaderForTest("<h2>bar</h2><div>baz</div>", "foo<h2>bar</h2>bazfoo");
26 output
+= insertHeaderForTest("<h3>bar</h3><div>baz</div>", "foo<h3>bar</h3>bazfoo");
27 output
+= insertHeaderForTest("<h4>bar</h4><div>baz</div>", "foo<h4>bar</h4>bazfoo");
28 output
+= insertHeaderForTest("<h5>bar</h5><div>baz</div>", "foo<h5>bar</h5>bazfoo");
29 output
+= insertHeaderForTest("<h6>bar</h6><div>baz</div>", "foo<h6>bar</h6>bazfoo");
31 // Test 2: Verify that a header at the end of inserted content is preserved.
32 output
+= "Test 2: Verify that a header at the end of inserted content is preserved.\n";
33 output
+= insertHeaderForTest("<div>bar</div><h1>baz</h1>", "foobar<h1>baz</h1>foo");
34 output
+= insertHeaderForTest("<div>bar</div><h2>baz</h2>", "foobar<h2>baz</h2>foo");
35 output
+= insertHeaderForTest("<div>bar</div><h3>baz</h3>", "foobar<h3>baz</h3>foo");
36 output
+= insertHeaderForTest("<div>bar</div><h4>baz</h4>", "foobar<h4>baz</h4>foo");
37 output
+= insertHeaderForTest("<div>bar</div><h5>baz</h5>", "foobar<h5>baz</h5>foo");
38 output
+= insertHeaderForTest("<div>bar</div><h6>baz</h6>", "foobar<h6>baz</h6>foo");
40 document
.body
.innerText
= output
;