33 const Cu = Components.utils;
36 "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
38 Cu.import(
"resource://app/jsmodules/DropHelper.jsm");
39 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
42 var
url =
"data:application/vnd.mozilla.xul+xml," +
43 "<?xml-stylesheet href='chrome://global/skin' type='text/css'?>" +
44 "<?xml-stylesheet href='chrome://songbird/content/bindings/bindings.css' type='text/css'?>" +
45 "<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'/>";
56 list = library.createMediaList(
"simple"),
57 pqList =
Cc[
"@songbirdnest.com/Songbird/playqueue/service;1"]
58 .getService(
Ci.sbIPlayQueueService)
61 function createElement(aList, aType) {
62 var playlist = document.createElementNS(
XUL_NS, aType);
63 playlist.setAttribute(
"flex",
"1");
64 document.documentElement.appendChild(playlist);
65 playlist.bind(aList.createView(),
null);
71 [ createElement(library,
"sb-playlist"),
72 createElement(list,
"sb-playlist"),
73 createElement(pqList,
"sb-playqueue-playlist") ]);
76 function test_canDrop(aLibraryPlaylist, aListPlaylist, aPlayQueuePlaylist) {
78 function runTests(
aPlaylist, aTestCases) {
79 for (let
i = 0, len = aTestCases.length;
i < len;
i++) {
80 let testCase =
new TestCase(aTestCases[
i]);
81 testCase.run([
aPlaylist, aPlayQueuePlaylist]);
101 desc:
"should always return false when the _disableDrop flag is true",
102 pre:
function (playlist) {
103 this.stub(playlist,
'_disableDrop',
true);
105 exec:
function (playlist) {
111 desc:
"should always return false when the target is read only",
112 pre:
function (playlist) {
113 this.stash = playlist.mediaList.getProperty(SBProperties.isReadOnly);
114 playlist.mediaList.setProperty(SBProperties.isReadOnly,
"1");
116 exec:
function(playlist) {
119 post:
function (playlist) {
120 playlist.mediaList.setProperty(SBProperties.isReadOnly,
this.stash);
125 desc:
"should always return false when the target has read only content",
126 pre:
function (playlist) {
127 this.stash = playlist.mediaList.getProperty(SBProperties.isContentReadOnly);
128 playlist.mediaList.setProperty(SBProperties.isContentReadOnly,
"1");
130 exec:
function (playlist) {
133 post:
function (playlist) {
134 playlist.mediaList.setProperty(SBProperties.isContentReadOnly,
this.stash);
139 desc:
"should return true is the drop is a supported external flavor",
140 pre:
function (playlist) {
141 this.stub(ExternalDropHandler,
'isSupported',
function () {
145 exec:
function (playlist) {
151 desc:
"should return false if the drop is not supported by any handler",
152 pre:
function (playlist) {
153 this.stub(ExternalDropHandler,
'isSupported',
function () {
156 this.stub(InternalDropHandler,
'isSupported',
function () {
160 exec:
function (playlist) {
166 desc:
"should return false for lists of customType 'download' when " +
167 "_canDownloadDrop returns false",
168 pre:
function (playlist) {
169 this.stub(ExternalDropHandler,
'isSupported',
function () {
172 this.stub(InternalDropHandler,
'isSupported',
function () {
175 this.stub(playlist,
'_canDownloadDrop',
function() {
178 var list = playlist.mediaList;
179 this.stash = list.getProperty(SBProperties.customType);
180 list.setProperty(SBProperties.customType,
"download");
182 exec:
function (playlist) {
185 post:
function (playlist) {
186 playlist.mediaList.setProperty(SBProperties.customType,
this.stash);
191 desc:
"should return true for lists of customType 'download' when " +
192 "_canDownloadDrop returns true",
193 pre:
function (playlist) {
194 this.stub(ExternalDropHandler,
'isSupported',
function () {
197 this.stub(InternalDropHandler,
'isSupported',
function () {
200 this.stub(playlist,
'_canDownloadDrop',
function() {
203 var list = playlist.mediaList;
204 this.stash = list.getProperty(SBProperties.customType);
205 list.setProperty(SBProperties.customType,
"download");
207 exec:
function (playlist) {
210 post:
function (playlist) {
211 playlist.mediaList.setProperty(SBProperties.customType,
this.stash);
216 desc:
"should return false if an internal drop does not contain data",
217 pre:
function (playlist) {
218 this.stub(ExternalDropHandler,
'isSupported',
function () {
221 this.stub(InternalDropHandler,
'isSupported',
function () {
224 this.stub(
DNDUtils,
'getTransferDataForFlavour',
function () {
228 exec:
function (playlist) {
234 desc:
"should return true if the internal drop is a supported flavor, " +
235 "the drop source is different from the drop target, " +
236 "and the drop target accepts drops from the source",
237 pre:
function (playlist) {
239 var dnd =
Cc[
"@songbirdnest.com/Songbird/DndSourceTracker;1"]
240 .getService(
Ci.sbIDndSourceTracker),
241 sourceList = playlist.library.createMediaList(
"simple"),
242 context =
new DNDUtils.MediaListTransferContext(sourceList, sourceList),
243 handle = dnd.registerSource(context);
245 this.stub(ExternalDropHandler,
'isSupported',
function () {
248 this.stub(InternalDropHandler,
'isSupported',
function () {
251 this.stub(
DNDUtils,
'getTransferDataForFlavour',
function (type) {
252 var sourceData =
null;
253 if (type ==
"application/x-sb-transfer-media-list") {
258 this.stub(playlist,
'acceptDropSource',
function () {
262 exec:
function (playlist) {
268 desc:
"should return false if the internal drop is a supported flavor, " +
269 "the drop source is different from the drop target, " +
270 "and the drop target does not accept drops from the source",
271 pre:
function (playlist) {
273 var dnd =
Cc[
"@songbirdnest.com/Songbird/DndSourceTracker;1"]
274 .getService(
Ci.sbIDndSourceTracker),
275 sourceList = playlist.library.createMediaList(
"simple"),
276 context =
new DNDUtils.MediaListTransferContext(sourceList, sourceList),
277 handle = dnd.registerSource(context);
279 this.stub(ExternalDropHandler,
'isSupported',
function () {
282 this.stub(InternalDropHandler,
'isSupported',
function () {
285 this.stub(
DNDUtils,
'getTransferDataForFlavour',
function (type) {
286 var sourceData =
null;
287 if (type ==
"application/x-sb-transfer-media-list") {
292 this.stub(playlist,
'acceptDropSource',
function () {
296 exec:
function (playlist) {
302 desc:
"should return false if the internal drop is a supported flavor, " +
303 "the drop source is the same as the drop target, " +
304 "and the drop target is a library",
305 pre:
function (playlist) {
307 var dnd =
Cc[
"@songbirdnest.com/Songbird/DndSourceTracker;1"]
308 .getService(
Ci.sbIDndSourceTracker),
309 sourceList = playlist.mediaList,
310 context =
new DNDUtils.MediaListTransferContext(sourceList, sourceList),
311 handle = dnd.registerSource(context);
313 this.stub(ExternalDropHandler,
'isSupported',
function () {
316 this.stub(InternalDropHandler,
'isSupported',
function () {
319 this.stub(
DNDUtils,
'getTransferDataForFlavour',
function (type) {
320 var sourceData =
null;
321 if (type ==
"application/x-sb-transfer-media-list") {
327 exec:
function (playlist) {
335 desc:
"should return true if the internal drop is a supported flavor, " +
336 "the drop source is the same as the drop target, " +
337 "and the drop target is not a library",
338 pre:
function (playlist) {
340 var dnd =
Cc[
"@songbirdnest.com/Songbird/DndSourceTracker;1"]
341 .getService(
Ci.sbIDndSourceTracker),
342 sourceList = playlist.mediaList,
343 context =
new DNDUtils.MediaListTransferContext(sourceList, sourceList),
344 handle = dnd.registerSource(context);
346 this.stub(ExternalDropHandler,
'isSupported',
function () {
349 this.stub(InternalDropHandler,
'isSupported',
function () {
352 this.stub(
DNDUtils,
'getTransferDataForFlavour',
function (type) {
353 var sourceData =
null;
354 if (type ==
"application/x-sb-transfer-media-list") {
360 exec:
function (playlist) {
366 desc:
"should return false if the internal drop is a supported flavor, " +
367 "the drop source is the same as the drop target, " +
368 "the drop target is not a library, and the drop target is not " +
370 pre:
function (playlist) {
372 var dnd =
Cc[
"@songbirdnest.com/Songbird/DndSourceTracker;1"]
373 .getService(
Ci.sbIDndSourceTracker),
374 sourceList = playlist.mediaList,
375 context =
new DNDUtils.MediaListTransferContext(sourceList, sourceList),
376 handle = dnd.registerSource(context);
378 this.stub(ExternalDropHandler,
'isSupported',
function () {
381 this.stub(InternalDropHandler,
'isSupported',
function () {
384 this.stub(
DNDUtils,
'getTransferDataForFlavour',
function (type) {
385 var sourceData =
null;
386 if (type ==
"application/x-sb-transfer-media-list") {
391 this.stub(playlist,
'isOrdinalSort',
function() {
395 exec:
function (playlist) {
403 desc:
"canDrop should return false when _canDrop returns false",
404 pre:
function (playlist) {
405 this.stub(playlist,
'_canDrop',
function () {
408 this.stub(playlist,
'isOrdinalSort',
function () {
412 exec:
function (playlist) {
418 desc:
"canDrop should return false when the sort is not ordinal",
419 pre:
function (playlist) {
420 this.stub(playlist,
'_canDrop',
function () {
423 this.stub(playlist,
'isOrdinalSort',
function () {
427 exec:
function (playlist) {
433 desc:
"canDrop should return true when canDrop returns true and the sort " +
435 pre:
function (playlist) {
436 this.stub(playlist,
'_canDrop',
function () {
439 this.stub(playlist,
'isOrdinalSort',
function () {
443 exec:
function (playlist) {
451 desc:
"_canDrop should return false when the target is the play queue and " +
452 "the source belongs to a device",
453 pre:
function (playlist, playQueuePlaylist) {
454 var dnd =
Cc[
"@songbirdnest.com/Songbird/DndSourceTracker;1"]
455 .getService(
Ci.sbIDndSourceTracker),
460 this.dev =
Cc[
"@songbirdnest.com/Songbird/Device/DeviceTester/MockDevice;1"]
461 .createInstance(
Ci.sbIDevice),
462 this.devMgr =
Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
463 .getService(
Ci.sbIDeviceManager2),
464 this.devMgr.registerDevice(this.dev);
465 sourceList = this.dev.defaultLibrary
466 .QueryInterface(
Ci.sbILibrary)
467 .createMediaList(
"simple");
468 context =
new DNDUtils.MediaListTransferContext(sourceList, sourceList),
469 handle = dnd.registerSource(context);
471 this.stub(ExternalDropHandler,
'isSupported',
function () {
474 this.stub(InternalDropHandler,
'isSupported',
function() {
477 this.stub(
DNDUtils,
'getTransferDataForFlavour',
function (type) {
478 var sourceData =
null;
479 if (type ==
"application/x-sb-transfer-media-list") {
480 sourceData = {
data: handle };
485 exec:
function (playlist, playQueuePlaylist) {
489 this.devMgr.unregisterDevice(this.dev);
490 this.dev.disconnect();
497 desc:
"_canDrop should return true when the target is the play queue and " +
498 "the source does not belong to a device, provided other normal " +
499 "drop constraints are satisfied",
500 pre:
function (playlist, playQueuePlaylist) {
501 var dnd =
Cc[
"@songbirdnest.com/Songbird/DndSourceTracker;1"]
502 .getService(
Ci.sbIDndSourceTracker),
503 sourceList = playlist.library.createMediaList(
"simple"),
504 context =
new DNDUtils.MediaListTransferContext(sourceList, sourceList),
505 handle = dnd.registerSource(context);
507 this.stub(ExternalDropHandler,
'isSupported',
function () {
510 this.stub(InternalDropHandler,
'isSupported',
function() {
513 this.stub(
DNDUtils,
'getTransferDataForFlavour',
function (type) {
514 var sourceData =
null;
515 if (type ==
"application/x-sb-transfer-media-list") {
521 exec:
function (playlist, playQueuePlaylist) {
function endWindowTest(e)
function TestCase(config)
const K_DROPONLIBRARY_TESTS
function beginWindowTest(url, continueFunction)
function assertEqual(aExpected, aActual, aMessage)
function handle(request, response)
function test_canDrop(aLibraryPlaylist, aListPlaylist, aPlayQueuePlaylist)
function runTest()
Advanced DataRemote unit tests.
const K_DROPINDICATOR_TESTS
const K_DROPONPLAYQUEUE_TESTS
function createLibrary(databaseGuid, databaseLocation)
_getSelectedPageStyle s i
function continueWindowTest(fn, parameters)