tor-browser

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

link-style-error.js (1961B)


      1 ["<link>", "@import"].forEach(linkType => {
      2  [
      3   ["same-origin", "resources/css.py"],
      4   ["cross-origin", get_host_info().HTTP_REMOTE_ORIGIN + "/html/semantics/document-metadata/the-link-element/resources/css.py"]
      5  ].forEach(originType => {
      6    ["no Content-Type", "wrong Content-Type", "broken Content-Type"].forEach(contentType => {
      7      ["no nosniff", "nosniff"].forEach(nosniff => {
      8        async_test(t => {
      9          const l = document.createElement("link");
     10          t.add_cleanup(() => l.remove());
     11          if (nosniff === "nosniff" || contentType === "wrong Content-Type" && (document.compatMode === "CSS1Compat" || originType[0] === "cross-origin")) {
     12            l.onerror = t.step_func_done();
     13            l.onload = t.unreached_func("error event should have fired");
     14          } else {
     15            l.onload = t.step_func_done();
     16            l.onerror = t.unreached_func("load event should have fired");
     17          }
     18          l.rel = "stylesheet";
     19          let query = [];
     20          if (contentType === "broken Content-Type") {
     21            query.push("content_type=oops");
     22          } else if (contentType === "wrong Content-Type") {
     23            query.push("content_type=text/plain")
     24          }
     25          if (nosniff === "nosniff") {
     26            query.push("nosniff");
     27          }
     28          let stringQuery = "";
     29          query.forEach(val => {
     30            if (stringQuery === "") {
     31              stringQuery += "?" + val;
     32            } else {
     33              stringQuery += "&" + val;
     34            }
     35          });
     36          const link = new URL(originType[1] + stringQuery, location).href;
     37          if (linkType === "<link>") {
     38            l.href = link;
     39          } else {
     40            l.href = "data:text/css,@import url(" + link + ");";
     41          }
     42          document.head.appendChild(l);
     43        }, "Stylesheet loading using " + linkType + " with " + contentType + ", " + originType[0] + ", and " + nosniff);
     44      });
     45    });
     46  });
     47 });