summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/editing/dnd/events/037-spec.xhtml
blob: 611891cb787caf6fe3972e0b1691c58e80649345 (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
85
86
87
88
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Drag and drop without cancelling dragenter and without body (spec compliant)</title>
		<style type="text/css">
head + div {
	height: 100px;
	width: 100px;
	background: orange;
	display: inline-block;
}
head + div + div {
	height: 100px;
	width: 100px;
	margin-left: 100px;
	background: blue;
	display: inline-block;
}
		</style>
		<script type="text/javascript"><![CDATA[
//Drag passes from orange to root element. Dragenter fires at root element.
//Dragenter is not cancelled. Body does not exist. Dragenter fires at document.
//Spec says the body (which does not exist) becomes current target element => null.
//Drag passes from root element to blue. Dragenter fires at blue.
//Dragenter is not cancelled. Body does not exist. Current target element is null.
//Dragenter fires at document. Current target is set to null again.
//Drag passes from blue to root element. Dragenter fires at root element.
//Dragenter is not cancelled. Body does not exist. Current target element is null.
//Dragenter is not cancelled. Body does not exist. Dragenter fires at document.
//Current target is set to null. Yet again.
//Drag passes from root element 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('div')[1];
	blue.ondragenter = blue.ondragover = blue.ondragleave = function (e) {
		sequence[sequence.length] = 'blue.'+e.type;
	};
	document.documentElement.ondragenter = document.documentElement.ondragleave = function (e) {
		if( e.target != this ) { return; }
		sequence[sequence.length] = 'html.'+e.type;
	};
	document.documentElement.ondragover = function (e) {
		if( e.target != this ) { return; }
		if( sequence[sequence.length-1] != 'html.dragover' ) {
			sequence[sequence.length] = 'html.dragover';
		}
	};
	document.ondragenter = document.ondragleave = document.ondragover = document.ondragleave = function (e) {
		if( e.target != this ) { return; }
		sequence[sequence.length] = 'document.'+e.type;
	};
	orange.ondragend = function (e) {
		sequence = sequence.join('=>')
		var desiredsequence = (['orange.dragenter','orange.dragover','html.dragenter','document.dragenter','orange.dragleave','blue.dragenter','document.dragenter','document.dragenter','orange.dragenter','orange.dragover','orange.drop']).join('=>')
		if( sequence == desiredsequence ) {
			document.getElementsByTagName('div')[2].textContent = 'PASS';
		} else {
			document.getElementsByTagName('div')[2].textContent = 'FAIL, got: '+sequence+' instead of: '+desiredsequence;
		}
	};
};
		]]></script>
	</head>
	<!--body-->

		<div draggable="true"></div><div></div>
		<div>&#160;</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>