65 var trapDrag =
function(
event) {
67 var dataTransfer =
event.dataTransfer;
68 is(dataTransfer.mozItemCount, aExpectedDragData.length,
69 "Number of dragged items should be the same.");
71 for (var
t = 0;
t < dataTransfer.mozItemCount;
t++) {
72 var
types = dataTransfer.mozTypesAt(
t);
73 var expecteditem = aExpectedDragData[
t];
74 is(types.length, expecteditem.length,
75 "Number of flavors for item " +
t +
" should be the same.");
77 for (var f = 0; f < types.length; f++) {
78 is(types[f], expecteditem[f].substring(0, types[f].length),
79 "Flavor " + types[f] +
" for item " +
t +
" should be the same.");
80 is(dataTransfer.mozGetDataAt(types[f],
t),
81 expecteditem[f].substring(types[f].length + 2),
82 "Contents for item " +
t +
" with flavor " + types[f] +
" should be the same.");
86 if (!aExpectedDragData.length)
87 ok(
event.getPreventDefault(),
"Drag has been canceled.");
89 event.preventDefault();
90 event.stopPropagation();
93 var prevent =
function(aEvent) {aEvent.preventDefault();}
99 case dragDirections.LEFT:
102 case dragDirections.RIGHT:
105 case dragDirections.UP:
108 case dragDirections.DOWN:
113 var
rect = aElement.getBoundingClientRect();
114 var startingPoint = { x: (rect.right - rect.left)/2,
115 y: (rect.bottom - rect.top)/2 };
117 EventUtils.synthesizeMouse(aElement,
120 { type:
"mousedown" });
121 EventUtils.synthesizeMouse(aElement,
122 startingPoint.x + xIncrement * 1,
123 startingPoint.y + yIncrement * 1,
124 { type:
"mousemove" });
126 EventUtils.synthesizeMouse(aElement,
127 startingPoint.x + xIncrement * 9,
128 startingPoint.y + yIncrement * 9,
129 { type:
"mousemove" });
130 ok(trapped,
"A dragstart event has been trapped.");
135 aElement.addEventListener(
"click", prevent,
false);
136 EventUtils.synthesizeMouse(aElement,
137 startingPoint.x + xIncrement * 9,
138 startingPoint.y + yIncrement * 9,
139 { type:
"mouseup" });
140 aElement.removeEventListener(
"click", prevent,
false);
143 if (aElement.localName ==
"menu" && aElement.open)
144 aElement.open =
false;
150 for (var
i = 0;
i < children.length;
i++) {
151 if (aItemId == children[
i].node.itemId) {
160 var wrappedNode = [];
161 var flavors = [
"text/x-moz-place",
166 flavors.forEach(
function(aFlavor) {
167 var wrappedFlavor = aFlavor +
": " +
168 PlacesUtils.wrapNode(aNode, aFlavor);
169 wrappedNode.push(wrappedFlavor);
172 return [wrappedNode];
180 desc:
"Drag a folder on toolbar",
183 var folderId = PlacesUtils.bookmarks
184 .createFolder(PlacesUtils.toolbarFolderId,
186 PlacesUtils.bookmarks.DEFAULT_INDEX);
188 isnot(element,
null,
"Found node on toolbar");
190 isnot(element.node,
null,
"Toolbar node has an associated Places node.");
193 ok(
true,
"Dragging left");
195 ok(
true,
"Dragging right");
197 ok(
true,
"Dragging up");
199 ok(
true,
"Dragging down");
203 PlacesUtils.bookmarks.removeItem(folderId);
210 desc:
"Drag a bookmark on toolbar",
213 var itemId = PlacesUtils.bookmarks
214 .insertBookmark(PlacesUtils.toolbarFolderId,
216 PlacesUtils.bookmarks.DEFAULT_INDEX,
219 isnot(element,
null,
"Found node on toolbar");
221 isnot(element.node,
null,
"Toolbar node has an associated Places node.");
224 ok(
true,
"Dragging left");
226 ok(
true,
"Dragging right");
228 ok(
true,
"Dragging up");
230 ok(
true,
"Dragging down");
234 PlacesUtils.bookmarks.removeItem(itemId);
241 var
test = gTests.shift();
242 info(
"Start of test: " + test.desc);
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
_getSelectedPageStyle s i