Bug 735987 - [New Tab Page] Dropping blocked links onto the grid again should unblock them; r=dietrich, a=akeybl
authorTim Taubert <tim.taubert@gmx.de>
Fri, 16 Mar 2012 09:00:18 +0100
changeset 90498 4b7327c0fd0050f629ee56c8b25cb2f9b309589e
parent 90497 158500e8fa4edf2feba20f33f550bd4dd89ac4c0
child 90499 13af0e0fdd41ce0680ddaba638fbb30d89376e7f
push id1002
push usertim.taubert@gmx.de
push dateWed, 21 Mar 2012 17:42:06 +0000
treeherdermozilla-aurora@4b7327c0fd00 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdietrich, akeybl
bugs735987
milestone13.0a2
Bug 735987 - [New Tab Page] Dropping blocked links onto the grid again should unblock them; r=dietrich, a=akeybl
browser/base/content/newtab/drop.js
browser/base/content/test/newtab/Makefile.in
browser/base/content/test/newtab/browser_newtab_bug735987.js
browser/modules/NewTabUtils.jsm
--- a/browser/base/content/newtab/drop.js
+++ b/browser/base/content/newtab/drop.js
@@ -89,17 +89,21 @@ let gDrop = {
     if (draggedSite) {
       // Pin the dragged site at its new place.
       if (aCell != draggedSite.cell)
         draggedSite.pin(index);
     } else {
       // A new link was dragged onto the grid. Create it by pinning its URL.
       let dt = aEvent.dataTransfer;
       let [url, title] = dt.getData("text/x-moz-url").split(/[\r\n]+/);
-      gPinnedLinks.pin({url: url, title: title}, index);
+      let link = {url: url, title: title};
+      gPinnedLinks.pin(link, index);
+
+      // Make sure the newly added link is not blocked.
+      gBlockedLinks.unblock(link);
     }
   },
 
   /**
    * Time a rearrange with a little delay.
    * @param aCell The drop target cell.
    */
   _delayedRearrange: function Drop_delayedRearrange(aCell) {
--- a/browser/base/content/test/newtab/Makefile.in
+++ b/browser/base/content/test/newtab/Makefile.in
@@ -20,13 +20,14 @@ include $(topsrcdir)/config/rules.mk
 	browser_newtab_reset.js \
 	browser_newtab_tabsync.js \
 	browser_newtab_unpin.js \
 	browser_newtab_bug722273.js \
 	browser_newtab_bug723102.js \
 	browser_newtab_bug723121.js \
 	browser_newtab_bug725996.js \
 	browser_newtab_bug734043.js \
+	browser_newtab_bug735987.js \
 	head.js \
 	$(NULL)
 
 libs::	$(_BROWSER_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/newtab/browser_newtab_bug735987.js
@@ -0,0 +1,22 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function runTests() {
+  setLinks("0,1,2,3,4,5,6,7,8");
+  setPinnedLinks("");
+
+  yield addNewTabPageTab();
+  checkGrid("0,1,2,3,4,5,6,7,8");
+
+  yield simulateDrop(cells[1]);
+  checkGrid("0,99p,1,2,3,4,5,6,7");
+
+  yield blockCell(cells[1]);
+  checkGrid("0,1,2,3,4,5,6,7,8");
+
+  yield simulateDrop(cells[1]);
+  checkGrid("0,99p,1,2,3,4,5,6,7");
+
+  yield blockCell(cells[1]);
+  checkGrid("0,1,2,3,4,5,6,7,8");
+}
--- a/browser/modules/NewTabUtils.jsm
+++ b/browser/modules/NewTabUtils.jsm
@@ -379,16 +379,25 @@ let BlockedLinks = {
 
     // Make sure we unpin blocked links.
     PinnedLinks.unpin(aLink);
 
     Storage.set("blockedLinks", this.links);
   },
 
   /**
+   * Unblocks a given link.
+   * @param aLink The link to unblock.
+   */
+  unblock: function BlockedLinks_unblock(aLink) {
+    if (this.isBlocked(aLink))
+      delete this.links[aLink.url];
+  },
+
+  /**
    * Returns whether a given link is blocked.
    * @param aLink The link to check.
    */
   isBlocked: function BlockedLinks_isBlocked(aLink) {
     return (aLink.url in this.links);
   },
 
   /**