content/base/test/test_XHRDocURI.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=459470
     5 -->
     6 <head>
     7   <title>XMLHttpRequest return document URIs</title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    10   <base href="http://example.org/">
    11 </head>
    12 <body>
    13 <a target="_blank"
    14    href="https://bugzilla.mozilla.org/show_bug.cgi?id=459470">Mozilla Bug 459470</a><br />
    15 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=859095">Mozilla Bug 859095</a>
    17 <p id="display">
    18 <iframe id=loader></iframe>
    19 </p>
    20 <div id="content" style="display: none">
    22 </div>
    23 <pre id="test">
    24 <script class="testbody" type="application/javascript;version=1.8">
    26 SimpleTest.waitForExplicitFinish();
    28 gen = runTest();
    29 gen.next();
    31 function testXMLDocURI(aDoc, aExpects) {
    32   is(aDoc.documentURI, aExpects.documentURI, "wrong url");
    33   is(aDoc.baseURI, aExpects.baseURI, "wrong base");
    34   is(aDoc.documentElement.baseURI, aExpects.elementBaseURI,
    35      "wrong base (xml:base)");
    36 }
    38 function testChromeXMLDocURI(aDoc, aExpects) {
    39   is(aDoc.documentURI, aExpects.documentURI, "wrong url");
    40   is(aDoc.documentURIObject.spec, aExpects.documentURI,
    41      "wrong url (.documentObjectURI)");
    42   is(aDoc.baseURI, aExpects.baseURI, "wrong base");
    43   is(aDoc.baseURIObject.spec, aExpects.baseURI,
    44      "wrong base (.baseURIObject)");
    45   is(aDoc.documentElement.baseURI, aExpects.elementBaseURI,
    46      "wrong base (xml:base)");
    47   is(aDoc.documentElement.baseURIObject.spec, aExpects.elementBaseURI,
    48      "wrong base (.baseURIObject, xml:base)");
    49 }
    51 function testHTMLDocURI(aDoc, aExpects) {
    52   is(aDoc.documentURI, aExpects.documentURI, "wrong url");
    53   is(aDoc.baseURI, aExpects.baseURI, "wrong base");
    55   var base = aDoc.createElement("base");
    56   var newBaseURI = "http://www.example.com/";
    57   base.href = newBaseURI;
    58   aDoc.head.appendChild(base);
    59   is(aDoc.baseURI, newBaseURI, "wrong base (after <base> changed)");
    60 }
    62 function testChromeHTMLDocURI(aDoc, aNonChromeBaseURI, aExpects) {
    63   is(aDoc.documentURI, aExpects.documentURI, "wrong url");
    64   is(aDoc.documentURIObject.spec, aExpects.documentURI,
    65      "wrong url (.documentURIObject)");
    66   is(aDoc.baseURI, aExpects.baseURI, "wrong base");
    67   is(aDoc.baseURIObject.spec, aExpects.baseURI,
    68      "wrong url (.baseURIObject)");
    70   aDoc.body.setAttributeNS("http://www.w3.org/XML/1998/namespace", "base",
    71                            aNonChromeBaseURI);
    72   is(aDoc.body.baseURI, aNonChromeBaseURI,
    73      "wrong base (doc base and xml:base are same)");
    74   is(aDoc.body.baseURIObject.spec, aNonChromeBaseURI,
    75      "wrong base (.baseURIObject, doc base and xml:base are same)")
    76   var attr = aDoc.getElementById("data").getAttributeNode("id");
    77   is(attr.baseURI, aNonChromeBaseURI,
    78      "wrong attr base (doc base and xml:base are same)")
    79   is(attr.baseURIObject.spec, aNonChromeBaseURI,
    80      "wrong attr base (.baseURIObject, doc base and xml:base are same)")
    82   var base = aDoc.createElement("base");
    83   var newBaseURI = "http://www.example.com/";
    84   base.href = newBaseURI;
    85   aDoc.head.appendChild(base);
    86   is(aDoc.baseURI, newBaseURI, "wrong base (after <base> changed)");
    87   is(aDoc.baseURIObject.spec, newBaseURI,
    88      "wrong base (.baseURIObject, after <base> changed)");
    89 }
    91 function testCloneDocURI(aDoc) {
    92   var clone = aDoc.cloneNode(true);
    93   is(clone.documentURI, aDoc.documentURI, "wrong url (clone)");
    94   is(clone.baseURI, aDoc.baseURI, "wrong base (clone)");
    95 }
    97 function runTest() {
    98   is(document.baseURI, "http://example.org/", "wrong doc baseURI");
   100   // use content XHR and access URI properties from content privileged script
   101   xhr = new XMLHttpRequest;
   102   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.xml");
   103   xhr.onreadystatechange = function(e) {
   104     if (!xhr.responseXML) {
   105       return;
   106     }
   107     var expects = {
   108       documentURI: "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.xml",
   109       baseURI: "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.xml",
   110       elementBaseURI: "http://www.example.com/"
   111     };
   112     testXMLDocURI(xhr.responseXML, expects);
   113     if (xhr.readyState == 4) {
   114       gen.next();
   115     }
   116   };
   117   xhr.send();
   118   yield undefined;
   120   xhr = new XMLHttpRequest;
   121   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.html");
   122   xhr.responseType = "document";
   123   xhr.onreadystatechange = function(e) {
   124     if (!xhr.response) {
   125       return;
   126     }
   127     var expects = {
   128       documentURI: "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.html",
   129       baseURI: "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.html"
   130     };
   131     testHTMLDocURI(xhr.response, expects);
   132     if (xhr.readyState == 4) {
   133       gen.next();
   134     }
   135   };
   136   xhr.send();
   137   yield undefined;
   139   xhr = new XMLHttpRequest;
   140   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.text");
   141   xhr.onreadystatechange = function(e) {
   142     is(xhr.responseXML, null, "should not have document");
   143     if (xhr.readyState == 4) {
   144       gen.next();
   145     }
   146   };
   147   xhr.send();
   148   yield undefined;
   150   xhr = new XMLHttpRequest;
   151   xhr.open("GET", "http://example.com/tests/content/base/test/file_XHRDocURI.xml");
   152   xhr.onreadystatechange = function(e) {
   153     if (!xhr.responseXML) {
   154       return;
   155     }
   156     var expects = {
   157       documentURI: "http://example.com/tests/content/base/test/file_XHRDocURI.xml",
   158       baseURI: "http://example.com/tests/content/base/test/file_XHRDocURI.xml",
   159       elementBaseURI: "http://www.example.com/"
   160     };
   161     testXMLDocURI(xhr.responseXML, expects);
   162     if (xhr.readyState == 4) {
   163       gen.next();
   164     }
   165   };
   166   xhr.send();
   167   yield undefined;
   169   xhr = new XMLHttpRequest;
   170   xhr.open("GET", "http://example.com/tests/content/base/test/file_XHRDocURI.html");
   171   xhr.responseType = "document";
   172   xhr.onreadystatechange = function(e) {
   173     if (!xhr.response) {
   174       return;
   175     }
   176     var expects = {
   177       documentURI: "http://example.com/tests/content/base/test/file_XHRDocURI.html",
   178       baseURI: "http://example.com/tests/content/base/test/file_XHRDocURI.html"
   179     };
   180     testHTMLDocURI(xhr.response, expects);
   181     if (xhr.readyState == 4) {
   182       gen.next();
   183     }
   184   };
   185   xhr.send();
   186   yield undefined;
   188   xhr = new XMLHttpRequest;
   189   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.sjs?url=http://example.com/tests/content/base/test/file_XHRDocURI.xml");
   190   xhr.onreadystatechange = function(e) {
   191     if (!xhr.responseXML) {
   192       return;
   193     }
   194     var expects = {
   195       documentURI: "http://example.com/tests/content/base/test/file_XHRDocURI.xml",
   196       baseURI: "http://example.com/tests/content/base/test/file_XHRDocURI.xml",
   197       elementBaseURI: "http://www.example.com/"
   198     };
   199     testXMLDocURI(xhr.responseXML, expects);
   200     if (xhr.readyState == 4) {
   201       gen.next();
   202     }
   203   };
   204   xhr.send();
   205   yield undefined;
   207   xhr = new XMLHttpRequest;
   208   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.sjs?url=http://example.com/tests/content/base/test/file_XHRDocURI.html");
   209   xhr.responseType = "document";
   210   xhr.onreadystatechange = function(e) {
   211     if (!xhr.response) {
   212       return;
   213     }
   214     var expects = {
   215       documentURI: "http://example.com/tests/content/base/test/file_XHRDocURI.html",
   216       baseURI: "http://example.com/tests/content/base/test/file_XHRDocURI.html"
   217     };
   218     testHTMLDocURI(xhr.response, expects);
   219     if (xhr.readyState == 4) {
   220       gen.next();
   221     }
   222   };
   223   xhr.send();
   224   yield undefined;
   226   xhr = new XMLHttpRequest;
   227   xhr.open("GET", "http://example.com/tests/content/base/test/file_XHRDocURI.text");
   228   xhr.onreadystatechange = function(e) {
   229     is(xhr.responseXML, null, "should not have document");
   230     if (xhr.readyState == 4) {
   231       gen.next();
   232     }
   233   };
   234   xhr.send();
   235   yield undefined;
   238   // use content XHR and access URI properties from chrome privileged script
   240   xhr = new XMLHttpRequest;
   241   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.xml");
   242   xhr.onreadystatechange = function(e) {
   243     if (!xhr.responseXML) {
   244       return;
   245     }
   246     var expects = {
   247       documentURI: "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.xml",
   248       baseURI: "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.xml",
   249       elementBaseURI: "http://www.example.com/"
   250     };
   251     var xml = SpecialPowers.wrap(xhr.responseXML);
   252     testChromeXMLDocURI(xml, expects);
   253     testCloneDocURI(xml);
   254     if (xhr.readyState == 4) {
   255       gen.next();
   256     }
   257   };
   258   xhr.send();
   259   yield undefined;
   261   xhr = new XMLHttpRequest;
   262   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.html");
   263   xhr.responseType = "document";
   264   xhr.onreadystatechange = function(e) {
   265     if (!xhr.response) {
   266       return;
   267     }
   268     var expects = {
   269       documentURI: "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.html",
   270       baseURI: "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.html"
   271     };
   272     var doc = SpecialPowers.wrap(xhr.response);
   273     testChromeHTMLDocURI(doc, "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.html", expects);
   274     testCloneDocURI(doc);
   275     if (xhr.readyState == 4) {
   276       gen.next();
   277     }
   278   };
   279   xhr.send();
   280   yield undefined;
   282   xhr = new XMLHttpRequest;
   283   xhr.open("GET", "http://example.com/tests/content/base/test/file_XHRDocURI.xml");
   284   xhr.onreadystatechange = function(e) {
   285     if (!xhr.responseXML) {
   286       return;
   287     }
   288     var expects = {
   289       documentURI: document.documentURI,
   290       baseURI: document.baseURI,
   291       elementBaseURI: "http://www.example.com/"
   292     };
   293     var xml = SpecialPowers.wrap(xhr.responseXML);
   294     testChromeXMLDocURI(xml, expects);
   295     testCloneDocURI(xml);
   296     if (xhr.readyState == 4) {
   297       gen.next();
   298     }
   299   };
   300   xhr.send();
   301   yield undefined;
   303   xhr = new XMLHttpRequest;
   304   xhr.open("GET", "http://example.com/tests/content/base/test/file_XHRDocURI.html");
   305   xhr.responseType = "document";
   306   xhr.onreadystatechange = function(e) {
   307     if (!xhr.response) {
   308       return;
   309     }
   310     var expects = {
   311       documentURI: document.documentURI,
   312       baseURI: document.baseURI
   313     };
   314     var doc = SpecialPowers.wrap(xhr.response);
   315     testChromeHTMLDocURI(doc, "http://example.com/tests/content/base/test/file_XHRDocURI.html", expects);
   316     testCloneDocURI(doc);
   317     if (xhr.readyState == 4) {
   318       gen.next();
   319     }
   320   };
   321   xhr.send();
   322   yield undefined;
   324   xhr = new XMLHttpRequest;
   325   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.sjs?url=http://example.com/tests/content/base/test/file_XHRDocURI.xml");
   326   xhr.onreadystatechange = function(e) {
   327     if (!xhr.responseXML) {
   328       return;
   329     }
   330     var expects = {
   331       documentURI: document.documentURI,
   332       baseURI: document.baseURI,
   333       elementBaseURI: "http://www.example.com/"
   334     };
   335     var xml = SpecialPowers.wrap(xhr.responseXML);
   336     testChromeXMLDocURI(xml, expects);
   337     testCloneDocURI(xml);
   338     if (xhr.readyState == 4) {
   339       gen.next();
   340     }
   341   };
   342   xhr.send();
   343   yield undefined;
   345   xhr = new XMLHttpRequest;
   346   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.sjs?url=http://example.com/tests/content/base/test/file_XHRDocURI.html");
   347   xhr.responseType = "document";
   348   xhr.onreadystatechange = function(e) {
   349     if (!xhr.response) {
   350       return;
   351     }
   352     var expects = {
   353       documentURI: document.documentURI,
   354       baseURI: document.baseURI
   355     };
   356     var doc = SpecialPowers.wrap(xhr.response);
   357     testChromeHTMLDocURI(doc, "http://example.com/tests/content/base/test/file_XHRDocURI.html", expects);
   358     testCloneDocURI(doc);
   359     if (xhr.readyState == 4) {
   360       gen.next();
   361     }
   362   };
   363   xhr.send();
   364   yield undefined;
   367   // use chrome XHR and access URI properties from chrome privileged script
   368   SpecialPowers.addPermission("systemXHR", true, document);
   369   xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
   370   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.xml");
   371   xhr.onreadystatechange = function(e) {
   372     if (!xhr.responseXML) {
   373       return;
   374     }
   375     var expects = {
   376       documentURI: "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.xml",
   377       baseURI: "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.xml",
   378       elementBaseURI: "http://www.example.com/"
   379     };
   380     var xml = SpecialPowers.wrap(xhr.responseXML);
   381     testChromeXMLDocURI(xml, expects);
   382     if (xhr.readyState == 4) {
   383       gen.next();
   384     }
   385   };
   386   xhr.send();
   387   yield undefined;
   389   xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
   390   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.html");
   391   xhr.responseType = "document";
   392   xhr.onreadystatechange = function(e) {
   393     if (!xhr.response) {
   394       return;
   395     }
   396     var expects = {
   397       documentURI: "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.html",
   398       baseURI: "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.html"
   399     };
   400     var doc = SpecialPowers.wrap(xhr.response);
   401     testChromeHTMLDocURI(doc, "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.html", expects);
   402     if (xhr.readyState == 4) {
   403       gen.next();
   404     }
   405   };
   406   xhr.send();
   407   yield undefined;
   409   xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
   410   xhr.open("GET", "http://example.com/tests/content/base/test/file_XHRDocURI.xml");
   411   xhr.onreadystatechange = function(e) {
   412     if (!xhr.responseXML) {
   413       return;
   414     }
   415     var expects = {
   416       documentURI: "http://example.com/tests/content/base/test/file_XHRDocURI.xml",
   417       baseURI: "http://example.com/tests/content/base/test/file_XHRDocURI.xml",
   418       elementBaseURI: "http://www.example.com/"
   419     };
   420     var xml = SpecialPowers.wrap(xhr.responseXML);
   421     testChromeXMLDocURI(xml, expects);
   422     if (xhr.readyState == 4) {
   423       gen.next();
   424     }
   425   };
   426   xhr.send();
   427   yield undefined;
   429   xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
   430   xhr.open("GET", "http://example.com/tests/content/base/test/file_XHRDocURI.html");
   431   xhr.responseType = "document";
   432   xhr.onreadystatechange = function(e) {
   433     if (!xhr.response) {
   434       return;
   435     }
   436     var expects = {
   437       documentURI: "http://example.com/tests/content/base/test/file_XHRDocURI.html",
   438       baseURI: "http://example.com/tests/content/base/test/file_XHRDocURI.html"
   439     };
   440     var doc = SpecialPowers.wrap(xhr.response);
   441     testChromeHTMLDocURI(doc, "http://example.com/tests/content/base/test/file_XHRDocURI.html", expects);
   442     if (xhr.readyState == 4) {
   443       gen.next();
   444     }
   445   };
   446   xhr.send();
   447   yield undefined;
   449   xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
   450   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.sjs?url=http://example.com/tests/content/base/test/file_XHRDocURI.xml");
   451   xhr.onreadystatechange = function(e) {
   452     if (!xhr.responseXML) {
   453       return;
   454     }
   455     var expects = {
   456       documentURI: "http://example.com/tests/content/base/test/file_XHRDocURI.xml",
   457       baseURI: "http://example.com/tests/content/base/test/file_XHRDocURI.xml",
   458       elementBaseURI: "http://www.example.com/"
   459     };
   460     var xml = SpecialPowers.wrap(xhr.responseXML);
   461     testChromeXMLDocURI(xml, expects);
   462     if (xhr.readyState == 4) {
   463       gen.next();
   464     }
   465   };
   466   xhr.send();
   467   yield undefined;
   469   xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
   470   xhr.open("GET", "http://mochi.test:8888/tests/content/base/test/file_XHRDocURI.sjs?url=http://example.com/tests/content/base/test/file_XHRDocURI.html");
   471   xhr.responseType = "document";
   472   xhr.onreadystatechange = function(e) {
   473     if (!xhr.response) {
   474       return;
   475     }
   476     var expects = {
   477       documentURI: "http://example.com/tests/content/base/test/file_XHRDocURI.html",
   478       baseURI: "http://example.com/tests/content/base/test/file_XHRDocURI.html"
   479     };
   480     var doc = SpecialPowers.wrap(xhr.response);
   481     testChromeHTMLDocURI(doc, "http://example.com/tests/content/base/test/file_XHRDocURI.html", expects);
   482     if (xhr.readyState == 4) {
   483       gen.next();
   484     }
   485   };
   486   xhr.send();
   487   yield undefined;
   489   SimpleTest.finish();
   490   SpecialPowers.removePermission("systemXHR", document);
   491   yield undefined;
   492 }
   494 </script>
   495 </pre>
   496 </body>
   497 </html>

mercurial