summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/editing/dnd/cross-document/001-1.html
blob: 1b3540b0350da0d39b4f76f21d59a8dc5fc6ac6a (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
<!DOCTYPE html>
<title>drag &amp; drop - cross-document data drop</title>
<style>
  body > div {
    height: 200px;
    width: 200px;
    background-color: blue;
  }
</style>

<script>
window.onload = function() {
  var blue = document.getElementsByTagName('div')[0], fails = [];
  blue.ondragover = blue.ondragenter = function(e) {
    e.preventDefault();
    e.dataTransfer.dropEffect = 'copy';
    if( e.dataTransfer.getData('text') ) {
      fails[fails.length] = '"' + e.dataTransfer.getData('text') + '" exposed during event ' + e.type;
    }
  };
  blue.ondrop = function(e) {
    e.preventDefault();
    if( !e.dataTransfer.types.length ) {
      fails[fails.length] = 'no types found during event drop';
    }
    var foundtext = false;
    for( var i = 0; i < e.dataTransfer.types.length; i++ ) {
      if( e.dataTransfer.types[i] == 'text/plain' ) {
        foundtext = true;
        break;
      }
    }
    if( !foundtext ) {
      fails[fails.length] = 'text/plain type not found during event drop';
    }
    if( e.dataTransfer.getData('text') != 'dummy text' ) {
      fails[fails.length] = 'getData returned ' + e.dataTransfer.getData('text') + ' instead of "dummy text"';
    }
    document.getElementsByTagName('p')[0].innerHTML = fails.length ? ( 'FAIL:<br>' + fails.join('<br>') ) : 'PASS';
  };
};
</script>

<p>Drag the orange square onto the blue square. Fail if this text does not change.</p>
<div></div>

<noscript><p>Enable JavaScript and reload</p></noscript>