test_bug404320.html (2314B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=404320 5 --> 6 <head> 7 <title>Test for Bug 404320</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=404320">Mozilla Bug 404320</a> 13 <p id="display"></p> 14 <div id="content"> 15 <iframe id="testIframe"></iframe> 16 </div> 17 <pre id="test"> 18 <script class="testbody" type="text/javascript"> 19 20 /** Test for Bug 404320 */ 21 22 SimpleTest.waitForExplicitFinish(); 23 24 function runTests() { 25 var win = document.getElementById("testIframe").contentWindow; 26 var doc = document.getElementById("testIframe").contentDocument; 27 28 function testFormatBlock(tag, withAngleBrackets, shouldSucceed) { 29 win.getSelection().selectAllChildren(doc.body.firstChild); 30 doc.execCommand("FormatBlock", false, 31 withAngleBrackets ? tag : "<" + tag + ">"); 32 var resultNode; 33 if (shouldSucceed && (tag == "dd" || tag == "dt")) { 34 is(doc.body.firstChild.tagName, "DL", "tag was changed"); 35 resultNode = doc.body.firstChild.firstChild; 36 } else { 37 resultNode = doc.body.firstChild; 38 } 39 40 is(resultNode.tagName, shouldSucceed ? tag.toUpperCase() : "P", "tag was changed"); 41 } 42 43 function formatBlockTests(tags, shouldSucceed) { 44 var html = "<p>Content</p>"; 45 for (var i = 0; i < tags.length; ++i) { 46 var tag = tags[i]; 47 48 doc.body.innerHTML = html; 49 testFormatBlock(tag, false, shouldSucceed); 50 51 doc.body.innerHTML = html; 52 testFormatBlock(tag, true, shouldSucceed); 53 } 54 } 55 56 doc.designMode = "on"; 57 58 var goodTags = [ "address", 59 "blockquote", 60 "dd", 61 "div", 62 "dl", 63 "dt", 64 "h1", 65 "h2", 66 "h3", 67 "h4", 68 "h5", 69 "h6", 70 "p", 71 "pre" ]; 72 var badTags = [ "b", 73 "i", 74 "span", 75 "foo" ]; 76 77 formatBlockTests(goodTags, true); 78 formatBlockTests(badTags, false); 79 SimpleTest.finish(); 80 } 81 82 addLoadEvent(runTests); 83 84 </script> 85 </pre> 86 </body> 87 </html>