Sat, 03 Jan 2015 20:18:00 +0100
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 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
michael@0 | 4 | <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 5 | xmlns:html="http://www.w3.org/1999/xhtml" |
michael@0 | 6 | title="Test for nsSelectionMoveCommands"> |
michael@0 | 7 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 8 | |
michael@0 | 9 | <script class="testbody" type="application/javascript"> |
michael@0 | 10 | <![CDATA[ |
michael@0 | 11 | |
michael@0 | 12 | var prefs = Components.classes["@mozilla.org/preferences-service;1"] |
michael@0 | 13 | .getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 14 | prefs.setBoolPref("general.smoothScroll", false); |
michael@0 | 15 | |
michael@0 | 16 | var winUtils = SpecialPowers.getDOMWindowUtils(window); |
michael@0 | 17 | winUtils.advanceTimeAndRefresh(100); |
michael@0 | 18 | |
michael@0 | 19 | function runTest() { |
michael@0 | 20 | var tests = execTests(); |
michael@0 | 21 | function execNext() { |
michael@0 | 22 | try { |
michael@0 | 23 | winUtils.advanceTimeAndRefresh(100); |
michael@0 | 24 | tests.next(); |
michael@0 | 25 | |
michael@0 | 26 | winUtils.advanceTimeAndRefresh(100); |
michael@0 | 27 | setTimeout(execNext, 20); |
michael@0 | 28 | } catch (e) {} |
michael@0 | 29 | } |
michael@0 | 30 | execNext(); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function execTests() { |
michael@0 | 34 | var e = document.getElementById("edit"); |
michael@0 | 35 | var doc = e.contentDocument; |
michael@0 | 36 | var win = e.contentWindow; |
michael@0 | 37 | var root = doc.documentElement; |
michael@0 | 38 | var body = doc.body; |
michael@0 | 39 | |
michael@0 | 40 | body.style.fontSize='16px'; |
michael@0 | 41 | body.style.lineHeight='16px'; |
michael@0 | 42 | body.style.height='400px'; |
michael@0 | 43 | body.style.padding='0px'; |
michael@0 | 44 | body.style.margin='0px'; |
michael@0 | 45 | body.style.borderWidth='0px'; |
michael@0 | 46 | |
michael@0 | 47 | var sel = win.getSelection(); |
michael@0 | 48 | doc.designMode='on'; |
michael@0 | 49 | body.innerHTML = "1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br>11<br>12<br>"; |
michael@0 | 50 | win.focus(); |
michael@0 | 51 | // Flush out layout to make sure that the subdocument will be the size we |
michael@0 | 52 | // expect by the time we try to scroll it. |
michael@0 | 53 | is(body.getBoundingClientRect().height, 400, |
michael@0 | 54 | "Body height should be what we set it to"); |
michael@0 | 55 | yield; |
michael@0 | 56 | |
michael@0 | 57 | function doCommand(cmd) { |
michael@0 | 58 | var controller = document.commandDispatcher.getControllerForCommand(cmd); |
michael@0 | 59 | if (controller) { |
michael@0 | 60 | controller.doCommand(cmd); |
michael@0 | 61 | } |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function testScrollCommand(cmd, expectTop) { |
michael@0 | 65 | is(root.getBoundingClientRect().top, -expectTop, cmd); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | function testMoveCommand(cmd, expectNode, expectOffset) { |
michael@0 | 69 | doCommand(cmd); |
michael@0 | 70 | is(sel.isCollapsed, true, "collapsed after " + cmd); |
michael@0 | 71 | is(sel.anchorNode, expectNode, "node after " + cmd); |
michael@0 | 72 | is(sel.anchorOffset, expectOffset, "offset after " + cmd); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function findChildNum(e, child) { |
michael@0 | 76 | var i = 0; |
michael@0 | 77 | var n = e.firstChild; |
michael@0 | 78 | while (n && n != child) { |
michael@0 | 79 | n = n.nextSibling; |
michael@0 | 80 | ++i; |
michael@0 | 81 | } |
michael@0 | 82 | if (!n) |
michael@0 | 83 | return -1; |
michael@0 | 84 | return i; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function testPageMoveCommand(cmd, expectOffset) { |
michael@0 | 88 | doCommand(cmd); |
michael@0 | 89 | is(sel.isCollapsed, true, "collapsed after " + cmd); |
michael@0 | 90 | is(sel.anchorOffset, expectOffset, "offset after " + cmd); |
michael@0 | 91 | return findChildNum(body, sel.anchorNode); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | function testSelectCommand(cmd, expectNode, expectOffset) { |
michael@0 | 95 | var anchorNode = sel.anchorNode; |
michael@0 | 96 | var anchorOffset = sel.anchorOffset; |
michael@0 | 97 | doCommand(cmd); |
michael@0 | 98 | is(sel.isCollapsed, false, "not collapsed after " + cmd); |
michael@0 | 99 | is(sel.anchorNode, anchorNode, "anchor not moved after " + cmd); |
michael@0 | 100 | is(sel.anchorOffset, anchorOffset, "anchor not moved after " + cmd); |
michael@0 | 101 | is(sel.focusNode, expectNode, "node after " + cmd); |
michael@0 | 102 | is(sel.focusOffset, expectOffset, "offset after " + cmd); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | function testPageSelectCommand(cmd, expectOffset) { |
michael@0 | 106 | var anchorNode = sel.anchorNode; |
michael@0 | 107 | var anchorOffset = sel.anchorOffset; |
michael@0 | 108 | doCommand(cmd); |
michael@0 | 109 | is(sel.isCollapsed, false, "not collapsed after " + cmd); |
michael@0 | 110 | is(sel.anchorNode, anchorNode, "anchor not moved after " + cmd); |
michael@0 | 111 | is(sel.anchorOffset, anchorOffset, "anchor not moved after " + cmd); |
michael@0 | 112 | is(sel.focusOffset, expectOffset, "offset after " + cmd); |
michael@0 | 113 | return findChildNum(body, sel.focusNode); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | function node(i) { |
michael@0 | 117 | var n = body.firstChild; |
michael@0 | 118 | while (i > 0) { |
michael@0 | 119 | n = n.nextSibling; |
michael@0 | 120 | --i; |
michael@0 | 121 | } |
michael@0 | 122 | return n; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | doCommand("cmd_scrollBottom"); |
michael@0 | 126 | yield; |
michael@0 | 127 | testScrollCommand("cmd_scrollBottom", root.scrollHeight - 100); |
michael@0 | 128 | doCommand("cmd_scrollTop"); |
michael@0 | 129 | yield; |
michael@0 | 130 | testScrollCommand("cmd_scrollTop", 0); |
michael@0 | 131 | |
michael@0 | 132 | doCommand("cmd_scrollPageDown"); |
michael@0 | 133 | yield; |
michael@0 | 134 | var pageHeight = -root.getBoundingClientRect().top; |
michael@0 | 135 | ok(pageHeight > 0, "cmd_scrollPageDown works"); |
michael@0 | 136 | ok(pageHeight <= 100, "cmd_scrollPageDown doesn't scroll too much"); |
michael@0 | 137 | doCommand("cmd_scrollBottom"); |
michael@0 | 138 | doCommand("cmd_scrollPageUp"); |
michael@0 | 139 | yield; |
michael@0 | 140 | testScrollCommand("cmd_scrollPageUp", root.scrollHeight - 100 - pageHeight); |
michael@0 | 141 | |
michael@0 | 142 | doCommand("cmd_scrollTop"); |
michael@0 | 143 | doCommand("cmd_scrollLineDown"); |
michael@0 | 144 | yield; |
michael@0 | 145 | var lineHeight = -root.getBoundingClientRect().top; |
michael@0 | 146 | ok(lineHeight > 0, "Can scroll by lines"); |
michael@0 | 147 | doCommand("cmd_scrollBottom"); |
michael@0 | 148 | doCommand("cmd_scrollLineUp"); |
michael@0 | 149 | yield; |
michael@0 | 150 | testScrollCommand("cmd_scrollLineUp", root.scrollHeight - 100 - lineHeight); |
michael@0 | 151 | |
michael@0 | 152 | var runSelectionTests = function(selectWordNextNode, selectWordNextOffset) { |
michael@0 | 153 | testMoveCommand("cmd_moveBottom", body, 23); |
michael@0 | 154 | testMoveCommand("cmd_moveTop", node(0), 0); |
michael@0 | 155 | testSelectCommand("cmd_selectBottom", body, 23); |
michael@0 | 156 | doCommand("cmd_moveBottom"); |
michael@0 | 157 | testSelectCommand("cmd_selectTop", node(0), 0); |
michael@0 | 158 | |
michael@0 | 159 | doCommand("cmd_moveTop"); |
michael@0 | 160 | testMoveCommand("cmd_lineNext", node(2), 0); |
michael@0 | 161 | testMoveCommand("cmd_linePrevious", node(0), 0); |
michael@0 | 162 | testSelectCommand("cmd_selectLineNext", node(2), 0); |
michael@0 | 163 | doCommand("cmd_moveBottom"); |
michael@0 | 164 | testSelectCommand("cmd_selectLinePrevious", node(20), 2); |
michael@0 | 165 | |
michael@0 | 166 | doCommand("cmd_moveBottom"); |
michael@0 | 167 | testMoveCommand("cmd_charPrevious", node(22), 1); |
michael@0 | 168 | testMoveCommand("cmd_charNext", node(22), 2); |
michael@0 | 169 | testSelectCommand("cmd_selectCharPrevious", node(22), 1); |
michael@0 | 170 | doCommand("cmd_moveTop"); |
michael@0 | 171 | testSelectCommand("cmd_selectCharNext", node(0), 1); |
michael@0 | 172 | |
michael@0 | 173 | doCommand("cmd_moveTop"); |
michael@0 | 174 | testMoveCommand("cmd_endLine", body, 1); |
michael@0 | 175 | testMoveCommand("cmd_beginLine", node(0), 0); |
michael@0 | 176 | testSelectCommand("cmd_selectEndLine", body, 1); |
michael@0 | 177 | doCommand("cmd_moveBottom"); |
michael@0 | 178 | testSelectCommand("cmd_selectBeginLine", node(22), 0); |
michael@0 | 179 | |
michael@0 | 180 | doCommand("cmd_moveBottom"); |
michael@0 | 181 | testMoveCommand("cmd_wordPrevious", node(22), 0); |
michael@0 | 182 | testMoveCommand("cmd_wordNext", body, 23); |
michael@0 | 183 | testSelectCommand("cmd_selectWordPrevious", node(22), 0); |
michael@0 | 184 | doCommand("cmd_moveTop"); |
michael@0 | 185 | testSelectCommand("cmd_selectWordNext", selectWordNextNode, selectWordNextOffset); |
michael@0 | 186 | |
michael@0 | 187 | doCommand("cmd_moveTop"); |
michael@0 | 188 | var lineNum = testPageMoveCommand("cmd_movePageDown", 0); |
michael@0 | 189 | ok(lineNum > 0, "cmd_movePageDown works"); |
michael@0 | 190 | doCommand("cmd_moveBottom"); |
michael@0 | 191 | doCommand("cmd_beginLine"); |
michael@0 | 192 | is(testPageMoveCommand("cmd_movePageUp", 0), 22 - lineNum, "cmd_movePageUp"); |
michael@0 | 193 | |
michael@0 | 194 | doCommand("cmd_moveTop"); |
michael@0 | 195 | is(testPageSelectCommand("cmd_selectPageDown", 0), lineNum, "cmd_selectPageDown"); |
michael@0 | 196 | doCommand("cmd_moveBottom"); |
michael@0 | 197 | doCommand("cmd_beginLine"); |
michael@0 | 198 | is(testPageSelectCommand("cmd_selectPageUp", 0), 22 - lineNum, "cmd_selectPageUp"); |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | try { |
michael@0 | 202 | prefs.setBoolPref("layout.word_select.eat_space_to_next_word", false); |
michael@0 | 203 | runSelectionTests(body, 1); |
michael@0 | 204 | prefs.setBoolPref("layout.word_select.eat_space_to_next_word", true); |
michael@0 | 205 | runSelectionTests(node(2), 0); |
michael@0 | 206 | } finally { |
michael@0 | 207 | prefs.clearUserPref("general.smoothScroll"); |
michael@0 | 208 | prefs.clearUserPref("layout.word_select.eat_space_to_next_word"); |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | winUtils.restoreNormalRefresh(); |
michael@0 | 212 | SimpleTest.finish(); |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 216 | addLoadEvent(runTest); |
michael@0 | 217 | ]]> |
michael@0 | 218 | </script> |
michael@0 | 219 | |
michael@0 | 220 | <body id="html_body" xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 221 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=372685">Mozilla Bug 372685</a> |
michael@0 | 222 | <p id="display"></p> |
michael@0 | 223 | |
michael@0 | 224 | <pre id="test"> |
michael@0 | 225 | </pre> |
michael@0 | 226 | <iframe id="edit" width="200" height="100" src="about:blank"/> |
michael@0 | 227 | </body> |
michael@0 | 228 | </window> |