tor-browser

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

054.html (3017B)


      1 <!doctype html>
      2 <html>
      3  <head>
      4    <title>Adding a file to dnd data store with drag out of window</title>
      5    <style type="text/css">
      6 span { display: inline-block; height: 100px; width: 100px; background: orange; }
      7 span + span { background: blue; }
      8    </style>
      9    <script type="text/javascript">
     10 window.onload = function () {
     11  var drag = document.getElementsByTagName('span')[0];
     12  drag.ondragstart = function (e) {
     13    e.dataTransfer.setData('text','PASS');
     14    e.dataTransfer.effectAllowed = 'copy';
     15    var filein = document.getElementsByTagName('input')[0];
     16    if( !filein.files ) {
     17      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - file API is not supported.';
     18      return;
     19    }
     20    if( !filein.files[0] ) {
     21      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - no file was found in the file input.';
     22      return;
     23    }
     24    var thefile = filein.files[0];
     25    try {
     26      e.dataTransfer.items.add(thefile);
     27    } catch(err) {
     28      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - error when adding file';
     29      e.preventDefault();
     30      return;
     31    }
     32    if( e.dataTransfer.files.length != 1 ) {
     33      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - file was not attached to data store';
     34      e.preventDefault();
     35      return;
     36    }
     37  };
     38  var drop = document.getElementsByTagName('span')[1];
     39  drop.ondragenter = drop.ondragover = function (e) {
     40    e.preventDefault();
     41  };
     42  drop.ondrop = function (e) {
     43    e.preventDefault();
     44    if( document.getElementsByTagName('p')[0].innerHTML ) { return; }
     45    if( e.dataTransfer.files.length != 1 ) {
     46      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - file was not attached to data store during drop';
     47      e.preventDefault();
     48      return;
     49    }
     50    if( !window.FileReader ) {
     51      document.getElementsByTagName('p')[0].innerHTML = 'No FileReader constructor';
     52      e.preventDefault();
     53      return;
     54    }
     55    var reader = new FileReader();
     56    reader.onload = function () {
     57      if( !reader.result ) {
     58        document.getElementsByTagName('p')[0].innerHTML = 'No file data after load';
     59      } else if( !document.getElementsByTagName('p')[0].innerHTML ) {
     60        document.getElementsByTagName('p')[0].innerHTML = 'PASS';
     61      }
     62    };
     63    reader.readAsBinaryString(e.dataTransfer.files[0]);
     64    setTimeout(function () {
     65      if( !reader.result ) {
     66        document.getElementsByTagName('p')[0].innerHTML = 'No file data after timeout';
     67      }
     68    },1000);
     69  };
     70 };
     71    </script>
     72  </head>
     73  <body>
     74    <ol>
     75      <li>Select a non-empty file on your computer using the following input: <input type="file"></li>
     76      <li>Drag the orange square outside the browser window (not over the taskbar), then back onto the blue square and release it:<br><span draggable="true"></span> <span></span><br>
     77      If a prompt appears, accept it.</li>
     78      <li>Fail if new text does not appear below.</li>
     79    </ol>
     80    <p></p>
     81    <noscript><p>Enable JavaScript and reload</p></noscript>
     82  </body>
     83 </html>