[DnD] effectAllowed and dropEffect can be set to bogus values.
[WebKit-https.git] / LayoutTests / fast / events / bogus-dropEffect-effectAllowed.html
1 <html>
2 <head>
3 <link rel="stylesheet" href="../js/resources/js-test-style.css">
4 <script src="../js/resources/js-test-pre.js"></script>
5 <style>
6 #dropTarget, #dragMe { text-align: center; display: table-cell; vertical-align: middle }
7 #dropTarget {width: 256px; height: 256px; border: 1px dashed}
8 #dragMe {-webkit-user-drag: element; -webkit-user-select: none; background: #ff0000; width: 64px; height: 64px; color: white}
9 </style>
10 <script>
11     var dragMe;
12     var dropTarget;
13     var effectAllowedElem;
14     var dropEffectElem;
15     var consoleElm;
16     var event;
17     
18     window.onload = function()
19     {
20         dragMe = document.getElementById("dragMe");
21         dropTarget = document.getElementById("dropTarget");
22         consoleElm = document.getElementById("console");
23         
24         if (!dragMe || !dropTarget || !consoleElm)
25             return;
26         
27         dragMe.ondragstart = dragStart;
28         dragMe.ondragend = dragEnd;
29         
30         dropTarget.ondragenter = dragEntered;
31         dropTarget.ondragover = dragOver;
32         dropTarget.ondrop = drop;
33         
34         runTest();
35     }
36     
37     function dragStart(e)
38     {
39         var validEffectAllowedList = ["all", "copy", "copyLink", "copyMove", "link", "linkMove", "move", "none", "uninitialized"];
40         var effectAllowedListToTest = ["all", "copy", "bogus", "copyLink", "wrong", "copyMove", "linkCopyMove", "link",
41             "linkMove", "move", "none", "uninitialized", "dummy", "bogus", "fake", "illegal"];
42         
43         event = e;
44         
45         for (var i = 0; i < effectAllowedListToTest.length; i++) {
46             var effectAllowedBefore = e.dataTransfer.effectAllowed;
47             e.dataTransfer.effectAllowed = effectAllowedListToTest[i];
48             if (validEffectAllowedList.indexOf(effectAllowedListToTest[i]) != -1)
49                 shouldBeEqualToString("event.dataTransfer.effectAllowed", effectAllowedListToTest[i]);
50             else
51                 shouldBeEqualToString("event.dataTransfer.effectAllowed", effectAllowedBefore);
52         }
53         
54         e.dataTransfer.setData('Text', e.target.textContent);
55     }
56     
57     function dragEnd(e)
58     {
59         return;
60     }
61     
62     function dragEntered(e)
63     {
64         dragEnteredAndUpdated(e);
65     }
66     
67     function dragOver(e)
68     {
69         dragEnteredAndUpdated(e);
70     }
71     
72     function dragEnteredAndUpdated(e)
73     {
74         var validDropEffectList = ["none", "copy", "link", "move", "link"];
75         var dropEffectListToTest = ["all", "copy", "bogus", "copyLink", "wrong", "copyMove", "linkCopyMove", "link",
76             "linkMove", "move", "none", "uninitialized", "dummy", "bogus", "fake", "illegal"];
77         
78         event = e;
79         
80         for (var i = 0; i < dropEffectListToTest.length; i++) {
81             var dropEffectBefore = e.dataTransfer.dropEffect;
82             e.dataTransfer.dropEffect = dropEffectListToTest[i];
83
84             if (validDropEffectList.indexOf(dropEffectListToTest[i]) != -1)
85                 shouldBeEqualToString("event.dataTransfer.dropEffect", dropEffectListToTest[i]);
86             else
87                 shouldBeEqualToString("event.dataTransfer.dropEffect", dropEffectBefore);
88
89         }
90
91         cancelDrag(e);
92     }
93     
94     function drop(e)
95     {
96         cancelDrag(e);
97     }
98     
99     function cancelDrag(e)
100     {
101         e.preventDefault();
102     }
103
104     function runTest()
105     {
106         if (!window.eventSender)
107             return;
108             
109         if (window.layoutTestController)
110             layoutTestController.dumpAsText();
111             
112         var startX = dragMe.offsetLeft + 10;
113         var startY = dragMe.offsetTop + dragMe.offsetHeight / 2;
114         var endX = dropTarget.offsetLeft + 10;
115         var endY = dropTarget.offsetTop + dropTarget.offsetHeight / 2;
116         
117         eventSender.mouseMoveTo(startX, startY);
118         eventSender.mouseDown();
119         eventSender.leapForward(100);
120         eventSender.mouseMoveTo(endX, endY);
121         eventSender.mouseUp();
122
123         var testContainer = document.getElementById("test-container");
124         if (testContainer)
125             document.body.removeChild(testContainer);
126         debug('<br /><span class="pass">TEST COMPLETE</span>');
127     }
128 </script>
129 </head>
130 <body>
131     <p id="description"></p>
132     <div id="test-container">
133         <br/><br/>
134         <div id="dropTarget">Drop the red square onto me.<br/><br/></div>
135         <hr/>
136         <p>Items that can be dragged to the drop target:</p>
137         <div id="dragMe" draggable="true">Square</div>
138         <hr/>
139     </div>
140     <div id="console"></div>
141     <script>
142         description("This test checks that effectAllowed and dropEffect cannot be set to values that aren't defined in the spec");
143         var successfullyParsed = true;
144     </script>
145 </body>
146 </html>