<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=459470
-->
<head>
<title>XMLHttpRequest return document URIs</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<base href="http://example.org/">
</head>
<body onload="startTest();">
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=459470">Mozilla Bug 459470</a><br />
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=859095">Mozilla Bug 859095</a>
<p id="display">
<iframe id=loader></iframe>
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.8">
SimpleTest.waitForExplicitFinish();
var gen;
function startTest() {
// The test uses history API, so don't do anything before load event has been
// handled.
SimpleTest.executeSoon(function() {
gen = runTest();
gen.next();
});
}
function testXMLDocURI(aDoc, aExpects) {
is(aDoc.documentURI, aExpects.documentURI, "wrong url");
is(aDoc.baseURI, aExpects.baseURI, "wrong base");
is(aDoc.documentElement.baseURI, aExpects.elementBaseURI,
"wrong base (xml:base)");
function testChromeXMLDocURI(aDoc, aExpects) {
is(aDoc.documentURIObject.spec, aExpects.documentURI,
"wrong url (.documentObjectURI)");
is(aDoc.baseURIObject.spec, aExpects.baseURI,
"wrong base (.baseURIObject)");
is(aDoc.documentElement.baseURIObject.spec, aExpects.elementBaseURI,
"wrong base (.baseURIObject, xml:base)");
function testHTMLDocURI(aDoc, aExpects) {
var base = aDoc.createElement("base");
var newBaseURI = "http://www.example.com/";
base.href = newBaseURI;
aDoc.head.appendChild(base);
is(aDoc.baseURI, newBaseURI, "wrong base (after <base> changed)");
function testChromeHTMLDocURI(aDoc, aNonChromeBaseURI, aExpects) {
"wrong url (.documentURIObject)");
"wrong url (.baseURIObject)");
aDoc.body.setAttributeNS("http://www.w3.org/XML/1998/namespace", "base",
aNonChromeBaseURI);
is(aDoc.body.baseURI, aNonChromeBaseURI,
"wrong base (doc base and xml:base are same)");
is(aDoc.body.baseURIObject.spec, aNonChromeBaseURI,
"wrong base (.baseURIObject, doc base and xml:base are same)")
var attr = aDoc.getElementById("data").getAttributeNode("id");
is(attr.baseURI, aNonChromeBaseURI,
"wrong attr base (doc base and xml:base are same)")
is(attr.baseURIObject.spec, aNonChromeBaseURI,
"wrong attr base (.baseURIObject, doc base and xml:base are same)")
is(aDoc.baseURIObject.spec, newBaseURI,
"wrong base (.baseURIObject, after <base> changed)");
function testCloneDocURI(aDoc) {
var clone = aDoc.cloneNode(true);
is(clone.documentURI, aDoc.documentURI, "wrong url (clone)");
is(clone.baseURI, aDoc.baseURI, "wrong base (clone)");
function runTest() {
is(document.baseURI, "http://example.org/", "wrong doc baseURI");
// use content XHR and access URI properties from content privileged script
xhr = new XMLHttpRequest;
xhr.open("GET", "http://mochi.test:8888/tests/dom/base/test/file_XHRDocURI.xml");
xhr.onreadystatechange = function(e) {
if (!xhr.responseXML) {
return;
var expects = {
documentURI: "http://mochi.test:8888/tests/dom/base/test/file_XHRDocURI.xml",
baseURI: "http://mochi.test:8888/tests/dom/base/test/file_XHRDocURI.xml",
elementBaseURI: "http://www.example.com/"
};
testXMLDocURI(xhr.responseXML, expects);
if (xhr.readyState == 4) {
xhr.send();
yield undefined;
xhr.open("GET", "http://mochi.test:8888/tests/dom/base/test/file_XHRDocURI.html");
xhr.responseType = "document";
if (!xhr.response) {
documentURI: "http://mochi.test:8888/tests/dom/base/test/file_XHRDocURI.html",
baseURI: "http://mochi.test:8888/tests/dom/base/test/file_XHRDocURI.html"
testHTMLDocURI(xhr.response, expects);
xhr.open("GET", "http://mochi.test:8888/tests/dom/base/test/file_XHRDocURI.text");
is(xhr.responseXML, null, "should not have document");
xhr.open("GET", "http://example.com/tests/dom/base/test/file_XHRDocURI.xml");
documentURI: "http://example.com/tests/dom/base/test/file_XHRDocURI.xml",
baseURI: "http://example.com/tests/dom/base/test/file_XHRDocURI.xml",
xhr.open("GET", "http://example.com/tests/dom/base/test/file_XHRDocURI.html");
documentURI: "http://example.com/tests/dom/base/test/file_XHRDocURI.html",
baseURI: "http://example.com/tests/dom/base/test/file_XHRDocURI.html"
xhr.open("GET", "http://mochi.test:8888/tests/dom/base/test/file_XHRDocURI.sjs?url=http://example.com/tests/dom/base/test/file_XHRDocURI.xml");
xhr.open("GET", "http://mochi.test:8888/tests/dom/base/test/file_XHRDocURI.sjs?url=http://example.com/tests/dom/base/test/file_XHRDocURI.html");
xhr.open("GET", "http://example.com/tests/dom/base/test/file_XHRDocURI.text");
// use content XHR and access URI properties from chrome privileged script
var xml = SpecialPowers.wrap(xhr.responseXML);
testChromeXMLDocURI(xml, expects);
testCloneDocURI(xml);
var doc = SpecialPowers.wrap(xhr.response);
testChromeHTMLDocURI(doc, "http://mochi.test:8888/tests/dom/base/test/file_XHRDocURI.html", expects);
testCloneDocURI(doc);
documentURI: document.documentURI,
baseURI: document.baseURI,
baseURI: document.baseURI
testChromeHTMLDocURI(doc, "http://example.com/tests/dom/base/test/file_XHRDocURI.html", expects);
// use chrome XHR and access URI properties from chrome privileged script
SpecialPowers.addPermission("systemXHR", true, document);
xhr = new XMLHttpRequest({mozAnon: false, mozSystem: true});
history.pushState({}, "pushStateTest", window.location.href + "/pushStateTest");
ok(document.documentURI.indexOf("pushStateTest") > -1);
var chromeDoc = SpecialPowers.wrap(document);
ok(chromeDoc.documentURI.indexOf("pushStateTest") > -1);
history.back();
SimpleTest.finish();
SpecialPowers.removePermission("systemXHR", document);
</script>
</pre>
</body>
</html>