summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/editing/dnd/synthetic/001.html
blob: c0bf8a5776a53954d2e40945cc4ddf6577910236 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!doctype html>
<html>
  <head>
    <title>Synthetic drag events</title>
    <script type="text/javascript" src="/resources/testharness.js"></script>
    <script type="text/javascript" src="/resources/testharnessreport.js"></script>
  </head>
  <body>
    <div id="log"></div>
    <script type="text/javascript">
test(function() {
  assert_own_property(window,'DragEvent');
}, 'window.DragEvent should be exposed' );
test(function() {
  var evt = new DragEvent('dragstart');
  assert_false( !!evt.initDragEvent, 'initDragEvent' );
  assert_true( !!evt.initMouseEvent, 'initMouseEvent' );
  assert_true( !!evt.initUIEvent, 'initUIEvent' );
  assert_true( !!evt.initEvent, 'initEvent' );
}, 'DragEvent should have all of the inherited init*Event methods' );

//cannot test non-synthetic dataTransfer objects as the param here because that needs a real DragEvent to create a proper one with global storage
//will be tested in another file
test(function() {
  var evt = new DragEvent('dragstart');
  evt.initMouseEvent('dragstart', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 1, document.body);
}, 'initMouseEvent should not throw' );
test(function() {
  var evt = new DragEvent('dragstart');
  evt.initUIEvent('dragstart', true, true, window, 1);
}, 'initUIEvent should not throw' );
test(function() {
  var evt = new DragEvent('dragstart');
  evt.initEvent('dragstart', true, true);
}, 'initEvent should not throw' );

test(function() {
  var evt = new DragEvent('dragstart', {dataTransfer:null}), div = document.createElement('div'), ranlistener = false;
  div.ondragstart = function () { ranlistener = true; };
  div.dispatchEvent(evt);
  assert_true(ranlistener);
}, 'DragEvent constructor with null as the dataTransfer parameter should be able to fire the event' );
test(function() {
  var evt = new DragEvent('dragstart', {dataTransfer:undefined}), div = document.createElement('div'), ranlistener = false;
  div.ondragstart = function () { ranlistener = true; };
  div.dispatchEvent(evt);
  assert_true(ranlistener);
}, 'DragEvent constructor with undefined as the dataTransfer parameter should be able to fire the event' );
test(function() {
  assert_throws_js(TypeError, function() {
    var evt = new DragEvent('dragstart', {dataTransfer:{}});
  });
}, 'DragEvent constructor with custom object as the dataTransfer parameter should throw TypeError' );
test(function() {
  var evt = new DragEvent('dragstart'), div = document.createElement('div'), ranlistener = false;
  div.ondragstart = function () { ranlistener = true; };
  evt.initMouseEvent('dragstart', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 1, document.body);
  div.dispatchEvent(evt);
  assert_true(ranlistener);
}, 'initMouseEvent should be able to fire the event' );
test(function() {
  var evt = new DragEvent('dragstart'), div = document.createElement('div'), ranlistener = false;
  div.ondragstart = function () { ranlistener = true; };
  evt.initUIEvent('dragstart', true, true, window, 1);
  div.dispatchEvent(evt);
  assert_true(ranlistener);
}, 'initUIEvent should be able to fire the event' );
test(function() {
  var evt = new DragEvent('dragstart'), div = document.createElement('div'), ranlistener = false;
  div.ondragstart = function () { ranlistener = true; };
  evt.initEvent('dragstart', true, true);
  div.dispatchEvent(evt);
  assert_true(ranlistener);
}, 'initEvent should be able to fire the event' );

test(function() {
  var evt = new DragEvent('dragstart', {dataTransfer:null}), div = document.createElement('div'), dTrans = 'fail';
  div.ondragstart = function (e) { dTrans = e.dataTransfer };
  div.dispatchEvent(evt);
  assert_equals(dTrans,null);
}, 'DragEvent constructor with null as the dataTransfer parameter should give null as the dataTransfer' );
test(function() {
  var evt = new DragEvent('dragstart', {dataTransfer:undefined}), div = document.createElement('div'), dTrans = 'fail';
  div.ondragstart = function (e) { dTrans = e.dataTransfer };
  div.dispatchEvent(evt);
  assert_equals(dTrans,null);
}, 'DragEvent constructor with undefined as the dataTransfer parameter should give null as the dataTransfer' );
test(function() {
  var evt = new DragEvent('dragstart'), div = document.createElement('div'), dTrans = 'fail';
  div.ondragstart = function (e) { dTrans = e.dataTransfer };
  evt.initMouseEvent('dragstart', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 1, document.body);
  div.dispatchEvent(evt);
  assert_equals(dTrans,null);
}, 'initMouseEvent should give null as the dataTransfer' );
test(function() {
  var evt = new DragEvent('dragstart'), div = document.createElement('div'), dTrans = 'fail';
  div.ondragstart = function (e) { dTrans = e.dataTransfer };
  evt.initUIEvent('dragstart', true, true, window, 1);
  div.dispatchEvent(evt);
  assert_equals(dTrans,null);
}, 'initUIEvent should give null as the dataTransfer' );
test(function() {
  var evt = new DragEvent('dragstart'), div = document.createElement('div'), dTrans = 'fail';
  div.ondragstart = function (e) { dTrans = e.dataTransfer };
  evt.initEvent('dragstart', true, true);
  div.dispatchEvent(evt);
  assert_equals(dTrans,null);
}, 'initEvent should give null as the dataTransfer' );

//cannot test that synthetic event does not use the same data store as non-synthetic event because that needs a real DragEvent to create a proper one with global storage
//will be tested in another file
    </script>
    <noscript><p>Enable JavaScript and reload</p></noscript>
  </body>
</html>