testing/web-platform/tests/html/editing/dnd/cross-document/003-1.html
author Mozilla Releng Treescript <release+treescript@mozilla.org>
Tue, 24 May 2022 06:57:56 +0000
changeset 618573 eeff404229054a7c671e97e60e50b73c603cc78a
parent 388141 f95a678186b46649eee6cf8c6adbdf46c320f300
permissions -rw-r--r--
no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD it -> e3ccb400d668c2d011038e74337866aac8f72f2d oc -> 65e529545e4250ea0e02f3b51a8f57bcae311091 zh-TW -> deebd17bb96799602a2f6aae4958a087b93015d1

<!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( !parent.evs[e.type] ) { parent.evs[e.type] = {}; }
    parent.evs[e.type].dataTransfer = e.dataTransfer;
    parent.evs[e.type].items = e.dataTransfer.items;
    parent.evs[e.type].types = e.dataTransfer.types;
    parent.evs[e.type].files = e.dataTransfer.files;
    if( parent.evs[e.type].dataTransfer != e.dataTransfer ) {
      fails[fails.length] = '.dataTransfer is not returning the same object during '+e.type;
    }
    if( !e.dataTransfer.items ) {
      fails[fails.length] = '.items is not returning anything during '+e.type;
    } else if( parent.evs[e.type].items !== e.dataTransfer.items ) {
      fails[fails.length] = '.items is not returning the same object during '+e.type;
    }
    if( !e.dataTransfer.types ) {
      fails[fails.length] = '.types is not returning anything during '+e.type;
    } else if( parent.evs[e.type].types !== e.dataTransfer.types ) {
      fails[fails.length] = '.types is not returning the same object during '+e.type;
    }
    if( !e.dataTransfer.files ) {
      fails[fails.length] = '.files is not returning anything during '+e.type;
    } else if( parent.evs[e.type].files !== e.dataTransfer.files ) {
      fails[fails.length] = '.files is not returning the same object during '+e.type;
    }
    //http://dev.w3.org/html5/spec/dnd.html#datatransfer
    //"The * attribute must return a * object associated with the DataTransfer object."
    //Note that it is associated with the DataTransfer object, *not* the data store
    //http://dev.w3.org/html5/spec/dnd.html#dragevent
    //"when a user agent is required to fire a DND event named e at an element, using a particular drag data store...
    //Let dataTransfer be a newly created DataTransfer object associated with the given drag data store."
    //A new DataTransfer object therefore means a new set of properties, not the same ones as last event
    if( parent.evs.dragstart.dataTransfer === e.dataTransfer ) {
      fails[fails.length] = '.dataTransfer is returning the same object during '+e.type+' as it did during dragstart';
    }
    if( e.dataTransfer.items && parent.evs.dragstart.items === e.dataTransfer.items ) {
      fails[fails.length] = '.items is returning the same object during '+e.type+' as it did during dragstart';
    }
    if( e.dataTransfer.types && parent.evs.dragstart.types === e.dataTransfer.types ) {
      fails[fails.length] = '.types is returning the same object during '+e.type+' as it did during dragstart';
    }
    if( e.dataTransfer.files && parent.evs.dragstart.files === e.dataTransfer.files ) {
      fails[fails.length] = '.files is returning the same object during '+e.type+' as it did during dragstart';
    }
  };
  blue.ondrop = function(e) {
    parent.evs[e.type] = {};
    parent.evs[e.type].dataTransfer = e.dataTransfer;
    parent.evs[e.type].items = e.dataTransfer.items;
    parent.evs[e.type].types = e.dataTransfer.types;
    parent.evs[e.type].files = e.dataTransfer.files;
    if( parent.evs[e.type].dataTransfer !== e.dataTransfer ) {
      fails[fails.length] = '.dataTransfer is not returning the same object during '+e.type;
    }
    if( !e.dataTransfer.items ) {
      fails[fails.length] = '.items is not returning anything during '+e.type;
    } else if( parent.evs[e.type].items !== e.dataTransfer.items ) {
      fails[fails.length] = '.items is not returning the same object during '+e.type;
    }
    if( !e.dataTransfer.types ) {
      fails[fails.length] = '.types is not returning anything during '+e.type;
    } else if( parent.evs[e.type].types !== e.dataTransfer.types ) {
      fails[fails.length] = '.types is not returning the same object during '+e.type;
    }
    if( !e.dataTransfer.files ) {
      fails[fails.length] = '.files is not returning anything during '+e.type;
    } else if( parent.evs[e.type].files !== e.dataTransfer.files ) {
      fails[fails.length] = '.files is not returning the same object during '+e.type;
    }
    if( parent.evs.dragstart.dataTransfer === e.dataTransfer ) {
      fails[fails.length] = '.dataTransfer is returning the same object during '+e.type+' as it did during dragstart';
    }
    if( e.dataTransfer.items && parent.evs.dragstart.items === e.dataTransfer.items ) {
      fails[fails.length] = '.items is returning the same object during '+e.type+' as it did during dragstart';
    }
    if( e.dataTransfer.types && parent.evs.dragstart.types === e.dataTransfer.types ) {
      fails[fails.length] = '.types is returning the same object during '+e.type+' as it did during dragstart';
    }
    if( e.dataTransfer.files && parent.evs.dragstart.files === e.dataTransfer.files ) {
      fails[fails.length] = '.files is returning the same object during '+e.type+' as it did during dragstart';
    }
    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>