зеркало из https://github.com/mozilla/pjs.git
Backed out changeset 43a19419ec4b
This commit is contained in:
Родитель
413d9e2690
Коммит
ba050090ef
|
@ -7,14 +7,10 @@ function test()
|
|||
var htmlString = "<a href=\"" + value + "\">" + value + "</a>";
|
||||
|
||||
var expected = [ [
|
||||
{ type : "text/x-moz-url",
|
||||
data : urlString },
|
||||
{ type : "text/uri-list",
|
||||
data : value },
|
||||
{ type : "text/plain",
|
||||
data : value },
|
||||
{ type : "text/html",
|
||||
data : htmlString }
|
||||
"text/x-moz-url: " + urlString,
|
||||
"text/uri-list: " + value,
|
||||
"text/plain: " + value,
|
||||
"text/html: " + htmlString
|
||||
] ];
|
||||
|
||||
// set the valid attribute so dropping is allowed
|
||||
|
|
|
@ -238,7 +238,7 @@ function synthesizeMouse(aTarget, aOffsetX, aOffsetY, aEvent, aWindow)
|
|||
*
|
||||
* If the axis is specified, it must be one of "horizontal" or "vertical". If not specified,
|
||||
* "vertical" is used.
|
||||
*
|
||||
*
|
||||
* 'delta' is the amount to scroll by (can be positive or negative). It must
|
||||
* be specified.
|
||||
*
|
||||
|
@ -420,124 +420,101 @@ function synthesizeKeyExpectEvent(key, aEvent, aExpectedTarget, aExpectedEvent,
|
|||
* Emulate a dragstart event.
|
||||
* element - element to fire the dragstart event on
|
||||
* expectedDragData - the data you expect the data transfer to contain afterwards
|
||||
* This data is in the format:
|
||||
* [ [ {type: value, data: value, test: function}, ... ], ... ]
|
||||
* can be null
|
||||
* aWindow - optional; defaults to the current window object.
|
||||
* Returns null if data matches.
|
||||
* Returns the event.dataTransfer if data does not match
|
||||
*
|
||||
* eqTest is an optional function if comparison can't be done with x == y;
|
||||
* function (actualData, expectedData) {return boolean}
|
||||
* @param actualData from dataTransfer
|
||||
* @param expectedData from expectedDragData
|
||||
* see bug 462172 for example of use
|
||||
*
|
||||
* This data is in the format:
|
||||
* [ [ "type: data", "type: data" ], ... ]
|
||||
* Returns the expected data in the same format if it is not correct. Returns null
|
||||
* if successful.
|
||||
*/
|
||||
|
||||
function synthesizeDragStart(element, expectedDragData, aWindow)
|
||||
function synthesizeDragStart(element, expectedDragData)
|
||||
{
|
||||
if (!aWindow)
|
||||
aWindow = window;
|
||||
|
||||
var result = "trapDrag was not called";
|
||||
var failed = null;
|
||||
|
||||
var trapDrag = function(event) {
|
||||
try {
|
||||
var dataTransfer = event.dataTransfer;
|
||||
result = null;
|
||||
if (!dataTransfer)
|
||||
throw "no dataTransfer";
|
||||
if (dataTransfer.mozItemCount != expectedDragData.length ||
|
||||
expectedDragData == null)
|
||||
throw dataTransfer;
|
||||
if (dataTransfer.mozItemCount != expectedDragData.length)
|
||||
throw "Failed";
|
||||
|
||||
for (let i = 0; i < dataTransfer.mozItemCount; i++) {
|
||||
let dtTypes = dataTransfer.mozTypesAt(i);
|
||||
if (dtTypes.length != expectedDragData[i].length)
|
||||
throw dataTransfer;
|
||||
for (var t = 0; t < dataTransfer.mozItemCount; t++) {
|
||||
var types = dataTransfer.mozTypesAt(t);
|
||||
var expecteditem = expectedDragData[t];
|
||||
if (types.length != expecteditem.length)
|
||||
throw "Failed";
|
||||
|
||||
for (let j = 0; j < dtTypes.length; j++) {
|
||||
if (dtTypes[j] != expectedDragData[i][j].type)
|
||||
throw dataTransfer;
|
||||
let dtData = dataTransfer.mozGetDataAt(dtTypes[j],i);
|
||||
if (expectedDragData[i][j].eqTest) {
|
||||
if (!expectedDragData[i][j].eqTest(dtData, expectedDragData[i][j].data))
|
||||
throw dataTransfer;
|
||||
}
|
||||
else if (expectedDragData[i][j].data != dtData)
|
||||
throw dataTransfer;
|
||||
for (var f = 0; f < types.length; f++) {
|
||||
if (types[f] != expecteditem[f].substring(0, types[f].length) ||
|
||||
dataTransfer.mozGetDataAt(types[f], t) != expecteditem[f].substring(types[f].length + 2))
|
||||
throw "Failed";
|
||||
}
|
||||
}
|
||||
} catch(ex) {
|
||||
result = ex;
|
||||
failed = dataTransfer;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
aWindow.addEventListener("dragstart", trapDrag, false);
|
||||
synthesizeMouse(element, 2, 2, { type: "mousedown" }, aWindow);
|
||||
synthesizeMouse(element, 9, 9, { type: "mousemove" }, aWindow);
|
||||
synthesizeMouse(element, 10, 10, { type: "mousemove" }, aWindow);
|
||||
aWindow.removeEventListener("dragstart", trapDrag, false);
|
||||
synthesizeMouse(element, 10, 10, { type: "mouseup" }, aWindow);
|
||||
window.addEventListener("dragstart", trapDrag, false);
|
||||
synthesizeMouse(element, 2, 2, { type: "mousedown" });
|
||||
synthesizeMouse(element, 9, 9, { type: "mousemove" });
|
||||
synthesizeMouse(element, 10, 10, { type: "mousemove" });
|
||||
window.removeEventListener("dragstart", trapDrag, false);
|
||||
synthesizeMouse(element, 10, 10, { type: "mouseup" });
|
||||
|
||||
return result;
|
||||
return failed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emulate a drop by emulating a dragstart and firing events dragenter, dragover, and drop.
|
||||
* element - the element to fire the dragover, dragleave and drop events
|
||||
* Emulate a drop by firing a dragover, dragexit and a drop event.
|
||||
* element - the element to fire the dragover, dragexit and drop events on
|
||||
* dragData - the data to supply for the data transfer
|
||||
* This data is in the format:
|
||||
* [ [ {type: value, data: value}, ...], ... ]
|
||||
* [ [ "type: data", "type: data" ], ... ]
|
||||
* effectAllowed - the allowed effects that the dragstart event would have set
|
||||
*
|
||||
* Returns the drop effect that was desired.
|
||||
*/
|
||||
function synthesizeDrop(element, dragData, aWindow)
|
||||
function synthesizeDrop(element, dragData, effectAllowed)
|
||||
{
|
||||
if (!aWindow)
|
||||
aWindow = window;
|
||||
|
||||
var dataTransfer;
|
||||
var trapDrag = function(event) {
|
||||
dataTransfer = event.dataTransfer;
|
||||
for (let i = 0; i < dragData.length; i++) {
|
||||
var item = dragData[i];
|
||||
for (let j = 0; j < item.length; j++) {
|
||||
dataTransfer.mozSetDataAt(item[j].type, item[j].data, i);
|
||||
for (var t = 0; t < dragData.length; t++) {
|
||||
var item = dragData[t];
|
||||
for (var v = 0; v < item.length; v++) {
|
||||
var idx = item[v].indexOf(":");
|
||||
dataTransfer.mozSetDataAt(item[v].substring(0, idx), item[v].substring(idx + 2), t);
|
||||
}
|
||||
}
|
||||
|
||||
dataTransfer.dropEffect = "move";
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
// need to use real mouse action
|
||||
aWindow.addEventListener("dragstart", trapDrag, true);
|
||||
synthesizeMouse(element, 2, 2, { type: "mousedown" }, aWindow);
|
||||
synthesizeMouse(element, 9, 9, { type: "mousemove" }, aWindow);
|
||||
synthesizeMouse(element, 10, 10, { type: "mousemove" }, aWindow);
|
||||
aWindow.removeEventListener("dragstart", trapDrag, true);
|
||||
// need to use a real
|
||||
window.addEventListener("dragstart", trapDrag, true);
|
||||
synthesizeMouse(element, 2, 2, { type: "mousedown" });
|
||||
synthesizeMouse(element, 9, 9, { type: "mousemove" });
|
||||
synthesizeMouse(element, 10, 10, { type: "mousemove" });
|
||||
window.removeEventListener("dragstart", trapDrag, true);
|
||||
synthesizeMouse(element, 10, 10, { type: "mouseup" });
|
||||
|
||||
event = aWindow.document.createEvent("DragEvents");
|
||||
event.initDragEvent("dragenter", true, true, aWindow, 0, 0, 0, 0, 0, false, false, false, false, 0, null, dataTransfer);
|
||||
var event = document.createEvent("DragEvents");
|
||||
event.initDragEvent("dragover", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null, dataTransfer);
|
||||
if (element.dispatchEvent(event))
|
||||
return "none";
|
||||
|
||||
event = document.createEvent("DragEvents");
|
||||
event.initDragEvent("dragexit", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null, dataTransfer);
|
||||
element.dispatchEvent(event);
|
||||
|
||||
var event = aWindow.document.createEvent("DragEvents");
|
||||
event.initDragEvent("dragover", true, true, aWindow, 0, 0, 0, 0, 0, false, false, false, false, 0, null, dataTransfer);
|
||||
if (element.dispatchEvent(event)) {
|
||||
synthesizeMouse(element, 10, 10, { type: "mouseup" }, aWindow);
|
||||
return "none";
|
||||
}
|
||||
|
||||
if (dataTransfer.dropEffect != "none") {
|
||||
event = aWindow.document.createEvent("DragEvents");
|
||||
event.initDragEvent("drop", true, true, aWindow, 0, 0, 0, 0, 0, false, false, false, false, 0, null, dataTransfer);
|
||||
event = document.createEvent("DragEvents");
|
||||
event.initDragEvent("drop", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null, dataTransfer);
|
||||
element.dispatchEvent(event);
|
||||
}
|
||||
synthesizeMouse(element, 10, 10, { type: "mouseup" }, aWindow);
|
||||
|
||||
return dataTransfer.dropEffect;
|
||||
}
|
||||
|
|
|
@ -42,10 +42,6 @@ VPATH = @srcdir@
|
|||
relativesrcdir = testing/mochitest/tests/SimpleTest
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = tests \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_SIMPLETEST_FILES = MozillaFileLogger.js \
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1998
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
relativesrcdir = testing/mochitest/tests/SimpleTest/tests
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_CHROME_FILES = test_synthesizeDragStart.xul \
|
||||
test_synthesizeDrop.xul \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_CHROME_FILES)
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
|
|
@ -1,159 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Phil Lacy <philbaseless-firefox@yahoo.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Assure EventUtils can perform synthesizeDragStart as specified
|
||||
*/
|
||||
|
||||
SimpleTest/tests/test_synthesizeDragStart.xul
|
||||
|
||||
complete one flavor drag of simple text
|
||||
check match of [[]]
|
||||
complete 2 flavor drag
|
||||
check order
|
||||
complete File flavor drag
|
||||
check if nsIFile can be determined
|
||||
|
||||
-->
|
||||
<window title="Mozilla Bug 462172 extra tests for synthesizeDragStart"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="setTimeout(test,0)">
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/MochiKit/packed.js"/>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/chrome/toolkit/mozapps/downloads/tests/chrome/utils.js"/>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
|
||||
<script type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
/** Test for Bug 462172 synthesizeDragStart**/
|
||||
var testFile = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties).get("CurWorkD", Ci.nsIFile);
|
||||
|
||||
function doOnDragStart(aEvent)
|
||||
{
|
||||
let dt = aEvent.dataTransfer;
|
||||
switch (aEvent.currentTarget.id) {
|
||||
case "drag2" :
|
||||
dt.setData("text/plain", "this is text/plain");
|
||||
case "drag1" :
|
||||
dt.setData("text/uri-list", "http://www.mozilla.org/");
|
||||
break;
|
||||
case "dragfile" :
|
||||
dt.mozSetDataAt("application/x-moz-file", testFile, 0);
|
||||
break;
|
||||
}
|
||||
dt.effectAllowed = "all";
|
||||
}
|
||||
|
||||
// this is the expected data arrays
|
||||
// for testing drag of 2 items create 2 inner arrays
|
||||
var drag1 = [[
|
||||
{ type : "text/uri-list",
|
||||
data : "http://www.mozilla.org/" }
|
||||
]];
|
||||
var drag2items = [[
|
||||
{ type : "text/uri-list",
|
||||
data : "http://www.mozilla.org/" }
|
||||
],[
|
||||
{ type : "text/uri-list",
|
||||
data : "http://www.mozilla.org/" }
|
||||
]];
|
||||
var drag1WrongFlavor = [[
|
||||
{ type : "text/plain",
|
||||
data : "this is text/plain" }
|
||||
]];
|
||||
var drag2 = [[
|
||||
{ type : "text/plain",
|
||||
data : "this is text/plain" },
|
||||
{ type : "text/uri-list",
|
||||
data : "http://www.mozilla.org/" }
|
||||
]];
|
||||
var drag2WrongOrder = [[
|
||||
{ type : "text/uri-list",
|
||||
data : "http://www.mozilla.org/" },
|
||||
{ type : "text/plain",
|
||||
data : "this is text/plain" }
|
||||
]];
|
||||
var dragfile = [[
|
||||
{ type : "application/x-moz-file",
|
||||
data : testFile,
|
||||
eqTest : function(actualData, expectedData) {return expectedData.equals(actualData);} }
|
||||
]];
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function test() {
|
||||
|
||||
var result;
|
||||
// Now we can run our tests
|
||||
result = synthesizeDragStart($("drag1"), drag1, window);
|
||||
is(result, null, "drag1 is text/uri-list");
|
||||
result = synthesizeDragStart($("drag1"), drag1WrongFlavor, window);
|
||||
isnot(result, null, "drag1 is not text/plain");
|
||||
result = synthesizeDragStart($("drag1"), drag2items, window);
|
||||
isnot(result, null, "drag1 is not 2 items");
|
||||
result = synthesizeDragStart($("drag2"), drag2, window);
|
||||
is(result, null, "drag2 is ordered text/plain then text/uri-list");
|
||||
result = synthesizeDragStart($("drag2"), drag1, window);
|
||||
isnot(result, null, "drag2 is not one flavor");
|
||||
result = synthesizeDragStart($("drag2"), drag2WrongOrder, window);
|
||||
isnot(result, null, "drag2 is not ordered text/uri-list then text/plain");
|
||||
result = synthesizeDragStart($("dragfile"), dragfile, window);
|
||||
is(result, null, "dragfile is nsIFile");
|
||||
|
||||
SimpleTest.finish();
|
||||
|
||||
}
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display:none;"></div>
|
||||
<pre id="test"></pre>
|
||||
<div id="drag1" ondragstart="doOnDragStart(event);">Need some space here</div>
|
||||
<div id="drag2" ondragstart="doOnDragStart(event);">Need more space</div>
|
||||
<div id="dragfile" ondragstart="doOnDragStart(event);">Sure why not here too</div>
|
||||
</body>
|
||||
</window>
|
|
@ -1,122 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Phil Lacy <philbaseless-firefox@yahoo.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Assure EventUtils can perform synthesizeDrop as specified
|
||||
*/
|
||||
|
||||
_tests\testing\mochitest\chrome\testing\mochitest\tests\SimpleTest\tests\test_synthesizeDrop.xul
|
||||
|
||||
-->
|
||||
<window title="Mozilla Bug 462172 extra tests for synthesizeDrop"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="setTimeout(test,0)">
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/MochiKit/packed.js"/>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/chrome/toolkit/mozapps/downloads/tests/chrome/utils.js"/>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
|
||||
<script type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
/** Test for Bug 462172 synthesizeDrop**/
|
||||
|
||||
var gData;
|
||||
var gEnter = false;
|
||||
var gOver = false;
|
||||
var drag1 = [[
|
||||
{ type : "text/plain",
|
||||
data : "This is a test" }
|
||||
]];
|
||||
|
||||
function doOnDrop(aEvent)
|
||||
{
|
||||
gData = aEvent.dataTransfer.getData(drag1[0][0].type);
|
||||
aEvent.preventDefault; // cancels event and keeps dropEffect
|
||||
// as was before event.
|
||||
}
|
||||
|
||||
function doOnDragEnter(aEvent)
|
||||
{
|
||||
gEnter = true;
|
||||
aEvent.dataTransfer.effectAllowed = "all";
|
||||
aEvent.preventDefault(); // sets target this element
|
||||
}
|
||||
|
||||
function doOnDragOver(aEvent)
|
||||
{
|
||||
gOver = true;
|
||||
aEvent.dataTransfer.dropEffect = "copy";
|
||||
aEvent.preventDefault();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function test() {
|
||||
|
||||
var result;
|
||||
// Now we can run our tests
|
||||
result = synthesizeDrop($("drag1"), drag1, window);
|
||||
ok(gEnter, "Fired dragenter");
|
||||
ok(gOver, "Fired dragover");
|
||||
is(result, "copy", "copy is dropEffect");
|
||||
is(gData, drag1[0][0].data, "Received valid drop data");
|
||||
|
||||
SimpleTest.finish();
|
||||
|
||||
}
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display:none;"></div>
|
||||
<pre id="test"></pre>
|
||||
<div id="drag1" ondragover ="doOnDragOver(event);"
|
||||
ondragenter ="doOnDragEnter(event);"
|
||||
ondragleave ="doOnDragLeave(event);"
|
||||
ondrop ="doOnDrop(event);">
|
||||
Need some depth and height to drag here
|
||||
</div>
|
||||
</body>
|
||||
</window>
|
|
@ -688,20 +688,6 @@ function buildContextMenu(aEvent)
|
|||
|
||||
var gDownloadDNDObserver =
|
||||
{
|
||||
onDragStart: function (aEvent)
|
||||
{
|
||||
if (!gDownloadsView.selectedItem)
|
||||
return;
|
||||
let dl = gDownloadsView.selectedItem;
|
||||
let f = getLocalFileFromNativePathOrUrl(dl.getAttribute("file"));
|
||||
if (!f.exists())
|
||||
return;
|
||||
|
||||
let dt = aEvent.dataTransfer;
|
||||
dt.mozSetDataAt("application/x-moz-file", f, 0);
|
||||
dt.effectAllowed = "copyMove";
|
||||
},
|
||||
|
||||
onDragOver: function (aEvent)
|
||||
{
|
||||
var types = aEvent.dataTransfer.types;
|
||||
|
|
|
@ -178,8 +178,7 @@
|
|||
<richlistbox id="downloadView" seltype="multiple" flex="1"
|
||||
context="downloadContextMenu"
|
||||
ondblclick="onDownloadDblClick(event);"
|
||||
ondragstart="gDownloadDNDObserver.onDragStart(event);"
|
||||
ondragover="gDownloadDNDObserver.onDragOver(event);event.stopPropagation();"
|
||||
ondragover="gDownloadDNDObserver.onDragOver(event)"
|
||||
ondrop="gDownloadDNDObserver.onDrop(event)">
|
||||
</richlistbox>
|
||||
|
||||
|
|
|
@ -69,7 +69,6 @@ _CHROME_FILES = \
|
|||
test_unkownContentType_dialog_layout.xul \
|
||||
test_bug_412360.xul \
|
||||
test_bug_429247.xul \
|
||||
test_bug_462172.xul \
|
||||
unknownContentType_dialog_layout_data.txt \
|
||||
unknownContentType_dialog_layout_data.txt^headers^ \
|
||||
unknownContentType_dialog_layout_data.pif \
|
||||
|
|
|
@ -1,194 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Phil Lacy <philbaseless-firefox@yahoo.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Assure download manager can load valid list item as
|
||||
* "application/moz-x-file"
|
||||
*/
|
||||
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=462172
|
||||
|
||||
create a file with unique name
|
||||
create another file with unique name and delete it
|
||||
load into downloads database
|
||||
open download manager
|
||||
synthesize drag on both files
|
||||
missing file should not init drag
|
||||
real file should return transferdata with application/x-moz-file
|
||||
close window
|
||||
|
||||
-->
|
||||
<window title="Mozilla Bug 462172"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="test();">
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/MochiKit/packed.js"/>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/chrome/toolkit/mozapps/downloads/tests/chrome/utils.js"/>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
|
||||
<script type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
/** Test for Bug 462172 **/
|
||||
var missingFileElid;
|
||||
var realFileElid;
|
||||
const kFiller = "notApplicable";
|
||||
const kFillerURL = "https://bugzilla.mozilla.org/show_bug.cgi?id=462172"
|
||||
var realFile = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties).get("CurWorkD", Ci.nsIFile);
|
||||
var missingFile = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties).get("CurWorkD", Ci.nsIFile);
|
||||
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
|
||||
realFile.append(kFiller);
|
||||
realFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
|
||||
var realFilePath = ios.newFileURI(realFile).spec;
|
||||
|
||||
missingFile.append(kFiller);
|
||||
missingFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
|
||||
var missingFilePath = ios.newFileURI(missingFile).spec;
|
||||
missingFile.remove(false);
|
||||
|
||||
// Dummy data for our files.
|
||||
// 'source' field must be in form of an URL.
|
||||
const DownloadData = [
|
||||
{ name: kFiller,
|
||||
source: kFillerURL,
|
||||
target: realFilePath,
|
||||
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED},
|
||||
{ name: kFiller,
|
||||
source: kFillerURL,
|
||||
target: missingFilePath,
|
||||
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED}
|
||||
];
|
||||
|
||||
function compareFunc(actualData, expectedData) {
|
||||
return expectedData.equals(actualData);
|
||||
}
|
||||
|
||||
var dragRealFile = [[
|
||||
{ type :"application/x-moz-file",
|
||||
data : realFile,
|
||||
eqTest : compareFunc }
|
||||
]];
|
||||
var dragMissingFile = [[
|
||||
{ type :"application/x-moz-file",
|
||||
data : missingFile,
|
||||
eqTest : compareFunc }
|
||||
]];
|
||||
|
||||
function test() {
|
||||
|
||||
var dmui = getDMUI();
|
||||
if (!dmui) {
|
||||
todo(false, "skip test for toolkit download manager UI");
|
||||
return;
|
||||
}
|
||||
|
||||
// load files into db
|
||||
let dm = Cc["@mozilla.org/download-manager;1"].
|
||||
getService(Ci.nsIDownloadManager);
|
||||
let db = dm.DBConnection;
|
||||
|
||||
let stmt = db.createStatement(
|
||||
"INSERT INTO moz_downloads ( name, source, target, state)" +
|
||||
"VALUES (:name, :source, :target, :state)");
|
||||
for each (let dl in DownloadData) {
|
||||
for (let prop in dl)
|
||||
stmt.params[prop] = dl[prop];
|
||||
stmt.execute();
|
||||
if (dl.target == missingFilePath)
|
||||
missingFileElid = "dl" + db.lastInsertRowID;
|
||||
else if (dl.target == realFilePath)
|
||||
realFileElid = "dl" + db.lastInsertRowID;
|
||||
}
|
||||
stmt.finalize();
|
||||
|
||||
// See if the DM is already open, and if it is, close it!
|
||||
let win = getDMWindow();
|
||||
if (win) win.close();
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
const DLMGR_UI_DONE = "download-manager-ui-done";
|
||||
|
||||
let testObs = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
if (aTopic != DLMGR_UI_DONE)
|
||||
return;
|
||||
|
||||
let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
|
||||
win.focus();
|
||||
|
||||
// Now we can run our tests
|
||||
let result = synthesizeDragStart(win.document.getElementById(realFileElid), dragRealFile, win);
|
||||
is(result, null, "Checking for Real file match");
|
||||
result = synthesizeDragStart(win.document.getElementById(missingFileElid), dragMissingFile, win);
|
||||
isnot(result, null, "Drag start did not return item for missing file");
|
||||
|
||||
// Done.
|
||||
win.close();
|
||||
realFile.remove(false);
|
||||
os.removeObserver(testObs, DLMGR_UI_DONE);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
};
|
||||
|
||||
// Register with the observer service
|
||||
os.addObserver(testObs, DLMGR_UI_DONE, false);
|
||||
|
||||
// Show the Download Manager UI
|
||||
dmui.show();
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
}
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display:none;"></div>
|
||||
<pre id="test"></pre>
|
||||
</body>
|
||||
</window>
|
Загрузка…
Ссылка в новой задаче