summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/editing/dnd/events/035.html
blob: 3d1ba04c710780d1c30cde59612773c8500d3440 (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
<!doctype html>
<html>
	<head>
		<title>Drag and drop passing over body with cancelling dragenter</title>
		<style type="text/css">
div:first-child {
	height: 100px;
	width: 100px;
	background: orange;
	display: inline-block;
}
div:first-child + div {
	height: 100px;
	width: 100px;
	margin-left: 200px;
	background: blue;
	display: inline-block;
}
		</style>
		<script type="text/javascript">
//this test enforces the following spec statement:
//"if this immediate user selection is not the same as the current target element"
window.onload = function () {
	var drag = document.getElementsByTagName('div')[0], sequence = [];
	drag.ondragstart = function (e) {
		e.dataTransfer.setData('text','hello');
		e.dataTransfer.effectAllowed = 'copy';
	};
	drag.ondragenter = function (e) {
		sequence[sequence.length] = 'drag.dragenter';
	};
	drag.ondragover = function (e) {
		if( sequence[sequence.length-1] != 'drag.dragover' ) {
			sequence[sequence.length] = 'drag.dragover';
		}
	};
	var drop = document.getElementsByTagName('div')[1];
	drop.ondragenter = function (e) {
		e.preventDefault();
		sequence[sequence.length] = 'drop.dragenter';
	};
	drop.ondragover = function (e) {
		e.preventDefault();
		if( sequence[sequence.length-1] != 'drop.dragover' ) {
			sequence[sequence.length] = 'drop.dragover';
		}
	};
	drop.ondrop = function (e) {
		e.preventDefault();
		sequence[sequence.length] = 'drop.ondrop';
	};
	document.body.ondragenter = function (e) {
		sequence[sequence.length] = ( e.target == this ) ? 'body.dragenter' : 'bubble.dragenter';
		if( e.target != this ) { return; }
		e.preventDefault(); //don't cancel when it bubbles from the child elements
	};
	document.body.ondragover = function (e) {
		if( e.target != this ) { return; }
		if( sequence[sequence.length-1] != 'body.dragover' ) {
			sequence[sequence.length] = 'body.dragover';
		}
	};
	drag.ondragend = function (e) {
		sequence = sequence.join('=&gt;')
		var desiredsequence = (['drag.dragenter','bubble.dragenter','body.dragenter','body.dragover','drop.dragenter','bubble.dragenter','drop.dragover','drop.ondrop']).join('=&gt;')
		if( sequence == desiredsequence ) {
			document.getElementsByTagName('div')[2].innerHTML = 'PASS';
		} else {
			document.getElementsByTagName('div')[2].innerHTML = 'FAIL, got:<br>'+sequence+'<br>instead of:<br>'+desiredsequence;
		}
	};
};
		</script>
	</head>
	<body>

		<div draggable="true"></div><div></div>
		<div>&nbsp;</div>
		<p>Drag the orange square onto the blue square and release it.</p>
		<noscript><p>Enable JavaScript and reload</p></noscript>

	</body>
</html>