editor/libeditor/html/tests/test_bug674770-2.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=674770
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 674770</title>
michael@0 8 <script type="application/javascript" src="/MochiKit/packed.js"></script>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 12 </head>
michael@0 13 <body>
michael@0 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=674770">Mozilla Bug 674770</a>
michael@0 15 <p id="display"></p>
michael@0 16 <div id="content">
michael@0 17 <iframe id="iframe" style="display: block; height: 14em;"
michael@0 18 src="data:text/html,<input id='text' value='pasted'><input id='input' style='display: block;'><p id='editor1' contenteditable>editor1:</p><p id='editor2' contenteditable>editor2:</p>"></iframe>
michael@0 19 </div>
michael@0 20 <pre id="test">
michael@0 21 <script type="application/javascript">
michael@0 22
michael@0 23 /** Test for Bug 674770 **/
michael@0 24 SimpleTest.waitForExplicitFinish();
michael@0 25
michael@0 26 var iframe = document.getElementById("iframe");
michael@0 27 var frameWindow, frameDocument;
michael@0 28
michael@0 29 var gClicked = false;
michael@0 30 var gClicking = null;
michael@0 31 var gDoPreventDefault1 = null;
michael@0 32 var gDoPreventDefault2 = null;
michael@0 33
michael@0 34 function clickEventHnalder(aEvent)
michael@0 35 {
michael@0 36 if (aEvent.button == 1 && aEvent.target == gClicking) {
michael@0 37 gClicked = true;
michael@0 38 }
michael@0 39 if (gDoPreventDefault1 == aEvent.target) {
michael@0 40 aEvent.preventDefault();
michael@0 41 }
michael@0 42 if (gDoPreventDefault2 == aEvent.target) {
michael@0 43 aEvent.preventDefault();
michael@0 44 }
michael@0 45 }
michael@0 46
michael@0 47 // NOTE: tests need to check the result *after* the content is actually
michael@0 48 // modified. Sometimes, the modification is delayed. Therefore, there
michael@0 49 // are a lot of functions and SimpleTest.executeSoon()s.
michael@0 50
michael@0 51 SimpleTest.waitForFocus(function() {
michael@0 52 SpecialPowers.setBoolPref("middlemouse.contentLoadURL", false);
michael@0 53 SpecialPowers.setBoolPref("middlemouse.paste", true);
michael@0 54
michael@0 55 frameWindow = iframe.contentWindow;
michael@0 56 frameDocument = iframe.contentDocument;
michael@0 57
michael@0 58 frameDocument.getElementById("input").addEventListener("click", clickEventHnalder, false);
michael@0 59 frameDocument.getElementById("editor1").addEventListener("click", clickEventHnalder, false);
michael@0 60 frameDocument.getElementById("editor2").addEventListener("click", clickEventHnalder, false);
michael@0 61
michael@0 62 var text = frameDocument.getElementById("text");
michael@0 63
michael@0 64 text.focus();
michael@0 65
michael@0 66 SimpleTest.executeSoon(function() {
michael@0 67 if (navigator.platform.indexOf("Linux") == 0) {
michael@0 68 synthesizeKey("a", { altKey: true }, frameWindow);
michael@0 69 } else {
michael@0 70 synthesizeKey("a", { accelKey: true }, frameWindow);
michael@0 71 }
michael@0 72 // Windows and Mac don't have primary selection, we should copy the text to
michael@0 73 // the global clipboard.
michael@0 74 if (!SpecialPowers.supportsSelectionClipboard()) {
michael@0 75 SimpleTest.waitForClipboard("pasted",
michael@0 76 function() { synthesizeKey("c", { accelKey: true }, frameWindow); },
michael@0 77 function() { SimpleTest.executeSoon(runInputTests1) },
michael@0 78 cleanup);
michael@0 79 } else {
michael@0 80 // Otherwise, don't call waitForClipboard since it breaks primary
michael@0 81 // selection.
michael@0 82 runInputTests1();
michael@0 83 }
michael@0 84 });
michael@0 85 });
michael@0 86
michael@0 87 function runInputTests1()
michael@0 88 {
michael@0 89 var input = frameDocument.getElementById("input");
michael@0 90
michael@0 91 // first, copy text.
michael@0 92
michael@0 93 // when middle clicked in focused input element, text should be pasted.
michael@0 94 input.value = "";
michael@0 95 input.focus();
michael@0 96
michael@0 97 SimpleTest.executeSoon(function() {
michael@0 98 gClicked = false;
michael@0 99 gClicking = input;
michael@0 100 gDoPreventDefault1 = null;
michael@0 101 gDoPreventDefault2 = null;
michael@0 102
michael@0 103 synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
michael@0 104
michael@0 105 SimpleTest.executeSoon(function() {
michael@0 106 todo(gClicked, "click event hasn't been fired for runInputTests1");
michael@0 107 is(input.value, "pasted", "failed to paste in input element");
michael@0 108
michael@0 109 SimpleTest.executeSoon(runInputTests2);
michael@0 110 });
michael@0 111 });
michael@0 112 }
michael@0 113
michael@0 114 function runInputTests2()
michael@0 115 {
michael@0 116 var input = frameDocument.getElementById("input");
michael@0 117
michael@0 118 // even if the input element hasn't had focus, middle click should set focus
michael@0 119 // to it and paste the text.
michael@0 120 input.value = "";
michael@0 121 input.blur();
michael@0 122
michael@0 123 SimpleTest.executeSoon(function() {
michael@0 124 gClicked = false;
michael@0 125 gClicking = input;
michael@0 126 gDoPreventDefault1 = null;
michael@0 127 gDoPreventDefault2 = null;
michael@0 128
michael@0 129 synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
michael@0 130
michael@0 131 SimpleTest.executeSoon(function() {
michael@0 132 todo(gClicked, "click event hasn't been fired for runInputTests2");
michael@0 133 is(input.value, "pasted",
michael@0 134 "failed to paste in input element when it hasn't had focus yet");
michael@0 135
michael@0 136 SimpleTest.executeSoon(runInputTests3);
michael@0 137 });
michael@0 138 });
michael@0 139 }
michael@0 140
michael@0 141 function runInputTests3()
michael@0 142 {
michael@0 143 var input = frameDocument.getElementById("input");
michael@0 144 var editor1 = frameDocument.getElementById("editor1");
michael@0 145
michael@0 146 // preventDefault() of HTML editor's click event handler shouldn't prevent
michael@0 147 // middle click pasting in input element.
michael@0 148 input.value = "";
michael@0 149 input.focus();
michael@0 150
michael@0 151 SimpleTest.executeSoon(function() {
michael@0 152 gClicked = false;
michael@0 153 gClicking = input;
michael@0 154 gDoPreventDefault1 = editor1;
michael@0 155 gDoPreventDefault2 = null;
michael@0 156
michael@0 157 synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
michael@0 158
michael@0 159 SimpleTest.executeSoon(function() {
michael@0 160 todo(gClicked, "click event hasn't been fired for runInputTests3");
michael@0 161 is(input.value, "pasted",
michael@0 162 "failed to paste in input element when editor1 does preventDefault()");
michael@0 163
michael@0 164 SimpleTest.executeSoon(runInputTests4);
michael@0 165 });
michael@0 166 });
michael@0 167 }
michael@0 168
michael@0 169 function runInputTests4()
michael@0 170 {
michael@0 171 var input = frameDocument.getElementById("input");
michael@0 172 var editor1 = frameDocument.getElementById("editor1");
michael@0 173
michael@0 174 // preventDefault() of input element's click event handler should prevent
michael@0 175 // middle click pasting in it.
michael@0 176 input.value = "";
michael@0 177 input.focus();
michael@0 178
michael@0 179 SimpleTest.executeSoon(function() {
michael@0 180 gClicked = false;
michael@0 181 gClicking = input;
michael@0 182 gDoPreventDefault1 = input;
michael@0 183 gDoPreventDefault2 = null;
michael@0 184
michael@0 185 synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
michael@0 186
michael@0 187 SimpleTest.executeSoon(function() {
michael@0 188 todo(gClicked, "click event hasn't been fired for runInputTests4");
michael@0 189 todo_is(input.value, "",
michael@0 190 "pasted in input element when it does preventDefault()");
michael@0 191
michael@0 192 SimpleTest.executeSoon(runContentEditableTests1);
michael@0 193 });
michael@0 194 });
michael@0 195 }
michael@0 196
michael@0 197 function runContentEditableTests1()
michael@0 198 {
michael@0 199 var editor1 = frameDocument.getElementById("editor1");
michael@0 200
michael@0 201 // when middle clicked in focused contentediable editor, text should be
michael@0 202 // pasted.
michael@0 203 editor1.innerHTML = "editor1:";
michael@0 204 editor1.focus();
michael@0 205
michael@0 206 SimpleTest.executeSoon(function() {
michael@0 207 gClicked = false;
michael@0 208 gClicking = editor1;
michael@0 209 gDoPreventDefault1 = null;
michael@0 210 gDoPreventDefault2 = null;
michael@0 211
michael@0 212 synthesizeMouseAtCenter(editor1, {button: 1}, frameWindow);
michael@0 213
michael@0 214 SimpleTest.executeSoon(function() {
michael@0 215 todo(gClicked, "click event hasn't been fired for runContentEditableTests1");
michael@0 216 is(editor1.innerHTML, "editor1:pasted",
michael@0 217 "failed to paste text in contenteditable editor");
michael@0 218 SimpleTest.executeSoon(runContentEditableTests2);
michael@0 219 });
michael@0 220 });
michael@0 221 }
michael@0 222
michael@0 223 function runContentEditableTests2()
michael@0 224 {
michael@0 225 var editor1 = frameDocument.getElementById("editor1");
michael@0 226
michael@0 227 // even if the contenteditable editor hasn't had focus, middle click should
michael@0 228 // set focus to it and paste the text.
michael@0 229 editor1.innerHTML = "editor1:";
michael@0 230 editor1.blur();
michael@0 231
michael@0 232 SimpleTest.executeSoon(function() {
michael@0 233 gClicked = false;
michael@0 234 gClicking = editor1;
michael@0 235 gDoPreventDefault1 = null;
michael@0 236 gDoPreventDefault2 = null;
michael@0 237
michael@0 238 synthesizeMouseAtCenter(editor1, {button: 1}, frameWindow);
michael@0 239
michael@0 240 SimpleTest.executeSoon(function() {
michael@0 241 todo(gClicked, "click event hasn't been fired for runContentEditableTests2");
michael@0 242 is(editor1.innerHTML, "editor1:pasted",
michael@0 243 "failed to paste in contenteditable editor #1 when it hasn't had focus yet");
michael@0 244 SimpleTest.executeSoon(runContentEditableTests3);
michael@0 245 });
michael@0 246 });
michael@0 247 }
michael@0 248
michael@0 249 function runContentEditableTests3()
michael@0 250 {
michael@0 251 var editor1 = frameDocument.getElementById("editor1");
michael@0 252 var editor2 = frameDocument.getElementById("editor2");
michael@0 253
michael@0 254 // When editor1 has focus but editor2 is middle clicked, should be pasted
michael@0 255 // in the editor2.
michael@0 256 editor1.innerHTML = "editor1:";
michael@0 257 editor2.innerHTML = "editor2:";
michael@0 258 editor1.focus();
michael@0 259
michael@0 260 SimpleTest.executeSoon(function() {
michael@0 261 gClicked = false;
michael@0 262 gClicking = editor2;
michael@0 263 gDoPreventDefault1 = null;
michael@0 264 gDoPreventDefault2 = null;
michael@0 265
michael@0 266 synthesizeMouseAtCenter(editor2, {button: 1}, frameWindow);
michael@0 267
michael@0 268 SimpleTest.executeSoon(function() {
michael@0 269 todo(gClicked, "click event hasn't been fired for runContentEditableTests3");
michael@0 270 is(editor1.innerHTML, "editor1:",
michael@0 271 "pasted in contenteditable editor #1 when editor2 is clicked");
michael@0 272 is(editor2.innerHTML, "editor2:pasted",
michael@0 273 "failed to paste in contenteditable editor #2 when editor2 is clicked");
michael@0 274 SimpleTest.executeSoon(runContentEditableTests4);
michael@0 275 });
michael@0 276 });
michael@0 277 }
michael@0 278
michael@0 279 function runContentEditableTests4()
michael@0 280 {
michael@0 281 var editor1 = frameDocument.getElementById("editor1");
michael@0 282
michael@0 283 // preventDefault() of editor1's click event handler should prevent
michael@0 284 // middle click pasting in it.
michael@0 285 editor1.innerHTML = "editor1:";
michael@0 286 editor1.focus();
michael@0 287
michael@0 288 SimpleTest.executeSoon(function() {
michael@0 289 gClicked = false;
michael@0 290 gClicking = editor1;
michael@0 291 gDoPreventDefault1 = editor1;
michael@0 292 gDoPreventDefault2 = null;
michael@0 293
michael@0 294 synthesizeMouseAtCenter(editor1, {button: 1}, frameWindow);
michael@0 295
michael@0 296 SimpleTest.executeSoon(function() {
michael@0 297 todo(gClicked, "click event hasn't been fired for runContentEditableTests4");
michael@0 298 todo_is(editor1.innerHTML, "editor1:",
michael@0 299 "pasted in contenteditable editor #1 when it does preventDefault()");
michael@0 300 SimpleTest.executeSoon(runContentEditableTests5);
michael@0 301 });
michael@0 302 });
michael@0 303 }
michael@0 304
michael@0 305 function runContentEditableTests5()
michael@0 306 {
michael@0 307 var editor1 = frameDocument.getElementById("editor1");
michael@0 308 var editor2 = frameDocument.getElementById("editor2");
michael@0 309
michael@0 310 // preventDefault() of editor1's click event handler shouldn't prevent
michael@0 311 // middle click pasting in editor2.
michael@0 312 editor1.innerHTML = "editor1:";
michael@0 313 editor2.innerHTML = "editor2:";
michael@0 314 editor2.focus();
michael@0 315
michael@0 316 SimpleTest.executeSoon(function() {
michael@0 317 gClicked = false;
michael@0 318 gClicking = editor2;
michael@0 319 gDoPreventDefault1 = editor1;
michael@0 320 gDoPreventDefault2 = null;
michael@0 321
michael@0 322 synthesizeMouseAtCenter(editor2, {button: 1}, frameWindow);
michael@0 323
michael@0 324 SimpleTest.executeSoon(function() {
michael@0 325 todo(gClicked, "click event hasn't been fired for runContentEditableTests5");
michael@0 326 is(editor1.innerHTML, "editor1:",
michael@0 327 "pasted in contenteditable editor #1?");
michael@0 328 is(editor2.innerHTML, "editor2:pasted",
michael@0 329 "failed to paste in contenteditable editor #2");
michael@0 330
michael@0 331 SimpleTest.executeSoon(initForBodyEditableDocumentTests);
michael@0 332 });
michael@0 333 });
michael@0 334 }
michael@0 335
michael@0 336 function initForBodyEditableDocumentTests()
michael@0 337 {
michael@0 338 frameDocument.getElementById("input").removeEventListener("click", clickEventHnalder, false);
michael@0 339 frameDocument.getElementById("editor1").removeEventListener("click", clickEventHnalder, false);
michael@0 340 frameDocument.getElementById("editor2").removeEventListener("click", clickEventHnalder, false);
michael@0 341
michael@0 342 iframe.onload =
michael@0 343 function (aEvent) { SimpleTest.executeSoon(runBodyEditableDocumentTests1); };
michael@0 344 iframe.src =
michael@0 345 "data:text/html,<body contenteditable>body:</body>";
michael@0 346 }
michael@0 347
michael@0 348 function runBodyEditableDocumentTests1()
michael@0 349 {
michael@0 350 frameWindow = iframe.contentWindow;
michael@0 351 frameDocument = iframe.contentDocument;
michael@0 352
michael@0 353 var body = frameDocument.body;
michael@0 354
michael@0 355 is(body.innerHTML, "body:",
michael@0 356 "failed to initialize at runBodyEditableDocumentTests1");
michael@0 357
michael@0 358 // middle click on html element should cause pasting text in its body.
michael@0 359 synthesizeMouseAtCenter(frameDocument.documentElement, {button: 1}, frameWindow);
michael@0 360
michael@0 361 SimpleTest.executeSoon(function() {
michael@0 362 is(body.innerHTML,
michael@0 363 "body:pasted",
michael@0 364 "failed to paste in editable body element when clicked on html element");
michael@0 365
michael@0 366 SimpleTest.executeSoon(runBodyEditableDocumentTests2);
michael@0 367 });
michael@0 368 }
michael@0 369
michael@0 370 function runBodyEditableDocumentTests2()
michael@0 371 {
michael@0 372 frameDocument.body.innerHTML = "body:<span id='span' contenteditable='false'>non-editable</span>";
michael@0 373
michael@0 374 var body = frameDocument.body;
michael@0 375
michael@0 376 is(body.innerHTML, "body:<span id=\"span\" contenteditable=\"false\">non-editable</span>",
michael@0 377 "failed to initialize at runBodyEditableDocumentTests2");
michael@0 378
michael@0 379 synthesizeMouseAtCenter(frameDocument.getElementById("span"), {button: 1}, frameWindow);
michael@0 380
michael@0 381 SimpleTest.executeSoon(function() {
michael@0 382 is(body.innerHTML,
michael@0 383 "body:<span id=\"span\" contenteditable=\"false\">non-editable</span>",
michael@0 384 "pasted when middle clicked in non-editable element");
michael@0 385
michael@0 386 SimpleTest.executeSoon(cleanup);
michael@0 387 });
michael@0 388 }
michael@0 389
michael@0 390 function cleanup()
michael@0 391 {
michael@0 392 SpecialPowers.clearUserPref("middlemouse.contentLoadURL");
michael@0 393 SpecialPowers.clearUserPref("middlemouse.paste");
michael@0 394
michael@0 395 SimpleTest.finish();
michael@0 396 }
michael@0 397
michael@0 398 </script>
michael@0 399 </pre>
michael@0 400 </body>
michael@0 401 </html>

mercurial