Bug 475045 - Can't drag unlinkified URL to bookmarks toolbar
☠☠ backed out by 25d81f689bd2 ☠ ☠
authorBrian R. Bondy <netzen@gmail.com>
Fri, 05 Aug 2011 21:08:34 +0200
changeset 73914 a8bca81215eadf4691cd31c5d38799a0fcb5996e
parent 73913 bb71b8c9441d0163cbb2b16d687ca5acc356d357
child 73915 fe6bd42cdc0dbd105682c1c9d7ea630324454736
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
bugs475045
milestone8.0a1
Bug 475045 - Can't drag unlinkified URL to bookmarks toolbar r=mak
browser/components/places/content/controller.js
browser/components/places/tests/browser/Makefile.in
browser/components/places/tests/browser/browser_475045.js
--- a/browser/components/places/content/controller.js
+++ b/browser/components/places/content/controller.js
@@ -1371,25 +1371,33 @@ let PlacesControllerDragHelper = {
   /**
    * @returns The current active drag session. Returns null if there is none.
    */
   getSession: function PCDH__getSession() {
     return this.dragService.getCurrentSession();
   },
 
   /**
-   * 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;
   },
 
   /**
    * Determines whether or not the data currently being dragged can be dropped
    * on a places view.
    * @param ip
    *        The insertion point where the items should be dropped.
--- a/browser/components/places/tests/browser/Makefile.in
+++ b/browser/components/places/tests/browser/Makefile.in
@@ -43,16 +43,17 @@ relativesrcdir  = browser/components/pla
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _BROWSER_TEST_FILES = \
 	head.js \
 	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 \
 	browser_sort_in_library.js \
 	browser_library_open_leak.js \
 	browser_library_panel_leak.js \
 	browser_library_search.js \
 	browser_history_sidebar_search.js \
new file mode 100644
--- /dev/null
+++ b/browser/components/places/tests/browser/browser_475045.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);
+    });
+  });
+}