test_bug520189.html (25192B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=520182 5 --> 6 <head> 7 <title>Test for Bug 520182</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=520182">Mozilla Bug 520182</a> 14 <p id="display"></p> 15 <div id="content"> 16 <iframe id="a" src="about:blank"></iframe> 17 <iframe id="b" src="about:blank"></iframe> 18 <iframe id="c" src="about:blank"></iframe> 19 <div id="d" contenteditable="true"></div> 20 <div id="e" contenteditable="true"></div> 21 <div id="f" contenteditable="true"></div> 22 <iframe id="g" src="about:blank"></iframe> 23 <iframe id="h" src="about:blank"></iframe> 24 <div id="i" contenteditable="true"></div> 25 <div id="j" contenteditable="true"></div> 26 <iframe id="k" src="about:blank"></iframe> 27 <div id="l" contenteditable="true"></div> 28 <iframe id="m" src="about:blank"></iframe> 29 <div id="n" contenteditable="true"></div> 30 <iframe id="o" src="about:blank"></iframe> 31 <div id="p" contenteditable="true"></div> 32 <iframe id="q" src="about:blank"></iframe> 33 <div id="r" contenteditable="true"></div> 34 <iframe id="s" src="about:blank"></iframe> 35 <div id="t" contenteditable="true"></div> 36 <iframe id="u" src="about:blank"></iframe> 37 <div id="v" contenteditable="true"></div> 38 <iframe id="w" src="about:blank"></iframe> 39 <div id="x" contenteditable="true"></div> 40 <iframe id="y" src="about:blank"></iframe> 41 <div id="z" contenteditable="true"></div> 42 <iframe id="aa" src="about:blank"></iframe> 43 <div id="bb" contenteditable="true"></div> 44 <iframe id="cc" src="about:blank"></iframe> 45 <div id="dd" contenteditable="true"></div> 46 <iframe id="ee" src="about:blank"></iframe> 47 <div id="ff" contenteditable="true"></div> 48 <iframe id="gg" src="about:blank"></iframe> 49 <div id="hh" contenteditable="true"></div> 50 <iframe id="ii" src="about:blank"></iframe> 51 <div id="jj" contenteditable="true"></div> 52 <iframe id="kk" src="about:blank"></iframe> 53 <div id="ll" contenteditable="true"></div> 54 <iframe id="mm" src="about:blank"></iframe> 55 <div id="nn" contenteditable="true"></div> 56 <iframe id="oo" src="about:blank"></iframe> 57 <div id="pp" contenteditable="true"></div> 58 <iframe id="qq" src="about:blank"></iframe> 59 <div id="rr" contenteditable="true"></div> 60 <iframe id="ss" src="about:blank"></iframe> 61 <div id="tt" contenteditable="true"></div> 62 <iframe id="uu" src="about:blank"></iframe> 63 <div id="vv" contenteditable="true"></div> 64 <div id="sss" contenteditable="true"></div> 65 <iframe id="ssss" src="about:blank"></iframe> 66 <div id="ttt" contenteditable="true"></div> 67 <iframe id="tttt" src="about:blank"></iframe> 68 <div id="uuu" contenteditable="true"></div> 69 <iframe id="uuuu" src="about:blank"></iframe> 70 <div id="vvv" contenteditable="true"></div> 71 <iframe id="vvvv" src="about:blank"></iframe> 72 <div id="www" contenteditable="true"></div> 73 <iframe id="wwww" src="about:blank"></iframe> 74 <div id="xxx" contenteditable="true"></div> 75 <iframe id="xxxx" src="about:blank"></iframe> 76 <div id="yyy" contenteditable="true"></div> 77 <iframe id="yyyy" src="about:blank"></iframe> 78 </div> 79 <pre id="test"> 80 <script type="application/javascript"> 81 82 /* eslint-disable no-useless-concat */ 83 84 /** Test for Bug 520182 */ 85 86 const dataPayload = "foo<iframe src=\"data:text/html,bar\"></iframe>baz"; 87 const jsPayload = "foo<iframe src=\"javascript:void('bar');\"></iframe>baz"; 88 const httpPayload = "foo<iframe src=\"http://mochi.test:8888/\"></iframe>baz"; 89 const scriptPayload = "foo<script>document.write(\"<iframe></iframe>\");</sc" + "ript>baz"; 90 const scriptExternalPayload = "foo<script src=\"data:text/javascript,document.write('<iframe></iframe>');\"></sc" + "ript>baz"; 91 const validStyle1Payload = "foo<style>#bar{color:red;}</style>baz"; 92 const validStyle2Payload = "foo<span style=\"color:red\">bar</span>baz"; 93 const validStyle3Payload = "foo<style>@font-face{font-family:xxx;src:'xxx.ttf';}</style>baz"; 94 const validStyle4Payload = "foo<style>@namespace xxx url(http://example.com/);</style>baz"; 95 const invalidStyle1Payload = "foo<style>#bar{-moz-binding:url('data:text/xml,<?xml version=\"1.0\"><binding xmlns=\"http://www.mozilla.org/xbl\"/>');}</style>baz"; 96 const invalidStyle2Payload = "foo<span style=\"-moz-binding:url('data:text/xml,<?xml version="1.0"><binding xmlns="http://www.mozilla.org/xbl"/>');\">bar</span>baz"; 97 const invalidStyle3Payload = "foo<style>@import 'xxx.css';</style>baz"; 98 const invalidStyle4Payload = "foo<span style=\"@import 'xxx.css';\">bar</span>baz"; 99 const invalidStyle5Payload = "foo<span style=\"@font-face{font-family:xxx;src:'xxx.ttf';}\">bar</span>baz"; 100 const invalidStyle6Payload = "foo<span style=\"@namespace xxx url(http://example.com/);\">bar</span>baz"; 101 const invalidStyle7Payload = "<html><head><title>xxx</title></head><body>foo</body></html>"; 102 const invalidStyle8Payload = "foo<style>@-moz-document url-prefix() {};</style>baz"; 103 const invalidStyle9Payload = "foo<style>@keyframes bar {};</style>baz"; 104 const nestedStylePayload = "foo<style>#bar1{-moz-binding:url('data:text/xml,<?xml version="1.0"><binding xmlns="http://www.mozilla.org/xbl" id="binding-1"/>');<style></style>#bar2{-moz-binding:url('data:text/xml,<?xml version="1.0"><binding xmlns="http://www.mozilla.org/xbl" id="binding-2"/>');</style>baz"; 105 const validImgSrc1Payload = "foo<img src=\"data:image/png,bar\">baz"; 106 const validImgSrc2Payload = "foo<img src=\"javascript:void('bar');\">baz"; 107 const validImgSrc3Payload = "foo<img src=\"file:///bar.png\">baz"; 108 const validDataFooPayload = "foo<span data-bar=\"value\">baz</span>"; 109 const validDataFoo2Payload = "foo<span _bar=\"value\">baz</span>"; 110 const svgPayload = "foo<svg><title>svgtitle</title></svg>bar"; 111 const svg2Payload = "foo<svg><bogussvg/></svg>bar"; 112 const mathPayload = "foo<math><bogusmath/></math>bar"; 113 const math2Payload = "foo<math><style>@import \"yyy.css\";</style</math>bar"; 114 const math3Payload = "foo<math><mi></mi></math>bar"; 115 const videoPayload = "foo<video></video>bar"; 116 const microdataPayload = "<head><meta name=foo content=bar><link rel=stylesheet href=url></head><body><meta itemprop=foo content=bar><link itemprop=bar href=url></body>"; 117 118 var tests = [ 119 { 120 id: "a", 121 isIFrame: true, 122 payload: dataPayload, 123 iframeCount: 0, 124 rootElement() { return document.getElementById("a").contentDocument.documentElement; }, 125 }, 126 { 127 id: "b", 128 isIFrame: true, 129 payload: jsPayload, 130 iframeCount: 0, 131 rootElement() { return document.getElementById("b").contentDocument.documentElement; }, 132 }, 133 { 134 id: "c", 135 isIFrame: true, 136 payload: httpPayload, 137 iframeCount: 0, 138 rootElement() { return document.getElementById("c").contentDocument.documentElement; }, 139 }, 140 { 141 id: "g", 142 isIFrame: true, 143 payload: scriptPayload, 144 rootElement() { return document.getElementById("g").contentDocument.documentElement; }, 145 iframeCount: 0, 146 }, 147 { 148 id: "h", 149 isIFrame: true, 150 payload: scriptExternalPayload, 151 rootElement() { return document.getElementById("h").contentDocument.documentElement; }, 152 iframeCount: 0, 153 }, 154 { 155 id: "d", 156 payload: dataPayload, 157 iframeCount: 0, 158 rootElement() { return document.getElementById("d"); }, 159 }, 160 { 161 id: "e", 162 payload: jsPayload, 163 iframeCount: 0, 164 rootElement() { return document.getElementById("e"); }, 165 }, 166 { 167 id: "f", 168 payload: httpPayload, 169 iframeCount: 0, 170 rootElement() { return document.getElementById("f"); }, 171 }, 172 { 173 id: "i", 174 payload: scriptPayload, 175 rootElement() { return document.getElementById("i"); }, 176 iframeCount: 0, 177 }, 178 { 179 id: "j", 180 payload: scriptExternalPayload, 181 rootElement() { return document.getElementById("j"); }, 182 iframeCount: 0, 183 }, 184 { 185 id: "k", 186 isIFrame: true, 187 payload: validStyle1Payload, 188 rootElement() { return document.getElementById("k").contentDocument.documentElement; }, 189 checkResult(html) { isnot(html.indexOf("style"), -1, "Should have retained style"); }, 190 }, 191 { 192 id: "l", 193 payload: validStyle1Payload, 194 rootElement() { return document.getElementById("l"); }, 195 checkResult(html) { isnot(html.indexOf("style"), -1, "Should have retained style"); }, 196 }, 197 { 198 id: "m", 199 isIFrame: true, 200 payload: validStyle2Payload, 201 rootElement() { return document.getElementById("m").contentDocument.documentElement; }, 202 checkResult(html) { isnot(html.indexOf("style"), -1, "Should have retained style"); }, 203 }, 204 { 205 id: "n", 206 payload: validStyle2Payload, 207 rootElement() { return document.getElementById("n"); }, 208 checkResult(html) { isnot(html.indexOf("style"), -1, "Should have retained style"); }, 209 }, 210 { 211 id: "s", 212 isIFrame: true, 213 payload: invalidStyle1Payload, 214 rootElement() { return document.getElementById("s").contentDocument.documentElement; }, 215 checkResult(html) { is(html.indexOf("xxx"), -1, "Should not have retained the import style"); }, 216 }, 217 { 218 id: "t", 219 payload: invalidStyle1Payload, 220 rootElement() { return document.getElementById("t"); }, 221 checkResult(html) { is(html.indexOf("xxx"), -1, "Should not have retained the import style"); }, 222 }, 223 { 224 id: "u", 225 isIFrame: true, 226 payload: invalidStyle2Payload, 227 rootElement() { return document.getElementById("u").contentDocument.documentElement; }, 228 checkResult(html) { is(html.indexOf("xxx"), -1, "Should not have retained the import style"); }, 229 }, 230 { 231 id: "v", 232 payload: invalidStyle2Payload, 233 rootElement() { return document.getElementById("v"); }, 234 checkResult(html) { is(html.indexOf("xxx"), -1, "Should not have retained the import style"); }, 235 }, 236 { 237 id: "w", 238 isIFrame: true, 239 payload: validStyle3Payload, 240 rootElement() { return document.getElementById("w").contentDocument.documentElement; }, 241 checkResult(html) { isnot(html.indexOf("xxx"), -1, "Should have retained the font-face style"); }, 242 }, 243 { 244 id: "x", 245 payload: validStyle3Payload, 246 rootElement() { return document.getElementById("x"); }, 247 checkResult(html) { isnot(html.indexOf("xxx"), -1, "Should have retained the font-face style"); }, 248 }, 249 { 250 id: "y", 251 isIFrame: true, 252 payload: invalidStyle5Payload, 253 rootElement() { return document.getElementById("y").contentDocument.documentElement; }, 254 checkResult(html) { isnot(html.indexOf("xxx"), -1, "Should not have retained the font-face style"); }, 255 }, 256 { 257 id: "z", 258 payload: invalidStyle5Payload, 259 rootElement() { return document.getElementById("z"); }, 260 checkResult(html) { isnot(html.indexOf("xxx"), -1, "Should not have retained the font-face style"); }, 261 }, 262 { 263 id: "cc", 264 isIFrame: true, 265 payload: validStyle4Payload, 266 rootElement() { return document.getElementById("cc").contentDocument.documentElement; }, 267 checkResult(html) { isnot(html.indexOf("xxx"), -1, "Should have retained the namespace style"); }, 268 }, 269 { 270 id: "dd", 271 payload: validStyle4Payload, 272 rootElement() { return document.getElementById("dd"); }, 273 checkResult(html) { isnot(html.indexOf("xxx"), -1, "Should have retained the namespace style"); }, 274 }, 275 { 276 id: "ee", 277 isIFrame: true, 278 payload: invalidStyle6Payload, 279 rootElement() { return document.getElementById("ee").contentDocument.documentElement; }, 280 checkResult(html) { isnot(html.indexOf("xxx"), -1, "Should not have retained the namespace style"); }, 281 }, 282 { 283 id: "ff", 284 payload: invalidStyle6Payload, 285 rootElement() { return document.getElementById("ff"); }, 286 checkResult(html) { isnot(html.indexOf("xxx"), -1, "Should not have retained the namespace style"); }, 287 }, 288 { 289 id: "gg", 290 isIFrame: true, 291 payload: invalidStyle6Payload, 292 rootElement() { return document.getElementById("gg").contentDocument.documentElement; }, 293 checkResult(html) { isnot(html.indexOf("bar"), -1, "Should have retained the src attribute for the image"); }, 294 }, 295 { 296 id: "hh", 297 payload: invalidStyle6Payload, 298 rootElement() { return document.getElementById("hh"); }, 299 checkResult(html) { isnot(html.indexOf("bar"), -1, "Should have retained the src attribute for the image"); }, 300 }, 301 { 302 id: "ii", 303 isIFrame: true, 304 payload: invalidStyle6Payload, 305 rootElement() { return document.getElementById("ii").contentDocument.documentElement; }, 306 checkResult(html) { isnot(html.indexOf("bar"), -1, "Should have retained the src attribute for the image"); }, 307 }, 308 { 309 id: "jj", 310 payload: invalidStyle6Payload, 311 rootElement() { return document.getElementById("jj"); }, 312 checkResult(html) { isnot(html.indexOf("bar"), -1, "Should have retained the src attribute for the image"); }, 313 }, 314 { 315 id: "kk", 316 isIFrame: true, 317 payload: invalidStyle6Payload, 318 rootElement() { return document.getElementById("kk").contentDocument.documentElement; }, 319 checkResult(html) { isnot(html.indexOf("bar"), -1, "Should have retained the src attribute for the image"); }, 320 }, 321 { 322 id: "ll", 323 payload: invalidStyle6Payload, 324 rootElement() { return document.getElementById("ll"); }, 325 checkResult(html) { isnot(html.indexOf("bar"), -1, "Should have retained the src attribute for the image"); }, 326 }, 327 { 328 id: "mm", 329 isIFrame: true, 330 indirectPaste: true, 331 payload: invalidStyle7Payload, 332 rootElement() { return document.getElementById("mm").contentDocument.documentElement; }, 333 checkResult(html) { 334 is(html.indexOf("xxx"), -1, "Should not have retained the title text"); 335 isnot(html.indexOf("foo"), -1, "Should have retained the body text"); 336 }, 337 }, 338 { 339 id: "nn", 340 indirectPaste: true, 341 payload: invalidStyle7Payload, 342 rootElement() { return document.getElementById("nn"); }, 343 checkResult(html) { 344 is(html.indexOf("xxx"), -1, "Should not have retained the title text"); 345 isnot(html.indexOf("foo"), -1, "Should have retained the body text"); 346 }, 347 }, 348 { 349 id: "oo", 350 isIFrame: true, 351 payload: validDataFooPayload, 352 rootElement() { return document.getElementById("oo").contentDocument.documentElement; }, 353 checkResult(html) { isnot(html.indexOf("bar"), -1, "Should have retained the data-bar attribute"); }, 354 }, 355 { 356 id: "pp", 357 payload: validDataFooPayload, 358 rootElement() { return document.getElementById("pp"); }, 359 checkResult(html) { isnot(html.indexOf("bar"), -1, "Should have retained the data-bar attribute"); }, 360 }, 361 { 362 id: "qq", 363 isIFrame: true, 364 payload: validDataFoo2Payload, 365 rootElement() { return document.getElementById("qq").contentDocument.documentElement; }, 366 checkResult(html) { isnot(html.indexOf("bar"), -1, "Should have retained the _bar attribute"); }, 367 }, 368 { 369 id: "rr", 370 payload: validDataFoo2Payload, 371 rootElement() { return document.getElementById("rr"); }, 372 checkResult(html) { isnot(html.indexOf("bar"), -1, "Should have retained the _bar attribute"); }, 373 }, 374 { 375 id: "ss", 376 isIFrame: true, 377 payload: invalidStyle8Payload, 378 rootElement() { return document.getElementById("ss").contentDocument.documentElement; }, 379 checkResult(html) { is(html.indexOf("@-moz-document"), -1, "Should not have retained the @-moz-document rule"); }, 380 }, 381 { 382 id: "tt", 383 payload: invalidStyle8Payload, 384 rootElement() { return document.getElementById("tt"); }, 385 checkResult(html) { is(html.indexOf("@-moz-document"), -1, "Should not have retained the @-moz-document rule"); }, 386 }, 387 { 388 id: "uu", 389 isIFrame: true, 390 payload: invalidStyle9Payload, 391 rootElement() { return document.getElementById("uu").contentDocument.documentElement; }, 392 checkResult(html) { is(html.indexOf("@keyframes"), -1, "Should not have retained the @keyframes rule"); }, 393 }, 394 { 395 id: "vv", 396 payload: invalidStyle9Payload, 397 rootElement() { return document.getElementById("vv"); }, 398 checkResult(html) { is(html.indexOf("@keyframes"), -1, "Should not have retained the @keyframes rule"); }, 399 }, 400 { 401 id: "sss", 402 payload: svgPayload, 403 rootElement() { return document.getElementById("sss"); }, 404 checkResult(html) { isnot(html.indexOf("svgtitle"), -1, "Should have retained SVG title"); }, 405 }, 406 { 407 id: "ssss", 408 isIFrame: true, 409 payload: svgPayload, 410 rootElement() { return document.getElementById("ssss").contentDocument.documentElement; }, 411 checkResult(html) { isnot(html.indexOf("svgtitle"), -1, "Should have retained SVG title"); }, 412 }, 413 { 414 id: "ttt", 415 payload: svg2Payload, 416 rootElement() { return document.getElementById("ttt"); }, 417 checkResult(html) { is(html.indexOf("bogussvg"), -1, "Should have dropped bogussvg element"); }, 418 }, 419 { 420 id: "tttt", 421 isIFrame: true, 422 payload: svg2Payload, 423 rootElement() { return document.getElementById("tttt").contentDocument.documentElement; }, 424 checkResult(html) { is(html.indexOf("bogussvg"), -1, "Should have dropped bogussvg element"); }, 425 }, 426 { 427 id: "uuu", 428 payload: mathPayload, 429 rootElement() { return document.getElementById("uuu"); }, 430 checkResult(html) { is(html.indexOf("bogusmath"), -1, "Should have dropped bogusmath element"); }, 431 }, 432 { 433 id: "uuuu", 434 isIFrame: true, 435 payload: mathPayload, 436 rootElement() { return document.getElementById("uuuu").contentDocument.documentElement; }, 437 checkResult(html) { is(html.indexOf("bogusmath"), -1, "Should have dropped bogusmath element"); }, 438 }, 439 { 440 id: "vvv", 441 payload: math2Payload, 442 rootElement() { return document.getElementById("vvv"); }, 443 checkResult(html) { is(html.indexOf("yyy.css"), -1, "Should have dropped MathML style element"); }, 444 }, 445 { 446 id: "vvvv", 447 isIFrame: true, 448 payload: math2Payload, 449 rootElement() { return document.getElementById("vvvv").contentDocument.documentElement; }, 450 checkResult(html) { is(html.indexOf("yyy.css"), -1, "Should have dropped MathML style element"); }, 451 }, 452 { 453 id: "www", 454 payload: math3Payload, 455 rootElement() { return document.getElementById("www"); }, 456 checkResult(html) { isnot(html.indexOf("<mi"), -1, "Should not have dropped MathML mi element"); }, 457 }, 458 { 459 id: "wwww", 460 isIFrame: true, 461 payload: math3Payload, 462 rootElement() { return document.getElementById("wwww").contentDocument.documentElement; }, 463 checkResult(html) { isnot(html.indexOf("<mi"), -1, "Should not have dropped MathML mi element"); }, 464 }, 465 { 466 id: "xxx", 467 payload: videoPayload, 468 rootElement() { return document.getElementById("xxx"); }, 469 checkResult(html) { isnot(html.indexOf("controls="), -1, "Should have added the controls attribute"); }, 470 }, 471 { 472 id: "xxxx", 473 isIFrame: true, 474 payload: videoPayload, 475 rootElement() { return document.getElementById("xxxx").contentDocument.documentElement; }, 476 checkResult(html) { isnot(html.indexOf("controls="), -1, "Should have added the controls attribute"); }, 477 }, 478 { 479 id: "yyy", 480 payload: microdataPayload, 481 rootElement() { return document.getElementById("yyy"); }, 482 checkResult(html) { is(html.indexOf("name"), -1, "Should have dropped name."); is(html.indexOf("rel"), -1, "Should have dropped rel."); isnot(html.indexOf("itemprop"), -1, "Should not have dropped itemprop."); }, 483 }, 484 { 485 id: "yyyy", 486 isIFrame: true, 487 payload: microdataPayload, 488 rootElement() { return document.getElementById("yyyy").contentDocument.documentElement; }, 489 checkResult(html) { is(html.indexOf("name"), -1, "Should have dropped name."); is(html.indexOf("rel"), -1, "Should have dropped rel."); isnot(html.indexOf("itemprop"), -1, "Should not have dropped itemprop."); }, 490 }, 491 ]; 492 493 function doNextTest() { 494 /* global testCounter:true */ 495 if (typeof testCounter == "undefined") { 496 testCounter = 0; 497 } else if (++testCounter == tests.length) { 498 SimpleTest.finish(); 499 return; 500 } 501 502 runTest(tests[testCounter]); 503 504 doNextTest(); 505 } 506 507 function getLoadContext() { 508 const Ci = SpecialPowers.Ci; 509 return SpecialPowers.wrap(window).docShell.QueryInterface(Ci.nsILoadContext); 510 } 511 512 function runTest(test) { 513 var elem = document.getElementById(test.id); 514 if ("isIFrame" in test) { 515 elem.contentDocument.designMode = "on"; 516 elem.contentWindow.focus(); 517 } else { 518 elem.focus(); 519 } 520 521 var trans = SpecialPowers.Cc["@mozilla.org/widget/transferable;1"] 522 .createInstance(SpecialPowers.Ci.nsITransferable); 523 trans.init(getLoadContext()); 524 var data = SpecialPowers.Cc["@mozilla.org/supports-string;1"] 525 .createInstance(SpecialPowers.Ci.nsISupportsString); 526 data.data = test.payload; 527 trans.addDataFlavor("text/html"); 528 trans.setTransferData("text/html", data); 529 530 if ("indirectPaste" in test) { 531 var editor, win; 532 if ("isIFrame" in test) { 533 win = elem.contentDocument.defaultView; 534 } else { 535 getSelection().collapse(elem, 0); 536 win = window; 537 } 538 editor = SpecialPowers.wrap(win).docShell.editor; 539 let beforeInputEvent = null; 540 let inputEvent = null; 541 let selectionRanges = []; 542 win.addEventListener("beforeinput", aEvent => { 543 beforeInputEvent = aEvent; 544 selectionRanges = []; 545 let selection = win.getSelection(); 546 for (let i = 0; i < selection.rangeCount; i++) { 547 let range = selection.getRangeAt(i); 548 selectionRanges.push( 549 new win.StaticRange({startContainer: range.startContainer, 550 startOffset: range.startOffset, 551 endContainer: range.endContainer, 552 endOffset: range.endOffset})); 553 } 554 }, {once: true}); 555 win.addEventListener("input", aEvent => { inputEvent = aEvent; }, {once: true}); 556 editor.pasteTransferable(trans); 557 isnot(beforeInputEvent, null, '"beforeinput" event should be fired'); 558 if (beforeInputEvent) { 559 is(beforeInputEvent.cancelable, true, '"beforeinput" event for "insertFromPaste" should be cancelable'); 560 is(beforeInputEvent.inputType, "insertFromPaste", `inputType of "beforeinput" event should be "insertFromPaste"`); 561 is(beforeInputEvent.data, null, 'data of "beforeinput" event should be null'); 562 is(beforeInputEvent.dataTransfer.getData("text/html"), test.payload, 'dataTransfer of "beforeinput" event should have the HTML data'); 563 is(beforeInputEvent.dataTransfer.getData("text/plain"), "", 'dataTransfer of "beforeinput" event should not have have plain text'); 564 let targetRanges = beforeInputEvent.getTargetRanges(); 565 is(targetRanges.length, selectionRanges.length, 'getTargetRanges() of "beforeinput" event should return selection ranges'); 566 if (targetRanges.length === selectionRanges.length) { 567 for (let i = 0; i < selectionRanges.length; i++) { 568 is(targetRanges[i].startContainer, selectionRanges[i].startContainer, 569 `startContainer of getTargetRanges()[${i}] of "beforeinput" event does not match`); 570 is(targetRanges[i].startOffset, selectionRanges[i].startOffset, 571 `startOffset of getTargetRanges()[${i}] of "beforeinput" event does not match`); 572 is(targetRanges[i].endContainer, selectionRanges[i].endContainer, 573 `endContainer of getTargetRanges()[${i}] of "beforeinput" event does not match`); 574 is(targetRanges[i].endOffset, selectionRanges[i].endOffset, 575 `endOffset of getTargetRanges()[${i}] of "beforeinput" event does not match`); 576 } 577 } 578 } 579 is(inputEvent.type, "input", '"input" event should be fired'); 580 is(inputEvent.inputType, "insertFromPaste", `inputType of "input" event should be "insertFromPaste"`); 581 is(inputEvent.data, null, 'data of "input" event should be null'); 582 is(inputEvent.dataTransfer.getData("text/html"), test.payload, 'dataTransfer of "input" event should have the HTML data'); 583 is(inputEvent.dataTransfer.getData("text/plain"), "", 'dataTransfer of "input" event should not have have plain text'); 584 is(inputEvent.getTargetRanges().length, 0, 'getTargetRanges() of "input" event should return empty array'); 585 } else { 586 var clipboard = SpecialPowers.Services.clipboard; 587 588 clipboard.setData(trans, null, SpecialPowers.Ci.nsIClipboard.kGlobalClipboard); 589 590 synthesizeKey("V", {accelKey: true}); 591 } 592 593 if ("checkResult" in test) { 594 if ("isIFrame" in test) { 595 test.checkResult(elem.contentDocument.documentElement.innerHTML, 596 elem.contentDocument.documentElement.textContent); 597 } else { 598 test.checkResult(elem.innerHTML, elem.textContent); 599 } 600 } else { 601 var iframes = test.rootElement().querySelectorAll("iframe"); 602 var expectedIFrameCount = ("iframeCount" in test) ? test.iframeCount : 1; 603 is(iframes.length, expectedIFrameCount, "Only " + expectedIFrameCount + " iframe should be pasted"); 604 if (expectedIFrameCount > 0) { 605 ok(!iframes[0].hasAttribute("src"), "iframe should not have a src attrib"); 606 } 607 } 608 } 609 610 SimpleTest.waitForExplicitFinish(); 611 612 addLoadEvent(function() { 613 doNextTest(); 614 }); 615 </script> 616 </pre> 617 </body> 618 </html>