tor-browser

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

domparser-url-tests.js (2255B)


      1 const loadPromise = new Promise(resolve => { window.resolveLoadPromise = resolve; });
      2 
      3 function assertURL(doc, expectedURL) {
      4  assert_equals(doc.URL, expectedURL, "document.URL");
      5  assert_equals(doc.documentURI, expectedURL, "document.documentURI");
      6  assert_equals(doc.baseURI, expectedURL, "document.baseURI");
      7 }
      8 
      9 const supportedTypes = [
     10  "text/html",
     11  "text/xml",
     12  "application/xml",
     13  "application/xhtml+xml",
     14  "image/svg+xml",
     15 ];
     16 
     17 const invalidXML = `<span x:test="testing">1</span>`;
     18 const inputs = {
     19  valid: "<html></html>",
     20  "invalid XML": invalidXML
     21 };
     22 
     23 for (const mimeType of supportedTypes) {
     24  for (const [inputName, input] of Object.entries(inputs)) {
     25    if (mimeType === "text/html" && input === invalidXML) {
     26      continue;
     27    }
     28 
     29    test(() => {
     30      const parser = new DOMParser();
     31      const doc = parser.parseFromString(input, mimeType);
     32 
     33      assertURL(doc, document.URL);
     34    }, `${mimeType} ${inputName}: created normally`);
     35 
     36    promise_test(async () => {
     37      await loadPromise;
     38 
     39      const parser = new frames[0].DOMParser();
     40      const doc = parser.parseFromString(input, mimeType);
     41 
     42      assertURL(doc, frames[0].document.URL);
     43    }, `${mimeType} ${inputName}: created using another iframe's DOMParser from this frame`);
     44 
     45    promise_test(async () => {
     46      await loadPromise;
     47 
     48      const parser = new frames[0].DOMParser();
     49      const doc = frames[0].doParse(input, mimeType);
     50 
     51      assertURL(doc, frames[0].document.URL);
     52    }, `${mimeType} ${inputName}: created using another iframe's DOMParser from that frame`);
     53 
     54    promise_test(async () => {
     55      await loadPromise;
     56 
     57      const parser = new DOMParser();
     58      const doc = frames[0].DOMParser.prototype.parseFromString.call(parser, input, mimeType);
     59 
     60      assertURL(doc, document.URL);
     61    }, `${mimeType} ${inputName}: created using a parser from this frame and the method from the iframe`);
     62 
     63    promise_test(async () => {
     64      await loadPromise;
     65 
     66      const parser = new frames[0].DOMParser();
     67      const doc = DOMParser.prototype.parseFromString.call(parser, input, mimeType);
     68 
     69      assertURL(doc, frames[0].document.URL);
     70    }, `${mimeType} ${inputName}: created using a parser from the iframe and the method from this frame`);
     71  }
     72 }