tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_bug396843.js (9410B)


      1 /** Test for Bug 396843 */
      2 
      3 function testInDocument(doc, documentID) {
      4  var allNodes = [];
      5  var XMLNodes = [];
      6 
      7  // HTML
      8  function HTML_TAG(name) {
      9    allNodes.push(doc.createElementNS("http://www.w3.org/1999/xhtml", name));
     10  }
     11 
     12  /* List copy/pasted from nsHTMLTagList.h */
     13  HTML_TAG("a", "Anchor");
     14  HTML_TAG("abbr", "Span");
     15  HTML_TAG("acronym", "Span");
     16  HTML_TAG("address", "Span");
     17  HTML_TAG("applet", "Unknown");
     18  HTML_TAG("area", "Area");
     19  HTML_TAG("b", "Span");
     20  HTML_TAG("base", "Shared");
     21  HTML_TAG("basefont", "Span");
     22  HTML_TAG("bdi", "");
     23  HTML_TAG("bdo", "Span");
     24  HTML_TAG("bgsound", "Span");
     25  HTML_TAG("big", "Span");
     26  HTML_TAG("blockquote", "Shared");
     27  HTML_TAG("body", "Body");
     28  HTML_TAG("br", "BR");
     29  HTML_TAG("button", "Button");
     30  HTML_TAG("canvas", "Canvas");
     31  HTML_TAG("caption", "TableCaption");
     32  HTML_TAG("center", "Span");
     33  HTML_TAG("cite", "Span");
     34  HTML_TAG("code", "Span");
     35  HTML_TAG("col", "TableCol");
     36  HTML_TAG("colgroup", "TableCol");
     37  HTML_TAG("dd", "Span");
     38  HTML_TAG("del", "Mod");
     39  HTML_TAG("dfn", "Span");
     40  HTML_TAG("dir", "Shared");
     41  HTML_TAG("div", "Div");
     42  HTML_TAG("dl", "SharedList");
     43  HTML_TAG("dt", "Span");
     44  HTML_TAG("em", "Span");
     45  HTML_TAG("embed", "Embed");
     46  HTML_TAG("fieldset", "FieldSet");
     47  HTML_TAG("font", "Font");
     48  HTML_TAG("form", "Form");
     49  HTML_TAG("frame", "Frame");
     50  HTML_TAG("frameset", "FrameSet");
     51  HTML_TAG("h1", "Heading");
     52  HTML_TAG("h2", "Heading");
     53  HTML_TAG("h3", "Heading");
     54  HTML_TAG("h4", "Heading");
     55  HTML_TAG("h5", "Heading");
     56  HTML_TAG("h6", "Heading");
     57  HTML_TAG("head", "Head");
     58  HTML_TAG("hr", "HR");
     59  HTML_TAG("html", "Html");
     60  HTML_TAG("i", "Span");
     61  HTML_TAG("iframe", "IFrame");
     62  HTML_TAG("image", "");
     63  HTML_TAG("img", "Image");
     64  HTML_TAG("input", "Input");
     65  HTML_TAG("ins", "Mod");
     66  HTML_TAG("isindex", "Unknown");
     67  HTML_TAG("kbd", "Span");
     68  HTML_TAG("keygen", "Span");
     69  HTML_TAG("label", "Label");
     70  HTML_TAG("legend", "Legend");
     71  HTML_TAG("li", "LI");
     72  HTML_TAG("link", "Link");
     73  HTML_TAG("listing", "Span");
     74  HTML_TAG("map", "Map");
     75  HTML_TAG("marquee", "Div");
     76  HTML_TAG("menu", "Shared");
     77  HTML_TAG("meta", "Meta");
     78  HTML_TAG("multicol", "Unknown");
     79  HTML_TAG("nobr", "Span");
     80  HTML_TAG("noembed", "Div");
     81  HTML_TAG("noframes", "Div");
     82  HTML_TAG("noscript", "Div");
     83  HTML_TAG("object", "Object");
     84  HTML_TAG("ol", "SharedList");
     85  HTML_TAG("optgroup", "OptGroup");
     86  HTML_TAG("option", "Option");
     87  HTML_TAG("p", "Paragraph");
     88  HTML_TAG("param", "Shared");
     89  HTML_TAG("plaintext", "Span");
     90  HTML_TAG("pre", "Pre");
     91  HTML_TAG("q", "Shared");
     92  HTML_TAG("s", "Span");
     93  HTML_TAG("samp", "Span");
     94  HTML_TAG("script", "Script");
     95  HTML_TAG("select", "Select");
     96  HTML_TAG("small", "Span");
     97  HTML_TAG("spacer", "Unknown");
     98  HTML_TAG("span", "Span");
     99  HTML_TAG("strike", "Span");
    100  HTML_TAG("strong", "Span");
    101  HTML_TAG("style", "Style");
    102  HTML_TAG("sub", "Span");
    103  HTML_TAG("sup", "Span");
    104  HTML_TAG("table", "Table");
    105  HTML_TAG("tbody", "TableSection");
    106  HTML_TAG("td", "TableCell");
    107  HTML_TAG("textarea", "TextArea");
    108  HTML_TAG("tfoot", "TableSection");
    109  HTML_TAG("th", "TableCell");
    110  HTML_TAG("thead", "TableSection");
    111  HTML_TAG("template", "Template");
    112  HTML_TAG("title", "Title");
    113  HTML_TAG("tr", "TableRow");
    114  HTML_TAG("tt", "Span");
    115  HTML_TAG("u", "Span");
    116  HTML_TAG("ul", "SharedList");
    117  HTML_TAG("var", "Span");
    118  HTML_TAG("wbr", "Shared");
    119  HTML_TAG("xmp", "Span");
    120 
    121  function SVG_TAG(name) {
    122    allNodes.push(doc.createElementNS("http://www.w3.org/2000/svg", name));
    123  }
    124 
    125  // List sorta stolen from SVG element factory.
    126  SVG_TAG("a");
    127  SVG_TAG("polyline");
    128  SVG_TAG("polygon");
    129  SVG_TAG("circle");
    130  SVG_TAG("ellipse");
    131  SVG_TAG("line");
    132  SVG_TAG("rect");
    133  SVG_TAG("svg");
    134  SVG_TAG("g");
    135  SVG_TAG("foreignObject");
    136  SVG_TAG("path");
    137  SVG_TAG("text");
    138  SVG_TAG("tspan");
    139  SVG_TAG("image");
    140  SVG_TAG("style");
    141  SVG_TAG("linearGradient");
    142  SVG_TAG("metadata");
    143  SVG_TAG("radialGradient");
    144  SVG_TAG("stop");
    145  SVG_TAG("defs");
    146  SVG_TAG("desc");
    147  SVG_TAG("script");
    148  SVG_TAG("use");
    149  SVG_TAG("symbol");
    150  SVG_TAG("marker");
    151  SVG_TAG("title");
    152  SVG_TAG("clipPath");
    153  SVG_TAG("textPath");
    154  SVG_TAG("filter");
    155  SVG_TAG("feBlend");
    156  SVG_TAG("feColorMatrix");
    157  SVG_TAG("feComponentTransfer");
    158  SVG_TAG("feComposite");
    159  SVG_TAG("feFuncR");
    160  SVG_TAG("feFuncG");
    161  SVG_TAG("feFuncB");
    162  SVG_TAG("feFuncA");
    163  SVG_TAG("feGaussianBlur");
    164  SVG_TAG("feMerge");
    165  SVG_TAG("feMergeNode");
    166  SVG_TAG("feMorphology");
    167  SVG_TAG("feOffset");
    168  SVG_TAG("feFlood");
    169  SVG_TAG("feTile");
    170  SVG_TAG("feTurbulence");
    171  SVG_TAG("feConvolveMatrix");
    172  SVG_TAG("feDistantLight");
    173  SVG_TAG("fePointLight");
    174  SVG_TAG("feSpotLight");
    175  SVG_TAG("feDiffuseLighting");
    176  SVG_TAG("feSpecularLighting");
    177  SVG_TAG("feDisplacementMap");
    178  SVG_TAG("feImage");
    179  SVG_TAG("pattern");
    180  SVG_TAG("mask");
    181  SVG_TAG("svgSwitch");
    182 
    183  // Toss in some other namespaced stuff too, for good measure
    184  // XUL stuff might not be creatable in content documents
    185  try {
    186    allNodes.push(
    187      doc.createElementNS(
    188        "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
    189        "window"
    190      )
    191    );
    192  } catch (e) {}
    193  allNodes.push(
    194    doc.createElementNS("http://www.w3.org/1998/Math/MathML", "math")
    195  );
    196  allNodes.push(
    197    doc.createElementNS("http://www.w3.org/2001/xml-events", "testname")
    198  );
    199  allNodes.push(doc.createElementNS("bogus.namespace", "testname"));
    200 
    201  var XMLDoc = doc.implementation.createDocument("", "", null);
    202 
    203  // And non-elements
    204  allNodes.push(doc.createTextNode("some text"));
    205  allNodes.push(doc.createComment("some text"));
    206  allNodes.push(doc.createDocumentFragment());
    207  XMLNodes.push(XMLDoc.createCDATASection("some text"));
    208  XMLNodes.push(XMLDoc.createProcessingInstruction("PI", "data"));
    209 
    210  function runTestUnwrapped() {
    211    if (!("wrappedJSObject" in doc)) {
    212      return;
    213    }
    214    Assert.strictEqual(
    215      doc.wrappedJSObject.nodePrincipal,
    216      undefined,
    217      "Must not have document principal for " + documentID
    218    );
    219    Assert.strictEqual(
    220      doc.wrappedJSObject.baseURIObject,
    221      undefined,
    222      "Must not have document base URI for " + documentID
    223    );
    224    Assert.strictEqual(
    225      doc.wrappedJSObject.documentURIObject,
    226      undefined,
    227      "Must not have document URI for " + documentID
    228    );
    229 
    230    for (var i = 0; i < allNodes.length; ++i) {
    231      Assert.strictEqual(
    232        allNodes[i].wrappedJSObject.nodePrincipal,
    233        undefined,
    234        "Unexpected principal appears for " +
    235          allNodes[i].nodeName +
    236          " in " +
    237          documentID
    238      );
    239      Assert.strictEqual(
    240        allNodes[i].wrappedJSObject.baseURIObject,
    241        undefined,
    242        "Unexpected base URI appears for " +
    243          allNodes[i].nodeName +
    244          " in " +
    245          documentID
    246      );
    247    }
    248  }
    249 
    250  function runTestProps() {
    251    isnot(
    252      doc.nodePrincipal,
    253      null,
    254      "Must have document principal in " + documentID
    255    );
    256    is(
    257      doc.nodePrincipal instanceof Ci.nsIPrincipal,
    258      true,
    259      "document principal must be a principal in " + documentID
    260    );
    261    isnot(
    262      doc.baseURIObject,
    263      null,
    264      "Must have document base URI in" + documentID
    265    );
    266    is(
    267      doc.baseURIObject instanceof Ci.nsIURI,
    268      true,
    269      "document base URI must be a URI in " + documentID
    270    );
    271    isnot(doc.documentURIObject, null, "Must have document URI " + documentID);
    272    is(
    273      doc.documentURIObject instanceof Ci.nsIURI,
    274      true,
    275      "document URI must be a URI in " + documentID
    276    );
    277    is(
    278      doc.documentURIObject.spec,
    279      doc.documentURI,
    280      "document URI must be the right URI in " + documentID
    281    );
    282 
    283    for (var i = 0; i < allNodes.length; ++i) {
    284      is(
    285        allNodes[i].nodePrincipal,
    286        doc.nodePrincipal,
    287        "Unexpected principal for " + allNodes[i].nodeName + " in " + documentID
    288      );
    289      is(
    290        allNodes[i].baseURIObject,
    291        doc.baseURIObject,
    292        "Unexpected base URI for " + allNodes[i].nodeName + " in " + documentID
    293      );
    294    }
    295 
    296    for (i = 0; i < XMLNodes.length; ++i) {
    297      is(
    298        XMLNodes[i].nodePrincipal,
    299        doc.nodePrincipal,
    300        "Unexpected principal for " + XMLNodes[i].nodeName + " in " + documentID
    301      );
    302      is(
    303        XMLNodes[i].baseURIObject.spec,
    304        "about:blank",
    305        "Unexpected base URI for " + XMLNodes[i].nodeName + " in " + documentID
    306      );
    307    }
    308  }
    309 
    310  runTestUnwrapped();
    311  runTestProps();
    312  runTestUnwrapped();
    313 }
    314 
    315 add_task(async function test1() {
    316  testInDocument(document, "browser window");
    317 });
    318 
    319 async function newTabTest(location) {
    320  await SpecialPowers.pushPrefEnv({
    321    set: [["security.allow_eval_with_system_principal", true]],
    322  });
    323 
    324  await BrowserTestUtils.withNewTab(
    325    { gBrowser, url: location },
    326    async function (browser) {
    327      await SpecialPowers.spawn(
    328        browser,
    329        [{ location, testInDocument_: testInDocument.toSource() }],
    330        async function ({ location, testInDocument_ }) {
    331          // eslint-disable-next-line no-eval
    332          let testInDocument = eval(`(() => (${testInDocument_}))()`);
    333          testInDocument(content.document, location);
    334        }
    335      );
    336    }
    337  );
    338 }
    339 
    340 add_task(async function test2() {
    341  await newTabTest("about:blank");
    342 });
    343 
    344 add_task(async function test3() {
    345  await newTabTest("about:config");
    346 });