editor/libeditor/html/tests/test_bug460740.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 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=460740
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 460740</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=460740">Mozilla Bug 460740</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content">
michael@0 16 <ul>
michael@0 17 <li contenteditable>
michael@0 18 Editable LI
michael@0 19 </li>
michael@0 20 <li>
michael@0 21 <div contenteditable>
michael@0 22 Editable DIV inside LI
michael@0 23 </div>
michael@0 24 </li>
michael@0 25 <li>
michael@0 26 <div>
michael@0 27 <div contenteditable>
michael@0 28 Editable DIV inside DIV inside LI
michael@0 29 </div>
michael@0 30 </div>
michael@0 31 </li>
michael@0 32 <li>
michael@0 33 <h3>
michael@0 34 <div contenteditable>
michael@0 35 Editable DIV inside H3 inside LI
michael@0 36 </div>
michael@0 37 </h3>
michael@0 38 </li>
michael@0 39 </ul>
michael@0 40 <div contenteditable>
michael@0 41 Editable DIV
michael@0 42 </div>
michael@0 43 <h3 contenteditable>
michael@0 44 Editable H3
michael@0 45 </h3>
michael@0 46 <p contenteditable>
michael@0 47 Editable P
michael@0 48 </p>
michael@0 49 <div>
michael@0 50 <p contenteditable>
michael@0 51 Editable P in a DIV
michael@0 52 </p>
michael@0 53 </div>
michael@0 54 <p><span contenteditable>Editable SPAN in a P</span></p>
michael@0 55 </div>
michael@0 56
michael@0 57 <pre id="test">
michael@0 58 <script type="application/javascript">
michael@0 59
michael@0 60 /** Test for Bug 460740 **/
michael@0 61 SimpleTest.waitForExplicitFinish();
michael@0 62 SimpleTest.waitForFocus(runTests);
michael@0 63
michael@0 64 const CARET_BEGIN = 0;
michael@0 65 const CARET_MIDDLE = 1;
michael@0 66 const CARET_END = 2;
michael@0 67
michael@0 68 function split(element, caretPos) {
michael@0 69 // compute the requested position
michael@0 70 var len = element.textContent.length;
michael@0 71 var pos = -1;
michael@0 72 switch (caretPos) {
michael@0 73 case CARET_BEGIN:
michael@0 74 pos = 0;
michael@0 75 break;
michael@0 76 case CARET_MIDDLE:
michael@0 77 pos = Math.floor(len/2);
michael@0 78 break;
michael@0 79 case CARET_END:
michael@0 80 pos = len;
michael@0 81 break;
michael@0 82 }
michael@0 83
michael@0 84 // put the caret on the requested position
michael@0 85 var range = document.createRange();
michael@0 86 var sel = window.getSelection();
michael@0 87 range.setStart(element.firstChild, pos);
michael@0 88 range.setEnd(element.firstChild, pos);
michael@0 89 sel.addRange(range);
michael@0 90
michael@0 91 // simulates a [Return] keypress
michael@0 92 synthesizeKey("VK_RETURN", {});
michael@0 93 }
michael@0 94
michael@0 95 // count the number of non-BR elements in #content
michael@0 96 function getBlockCount() {
michael@0 97 return document.querySelectorAll("#content *:not(br)").length;
michael@0 98 }
michael@0 99
michael@0 100 // count the number of BRs in element
michael@0 101 function checkBR(element) {
michael@0 102 return element.querySelectorAll("br").length;
michael@0 103 }
michael@0 104
michael@0 105 function runTests() {
michael@0 106 var count = getBlockCount();
michael@0 107 var nodes = document.querySelectorAll("#content [contenteditable]");
michael@0 108 for (var i = 0; i < nodes.length; i++) {
michael@0 109 var node = nodes[i];
michael@0 110 node.focus();
michael@0 111 is(checkBR(node), 0, node.textContent.trim() + ": This node should not have any <br> element yet.");
michael@0 112 for (var j = 0; j < 3; j++) { // CARET_BEGIN|MIDDLE|END
michael@0 113 split(node, j);
michael@0 114 ok(checkBR(node) > 0, node.textContent.trim() + " " + j + ": Pressing [Return] should add (at least) one <br> element.");
michael@0 115 is(getBlockCount(), count, node.textContent.trim() + " " + j + ": Pressing [Return] should not change the number of non-<br> elements.");
michael@0 116 document.execCommand("Undo", false, null);
michael@0 117 }
michael@0 118 }
michael@0 119 SimpleTest.finish();
michael@0 120 }
michael@0 121 </script>
michael@0 122 </pre>
michael@0 123 </body>
michael@0 124 </html>

mercurial