dom/tests/browser/browser_bug396843.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/browser/browser_bug396843.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,294 @@
     1.4 +function test() {
     1.5 +    /** Test for Bug 396843 **/
     1.6 +    waitForExplicitFinish();
     1.7 +
     1.8 +    function testInDocument(doc, documentID) {
     1.9 +        
    1.10 +        var allNodes = [];
    1.11 +        var XMLNodes = [];
    1.12 +
    1.13 +        // HTML
    1.14 +        function HTML_TAG(name) {
    1.15 +            allNodes.push(doc.createElement(name));
    1.16 +        }
    1.17 +
    1.18 +        /* List copy/pasted from nsHTMLTagList.h */
    1.19 +        HTML_TAG("a", "Anchor")
    1.20 +        HTML_TAG("abbr", "Span")
    1.21 +        HTML_TAG("acronym", "Span")
    1.22 +        HTML_TAG("address", "Span")
    1.23 +        HTML_TAG("applet", "SharedObject")
    1.24 +        HTML_TAG("area", "Area")
    1.25 +        HTML_TAG("b", "Span")
    1.26 +        HTML_TAG("base", "Shared")
    1.27 +        HTML_TAG("basefont", "Span")
    1.28 +        HTML_TAG("bdo", "Span")
    1.29 +        HTML_TAG("bgsound", "Span")
    1.30 +        HTML_TAG("big", "Span")
    1.31 +        HTML_TAG("blockquote", "Shared")
    1.32 +        HTML_TAG("body", "Body")
    1.33 +        HTML_TAG("br", "BR")
    1.34 +        HTML_TAG("button", "Button")
    1.35 +        HTML_TAG("canvas", "Canvas")
    1.36 +        HTML_TAG("caption", "TableCaption")
    1.37 +        HTML_TAG("center", "Span")
    1.38 +        HTML_TAG("cite", "Span")
    1.39 +        HTML_TAG("code", "Span")
    1.40 +        HTML_TAG("col", "TableCol")
    1.41 +        HTML_TAG("colgroup", "TableCol")
    1.42 +        HTML_TAG("dd", "Span")
    1.43 +        HTML_TAG("del", "Mod")
    1.44 +        HTML_TAG("dfn", "Span")
    1.45 +        HTML_TAG("dir", "Shared")
    1.46 +        HTML_TAG("div", "Div")
    1.47 +        HTML_TAG("dl", "SharedList")
    1.48 +        HTML_TAG("dt", "Span")
    1.49 +        HTML_TAG("em", "Span")
    1.50 +        HTML_TAG("embed", "SharedObject")
    1.51 +        HTML_TAG("fieldset", "FieldSet")
    1.52 +        HTML_TAG("font", "Font")
    1.53 +        HTML_TAG("form", "Form")
    1.54 +        HTML_TAG("frame", "Frame")
    1.55 +        HTML_TAG("frameset", "FrameSet")
    1.56 +        HTML_TAG("h1", "Heading")
    1.57 +        HTML_TAG("h2", "Heading")
    1.58 +        HTML_TAG("h3", "Heading")
    1.59 +        HTML_TAG("h4", "Heading")
    1.60 +        HTML_TAG("h5", "Heading")
    1.61 +        HTML_TAG("h6", "Heading")
    1.62 +        HTML_TAG("head", "Head")
    1.63 +        HTML_TAG("hr", "HR")
    1.64 +        HTML_TAG("html", "Html")
    1.65 +        HTML_TAG("i", "Span")
    1.66 +        HTML_TAG("iframe", "IFrame")
    1.67 +        HTML_TAG("image", "")
    1.68 +        HTML_TAG("img", "Image")
    1.69 +        HTML_TAG("input", "Input")
    1.70 +        HTML_TAG("ins", "Mod")
    1.71 +        HTML_TAG("isindex", "Unknown")
    1.72 +        HTML_TAG("kbd", "Span")
    1.73 +        HTML_TAG("keygen", "Span")
    1.74 +        HTML_TAG("label", "Label")
    1.75 +        HTML_TAG("legend", "Legend")
    1.76 +        HTML_TAG("li", "LI")
    1.77 +        HTML_TAG("link", "Link")
    1.78 +        HTML_TAG("listing", "Span")
    1.79 +        HTML_TAG("map", "Map")
    1.80 +        HTML_TAG("marquee", "Div")
    1.81 +        HTML_TAG("menu", "Shared")
    1.82 +        HTML_TAG("meta", "Meta")
    1.83 +        HTML_TAG("multicol", "Unknown")
    1.84 +        HTML_TAG("nobr", "Span")
    1.85 +        HTML_TAG("noembed", "Div")
    1.86 +        HTML_TAG("noframes", "Div")
    1.87 +        HTML_TAG("noscript", "Div")
    1.88 +        HTML_TAG("object", "Object")
    1.89 +        HTML_TAG("ol", "SharedList")
    1.90 +        HTML_TAG("optgroup", "OptGroup")
    1.91 +        HTML_TAG("option", "Option")
    1.92 +        HTML_TAG("p", "Paragraph")
    1.93 +        HTML_TAG("param", "Shared")
    1.94 +        HTML_TAG("plaintext", "Span")
    1.95 +        HTML_TAG("pre", "Pre")
    1.96 +        HTML_TAG("q", "Shared")
    1.97 +        HTML_TAG("s", "Span")
    1.98 +        HTML_TAG("samp", "Span")
    1.99 +        HTML_TAG("script", "Script")
   1.100 +        HTML_TAG("select", "Select")
   1.101 +        HTML_TAG("small", "Span")
   1.102 +        HTML_TAG("spacer", "Unknown")
   1.103 +        HTML_TAG("span", "Span")
   1.104 +        HTML_TAG("strike", "Span")
   1.105 +        HTML_TAG("strong", "Span")
   1.106 +        HTML_TAG("style", "Style")
   1.107 +        HTML_TAG("sub", "Span")
   1.108 +        HTML_TAG("sup", "Span")
   1.109 +        HTML_TAG("table", "Table")
   1.110 +        HTML_TAG("tbody", "TableSection")
   1.111 +        HTML_TAG("td", "TableCell")
   1.112 +        HTML_TAG("textarea", "TextArea")
   1.113 +        HTML_TAG("tfoot", "TableSection")
   1.114 +        HTML_TAG("th", "TableCell")
   1.115 +        HTML_TAG("thead", "TableSection")
   1.116 +        HTML_TAG("template", "Template")
   1.117 +        HTML_TAG("title", "Title")
   1.118 +        HTML_TAG("tr", "TableRow")
   1.119 +        HTML_TAG("tt", "Span")
   1.120 +        HTML_TAG("u", "Span")
   1.121 +        HTML_TAG("ul", "SharedList")
   1.122 +        HTML_TAG("var", "Span")
   1.123 +        HTML_TAG("wbr", "Shared")
   1.124 +        HTML_TAG("xmp", "Span")
   1.125 +
   1.126 +        function SVG_TAG(name) {
   1.127 +            allNodes.push(doc.createElementNS("http://www.w3.org/2000/svg", name));
   1.128 +        }
   1.129 +
   1.130 +        // List sorta stolen from SVG element factory.
   1.131 +        SVG_TAG("a")
   1.132 +        SVG_TAG("polyline")
   1.133 +        SVG_TAG("polygon")
   1.134 +        SVG_TAG("circle")
   1.135 +        SVG_TAG("ellipse")
   1.136 +        SVG_TAG("line")
   1.137 +        SVG_TAG("rect")
   1.138 +        SVG_TAG("svg")
   1.139 +        SVG_TAG("g")
   1.140 +        SVG_TAG("foreignObject")
   1.141 +        SVG_TAG("path")
   1.142 +        SVG_TAG("text")
   1.143 +        SVG_TAG("tspan")
   1.144 +        SVG_TAG("image")
   1.145 +        SVG_TAG("style")
   1.146 +        SVG_TAG("linearGradient")
   1.147 +        SVG_TAG("metadata")
   1.148 +        SVG_TAG("radialGradient")
   1.149 +        SVG_TAG("stop")
   1.150 +        SVG_TAG("defs")
   1.151 +        SVG_TAG("desc")
   1.152 +        SVG_TAG("script")
   1.153 +        SVG_TAG("use")
   1.154 +        SVG_TAG("symbol")
   1.155 +        SVG_TAG("marker")
   1.156 +        SVG_TAG("title")
   1.157 +        SVG_TAG("clipPath")
   1.158 +        SVG_TAG("textPath")
   1.159 +        SVG_TAG("filter")
   1.160 +        SVG_TAG("feBlend")
   1.161 +        SVG_TAG("feColorMatrix")
   1.162 +        SVG_TAG("feComponentTransfer")
   1.163 +        SVG_TAG("feComposite")
   1.164 +        SVG_TAG("feFuncR")
   1.165 +        SVG_TAG("feFuncG")
   1.166 +        SVG_TAG("feFuncB")
   1.167 +        SVG_TAG("feFuncA")
   1.168 +        SVG_TAG("feGaussianBlur")
   1.169 +        SVG_TAG("feMerge")
   1.170 +        SVG_TAG("feMergeNode")
   1.171 +        SVG_TAG("feMorphology")
   1.172 +        SVG_TAG("feOffset")
   1.173 +        SVG_TAG("feFlood")
   1.174 +        SVG_TAG("feTile")
   1.175 +        SVG_TAG("feTurbulence")
   1.176 +        SVG_TAG("feConvolveMatrix")
   1.177 +        SVG_TAG("feDistantLight")
   1.178 +        SVG_TAG("fePointLight")
   1.179 +        SVG_TAG("feSpotLight")
   1.180 +        SVG_TAG("feDiffuseLighting")
   1.181 +        SVG_TAG("feSpecularLighting")
   1.182 +        SVG_TAG("feDisplacementMap")
   1.183 +        SVG_TAG("feImage")
   1.184 +        SVG_TAG("pattern")
   1.185 +        SVG_TAG("mask")
   1.186 +        SVG_TAG("svgSwitch")
   1.187 +
   1.188 +        // Toss in some other namespaced stuff too, for good measure
   1.189 +        // XUL stuff might not be creatable in content documents
   1.190 +        try {
   1.191 +            allNodes.push(doc.createElementNS(
   1.192 +                "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
   1.193 +                "window"));
   1.194 +        } catch (e) {}
   1.195 +        allNodes.push(doc.createElementNS("http://www.w3.org/1998/Math/MathML",
   1.196 +                                          "math"));
   1.197 +        allNodes.push(doc.createElementNS("http://www.w3.org/2001/xml-events",
   1.198 +                                          "testname"));
   1.199 +        allNodes.push(doc.createElementNS("bogus.namespace", "testname"));
   1.200 +
   1.201 +        var XMLDoc = doc.implementation.createDocument("", "", null);
   1.202 +
   1.203 +        // And non-elements
   1.204 +        allNodes.push(doc.createTextNode("some text"));
   1.205 +        allNodes.push(doc.createComment("some text"));
   1.206 +        allNodes.push(doc.createDocumentFragment());
   1.207 +        XMLNodes.push(XMLDoc.createCDATASection("some text"));
   1.208 +        XMLNodes.push(XMLDoc.createProcessingInstruction("PI", "data"));
   1.209 +        
   1.210 +        function runTestUnwrapped() {
   1.211 +            if (!("wrappedJSObject" in doc)) {
   1.212 +                return;
   1.213 +            }
   1.214 +            ok(doc.wrappedJSObject.nodePrincipal === undefined,
   1.215 +               "Must not have document principal for " + documentID);
   1.216 +            ok(doc.wrappedJSObject.baseURIObject === undefined,
   1.217 +               "Must not have document base URI for " + documentID);
   1.218 +            ok(doc.wrappedJSObject.documentURIObject === undefined,
   1.219 +               "Must not have document URI for " + documentID);
   1.220 +
   1.221 +            for (var i = 0; i < allNodes.length; ++i) {
   1.222 +                ok(allNodes[i].wrappedJSObject.nodePrincipal === undefined,
   1.223 +                   "Unexpected principal appears for " + allNodes[i].nodeName +
   1.224 +                   " in " + documentID);
   1.225 +                ok(allNodes[i].wrappedJSObject.baseURIObject === undefined,
   1.226 +                   "Unexpected base URI appears for " + allNodes[i].nodeName +
   1.227 +                   " in " + documentID);
   1.228 +            }
   1.229 +        }
   1.230 +        
   1.231 +        function runTestProps() {
   1.232 +            isnot(doc.nodePrincipal, null,
   1.233 +                  "Must have document principal in " + documentID);
   1.234 +            is(doc.nodePrincipal instanceof Components.interfaces.nsIPrincipal,
   1.235 +               true, "document principal must be a principal in " + documentID);
   1.236 +            isnot(doc.baseURIObject, null,
   1.237 +                  "Must have document base URI in" + documentID);
   1.238 +            is(doc.baseURIObject instanceof Components.interfaces.nsIURI,
   1.239 +               true, "document base URI must be a URI in " + documentID);
   1.240 +            isnot(doc.documentURIObject, null,
   1.241 +                  "Must have document URI " + documentID);
   1.242 +            is(doc.documentURIObject instanceof Components.interfaces.nsIURI,
   1.243 +               true, "document URI must be a URI in " + documentID);
   1.244 +            is(doc.documentURIObject.spec, doc.documentURI,
   1.245 +               "document URI must be the right URI in " + documentID);
   1.246 +     
   1.247 +            for (var i = 0; i < allNodes.length; ++i) {
   1.248 +                is(allNodes[i].nodePrincipal, doc.nodePrincipal,
   1.249 +                   "Unexpected principal for " + allNodes[i].nodeName +
   1.250 +                   " in " + documentID);
   1.251 +                is(allNodes[i].baseURIObject, doc.baseURIObject,
   1.252 +                   "Unexpected base URI for " + allNodes[i].nodeName +
   1.253 +                   " in " + documentID);
   1.254 +            }
   1.255 +
   1.256 +            for (i = 0; i < XMLNodes.length; ++i) {
   1.257 +                is(XMLNodes[i].nodePrincipal, doc.nodePrincipal,
   1.258 +                   "Unexpected principal for " + XMLNodes[i].nodeName +
   1.259 +                   " in " + documentID);
   1.260 +                is(XMLNodes[i].baseURIObject.spec, "about:blank",
   1.261 +                   "Unexpected base URI for " + XMLNodes[i].nodeName +
   1.262 +                   " in " + documentID);
   1.263 +            }
   1.264 +        }
   1.265 +
   1.266 +        runTestUnwrapped();
   1.267 +        runTestProps();
   1.268 +        runTestUnwrapped();
   1.269 +    }
   1.270 +
   1.271 +    var testsRunning = 2;
   1.272 +    
   1.273 +    testInDocument(document, "browser window");
   1.274 +
   1.275 +    function newTabTest(url) {
   1.276 +        var newTab = gBrowser.addTab();
   1.277 +        var newBrowser = gBrowser.getBrowserForTab(newTab);
   1.278 +        newBrowser.contentWindow.location.href = url;
   1.279 +        function testBrowser(event) {
   1.280 +            newBrowser.removeEventListener("load", testBrowser, true);
   1.281 +            is(event.target, newBrowser.contentDocument,
   1.282 +               "Unexpected target in " + url);
   1.283 +            testInDocument(newBrowser.contentDocument, url);
   1.284 +
   1.285 +            gBrowser.removeTab(newTab);
   1.286 +
   1.287 +            --testsRunning;
   1.288 +            if (testsRunning == 0) {
   1.289 +                finish();
   1.290 +            }
   1.291 +        }
   1.292 +        newBrowser.addEventListener("load", testBrowser, true);
   1.293 +    }
   1.294 +
   1.295 +    newTabTest("about:blank");
   1.296 +    newTabTest("about:config");
   1.297 +}

mercurial