1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/html/tests/test_root_element_replacement.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,148 @@ 1.4 +<html> 1.5 +<head> 1.6 + <title>Test for root element replacement</title> 1.7 + <script type="text/javascript" 1.8 + src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="text/javascript" 1.10 + src="/tests/SimpleTest/EventUtils.js"></script> 1.11 + <link rel="stylesheet" type="text/css" 1.12 + href="/tests/SimpleTest/test.css" /> 1.13 +</head> 1.14 +<body> 1.15 +<p id="display"> 1.16 +</p> 1.17 +<div id="content" style="display: none"> 1.18 + 1.19 +</div> 1.20 +<pre id="test"> 1.21 +</pre> 1.22 + 1.23 +<script class="testbody" type="application/javascript"> 1.24 + 1.25 +SimpleTest.waitForExplicitFinish(); 1.26 +SimpleTest.waitForFocus(runTest); 1.27 + 1.28 +function runDesignModeTest(aDoc, aFocus, aNewSource) 1.29 +{ 1.30 + aDoc.designMode = "on"; 1.31 + 1.32 + if (aFocus) { 1.33 + aDoc.documentElement.focus(); 1.34 + } 1.35 + 1.36 + aDoc.open(); 1.37 + aDoc.write(aNewSource); 1.38 + aDoc.close(); 1.39 + aDoc.documentElement.focus(); 1.40 +} 1.41 + 1.42 +function runContentEditableTest(aDoc, aFocus, aNewSource) 1.43 +{ 1.44 + if (aFocus) { 1.45 + aDoc.body.setAttribute("contenteditable", "true"); 1.46 + aDoc.body.focus(); 1.47 + } 1.48 + 1.49 + aDoc.open(); 1.50 + aDoc.write(aNewSource); 1.51 + aDoc.close(); 1.52 + aDoc.getElementById("focus").focus(); 1.53 +} 1.54 + 1.55 +var gTestIndex = 0; 1.56 + 1.57 +const kTests = [ 1.58 + { description: "Replace to '<body></body>', designMode", 1.59 + initializer: runDesignModeTest, 1.60 + args: [ "<body></body>" ] }, 1.61 + { description: "Replace to '<html><body></body></html>', designMode", 1.62 + initializer: runDesignModeTest, 1.63 + args: [ "<html><body></body></html>" ] }, 1.64 + { description: "Replace to '<html> <body></body></html>', designMode", 1.65 + initializer: runDesignModeTest, 1.66 + args: [ "<html> <body></body></html>" ] }, 1.67 + { description: "Replace to ' <html> <body></body></html>', designMode", 1.68 + initializer: runDesignModeTest, 1.69 + args: [ " <html> <body></body></html>" ] }, 1.70 + 1.71 + { description: "Replace to '<html contenteditable='true'><body></body></html>", 1.72 + initializer: runContentEditableTest, 1.73 + args: [ "<html contenteditable='true' id='focus'><body></body></html>" ] }, 1.74 + { description: "Replace to '<html><body contenteditable='true'></body></html>", 1.75 + initializer: runContentEditableTest, 1.76 + args: [ "<html><body contenteditable='true' id='focus'></body></html>" ] }, 1.77 + { description: "Replace to '<body contenteditable='true'></body>", 1.78 + initializer: runContentEditableTest, 1.79 + args: [ "<body contenteditable='true' id='focus'></body>" ] }, 1.80 +]; 1.81 + 1.82 +var gIFrame; 1.83 +var gSetFocusToIFrame = false; 1.84 + 1.85 +function onLoadIFrame() 1.86 +{ 1.87 + var frameDoc = gIFrame.contentWindow.document; 1.88 + 1.89 + var selCon = SpecialPowers.wrap(gIFrame).contentWindow. 1.90 + QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor). 1.91 + getInterface(SpecialPowers.Ci.nsIWebNavigation). 1.92 + QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor). 1.93 + getInterface(SpecialPowers.Ci.nsISelectionDisplay). 1.94 + QueryInterface(SpecialPowers.Ci.nsISelectionController); 1.95 + var utils = SpecialPowers.getDOMWindowUtils(window); 1.96 + const nsIDOMNode = SpecialPowers.Ci.nsIDOMNode; 1.97 + 1.98 + // move focus to the HTML editor 1.99 + const kTest = kTests[gTestIndex]; 1.100 + ok(true, "Running " + kTest.description); 1.101 + if (kTest.args.length == 1) { 1.102 + kTest.initializer(frameDoc, gSetFocusToIFrame, kTest.args[0]); 1.103 + ok(selCon.caretVisible, "caret isn't visible -- " + kTest.description); 1.104 + } else { 1.105 + ok(false, "kTests is broken at index=" + gTestIndex); 1.106 + } 1.107 + 1.108 + is(utils.IMEStatus, utils.IME_STATUS_ENABLED, 1.109 + "IME isn't enabled -- " + kTest.description); 1.110 + synthesizeKey("A", { }, gIFrame.contentWindow); 1.111 + synthesizeKey("B", { }, gIFrame.contentWindow); 1.112 + synthesizeKey("C", { }, gIFrame.contentWindow); 1.113 + var content = frameDoc.body.firstChild; 1.114 + ok(content, "body doesn't have contents -- " + kTest.description); 1.115 + if (content) { 1.116 + is(content.nodeType, nsIDOMNode.TEXT_NODE, 1.117 + "the content of body isn't text node -- " + kTest.description); 1.118 + if (content.nodeType == nsIDOMNode.TEXT_NODE) { 1.119 + is(content.data, "ABC", 1.120 + "the content of body text isn't 'ABC' -- " + kTest.description); 1.121 + is(frameDoc.body.innerHTML, "ABC", 1.122 + "the innerHTML of body isn't 'ABC' -- " + kTest.description); 1.123 + } 1.124 + } 1.125 + 1.126 + document.getElementById("display").removeChild(gIFrame); 1.127 + 1.128 + // Do next test or finish the tests. 1.129 + if (++gTestIndex < kTests.length) { 1.130 + setTimeout(runTest, 0); 1.131 + } else if (!gSetFocusToIFrame) { 1.132 + gSetFocusToIFrame = true; 1.133 + gTestIndex = 0; 1.134 + setTimeout(runTest, 0); 1.135 + } else { 1.136 + SimpleTest.finish(); 1.137 + } 1.138 +} 1.139 + 1.140 +function runTest() 1.141 +{ 1.142 + gIFrame = document.createElement("iframe"); 1.143 + document.getElementById("display").appendChild(gIFrame); 1.144 + gIFrame.src = "about:blank"; 1.145 + gIFrame.onload = onLoadIFrame; 1.146 +} 1.147 + 1.148 +</script> 1.149 +</body> 1.150 + 1.151 +</html>