upload tizen1.0 source
[framework/web/webkit-efl.git] / LayoutTests / editing / execCommand / arguments-combinations.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <title>ExecCommand argument combinations</title>
5         <style>
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; }
9         </style>
10         <script type="text/javascript">
11             function debug(msg)
12             {
13                 var span = document.createElement("span");
14                 span.innerHTML = msg + '<br>';
15                 document.getElementById("console").appendChild(span);
16             }
17
18             function escapeHTML(text)
19             {
20                 return text.replace(/&/g, "&amp;").replace(/</g, "&lt;");
21             }
22
23             function testPassed(msg)
24             {
25                 debug('<span class="pass">PASS</span> ' + msg + '</span>');
26             }
27
28             function testFailed(msg)
29             {
30                 debug('<span class="fail">FAIL</span> ' + msg + '</span>');
31             }
32
33             function testEquals(a, b)
34             {
35                 if (a == b) {
36                     testPassed(escapeHTML(a) + " <b>is</b> " + escapeHTML(b));
37                 } else {
38                     testFailed("<b>expected output was</b> " + escapeHTML(a) + " <b>should have been</b> " + escapeHTML(b));
39                 }
40             }
41
42             function test(codeToEval, expectedOutput)
43             {
44                 var e = document.createElement('div');
45                 e.setAttribute('contentEditable', 'true');
46                 document.body.appendChild(e);
47                 e.focus();
48                 eval(codeToEval);
49                 testEquals(e.innerHTML, expectedOutput);
50             }
51
52             function runTests()
53             {
54                 if (window.layoutTestController)
55                      layoutTestController.dumpAsText();
56
57                 // Test with 1 argument.
58                 test('document.execCommand("InsertHorizontalRule")', '<hr>');
59
60                 // Test with 2 arguments.
61                 test('document.execCommand("InsertHorizontalRule", false)', '<hr>');
62
63                 // Test with 3 arguments.
64                 test('document.execCommand("InsertHorizontalRule", false, "foo")', '<hr id="foo">');
65
66                 // Test with 4 arguments. (should ignore the fourth argument silently)
67                 test('document.execCommand("InsertHorizontalRule", false, "foo", "bar")', '<hr id="foo">');
68
69                 // Test empty String 3rd parameter. (should not add an empty id value)
70                 test('document.execCommand("InsertHorizontalRule", false, "")', '<hr>');
71
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>');
74
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>');
77
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">');
80
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>');
83             }
84         </script>
85     </head>
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>
89
90         <h4>CONSOLE</h4>
91         <pre id='console'></pre>
92     </body>
93 </html>