4 <title>ExecCommand argument combinations</title>
6 .pass { font-weight: bold; color: green; }
7 .fail { font-weight: bold; color: red; }
8 #console { border: 1px solid black; padding: 10px; margin-bottom: 20px; }
10 <script type="text/javascript">
13 var span = document.createElement("span");
14 span.innerHTML = msg + '<br>';
15 document.getElementById("console").appendChild(span);
18 function escapeHTML(text)
20 return text.replace(/&/g, "&").replace(/</g, "<");
23 function testPassed(msg)
25 debug('<span class="pass">PASS</span> ' + msg + '</span>');
28 function testFailed(msg)
30 debug('<span class="fail">FAIL</span> ' + msg + '</span>');
33 function testEquals(a, b)
36 testPassed(escapeHTML(a) + " <b>is</b> " + escapeHTML(b));
38 testFailed("<b>expected output was</b> " + escapeHTML(a) + " <b>should have been</b> " + escapeHTML(b));
42 function test(codeToEval, expectedOutput)
44 var e = document.createElement('div');
45 e.setAttribute('contentEditable', 'true');
46 document.body.appendChild(e);
49 testEquals(e.innerHTML, expectedOutput);
54 if (window.layoutTestController)
55 layoutTestController.dumpAsText();
57 // Test with 1 argument.
58 test('document.execCommand("InsertHorizontalRule")', '<hr>');
60 // Test with 2 arguments.
61 test('document.execCommand("InsertHorizontalRule", false)', '<hr>');
63 // Test with 3 arguments.
64 test('document.execCommand("InsertHorizontalRule", false, "foo")', '<hr id="foo">');
66 // Test with 4 arguments. (should ignore the fourth argument silently)
67 test('document.execCommand("InsertHorizontalRule", false, "foo", "bar")', '<hr id="foo">');
69 // Test empty String 3rd parameter. (should not add an empty id value)
70 test('document.execCommand("InsertHorizontalRule", false, "")', '<hr>');
72 // Test null 3rd parameter. (should treat as if only two arguments were passed, same as undefined)
73 test('document.execCommand("InsertHorizontalRule", false, null)', '<hr>');
75 // Test undefined 3rd parameter. (should treat as if only two arguments were passed, same as null)
76 test('document.execCommand("InsertHorizontalRule", false, undefined)', '<hr>');
78 // Test 0 for 3rd parameter. (nothing special, id value should equal the string 0)
79 test('document.execCommand("InsertHorizontalRule", false, 0)', '<hr id="0">');
81 // Test undefined 3rd parameter implicitly using helper function. (should treat as if only two arguments were passed, same as null)
82 test('function ExecCommand(command, commandParam) { document.execCommand(command, false, commandParam); } ExecCommand("InsertHorizontalRule");', '<hr>');
86 <body onload="runTests();">
87 <p>These are tests for testing the how execCommand() works with different combinations of arguments. The "InsertHorizontalRule" command was
88 chosen arbitrarily because it was what I was working on at the time, but the results should be paralleled in the other commands as well.</p>
91 <pre id='console'></pre>