File: 053.html

package info (click to toggle)
firefox 145.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,528 kB
  • sloc: cpp: 7,594,999; javascript: 6,459,658; ansic: 3,752,909; python: 1,403,455; xml: 629,809; asm: 438,679; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (83 lines) | stat: -rw-r--r-- 2,932 bytes parent folder | download | duplicates (32)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!doctype html>
<html>
  <head>
    <title>Adding a file to dnd data store</title>
    <style type="text/css">
span { display: inline-block; height: 100px; width: 100px; background: orange; }
span + span { background: blue; }
    </style>
    <script type="text/javascript">
window.onload = function () {
  var drag = document.getElementsByTagName('span')[0];
  drag.ondragstart = function (e) {
    e.dataTransfer.setData('text','PASS');
    e.dataTransfer.effectAllowed = 'copy';
    var filein = document.getElementsByTagName('input')[0];
    if( !filein.files ) {
      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - file API is not supported.';
      return;
    }
    if( !filein.files[0] ) {
      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - no file was found in the file input.';
      return;
    }
    var thefile = filein.files[0];
    try {
      e.dataTransfer.items.add(thefile);
    } catch(err) {
      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - error when adding file';
      e.preventDefault();
      return;
    }
    if( e.dataTransfer.files.length != 1 ) {
      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - file was not attached to data store';
      e.preventDefault();
      return;
    }
  };
  var drop = document.getElementsByTagName('span')[1];
  drop.ondragenter = drop.ondragover = function (e) {
    e.preventDefault();
  };
  drop.ondrop = function (e) {
    e.preventDefault();
    if( document.getElementsByTagName('p')[0].innerHTML ) { return; }
    if( e.dataTransfer.files.length != 1 ) {
      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - file was not attached to data store during drop';
      e.preventDefault();
      return;
    }
    if( !window.FileReader ) {
      document.getElementsByTagName('p')[0].innerHTML = 'No FileReader constructor';
      e.preventDefault();
      return;
    }
    var reader = new FileReader();
    reader.onload = function () {
      if( !reader.result ) {
        document.getElementsByTagName('p')[0].innerHTML = 'No file data after load';
      } else if( !document.getElementsByTagName('p')[0].innerHTML ) {
        document.getElementsByTagName('p')[0].innerHTML = 'PASS';
      }
    };
    reader.readAsBinaryString(e.dataTransfer.files[0]);
    setTimeout(function () {
      if( !reader.result ) {
        document.getElementsByTagName('p')[0].innerHTML = 'No file data after timeout';
      }
    },1000);
  };
};
    </script>
  </head>
  <body>
    <ol>
      <li>Select a non-empty file on your computer using the following input: <input type="file"></li>
      <li>Drag the orange square onto the blue square and release it:<br><span draggable="true"></span> <span></span><br>
      If a prompt appears, accept it.</li>
      <li>Fail if new text does not appear below.</li>
    </ol>
    <p></p>
    <noscript><p>Enable JavaScript and reload</p></noscript>
  </body>
</html>