tor-browser

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

test_bug1645781.html (2966B)


      1 <!doctype html>
      2 <html>
      3  <head>
      4    <title>Test for Bug 1590762</title>
      5    <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6    <script src="/tests/SimpleTest/EventUtils.js"></script>
      7    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      8  </head>
      9  <body>
     10    <form id="form" action="form_submit.sjs" method="POST" target="targetFrame">
     11      <input id="input" type="text" name="name" value="">
     12      <input id="button" type="submit">
     13    </form>
     14    <script>
     15      "use strict";
     16      const PATH = "/tests/docshell/test/mochitest/";
     17      const SAME_ORIGIN = new URL(PATH, window.location.origin);;
     18      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     19      const CROSS_ORIGIN_1 = new URL(PATH, "http://test1.example.com/");
     20      const CROSS_ORIGIN_2 = new URL(PATH, "https://example.com/");
     21      const TARGET = "ping.html";
     22      const ACTION = "form_submit.sjs";
     23 
     24      function generateBody(size) {
     25        let data = new Uint8Array(size);
     26        for (let i = 0; i < size; ++i) {
     27          data[i] = 97 + Math.random() * (123 - 97);
     28        }
     29 
     30        return new TextDecoder().decode(data);
     31      }
     32 
     33      async function withFrame(url) {
     34        info("Creating frame");
     35        let frame = document.createElement('iframe');
     36        frame.name = "targetFrame";
     37 
     38        return new Promise(resolve => {
     39          addEventListener('message', async function({source}) {
     40            info("Frame loaded");
     41            if (frame.contentWindow == source) {
     42              resolve(frame);
     43            }
     44          }, { once: true });
     45          frame.src = url;
     46          document.body.appendChild(frame);
     47        });
     48      }
     49 
     50      function click() {
     51        synthesizeMouse(document.getElementById('button'), 5, 5, {});
     52      }
     53 
     54      function* spec() {
     55        let urls = [SAME_ORIGIN, CROSS_ORIGIN_1, CROSS_ORIGIN_2];
     56        for (let action of urls) {
     57          for (let target of urls) {
     58            yield { action: new URL(ACTION, action),
     59                    target: new URL(TARGET, target) };
     60          }
     61        }
     62      }
     63 
     64      info("Starting tests");
     65      let form = document.getElementById('form');
     66 
     67      // The body of the POST needs to be large to trigger this.
     68      // 1024*1024 seems to be enough, but scaling to get a margin.
     69      document.getElementById('input').value = generateBody(1024*1024);
     70      for (let { target, action } of spec()) {
     71        add_task(async function runTest() {
     72          info(`Running test ${target} with ${action}`);
     73          form.action = action;
     74          let frame = await withFrame(target);
     75          await new Promise(resolve => {
     76            addEventListener('message', async function() {
     77              info("Form loaded");
     78              frame.remove();
     79              resolve();
     80            }, { once: true });
     81 
     82            click();
     83          });
     84 
     85          ok(true, `Submitted to ${origin} with target ${action}`)
     86        });
     87      };
     88    </script>
     89  </body>
     90 </html>