editor/libeditor/html/tests/test_root_element_replacement.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <html>
michael@0 2 <head>
michael@0 3 <title>Test for root element replacement</title>
michael@0 4 <script type="text/javascript"
michael@0 5 src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript"
michael@0 7 src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 8 <link rel="stylesheet" type="text/css"
michael@0 9 href="/tests/SimpleTest/test.css" />
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <p id="display">
michael@0 13 </p>
michael@0 14 <div id="content" style="display: none">
michael@0 15
michael@0 16 </div>
michael@0 17 <pre id="test">
michael@0 18 </pre>
michael@0 19
michael@0 20 <script class="testbody" type="application/javascript">
michael@0 21
michael@0 22 SimpleTest.waitForExplicitFinish();
michael@0 23 SimpleTest.waitForFocus(runTest);
michael@0 24
michael@0 25 function runDesignModeTest(aDoc, aFocus, aNewSource)
michael@0 26 {
michael@0 27 aDoc.designMode = "on";
michael@0 28
michael@0 29 if (aFocus) {
michael@0 30 aDoc.documentElement.focus();
michael@0 31 }
michael@0 32
michael@0 33 aDoc.open();
michael@0 34 aDoc.write(aNewSource);
michael@0 35 aDoc.close();
michael@0 36 aDoc.documentElement.focus();
michael@0 37 }
michael@0 38
michael@0 39 function runContentEditableTest(aDoc, aFocus, aNewSource)
michael@0 40 {
michael@0 41 if (aFocus) {
michael@0 42 aDoc.body.setAttribute("contenteditable", "true");
michael@0 43 aDoc.body.focus();
michael@0 44 }
michael@0 45
michael@0 46 aDoc.open();
michael@0 47 aDoc.write(aNewSource);
michael@0 48 aDoc.close();
michael@0 49 aDoc.getElementById("focus").focus();
michael@0 50 }
michael@0 51
michael@0 52 var gTestIndex = 0;
michael@0 53
michael@0 54 const kTests = [
michael@0 55 { description: "Replace to '<body></body>', designMode",
michael@0 56 initializer: runDesignModeTest,
michael@0 57 args: [ "<body></body>" ] },
michael@0 58 { description: "Replace to '<html><body></body></html>', designMode",
michael@0 59 initializer: runDesignModeTest,
michael@0 60 args: [ "<html><body></body></html>" ] },
michael@0 61 { description: "Replace to '<html>&nbsp;<body></body></html>', designMode",
michael@0 62 initializer: runDesignModeTest,
michael@0 63 args: [ "<html> <body></body></html>" ] },
michael@0 64 { description: "Replace to '&nbsp;<html>&nbsp;<body></body></html>', designMode",
michael@0 65 initializer: runDesignModeTest,
michael@0 66 args: [ " <html> <body></body></html>" ] },
michael@0 67
michael@0 68 { description: "Replace to '<html contenteditable='true'><body></body></html>",
michael@0 69 initializer: runContentEditableTest,
michael@0 70 args: [ "<html contenteditable='true' id='focus'><body></body></html>" ] },
michael@0 71 { description: "Replace to '<html><body contenteditable='true'></body></html>",
michael@0 72 initializer: runContentEditableTest,
michael@0 73 args: [ "<html><body contenteditable='true' id='focus'></body></html>" ] },
michael@0 74 { description: "Replace to '<body contenteditable='true'></body>",
michael@0 75 initializer: runContentEditableTest,
michael@0 76 args: [ "<body contenteditable='true' id='focus'></body>" ] },
michael@0 77 ];
michael@0 78
michael@0 79 var gIFrame;
michael@0 80 var gSetFocusToIFrame = false;
michael@0 81
michael@0 82 function onLoadIFrame()
michael@0 83 {
michael@0 84 var frameDoc = gIFrame.contentWindow.document;
michael@0 85
michael@0 86 var selCon = SpecialPowers.wrap(gIFrame).contentWindow.
michael@0 87 QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
michael@0 88 getInterface(SpecialPowers.Ci.nsIWebNavigation).
michael@0 89 QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
michael@0 90 getInterface(SpecialPowers.Ci.nsISelectionDisplay).
michael@0 91 QueryInterface(SpecialPowers.Ci.nsISelectionController);
michael@0 92 var utils = SpecialPowers.getDOMWindowUtils(window);
michael@0 93 const nsIDOMNode = SpecialPowers.Ci.nsIDOMNode;
michael@0 94
michael@0 95 // move focus to the HTML editor
michael@0 96 const kTest = kTests[gTestIndex];
michael@0 97 ok(true, "Running " + kTest.description);
michael@0 98 if (kTest.args.length == 1) {
michael@0 99 kTest.initializer(frameDoc, gSetFocusToIFrame, kTest.args[0]);
michael@0 100 ok(selCon.caretVisible, "caret isn't visible -- " + kTest.description);
michael@0 101 } else {
michael@0 102 ok(false, "kTests is broken at index=" + gTestIndex);
michael@0 103 }
michael@0 104
michael@0 105 is(utils.IMEStatus, utils.IME_STATUS_ENABLED,
michael@0 106 "IME isn't enabled -- " + kTest.description);
michael@0 107 synthesizeKey("A", { }, gIFrame.contentWindow);
michael@0 108 synthesizeKey("B", { }, gIFrame.contentWindow);
michael@0 109 synthesizeKey("C", { }, gIFrame.contentWindow);
michael@0 110 var content = frameDoc.body.firstChild;
michael@0 111 ok(content, "body doesn't have contents -- " + kTest.description);
michael@0 112 if (content) {
michael@0 113 is(content.nodeType, nsIDOMNode.TEXT_NODE,
michael@0 114 "the content of body isn't text node -- " + kTest.description);
michael@0 115 if (content.nodeType == nsIDOMNode.TEXT_NODE) {
michael@0 116 is(content.data, "ABC",
michael@0 117 "the content of body text isn't 'ABC' -- " + kTest.description);
michael@0 118 is(frameDoc.body.innerHTML, "ABC",
michael@0 119 "the innerHTML of body isn't 'ABC' -- " + kTest.description);
michael@0 120 }
michael@0 121 }
michael@0 122
michael@0 123 document.getElementById("display").removeChild(gIFrame);
michael@0 124
michael@0 125 // Do next test or finish the tests.
michael@0 126 if (++gTestIndex < kTests.length) {
michael@0 127 setTimeout(runTest, 0);
michael@0 128 } else if (!gSetFocusToIFrame) {
michael@0 129 gSetFocusToIFrame = true;
michael@0 130 gTestIndex = 0;
michael@0 131 setTimeout(runTest, 0);
michael@0 132 } else {
michael@0 133 SimpleTest.finish();
michael@0 134 }
michael@0 135 }
michael@0 136
michael@0 137 function runTest()
michael@0 138 {
michael@0 139 gIFrame = document.createElement("iframe");
michael@0 140 document.getElementById("display").appendChild(gIFrame);
michael@0 141 gIFrame.src = "about:blank";
michael@0 142 gIFrame.onload = onLoadIFrame;
michael@0 143 }
michael@0 144
michael@0 145 </script>
michael@0 146 </body>
michael@0 147
michael@0 148 </html>

mercurial