michael@0: function test() { michael@0: /** Test for Bug 396843 **/ michael@0: waitForExplicitFinish(); michael@0: michael@0: function testInDocument(doc, documentID) { michael@0: michael@0: var allNodes = []; michael@0: var XMLNodes = []; michael@0: michael@0: // HTML michael@0: function HTML_TAG(name) { michael@0: allNodes.push(doc.createElement(name)); michael@0: } michael@0: michael@0: /* List copy/pasted from nsHTMLTagList.h */ michael@0: HTML_TAG("a", "Anchor") michael@0: HTML_TAG("abbr", "Span") michael@0: HTML_TAG("acronym", "Span") michael@0: HTML_TAG("address", "Span") michael@0: HTML_TAG("applet", "SharedObject") michael@0: HTML_TAG("area", "Area") michael@0: HTML_TAG("b", "Span") michael@0: HTML_TAG("base", "Shared") michael@0: HTML_TAG("basefont", "Span") michael@0: HTML_TAG("bdo", "Span") michael@0: HTML_TAG("bgsound", "Span") michael@0: HTML_TAG("big", "Span") michael@0: HTML_TAG("blockquote", "Shared") michael@0: HTML_TAG("body", "Body") michael@0: HTML_TAG("br", "BR") michael@0: HTML_TAG("button", "Button") michael@0: HTML_TAG("canvas", "Canvas") michael@0: HTML_TAG("caption", "TableCaption") michael@0: HTML_TAG("center", "Span") michael@0: HTML_TAG("cite", "Span") michael@0: HTML_TAG("code", "Span") michael@0: HTML_TAG("col", "TableCol") michael@0: HTML_TAG("colgroup", "TableCol") michael@0: HTML_TAG("dd", "Span") michael@0: HTML_TAG("del", "Mod") michael@0: HTML_TAG("dfn", "Span") michael@0: HTML_TAG("dir", "Shared") michael@0: HTML_TAG("div", "Div") michael@0: HTML_TAG("dl", "SharedList") michael@0: HTML_TAG("dt", "Span") michael@0: HTML_TAG("em", "Span") michael@0: HTML_TAG("embed", "SharedObject") michael@0: HTML_TAG("fieldset", "FieldSet") michael@0: HTML_TAG("font", "Font") michael@0: HTML_TAG("form", "Form") michael@0: HTML_TAG("frame", "Frame") michael@0: HTML_TAG("frameset", "FrameSet") michael@0: HTML_TAG("h1", "Heading") michael@0: HTML_TAG("h2", "Heading") michael@0: HTML_TAG("h3", "Heading") michael@0: HTML_TAG("h4", "Heading") michael@0: HTML_TAG("h5", "Heading") michael@0: HTML_TAG("h6", "Heading") michael@0: HTML_TAG("head", "Head") michael@0: HTML_TAG("hr", "HR") michael@0: HTML_TAG("html", "Html") michael@0: HTML_TAG("i", "Span") michael@0: HTML_TAG("iframe", "IFrame") michael@0: HTML_TAG("image", "") michael@0: HTML_TAG("img", "Image") michael@0: HTML_TAG("input", "Input") michael@0: HTML_TAG("ins", "Mod") michael@0: HTML_TAG("isindex", "Unknown") michael@0: HTML_TAG("kbd", "Span") michael@0: HTML_TAG("keygen", "Span") michael@0: HTML_TAG("label", "Label") michael@0: HTML_TAG("legend", "Legend") michael@0: HTML_TAG("li", "LI") michael@0: HTML_TAG("link", "Link") michael@0: HTML_TAG("listing", "Span") michael@0: HTML_TAG("map", "Map") michael@0: HTML_TAG("marquee", "Div") michael@0: HTML_TAG("menu", "Shared") michael@0: HTML_TAG("meta", "Meta") michael@0: HTML_TAG("multicol", "Unknown") michael@0: HTML_TAG("nobr", "Span") michael@0: HTML_TAG("noembed", "Div") michael@0: HTML_TAG("noframes", "Div") michael@0: HTML_TAG("noscript", "Div") michael@0: HTML_TAG("object", "Object") michael@0: HTML_TAG("ol", "SharedList") michael@0: HTML_TAG("optgroup", "OptGroup") michael@0: HTML_TAG("option", "Option") michael@0: HTML_TAG("p", "Paragraph") michael@0: HTML_TAG("param", "Shared") michael@0: HTML_TAG("plaintext", "Span") michael@0: HTML_TAG("pre", "Pre") michael@0: HTML_TAG("q", "Shared") michael@0: HTML_TAG("s", "Span") michael@0: HTML_TAG("samp", "Span") michael@0: HTML_TAG("script", "Script") michael@0: HTML_TAG("select", "Select") michael@0: HTML_TAG("small", "Span") michael@0: HTML_TAG("spacer", "Unknown") michael@0: HTML_TAG("span", "Span") michael@0: HTML_TAG("strike", "Span") michael@0: HTML_TAG("strong", "Span") michael@0: HTML_TAG("style", "Style") michael@0: HTML_TAG("sub", "Span") michael@0: HTML_TAG("sup", "Span") michael@0: HTML_TAG("table", "Table") michael@0: HTML_TAG("tbody", "TableSection") michael@0: HTML_TAG("td", "TableCell") michael@0: HTML_TAG("textarea", "TextArea") michael@0: HTML_TAG("tfoot", "TableSection") michael@0: HTML_TAG("th", "TableCell") michael@0: HTML_TAG("thead", "TableSection") michael@0: HTML_TAG("template", "Template") michael@0: HTML_TAG("title", "Title") michael@0: HTML_TAG("tr", "TableRow") michael@0: HTML_TAG("tt", "Span") michael@0: HTML_TAG("u", "Span") michael@0: HTML_TAG("ul", "SharedList") michael@0: HTML_TAG("var", "Span") michael@0: HTML_TAG("wbr", "Shared") michael@0: HTML_TAG("xmp", "Span") michael@0: michael@0: function SVG_TAG(name) { michael@0: allNodes.push(doc.createElementNS("http://www.w3.org/2000/svg", name)); michael@0: } michael@0: michael@0: // List sorta stolen from SVG element factory. michael@0: SVG_TAG("a") michael@0: SVG_TAG("polyline") michael@0: SVG_TAG("polygon") michael@0: SVG_TAG("circle") michael@0: SVG_TAG("ellipse") michael@0: SVG_TAG("line") michael@0: SVG_TAG("rect") michael@0: SVG_TAG("svg") michael@0: SVG_TAG("g") michael@0: SVG_TAG("foreignObject") michael@0: SVG_TAG("path") michael@0: SVG_TAG("text") michael@0: SVG_TAG("tspan") michael@0: SVG_TAG("image") michael@0: SVG_TAG("style") michael@0: SVG_TAG("linearGradient") michael@0: SVG_TAG("metadata") michael@0: SVG_TAG("radialGradient") michael@0: SVG_TAG("stop") michael@0: SVG_TAG("defs") michael@0: SVG_TAG("desc") michael@0: SVG_TAG("script") michael@0: SVG_TAG("use") michael@0: SVG_TAG("symbol") michael@0: SVG_TAG("marker") michael@0: SVG_TAG("title") michael@0: SVG_TAG("clipPath") michael@0: SVG_TAG("textPath") michael@0: SVG_TAG("filter") michael@0: SVG_TAG("feBlend") michael@0: SVG_TAG("feColorMatrix") michael@0: SVG_TAG("feComponentTransfer") michael@0: SVG_TAG("feComposite") michael@0: SVG_TAG("feFuncR") michael@0: SVG_TAG("feFuncG") michael@0: SVG_TAG("feFuncB") michael@0: SVG_TAG("feFuncA") michael@0: SVG_TAG("feGaussianBlur") michael@0: SVG_TAG("feMerge") michael@0: SVG_TAG("feMergeNode") michael@0: SVG_TAG("feMorphology") michael@0: SVG_TAG("feOffset") michael@0: SVG_TAG("feFlood") michael@0: SVG_TAG("feTile") michael@0: SVG_TAG("feTurbulence") michael@0: SVG_TAG("feConvolveMatrix") michael@0: SVG_TAG("feDistantLight") michael@0: SVG_TAG("fePointLight") michael@0: SVG_TAG("feSpotLight") michael@0: SVG_TAG("feDiffuseLighting") michael@0: SVG_TAG("feSpecularLighting") michael@0: SVG_TAG("feDisplacementMap") michael@0: SVG_TAG("feImage") michael@0: SVG_TAG("pattern") michael@0: SVG_TAG("mask") michael@0: SVG_TAG("svgSwitch") michael@0: michael@0: // Toss in some other namespaced stuff too, for good measure michael@0: // XUL stuff might not be creatable in content documents michael@0: try { michael@0: allNodes.push(doc.createElementNS( michael@0: "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", michael@0: "window")); michael@0: } catch (e) {} michael@0: allNodes.push(doc.createElementNS("http://www.w3.org/1998/Math/MathML", michael@0: "math")); michael@0: allNodes.push(doc.createElementNS("http://www.w3.org/2001/xml-events", michael@0: "testname")); michael@0: allNodes.push(doc.createElementNS("bogus.namespace", "testname")); michael@0: michael@0: var XMLDoc = doc.implementation.createDocument("", "", null); michael@0: michael@0: // And non-elements michael@0: allNodes.push(doc.createTextNode("some text")); michael@0: allNodes.push(doc.createComment("some text")); michael@0: allNodes.push(doc.createDocumentFragment()); michael@0: XMLNodes.push(XMLDoc.createCDATASection("some text")); michael@0: XMLNodes.push(XMLDoc.createProcessingInstruction("PI", "data")); michael@0: michael@0: function runTestUnwrapped() { michael@0: if (!("wrappedJSObject" in doc)) { michael@0: return; michael@0: } michael@0: ok(doc.wrappedJSObject.nodePrincipal === undefined, michael@0: "Must not have document principal for " + documentID); michael@0: ok(doc.wrappedJSObject.baseURIObject === undefined, michael@0: "Must not have document base URI for " + documentID); michael@0: ok(doc.wrappedJSObject.documentURIObject === undefined, michael@0: "Must not have document URI for " + documentID); michael@0: michael@0: for (var i = 0; i < allNodes.length; ++i) { michael@0: ok(allNodes[i].wrappedJSObject.nodePrincipal === undefined, michael@0: "Unexpected principal appears for " + allNodes[i].nodeName + michael@0: " in " + documentID); michael@0: ok(allNodes[i].wrappedJSObject.baseURIObject === undefined, michael@0: "Unexpected base URI appears for " + allNodes[i].nodeName + michael@0: " in " + documentID); michael@0: } michael@0: } michael@0: michael@0: function runTestProps() { michael@0: isnot(doc.nodePrincipal, null, michael@0: "Must have document principal in " + documentID); michael@0: is(doc.nodePrincipal instanceof Components.interfaces.nsIPrincipal, michael@0: true, "document principal must be a principal in " + documentID); michael@0: isnot(doc.baseURIObject, null, michael@0: "Must have document base URI in" + documentID); michael@0: is(doc.baseURIObject instanceof Components.interfaces.nsIURI, michael@0: true, "document base URI must be a URI in " + documentID); michael@0: isnot(doc.documentURIObject, null, michael@0: "Must have document URI " + documentID); michael@0: is(doc.documentURIObject instanceof Components.interfaces.nsIURI, michael@0: true, "document URI must be a URI in " + documentID); michael@0: is(doc.documentURIObject.spec, doc.documentURI, michael@0: "document URI must be the right URI in " + documentID); michael@0: michael@0: for (var i = 0; i < allNodes.length; ++i) { michael@0: is(allNodes[i].nodePrincipal, doc.nodePrincipal, michael@0: "Unexpected principal for " + allNodes[i].nodeName + michael@0: " in " + documentID); michael@0: is(allNodes[i].baseURIObject, doc.baseURIObject, michael@0: "Unexpected base URI for " + allNodes[i].nodeName + michael@0: " in " + documentID); michael@0: } michael@0: michael@0: for (i = 0; i < XMLNodes.length; ++i) { michael@0: is(XMLNodes[i].nodePrincipal, doc.nodePrincipal, michael@0: "Unexpected principal for " + XMLNodes[i].nodeName + michael@0: " in " + documentID); michael@0: is(XMLNodes[i].baseURIObject.spec, "about:blank", michael@0: "Unexpected base URI for " + XMLNodes[i].nodeName + michael@0: " in " + documentID); michael@0: } michael@0: } michael@0: michael@0: runTestUnwrapped(); michael@0: runTestProps(); michael@0: runTestUnwrapped(); michael@0: } michael@0: michael@0: var testsRunning = 2; michael@0: michael@0: testInDocument(document, "browser window"); michael@0: michael@0: function newTabTest(url) { michael@0: var newTab = gBrowser.addTab(); michael@0: var newBrowser = gBrowser.getBrowserForTab(newTab); michael@0: newBrowser.contentWindow.location.href = url; michael@0: function testBrowser(event) { michael@0: newBrowser.removeEventListener("load", testBrowser, true); michael@0: is(event.target, newBrowser.contentDocument, michael@0: "Unexpected target in " + url); michael@0: testInDocument(newBrowser.contentDocument, url); michael@0: michael@0: gBrowser.removeTab(newTab); michael@0: michael@0: --testsRunning; michael@0: if (testsRunning == 0) { michael@0: finish(); michael@0: } michael@0: } michael@0: newBrowser.addEventListener("load", testBrowser, true); michael@0: } michael@0: michael@0: newTabTest("about:blank"); michael@0: newTabTest("about:config"); michael@0: }