summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/editing/dnd/events/038-proposed.html
blob: ee1cc8ed0ebf8f04581646ef0801251eb168828e (plain)
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
84
<!doctype html>
<html>
  <head>
    <title>Drag and drop without cancelling dragenter and without body or html</title>
    <style type="text/css">
body > div:first-child {
  height: 100px;
  width: 100px;
  background: orange;
  display: inline-block;
}
iframe {
  height: 100px;
  width: 100px;
  margin-left: 100px;
  display: inline-block;
  border: none;
}
    </style>
    <script type="text/javascript">
//Drag passes from parent to blue. Dragenter fires at blue. Root element is deleted.
//Dragenter is not cancelled. Body does not exist. Root element does not exist.
//Current target element is set to null. Drag now points at unrendered document - null.
//Current target element remains null.
//Drag passes over parent to orange. Dragenter fires at orange, and is cancelled.
window.onload = function () {
  var orange = document.getElementsByTagName('div')[0], sequence = [];
  orange.ondragstart = function (e) {
    e.dataTransfer.setData('text','hello');
    e.dataTransfer.effectAllowed = 'copy';
  };
  orange.ondragenter = orange.ondrop = function (e) {
    sequence[sequence.length] = 'orange.'+e.type;
    e.preventDefault();
  };
  orange.ondragleave = function (e) {
    sequence[sequence.length] = 'orange.dragleave';
  };
  orange.ondragover = function (e) {
    if( sequence[sequence.length-1] != 'orange.dragover' ) {
      sequence[sequence.length] = 'orange.dragover';
    }
    e.preventDefault();
  };
  var blue = document.getElementsByTagName('iframe')[0].contentDocument;
  if( !blue.documentElement ) { blue.appendChild(blue.createElement('html')); }
  blue.documentElement.style.margin = '0';
  blue.documentElement.style.padding = '0';
  if( !blue.body ) { blue.documentElement.appendChild(blue.createElement('body')); }
  blue.body.style.margin = '0';
  blue.body.style.padding = '0';
  var bluediv = blue.body.appendChild(blue.createElement('div'));
  bluediv.style.height = '100px';
  bluediv.style.width = '100px';
  bluediv.style.background = 'blue';
  bluediv.ondragenter = bluediv.ondragover = function (e) {
    sequence[sequence.length] = 'blue.'+e.type;
    if( blue.documentElement ) { blue.removeChild(blue.documentElement); }
  };
  blue.ondragenter = blue.ondragover = blue.ondragleave = function (e) {
    if( e.target != this ) { return; }
    sequence[sequence.length] = 'bluedocument.'+e.type;
  };
  orange.ondragend = function (e) {
    sequence = sequence.join('=&gt;')
    var desiredsequence = (['orange.dragenter','orange.dragover','orange.dragleave','blue.dragenter','orange.dragenter','orange.dragover','orange.drop']).join('=&gt;')
    if( sequence == desiredsequence ) {
      document.getElementsByTagName('div')[1].innerHTML = 'PASS';
    } else {
      document.getElementsByTagName('div')[1].innerHTML = 'FAIL, got:<br>'+sequence+'<br>instead of:<br>'+desiredsequence;
    }
  };
};
    </script>
  </head>
  <body>

    <div draggable="true"></div><iframe src="about:blank"></iframe>
    <div>&nbsp;</div>
    <p>Drag the orange square onto the blue square, then back to the orange square, and release it.</p>
    <noscript><p>Enable JavaScript and reload</p></noscript>

  </body>
</html>