editor/libeditor/html/tests/test_bug520189.html

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial