tor-browser

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

test_set_input_files.html (1542B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1384030
      5 -->
      6 <head>
      7  <title>Test for Setting &lt;input type=file&gt;.files </title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10 </head>
     11 <body>
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1384030">Mozilla Bug 1384030</a>
     13 <pre id="test">
     14 <script type="application/javascript">
     15 
     16 /** Test for Setting <input type=file>.files */
     17 
     18 function runTest()
     19 {
     20  const form = document.createElement("form");
     21  const formInput = document.createElement("input");
     22  formInput.type = "file";
     23  formInput.name = "inputFile";
     24  form.appendChild(formInput);
     25 
     26  const input = document.createElement("input");
     27  input.type = "file";
     28  SpecialPowers.wrap(input).mozSetFileArray([
     29    new File(["foo"], "foo"),
     30    new File(["bar"], "bar")
     31  ]);
     32 
     33  formInput.files = input.files;
     34 
     35  const inputFiles = (new FormData(form)).getAll("inputFile");
     36  is(inputFiles.length, 2, "FormData should contain two input files");
     37 
     38  is(inputFiles[0].name, "foo", "Input file name should be 'foo'");
     39  is(inputFiles[1].name, "bar", "Input file name should be 'bar'");
     40 
     41  is(inputFiles[0], input.files[0],
     42     "Expect the same File object as input file 'foo'");
     43  is(inputFiles[1], input.files[1],
     44     "Expect the same File object as input file 'bar'");
     45 
     46  SimpleTest.finish();
     47 }
     48 
     49 SimpleTest.waitForExplicitFinish();
     50 window.addEventListener('load', runTest);
     51 
     52 </script>
     53 </pre>
     54 </body>
     55 </html>