editor/libeditor/html/tests/test_bug520189.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/libeditor/html/tests/test_bug520189.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,621 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=520182
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 520182</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>  
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=520182">Mozilla Bug 520182</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content">
    1.19 +  <iframe id="a" src="about:blank"></iframe>
    1.20 +  <iframe id="b" src="about:blank"></iframe>
    1.21 +  <iframe id="c" src="about:blank"></iframe>
    1.22 +  <div id="d" contenteditable="true"></div>
    1.23 +  <div id="e" contenteditable="true"></div>
    1.24 +  <div id="f" contenteditable="true"></div>
    1.25 +  <iframe id="g" src="about:blank"></iframe>
    1.26 +  <iframe id="h" src="about:blank"></iframe>
    1.27 +  <div id="i" contenteditable="true"></div>
    1.28 +  <div id="j" contenteditable="true"></div>
    1.29 +  <iframe id="k" src="about:blank"></iframe>
    1.30 +  <div id="l" contenteditable="true"></div>
    1.31 +  <iframe id="m" src="about:blank"></iframe>
    1.32 +  <div id="n" contenteditable="true"></div>
    1.33 +  <iframe id="o" src="about:blank"></iframe>
    1.34 +  <div id="p" contenteditable="true"></div>
    1.35 +  <iframe id="q" src="about:blank"></iframe>
    1.36 +  <div id="r" contenteditable="true"></div>
    1.37 +  <iframe id="s" src="about:blank"></iframe>
    1.38 +  <div id="t" contenteditable="true"></div>
    1.39 +  <iframe id="u" src="about:blank"></iframe>
    1.40 +  <div id="v" contenteditable="true"></div>
    1.41 +  <iframe id="w" src="about:blank"></iframe>
    1.42 +  <div id="x" contenteditable="true"></div>
    1.43 +  <iframe id="y" src="about:blank"></iframe>
    1.44 +  <div id="z" contenteditable="true"></div>
    1.45 +  <iframe id="aa" src="about:blank"></iframe>
    1.46 +  <div id="bb" contenteditable="true"></div>
    1.47 +  <iframe id="cc" src="about:blank"></iframe>
    1.48 +  <div id="dd" contenteditable="true"></div>
    1.49 +  <iframe id="ee" src="about:blank"></iframe>
    1.50 +  <div id="ff" contenteditable="true"></div>
    1.51 +  <iframe id="gg" src="about:blank"></iframe>
    1.52 +  <div id="hh" contenteditable="true"></div>
    1.53 +  <iframe id="ii" src="about:blank"></iframe>
    1.54 +  <div id="jj" contenteditable="true"></div>
    1.55 +  <iframe id="kk" src="about:blank"></iframe>
    1.56 +  <div id="ll" contenteditable="true"></div>
    1.57 +  <iframe id="mm" src="about:blank"></iframe>
    1.58 +  <div id="nn" contenteditable="true"></div>
    1.59 +  <iframe id="oo" src="about:blank"></iframe>
    1.60 +  <div id="pp" contenteditable="true"></div>
    1.61 +  <iframe id="qq" src="about:blank"></iframe>
    1.62 +  <div id="rr" contenteditable="true"></div>
    1.63 +  <iframe id="ss" src="about:blank"></iframe>
    1.64 +  <div id="tt" contenteditable="true"></div>
    1.65 +  <iframe id="uu" src="about:blank"></iframe>
    1.66 +  <div id="vv" contenteditable="true"></div>
    1.67 +  <div id="sss" contenteditable="true"></div>
    1.68 +  <iframe id="ssss" src="about:blank"></iframe>
    1.69 +  <div id="ttt" contenteditable="true"></div>
    1.70 +  <iframe id="tttt" src="about:blank"></iframe>
    1.71 +  <div id="uuu" contenteditable="true"></div>
    1.72 +  <iframe id="uuuu" src="about:blank"></iframe>
    1.73 +  <div id="vvv" contenteditable="true"></div>
    1.74 +  <iframe id="vvvv" src="about:blank"></iframe>
    1.75 +  <div id="www" contenteditable="true"></div>
    1.76 +  <iframe id="wwww" src="about:blank"></iframe>
    1.77 +  <div id="xxx" contenteditable="true"></div>
    1.78 +  <iframe id="xxxx" src="about:blank"></iframe>
    1.79 +  <div id="yyy" contenteditable="true"></div>
    1.80 +  <iframe id="yyyy" src="about:blank"></iframe>
    1.81 +</div>
    1.82 +<pre id="test">
    1.83 +<script type="application/javascript">
    1.84 +
    1.85 +/** Test for Bug 520182 **/
    1.86 +
    1.87 +const dataPayload = "foo<iframe src=\"data:text/html,bar\"></iframe>baz";
    1.88 +const jsPayload = "foo<iframe src=\"javascript:void('bar');\"></iframe>baz";
    1.89 +const httpPayload = "foo<iframe src=\"http://mochi.test:8888/\"></iframe>baz";
    1.90 +const scriptPayload ="foo<script>document.write(\"<iframe></iframe>\");</sc" + "ript>baz";
    1.91 +const scriptExternalPayload = "foo<script src=\"data:text/javascript,document.write('<iframe></iframe>');\"></sc" + "ript>baz";
    1.92 +const validStyle1Payload = "foo<style>#bar{color:red;}</style>baz";
    1.93 +const validStyle2Payload = "foo<span style=\"color:red\">bar</span>baz";
    1.94 +const validStyle3Payload = "foo<style>@font-face{font-family:xxx;src:'xxx.ttf';}</style>baz";
    1.95 +const validStyle4Payload = "foo<style>@namespace xxx url(http://example.com/);</style>baz";
    1.96 +const invalidStyle1Payload = "foo<style>#bar{-moz-binding:url('data:text/xml,<?xml version=\"1.0\"><binding xmlns=\"http://www.mozilla.org/xbl\"/>');}</style>baz";
    1.97 +const invalidStyle2Payload = "foo<span style=\"-moz-binding:url('data:text/xml,<?xml version=&quot;1.0&quot;><binding xmlns=&quot;http://www.mozilla.org/xbl&quot;/>');\">bar</span>baz";
    1.98 +const invalidStyle3Payload = "foo<style>@import 'xxx.css';</style>baz";
    1.99 +const invalidStyle4Payload = "foo<span style=\"@import 'xxx.css';\">bar</span>baz";
   1.100 +const invalidStyle5Payload = "foo<span style=\"@font-face{font-family:xxx;src:'xxx.ttf';}\">bar</span>baz";
   1.101 +const invalidStyle6Payload = "foo<span style=\"@namespace xxx url(http://example.com/);\">bar</span>baz";
   1.102 +const invalidStyle7Payload = "<html><head><title>xxx</title></head><body>foo</body></html>";
   1.103 +const invalidStyle8Payload = "foo<style>@-moz-document url(http://example.com/) {};</style>baz";
   1.104 +const invalidStyle9Payload = "foo<style>@-moz-keyframes bar {};</style>baz";
   1.105 +const nestedStylePayload = "foo<style>#bar1{-moz-binding:url('data:text/xml,<?xml version=&quot;1.0&quot;><binding xmlns=&quot;http://www.mozilla.org/xbl&quot; id=&quot;binding-1&quot;/>');<style></style>#bar2{-moz-binding:url('data:text/xml,<?xml version=&quot;1.0&quot;><binding xmlns=&quot;http://www.mozilla.org/xbl&quot; id=&quot;binding-2&quot;/>');</style>baz";
   1.106 +const validImgSrc1Payload = "foo<img src=\"data:image/png,bar\">baz";
   1.107 +const validImgSrc2Payload = "foo<img src=\"javascript:void('bar');\">baz";
   1.108 +const validImgSrc3Payload = "foo<img src=\"file:///bar.png\">baz";
   1.109 +const validDataFooPayload = "foo<span data-bar=\"value\">baz</span>";
   1.110 +const validDataFoo2Payload = "foo<span _bar=\"value\">baz</span>";
   1.111 +const svgPayload = "foo<svg><title>svgtitle</title></svg>bar";
   1.112 +const svg2Payload = "foo<svg><bogussvg/></svg>bar";
   1.113 +const mathPayload = "foo<math><bogusmath/></math>bar";
   1.114 +const math2Payload = "foo<math><style>@import \"yyy.css\";</style</math>bar";
   1.115 +const math3Payload = "foo<math><mi></mi></math>bar";
   1.116 +const videoPayload = "foo<video></video>bar";
   1.117 +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>";
   1.118 +
   1.119 +var tests = [
   1.120 +  {
   1.121 +    id: "a",
   1.122 +    isIFrame: true,
   1.123 +    payload: dataPayload,
   1.124 +    iframeCount: 0,
   1.125 +    rootElement: function() document.getElementById("a").contentDocument.documentElement
   1.126 +  },
   1.127 +  {
   1.128 +    id: "b",
   1.129 +    isIFrame: true,
   1.130 +    payload: jsPayload,
   1.131 +    iframeCount: 0,
   1.132 +    rootElement: function() document.getElementById("b").contentDocument.documentElement
   1.133 +  },
   1.134 +  {
   1.135 +    id: "c",
   1.136 +    isIFrame: true,
   1.137 +    payload: httpPayload,
   1.138 +    iframeCount: 0,
   1.139 +    rootElement: function() document.getElementById("c").contentDocument.documentElement
   1.140 +  },
   1.141 +  {
   1.142 +    id: "g",
   1.143 +    isIFrame: true,
   1.144 +    payload: scriptPayload,
   1.145 +    rootElement: function() document.getElementById("g").contentDocument.documentElement,
   1.146 +    iframeCount: 0
   1.147 +  },
   1.148 +  {
   1.149 +    id: "h",
   1.150 +    isIFrame: true,
   1.151 +    payload: scriptExternalPayload,
   1.152 +    rootElement: function() document.getElementById("h").contentDocument.documentElement,
   1.153 +    iframeCount: 0
   1.154 +  },
   1.155 +  {
   1.156 +    id: "d",
   1.157 +    payload: dataPayload,
   1.158 +    iframeCount: 0,
   1.159 +    rootElement: function() document.getElementById("d")
   1.160 +  },
   1.161 +  {
   1.162 +    id: "e",
   1.163 +    payload: jsPayload,
   1.164 +    iframeCount: 0,
   1.165 +    rootElement: function() document.getElementById("e")
   1.166 +  },
   1.167 +  {
   1.168 +    id: "f",
   1.169 +    payload: httpPayload,
   1.170 +    iframeCount: 0,
   1.171 +    rootElement: function() document.getElementById("f")
   1.172 +  },
   1.173 +  {
   1.174 +    id: "i",
   1.175 +    payload: scriptPayload,
   1.176 +    rootElement: function() document.getElementById("i"),
   1.177 +    iframeCount: 0
   1.178 +  },
   1.179 +  {
   1.180 +    id: "j",
   1.181 +    payload: scriptExternalPayload,
   1.182 +    rootElement: function() document.getElementById("j"),
   1.183 +    iframeCount: 0
   1.184 +  },
   1.185 +  {
   1.186 +    id: "k",
   1.187 +    isIFrame: true,
   1.188 +    payload: validStyle1Payload,
   1.189 +    rootElement: function() document.getElementById("k").contentDocument.documentElement,
   1.190 +    checkResult: function(html) isnot(html.indexOf("style"), -1, "Should have retained style")
   1.191 +  },
   1.192 +  {
   1.193 +    id: "l",
   1.194 +    payload: validStyle1Payload,
   1.195 +    rootElement: function() document.getElementById("l"),
   1.196 +    checkResult: function(html) isnot(html.indexOf("style"), -1, "Should have retained style")
   1.197 +  },
   1.198 +  {
   1.199 +    id: "m",
   1.200 +    isIFrame: true,
   1.201 +    payload: validStyle2Payload,
   1.202 +    rootElement: function() document.getElementById("m").contentDocument.documentElement,
   1.203 +    checkResult: function(html) isnot(html.indexOf("style"), -1, "Should have retained style")
   1.204 +  },
   1.205 +  {
   1.206 +    id: "n",
   1.207 +    payload: validStyle2Payload,
   1.208 +    rootElement: function() document.getElementById("n"),
   1.209 +    checkResult: function(html) isnot(html.indexOf("style"), -1, "Should have retained style")
   1.210 +  },
   1.211 +  {
   1.212 +    id: "o",
   1.213 +    isIFrame: true,
   1.214 +    payload: invalidStyle1Payload,
   1.215 +    rootElement: function() document.getElementById("o").contentDocument.documentElement,
   1.216 +    checkResult: function(html) is(html.indexOf("binding"), -1, "Should not have retained the binding style")
   1.217 +  },
   1.218 +  {
   1.219 +    id: "p",
   1.220 +    payload: invalidStyle1Payload,
   1.221 +    rootElement: function() document.getElementById("p"),
   1.222 +    checkResult: function(html) is(html.indexOf("binding"), -1, "Should not have retained the binding style")
   1.223 +  },
   1.224 +  {
   1.225 +    id: "q",
   1.226 +    isIFrame: true,
   1.227 +    payload: invalidStyle2Payload,
   1.228 +    rootElement: function() document.getElementById("q").contentDocument.documentElement,
   1.229 +    checkResult: function(html) is(html.indexOf("binding"), -1, "Should not have retained the binding style")
   1.230 +  },
   1.231 +  {
   1.232 +    id: "r",
   1.233 +    payload: invalidStyle2Payload,
   1.234 +    rootElement: function() document.getElementById("r"),
   1.235 +    checkResult: function(html) is(html.indexOf("binding"), -1, "Should not have retained the binding style")
   1.236 +  },
   1.237 +  {
   1.238 +    id: "s",
   1.239 +    isIFrame: true,
   1.240 +    payload: invalidStyle1Payload,
   1.241 +    rootElement: function() document.getElementById("s").contentDocument.documentElement,
   1.242 +    checkResult: function(html) is(html.indexOf("xxx"), -1, "Should not have retained the import style")
   1.243 +  },
   1.244 +  {
   1.245 +    id: "t",
   1.246 +    payload: invalidStyle1Payload,
   1.247 +    rootElement: function() document.getElementById("t"),
   1.248 +    checkResult: function(html) is(html.indexOf("xxx"), -1, "Should not have retained the import style")
   1.249 +  },
   1.250 +  {
   1.251 +    id: "u",
   1.252 +    isIFrame: true,
   1.253 +    payload: invalidStyle2Payload,
   1.254 +    rootElement: function() document.getElementById("u").contentDocument.documentElement,
   1.255 +    checkResult: function(html) is(html.indexOf("xxx"), -1, "Should not have retained the import style")
   1.256 +  },
   1.257 +  {
   1.258 +    id: "v",
   1.259 +    payload: invalidStyle2Payload,
   1.260 +    rootElement: function() document.getElementById("v"),
   1.261 +    checkResult: function(html) is(html.indexOf("xxx"), -1, "Should not have retained the import style")
   1.262 +  },
   1.263 +  {
   1.264 +    id: "w",
   1.265 +    isIFrame: true,
   1.266 +    payload: validStyle3Payload,
   1.267 +    rootElement: function() document.getElementById("w").contentDocument.documentElement,
   1.268 +    checkResult: function(html) isnot(html.indexOf("xxx"), -1, "Should have retained the font-face style")
   1.269 +  },
   1.270 +  {
   1.271 +    id: "x",
   1.272 +    payload: validStyle3Payload,
   1.273 +    rootElement: function() document.getElementById("x"),
   1.274 +    checkResult: function(html) isnot(html.indexOf("xxx"), -1, "Should have retained the font-face style")
   1.275 +  },
   1.276 +  {
   1.277 +    id: "y",
   1.278 +    isIFrame: true,
   1.279 +    payload: invalidStyle5Payload,
   1.280 +    rootElement: function() document.getElementById("y").contentDocument.documentElement,
   1.281 +    checkResult: function(html) isnot(html.indexOf("xxx"), -1, "Should not have retained the font-face style")
   1.282 +  },
   1.283 +  {
   1.284 +    id: "z",
   1.285 +    payload: invalidStyle5Payload,
   1.286 +    rootElement: function() document.getElementById("z"),
   1.287 +    checkResult: function(html) isnot(html.indexOf("xxx"), -1, "Should not have retained the font-face style")
   1.288 +  },
   1.289 +  {
   1.290 +    id: "aa",
   1.291 +    isIFrame: true,
   1.292 +    payload: nestedStylePayload,
   1.293 +    rootElement: function() document.getElementById("aa").contentDocument.documentElement,
   1.294 +    checkResult: function(html, text) {
   1.295 +      is(html.indexOf("binding-1"), -1, "Should not have retained the binding-1 style");
   1.296 +      isnot(text.indexOf("#bar2"), -1, "Should have retained binding-2 as text content");
   1.297 +      is(text.indexOf("binding-2"), -1, "Should not have retained binding-2 as a tag");
   1.298 +    }
   1.299 +  },
   1.300 +  {
   1.301 +    id: "bb",
   1.302 +    payload: nestedStylePayload,
   1.303 +    rootElement: function() document.getElementById("bb"),
   1.304 +    checkResult: function(html, text) {
   1.305 +      is(html.indexOf("binding-1"), -1, "Should not have retained the binding-1 style");
   1.306 +      isnot(text.indexOf("#bar2"), -1, "Should have retained binding-2 as text content");
   1.307 +      is(text.indexOf("binding-2"), -1, "Should not have retained binding-2 as a tag");
   1.308 +    }
   1.309 +  },
   1.310 +  {
   1.311 +    id: "cc",
   1.312 +    isIFrame: true,
   1.313 +    payload: validStyle4Payload,
   1.314 +    rootElement: function() document.getElementById("cc").contentDocument.documentElement,
   1.315 +    checkResult: function(html) isnot(html.indexOf("xxx"), -1, "Should have retained the namespace style")
   1.316 +  },
   1.317 +  {
   1.318 +    id: "dd",
   1.319 +    payload: validStyle4Payload,
   1.320 +    rootElement: function() document.getElementById("dd"),
   1.321 +    checkResult: function(html) isnot(html.indexOf("xxx"), -1, "Should have retained the namespace style")
   1.322 +  },
   1.323 +  {
   1.324 +    id: "ee",
   1.325 +    isIFrame: true,
   1.326 +    payload: invalidStyle6Payload,
   1.327 +    rootElement: function() document.getElementById("ee").contentDocument.documentElement,
   1.328 +    checkResult: function(html) isnot(html.indexOf("xxx"), -1, "Should not have retained the namespace style")
   1.329 +  },
   1.330 +  {
   1.331 +    id: "ff",
   1.332 +    payload: invalidStyle6Payload,
   1.333 +    rootElement: function() document.getElementById("ff"),
   1.334 +    checkResult: function(html) isnot(html.indexOf("xxx"), -1, "Should not have retained the namespace style")
   1.335 +  },
   1.336 +  {
   1.337 +    id: "gg",
   1.338 +    isIFrame: true,
   1.339 +    payload: invalidStyle6Payload,
   1.340 +    rootElement: function() document.getElementById("gg").contentDocument.documentElement,
   1.341 +    checkResult: function(html) isnot(html.indexOf("bar"), -1, "Should have retained the src attribute for the image")
   1.342 +  },
   1.343 +  {
   1.344 +    id: "hh",
   1.345 +    payload: invalidStyle6Payload,
   1.346 +    rootElement: function() document.getElementById("hh"),
   1.347 +    checkResult: function(html) isnot(html.indexOf("bar"), -1, "Should have retained the src attribute for the image")
   1.348 +  },
   1.349 +  {
   1.350 +    id: "ii",
   1.351 +    isIFrame: true,
   1.352 +    payload: invalidStyle6Payload,
   1.353 +    rootElement: function() document.getElementById("ii").contentDocument.documentElement,
   1.354 +    checkResult: function(html) isnot(html.indexOf("bar"), -1, "Should have retained the src attribute for the image")
   1.355 +  },
   1.356 +  {
   1.357 +    id: "jj",
   1.358 +    payload: invalidStyle6Payload,
   1.359 +    rootElement: function() document.getElementById("jj"),
   1.360 +    checkResult: function(html) isnot(html.indexOf("bar"), -1, "Should have retained the src attribute for the image")
   1.361 +  },
   1.362 +  {
   1.363 +    id: "kk",
   1.364 +    isIFrame: true,
   1.365 +    payload: invalidStyle6Payload,
   1.366 +    rootElement: function() document.getElementById("kk").contentDocument.documentElement,
   1.367 +    checkResult: function(html) isnot(html.indexOf("bar"), -1, "Should have retained the src attribute for the image")
   1.368 +  },
   1.369 +  {
   1.370 +    id: "ll",
   1.371 +    payload: invalidStyle6Payload,
   1.372 +    rootElement: function() document.getElementById("ll"),
   1.373 +    checkResult: function(html) isnot(html.indexOf("bar"), -1, "Should have retained the src attribute for the image")
   1.374 +  },
   1.375 +  {
   1.376 +    id: "mm",
   1.377 +    isIFrame: true,
   1.378 +    indirectPaste: true,
   1.379 +    payload: invalidStyle7Payload,
   1.380 +    rootElement: function() document.getElementById("mm").contentDocument.documentElement,
   1.381 +    checkResult: function(html) {
   1.382 +      is(html.indexOf("xxx"), -1, "Should not have retained the title text");
   1.383 +      isnot(html.indexOf("foo"), -1, "Should have retained the body text");
   1.384 +    }
   1.385 +  },
   1.386 +  {
   1.387 +    id: "nn",
   1.388 +    indirectPaste: true,
   1.389 +    payload: invalidStyle7Payload,
   1.390 +    rootElement: function() document.getElementById("nn"),
   1.391 +    checkResult: function(html) {
   1.392 +      is(html.indexOf("xxx"), -1, "Should not have retained the title text");
   1.393 +      isnot(html.indexOf("foo"), -1, "Should have retained the body text");
   1.394 +    }
   1.395 +  },
   1.396 +  {
   1.397 +    id: "oo",
   1.398 +    isIFrame: true,
   1.399 +    payload: validDataFooPayload,
   1.400 +    rootElement: function() document.getElementById("oo").contentDocument.documentElement,
   1.401 +    checkResult: function(html) isnot(html.indexOf("bar"), -1, "Should have retained the data-bar attribute")
   1.402 +  },
   1.403 +  {
   1.404 +    id: "pp",
   1.405 +    payload: validDataFooPayload,
   1.406 +    rootElement: function() document.getElementById("pp"),
   1.407 +    checkResult: function(html) isnot(html.indexOf("bar"), -1, "Should have retained the data-bar attribute")
   1.408 +  },
   1.409 +  {
   1.410 +    id: "qq",
   1.411 +    isIFrame: true,
   1.412 +    payload: validDataFoo2Payload,
   1.413 +    rootElement: function() document.getElementById("qq").contentDocument.documentElement,
   1.414 +    checkResult: function(html) isnot(html.indexOf("bar"), -1, "Should have retained the _bar attribute")
   1.415 +  },
   1.416 +  {
   1.417 +    id: "rr",
   1.418 +    payload: validDataFoo2Payload,
   1.419 +    rootElement: function() document.getElementById("rr"),
   1.420 +    checkResult: function(html) isnot(html.indexOf("bar"), -1, "Should have retained the _bar attribute")
   1.421 +  },
   1.422 +  {
   1.423 +    id: "ss",
   1.424 +    isIFrame: true,
   1.425 +    payload: invalidStyle8Payload,
   1.426 +    rootElement: function() document.getElementById("ss").contentDocument.documentElement,
   1.427 +    checkResult: function(html) is(html.indexOf("@-moz-document"), -1, "Should not have retained the @-moz-document rule")
   1.428 +  },
   1.429 +  {
   1.430 +    id: "tt",
   1.431 +    payload: invalidStyle8Payload,
   1.432 +    rootElement: function() document.getElementById("tt"),
   1.433 +    checkResult: function(html) is(html.indexOf("@-moz-document"), -1, "Should not have retained the @-moz-document rule")
   1.434 +  },
   1.435 +  {
   1.436 +    id: "uu",
   1.437 +    isIFrame: true,
   1.438 +    payload: invalidStyle9Payload,
   1.439 +    rootElement: function() document.getElementById("uu").contentDocument.documentElement,
   1.440 +    checkResult: function(html) is(html.indexOf("@-moz-keyframes"), -1, "Should not have retained the @-moz-keyframes rule")
   1.441 +  },
   1.442 +  {
   1.443 +    id: "vv",
   1.444 +    payload: invalidStyle9Payload,
   1.445 +    rootElement: function() document.getElementById("vv"),
   1.446 +    checkResult: function(html) is(html.indexOf("@-moz-keyframes"), -1, "Should not have retained the @-moz-keyframes rule")
   1.447 +  },
   1.448 +  {
   1.449 +    id: "sss",
   1.450 +    payload: svgPayload,
   1.451 +    rootElement: function() document.getElementById("sss"),
   1.452 +    checkResult: function(html) isnot(html.indexOf("svgtitle"), -1, "Should have retained SVG title")
   1.453 +  },
   1.454 +  {
   1.455 +    id: "ssss",
   1.456 +    isIFrame: true,
   1.457 +    payload: svgPayload,
   1.458 +    rootElement: function() document.getElementById("ssss").contentDocument.documentElement,
   1.459 +    checkResult: function(html) isnot(html.indexOf("svgtitle"), -1, "Should have retained SVG title")
   1.460 +  },
   1.461 +  {
   1.462 +    id: "ttt",
   1.463 +    payload: svg2Payload,
   1.464 +    rootElement: function() document.getElementById("ttt"),
   1.465 +    checkResult: function(html) is(html.indexOf("bogussvg"), -1, "Should have dropped bogussvg element")
   1.466 +  },
   1.467 +  {
   1.468 +    id: "tttt",
   1.469 +    isIFrame: true,
   1.470 +    payload: svg2Payload,
   1.471 +    rootElement: function() document.getElementById("tttt").contentDocument.documentElement,
   1.472 +    checkResult: function(html) is(html.indexOf("bogussvg"), -1, "Should have dropped bogussvg element")
   1.473 +  },
   1.474 +  {
   1.475 +    id: "uuu",
   1.476 +    payload: mathPayload,
   1.477 +    rootElement: function() document.getElementById("uuu"),
   1.478 +    checkResult: function(html) is(html.indexOf("bogusmath"), -1, "Should have dropped bogusmath element")
   1.479 +  },
   1.480 +  {
   1.481 +    id: "uuuu",
   1.482 +    isIFrame: true,
   1.483 +    payload: mathPayload,
   1.484 +    rootElement: function() document.getElementById("uuuu").contentDocument.documentElement,
   1.485 +    checkResult: function(html) is(html.indexOf("bogusmath"), -1, "Should have dropped bogusmath element")
   1.486 +  },
   1.487 +  {
   1.488 +    id: "vvv",
   1.489 +    payload: math2Payload,
   1.490 +    rootElement: function() document.getElementById("vvv"),
   1.491 +    checkResult: function(html) is(html.indexOf("yyy.css"), -1, "Should have dropped MathML style element")
   1.492 +  },
   1.493 +  {
   1.494 +    id: "vvvv",
   1.495 +    isIFrame: true,
   1.496 +    payload: math2Payload,
   1.497 +    rootElement: function() document.getElementById("vvvv").contentDocument.documentElement,
   1.498 +    checkResult: function(html) is(html.indexOf("yyy.css"), -1, "Should have dropped MathML style element")
   1.499 +  },
   1.500 +  {
   1.501 +    id: "www",
   1.502 +    payload: math3Payload,
   1.503 +    rootElement: function() document.getElementById("www"),
   1.504 +    checkResult: function(html) isnot(html.indexOf("<mi"), -1, "Should not have dropped MathML mi element")
   1.505 +  },
   1.506 +  {
   1.507 +    id: "wwww",
   1.508 +    isIFrame: true,
   1.509 +    payload: math3Payload,
   1.510 +    rootElement: function() document.getElementById("wwww").contentDocument.documentElement,
   1.511 +    checkResult: function(html) isnot(html.indexOf("<mi"), -1, "Should not have dropped MathML mi element")
   1.512 +  },
   1.513 +  {
   1.514 +    id: "xxx",
   1.515 +    payload: videoPayload,
   1.516 +    rootElement: function() document.getElementById("xxx"),
   1.517 +    checkResult: function(html) isnot(html.indexOf("controls="), -1, "Should have added the controls attribute")
   1.518 +  },
   1.519 +  {
   1.520 +    id: "xxxx",
   1.521 +    isIFrame: true,
   1.522 +    payload: videoPayload,
   1.523 +    rootElement: function() document.getElementById("xxxx").contentDocument.documentElement,
   1.524 +    checkResult: function(html) isnot(html.indexOf("controls="), -1, "Should have added the controls attribute")
   1.525 +  },
   1.526 +  {
   1.527 +    id: "yyy",
   1.528 +    payload: microdataPayload,
   1.529 +    rootElement: function() document.getElementById("yyy"),
   1.530 +    checkResult: function(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."); }
   1.531 +  },
   1.532 +  {
   1.533 +    id: "yyyy",
   1.534 +    isIFrame: true,
   1.535 +    payload: microdataPayload,
   1.536 +    rootElement: function() document.getElementById("yyyy").contentDocument.documentElement,
   1.537 +    checkResult: function(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."); }
   1.538 +  }
   1.539 +];
   1.540 +
   1.541 +function doNextTest() {
   1.542 +  if (typeof testCounter == "undefined")
   1.543 +    testCounter = 0;
   1.544 +  else if (++testCounter == tests.length) {
   1.545 +    SimpleTest.finish();
   1.546 +    return;
   1.547 +  }
   1.548 +
   1.549 +  runTest(tests[testCounter]);
   1.550 +
   1.551 +  doNextTest();
   1.552 +}
   1.553 +
   1.554 +function getLoadContext() {
   1.555 +  const Ci = SpecialPowers.Ci;
   1.556 +  return SpecialPowers.wrap(window)
   1.557 +               .QueryInterface(Ci.nsIInterfaceRequestor)
   1.558 +               .getInterface(Ci.nsIWebNavigation)
   1.559 +               .QueryInterface(Ci.nsILoadContext);
   1.560 +}
   1.561 +
   1.562 +function runTest(test) {
   1.563 +  var elem = document.getElementById(test.id);
   1.564 +  if ("isIFrame" in test) {
   1.565 +    elem.contentDocument.designMode = "on";
   1.566 +    elem.contentWindow.focus();
   1.567 +  } else
   1.568 +    elem.focus();
   1.569 +
   1.570 +  var trans = SpecialPowers.Cc["@mozilla.org/widget/transferable;1"]
   1.571 +                           .createInstance(SpecialPowers.Ci.nsITransferable);
   1.572 +  trans.init(getLoadContext());
   1.573 +  var data = SpecialPowers.Cc["@mozilla.org/supports-string;1"]
   1.574 +                          .createInstance(SpecialPowers.Ci.nsISupportsString);
   1.575 +  data.data = test.payload;
   1.576 +  trans.addDataFlavor("text/html");
   1.577 +  trans.setTransferData("text/html", data, data.data.length * 2);
   1.578 +
   1.579 +  if ("indirectPaste" in test) {
   1.580 +    var editor, win;
   1.581 +    if ("isIFrame" in test) {
   1.582 +      win = elem.contentDocument.defaultView;
   1.583 +    } else {
   1.584 +      getSelection().collapse(elem, 0);
   1.585 +      win = window;
   1.586 +    }
   1.587 +    editor = SpecialPowers.wrap(win).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
   1.588 +                          .getInterface(SpecialPowers.Ci.nsIWebNavigation)
   1.589 +                          .QueryInterface(SpecialPowers.Ci.nsIDocShell)
   1.590 +                          .editor;
   1.591 +    editor.pasteTransferable(trans);
   1.592 +  } else {
   1.593 +    var clipboard = SpecialPowers.Cc["@mozilla.org/widget/clipboard;1"]
   1.594 +                                 .getService(SpecialPowers.Ci.nsIClipboard);
   1.595 +
   1.596 +    clipboard.setData(trans, null, SpecialPowers.Ci.nsIClipboard.kGlobalClipboard);
   1.597 +
   1.598 +    synthesizeKey("V", {accelKey: true});
   1.599 +  }
   1.600 +
   1.601 +  if ("checkResult" in test) {
   1.602 +    if ("isIFrame" in test) {
   1.603 +      test.checkResult(elem.contentDocument.documentElement.innerHTML,
   1.604 +        elem.contentDocument.documentElement.textContent);
   1.605 +    } else {
   1.606 +      test.checkResult(elem.innerHTML, elem.textContent);
   1.607 +    }
   1.608 +  } else {
   1.609 +    var iframes = test.rootElement().querySelectorAll("iframe");
   1.610 +    var expectedIFrameCount = ("iframeCount" in test) ? test.iframeCount : 1;
   1.611 +    is(iframes.length, expectedIFrameCount, "Only " + expectedIFrameCount + " iframe should be pasted");
   1.612 +    if (expectedIFrameCount > 0) {
   1.613 +      ok(!iframes[0].hasAttribute("src"), "iframe should not have a src attrib");
   1.614 +    }
   1.615 +  }
   1.616 +}
   1.617 +
   1.618 +SimpleTest.waitForExplicitFinish();
   1.619 +addLoadEvent(doNextTest);
   1.620 +
   1.621 +</script>
   1.622 +</pre>
   1.623 +</body>
   1.624 +</html>

mercurial