Bug 475045 - Can't drag unlinkified URL to bookmarks toolbar

r=mak
This commit is contained in:
Brian R. Bondy 2011-08-05 21:08:34 +02:00
Родитель 20974cc046
Коммит ab753bb0b6
3 изменённых файлов: 68 добавлений и 2 удалений

Просмотреть файл

@ -1376,15 +1376,23 @@ let PlacesControllerDragHelper = {
},
/**
* Extract the first accepted flavor from a flavors array.
* Extract the first accepted flavor from a list of flavors.
* @param aFlavors
* The flavors array.
* The flavors list of type nsIDOMDOMStringList.
*/
getFirstValidFlavor: function PCDH_getFirstValidFlavor(aFlavors) {
for (let i = 0; i < aFlavors.length; i++) {
if (this.GENERIC_VIEW_DROP_TYPES.indexOf(aFlavors[i]) != -1)
return aFlavors[i];
}
// If no supported flavor is found, check if data includes text/plain
// contents. If so, request them as text/unicode, a conversion will happen
// automatically.
if (aFlavors.contains("text/plain")) {
return PlacesUtils.TYPE_UNICODE;
}
return null;
},

Просмотреть файл

@ -48,6 +48,7 @@ _BROWSER_TEST_FILES = \
browser_0_library_left_pane_migration.js \
browser_library_left_pane_fixnames.js \
browser_425884.js \
browser_475045.js \
browser_423515.js \
browser_410196_paste_into_tags.js \
browser_457473_no_copy_guid.js \

Просмотреть файл

@ -0,0 +1,57 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function test() {
// Make sure the bookmarks bar is visible and restore its state on cleanup.
let toolbar = document.getElementById("PersonalToolbar");
ok(toolbar, "PersonalToolbar should not be null");
if (toolbar.collapsed) {
setToolbarVisibility(toolbar, true);
registerCleanupFunction(function() {
setToolbarVisibility(toolbar, false);
});
}
// Setup the node we will use to be dropped. The actual node used does not
// matter because we will set its data, effect, and mimeType manually.
let placesItems = document.getElementById("PlacesToolbarItems");
ok(placesItems, "PlacesToolbarItems should not be null");
ok(placesItems.localName == "scrollbox", "PlacesToolbarItems should not be null");
/**
* Simulates a drop of a URI onto the bookmarks bar.
*
* @param aEffect
* The effect to use for the drop operation: move, copy, or link.
* @param aMimeType
* The mime type to use for the drop operation.
*/
let simulateDragDrop = function(aEffect, aMimeType) {
const uriSpec = "http://www.mozilla.org/D1995729-A152-4e30-8329-469B01F30AA7";
let uri = makeURI(uriSpec);
EventUtils.synthesizeDrop(placesItems, placesItems,
[[{type: aMimeType,
data: uriSpec}]],
aEffect, window);
// Verify that the drop produces exactly one bookmark.
let bookmarkIds = PlacesUtils.bookmarks
.getBookmarkIdsForURI(uri);
ok(bookmarkIds.length == 1, "There should be exactly one bookmark");
PlacesUtils.bookmarks.removeItem(bookmarkIds[0]);
// Verify that we removed the bookmark successfully.
ok(!PlacesUtils.bookmarks.isBookmarked(uri), "URI should be removed");
}
// Simulate a bookmark drop for all of the mime types and effects.
let mimeTypes = ["text/plain", "text/unicode", "text/x-moz-url"];
let effects = ["move", "copy", "link"];
effects.forEach(function (effect) {
mimeTypes.forEach(function (mimeType) {
simulateDragDrop(effect, mimeType);
});
});
}