|
1 <?xml version="1.0"?> |
|
2 <!-- This Source Code Form is subject to the terms of the Mozilla Public |
|
3 - License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> |
|
5 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" |
|
6 type="text/css"?> |
|
7 <window title="Test ChromeUtils functions" |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <script type="application/javascript" |
|
10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
11 <!-- ChromeUtils.js depends on EventUtils.js --> |
|
12 <script type="application/javascript" |
|
13 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
|
14 <script type="text/javascript"> |
|
15 var start = new Date(); |
|
16 </script> |
|
17 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script> |
|
18 <script type="text/javascript"> |
|
19 var loadTime = new Date(); |
|
20 </script> |
|
21 <script type="application/javascript"> |
|
22 <![CDATA[ |
|
23 info("\nProfile::ChromeUtilsLoadTime: " + (loadTime - start) + "\n"); |
|
24 var testFile = Components.classes["@mozilla.org/file/directory_service;1"]. |
|
25 getService(Components.interfaces.nsIProperties). |
|
26 get("CurWorkD", Components.interfaces.nsIFile); |
|
27 var regularDtForDrag1 = null; |
|
28 var gSetDropEffect = true; |
|
29 var gData; |
|
30 var gEnter = false; |
|
31 var gOver = false; |
|
32 var dragDrop = [[ |
|
33 { type : "text/plain", |
|
34 data : "This is a test" } |
|
35 ]]; |
|
36 // this is the expected data arrays |
|
37 // for testing drag of 2 items create 2 inner arrays |
|
38 var drag1 = [[ |
|
39 { type : "text/uri-list", |
|
40 data : "http://www.mozilla.org/" } |
|
41 ]]; |
|
42 var drag2items = [[ |
|
43 { type : "text/uri-list", |
|
44 data : "http://www.mozilla.org/" } |
|
45 ],[ |
|
46 { type : "text/uri-list", |
|
47 data : "http://www.mozilla.org/" } |
|
48 ]]; |
|
49 var drag1WrongFlavor = [[ |
|
50 { type : "text/plain", |
|
51 data : "this is text/plain" } |
|
52 ]]; |
|
53 var drag2 = [[ |
|
54 { type : "text/plain", |
|
55 data : "this is text/plain" }, |
|
56 { type : "text/uri-list", |
|
57 data : "http://www.mozilla.org/" } |
|
58 ]]; |
|
59 var drag2WrongOrder = [[ |
|
60 { type : "text/uri-list", |
|
61 data : "http://www.mozilla.org/" }, |
|
62 { type : "text/plain", |
|
63 data : "this is text/plain" } |
|
64 ]]; |
|
65 var dragfile = [[ |
|
66 { type : "application/x-moz-file", |
|
67 data : testFile, |
|
68 eqTest : function(actualData, expectedData) {return expectedData.equals(actualData);} } |
|
69 ]]; |
|
70 |
|
71 function doOnDrop(aEvent) { |
|
72 gData = aEvent.dataTransfer.getData(dragDrop[0][0].type); |
|
73 aEvent.preventDefault(); // cancels event and keeps dropEffect |
|
74 // as was before event. |
|
75 } |
|
76 |
|
77 function doOnDragStart(aEvent) { |
|
78 var dt = aEvent.dataTransfer; |
|
79 switch (aEvent.currentTarget.id) { |
|
80 case "drag2" : |
|
81 dt.setData("text/plain", "this is text/plain"); |
|
82 case "drag1" : |
|
83 regularDtForDrag1 = dt; |
|
84 dt.setData("text/uri-list", "http://www.mozilla.org/"); |
|
85 break; |
|
86 case "dragfile" : |
|
87 dt.mozSetDataAt("application/x-moz-file", testFile, 0); |
|
88 break; |
|
89 } |
|
90 dt.effectAllowed = "all"; |
|
91 } |
|
92 |
|
93 function doOnDragEnter(aEvent) { |
|
94 gEnter = true; |
|
95 aEvent.dataTransfer.effectAllowed = "all"; |
|
96 aEvent.preventDefault(); // sets target this element |
|
97 } |
|
98 |
|
99 function doOnDragOver(aEvent) { |
|
100 gOver = true; |
|
101 if (gSetDropEffect) |
|
102 aEvent.dataTransfer.dropEffect = "copy"; |
|
103 aEvent.preventDefault(); |
|
104 } |
|
105 |
|
106 SimpleTest.waitForExplicitFinish(); |
|
107 function test() { |
|
108 var startTime = new Date(); |
|
109 var result; |
|
110 |
|
111 /* test synthesizeDragStart */ |
|
112 result = synthesizeDragStart($("drag1"), drag1, window); |
|
113 is(result, null, "drag1 is text/uri-list"); |
|
114 result = synthesizeDragStart($("drag1"), drag1WrongFlavor, window); |
|
115 isnot(result, null, "drag1 is not text/plain"); |
|
116 result = synthesizeDragStart($("drag1"), drag2items, window); |
|
117 isnot(result, null, "drag1 is not 2 items"); |
|
118 result = synthesizeDragStart($("drag2"), drag2, window); |
|
119 is(result, null, "drag2 is ordered text/plain then text/uri-list"); |
|
120 result = synthesizeDragStart($("drag2"), drag1, window); |
|
121 isnot(result, null, "drag2 is not one flavor"); |
|
122 result = synthesizeDragStart($("drag2"), drag2WrongOrder, window); |
|
123 isnot(result, null, "drag2 is not ordered text/uri-list then text/plain"); |
|
124 result = synthesizeDragStart($("dragfile"), dragfile, window); |
|
125 is(result, null, "dragfile is nsIFile"); |
|
126 result = synthesizeDragStart($("drag1"), null, window); |
|
127 is(result, regularDtForDrag1, "synthesizeDragStart accepts null expectedDragData"); |
|
128 |
|
129 /* test synthesizeDrop */ |
|
130 result = synthesizeDrop($("dragDrop"), $("dragDrop"), dragDrop, null, window); |
|
131 ok(gEnter, "Fired dragenter"); |
|
132 ok(gOver, "Fired dragover"); |
|
133 is(result, "copy", "copy is dropEffect"); |
|
134 is(gData, dragDrop[0][0].data, "Received valid drop data"); |
|
135 |
|
136 gSetDropEffect = false; |
|
137 result = synthesizeDrop($("dragDrop"), $("dragDrop"), dragDrop, "link", window); |
|
138 is(result, "link", "link is dropEffect"); |
|
139 gSetDropEffect = true; |
|
140 |
|
141 $("textB").focus(); |
|
142 var content = synthesizeQueryTextContent(0, 100); |
|
143 ok(content, "synthesizeQueryTextContent should not be null"); |
|
144 ok(content.succeeded, "synthesizeQueryTextContent should succeed"); |
|
145 is(content.text, "I haz a content", "synthesizeQueryTextContent should be 'I haz a content': " + content.text); |
|
146 |
|
147 content = synthesizeQueryCaretRect(0); |
|
148 ok(content, "synthesizeQueryCaretRect should not be null"); |
|
149 ok(content.succeeded, "synthesizeQueryCaretRect should succeed"); |
|
150 |
|
151 content = synthesizeQueryTextRect(0, 100); |
|
152 ok(content, "synthesizeQueryTextRect should not be null"); |
|
153 ok(content.succeeded, "synthesizeQueryTextRect should succeed"); |
|
154 |
|
155 content = synthesizeQueryEditorRect(); |
|
156 ok(content, "synthesizeQueryEditorRect should not be null"); |
|
157 ok(content.succeeded, "synthesizeQueryEditorRect should succeed"); |
|
158 |
|
159 content = synthesizeCharAtPoint(0, 0); |
|
160 ok(content, "synthesizeCharAtPoint should not be null"); |
|
161 ok(content.succeeded, "synthesizeCharAtPoint should succeed"); |
|
162 |
|
163 content = synthesizeSelectionSet(0, 100); |
|
164 ok(content, "synthesizeSelectionSet should not be null"); |
|
165 is(content, true, "synthesizeSelectionSet should succeed"); |
|
166 |
|
167 var endTime = new Date(); |
|
168 info("\nProfile::ChromeUtilsRunTime: " + (endTime-startTime) + "\n"); |
|
169 SimpleTest.finish(); |
|
170 }; |
|
171 ]]> |
|
172 </script> |
|
173 |
|
174 <body xmlns="http://www.w3.org/1999/xhtml" onload="setTimeout('test()', 0)"> |
|
175 <input id="textB" value="I haz a content"/> |
|
176 <p id="display"></p> |
|
177 <div id="content" style="display:none;"></div> |
|
178 <pre id="test"></pre> |
|
179 <div id="drag1" ondragstart="doOnDragStart(event);">Need some space here</div> |
|
180 <p id="display"></p> |
|
181 <div id="content" style="display:none;"></div> |
|
182 <pre id="test"></pre> |
|
183 <div id="dragDrop" ondragover ="doOnDragOver(event);" |
|
184 ondragenter ="doOnDragEnter(event);" |
|
185 ondragleave ="doOnDragLeave(event);" |
|
186 ondrop ="doOnDrop(event);"> |
|
187 Need some depth and height to drag here |
|
188 </div> |
|
189 <div id="drag2" ondragstart="doOnDragStart(event);">Need more space</div> |
|
190 <div id="dragfile" ondragstart="doOnDragStart(event);">Sure why not here too</div> |
|
191 </body> |
|
192 </window> |