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