tor-browser

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

test_embed_xorigin_document.html (3318B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4 <title>test for embedding a cross-origin document</title>
      5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      7 </head>
      8 <body>
      9 <script>
     10 // Get the path of the current test, without hostname or filename.
     11 const testPath = window.location.href.replace("http://mochi.test:8888", "");
     12 const testDir = testPath.substring(0, testPath.lastIndexOf('/') + 1);
     13 
     14 add_task(async function() {
     15  info("Loading image in embed");
     16  let embed = document.createElement("embed");
     17  document.body.appendChild(embed);
     18 
     19  info("x-site image load from element");
     20  embed.setAttribute("src", "http://example.com" + testDir + "green.png");
     21  await new Promise(resolve => embed.addEventListener("load", resolve, { once: true }));
     22  is(
     23    SpecialPowers.wrap(embed).displayedType,
     24    SpecialPowers.Ci.nsIObjectLoadingContent.TYPE_DOCUMENT,
     25    `image load should have document type`
     26  );
     27 
     28  ok(SpecialPowers.wrap(embed).frameLoader, "should have frameloader");
     29  ok(SpecialPowers.wrap(embed).browsingContext, "should have bc");
     30 
     31  info("x-site document load from element");
     32  embed.setAttribute("src", "http://example.com" + testDir + "file_empty.html");
     33  await new Promise(resolve => embed.addEventListener("load", resolve, { once: true }));
     34  is(
     35    SpecialPowers.wrap(embed).displayedType,
     36    SpecialPowers.Ci.nsIObjectLoadingContent.TYPE_DOCUMENT,
     37    "document load should have document type"
     38  );
     39  ok(SpecialPowers.wrap(embed).frameLoader, "should have frameloader");
     40  ok(SpecialPowers.wrap(embed).browsingContext, "should have bc");
     41 
     42  info("load x-site document in iframe & compare processes");
     43  let iframe = document.createElement("iframe");
     44  iframe.setAttribute("src", "http://example.com" + testDir + "file_empty.html");
     45  document.body.appendChild(iframe);
     46  await new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
     47 
     48  let embedRemoteType = await SpecialPowers.spawn(embed, [], () => Services.appinfo.remoteType);
     49  let iframeRemoteType = await SpecialPowers.spawn(iframe, [], () => Services.appinfo.remoteType);
     50  is(iframeRemoteType, embedRemoteType, "remote types should match");
     51 
     52  info("x-site image load from docshell");
     53  SpecialPowers.spawn(embed, ["http://example.com" + testDir + "green.png"], uri => {
     54    content.location.href = uri;
     55  })
     56  await new Promise(resolve => embed.addEventListener("load", resolve, { once: true }));
     57  is(
     58    SpecialPowers.wrap(embed).displayedType,
     59    SpecialPowers.Ci.nsIObjectLoadingContent.TYPE_DOCUMENT,
     60    "image load via location should have document type"
     61  );
     62  ok(SpecialPowers.wrap(embed).frameLoader, "should have frameloader");
     63  ok(SpecialPowers.wrap(embed).browsingContext, "should have bc");
     64 
     65  info("x-site image load from element");
     66  embed.setAttribute("src", "http://example.com" + testDir + "green.png");
     67  await new Promise(resolve => embed.addEventListener("load", resolve, { once: true }));
     68  is(
     69    SpecialPowers.wrap(embed).displayedType,
     70    SpecialPowers.Ci.nsIObjectLoadingContent.TYPE_DOCUMENT,
     71    `image load should have document type`
     72  );
     73 
     74  ok(SpecialPowers.wrap(embed).frameLoader, "should have frameloader");
     75  ok(SpecialPowers.wrap(embed).browsingContext, "should have bc");
     76 });
     77 </script>
     78 </body>
     79 </html>