Bug 981592 - Ensure the Library selected left pane container is open before selecting one of its descendants. r=mano
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 12 Mar 2014 16:24:28 +0100
changeset 191493 56ac183ad1e21219994a080f3f65454b945b9bb0
parent 191492 60c1af78091ab904718d3c69d7e4797190a3c134
child 191494 e6636696d6de5f4b2f32812eeff731aae7341c96
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmano
bugs981592
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 981592 - Ensure the Library selected left pane container is open before selecting one of its descendants. r=mano
browser/components/places/content/places.js
browser/components/places/tests/browser/browser.ini
browser/components/places/tests/browser/browser_library_openFlatContainer.js
browser/components/places/tests/browser/browser_sidebarpanels_click.js
browser/components/places/tests/browser/head.js
--- a/browser/components/places/content/places.js
+++ b/browser/components/places/content/places.js
@@ -321,20 +321,23 @@ var PlacesOrganizer = {
     if (view) {
       let selectedNodes = view.selectedNode ?
                           [view.selectedNode] : view.selectedNodes;
       this._fillDetailsPane(selectedNodes);
     }
   },
 
   openFlatContainer: function PO_openFlatContainerFlatContainer(aContainer) {
-    if (aContainer.itemId != -1)
+    if (aContainer.itemId != -1) {
+      PlacesUtils.asContainer(this._places.selectedNode).containerOpen = true;
       this._places.selectItems([aContainer.itemId], false);
-    else if (PlacesUtils.nodeIsQuery(aContainer))
+    }
+    else if (PlacesUtils.nodeIsQuery(aContainer)) {
       this._places.selectPlaceURI(aContainer.uri);
+    }
   },
 
   /**
    * Returns the options associated with the query currently loaded in the
    * main places pane.
    */
   getCurrentOptions: function PO_getCurrentOptions() {
     return PlacesUtils.asQuery(ContentArea.currentView.result.root).queryOptions;
--- a/browser/components/places/tests/browser/browser.ini
+++ b/browser/components/places/tests/browser/browser.ini
@@ -42,8 +42,9 @@ skip-if = true
 [browser_toolbar_migration.js]
 [browser_library_batch_delete.js]
 [browser_555547.js]
 [browser_416459_cut.js]
 [browser_library_downloads.js]
 [browser_library_left_pane_select_hierarchy.js]
 [browser_435851_copy_query.js]
 [browser_toolbarbutton_menu_context.js]
+[browser_library_openFlatContainer.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/places/tests/browser/browser_library_openFlatContainer.js
@@ -0,0 +1,42 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/**
+ * Test opening a flat container in the right pane even if its parent in the
+ * left pane is closed.
+ */
+
+add_task(function* () {
+  let folder = PlacesUtils.bookmarks
+                          .createFolder(PlacesUtils.unfiledBookmarksFolderId,
+                                        "Folder",
+                                        PlacesUtils.bookmarks.DEFAULT_INDEX);
+  let bookmark = PlacesUtils.bookmarks
+                            .insertBookmark(folder, NetUtil.newURI("http://example.com/"),
+                                            PlacesUtils.bookmarks.DEFAULT_INDEX,
+                                            "Bookmark");
+
+  let library = yield promiseLibrary("AllBookmarks");
+  registerCleanupFunction(function () {
+    library.close();
+    PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
+  });
+
+  // Select unfiled later, to ensure it's closed.
+  library.PlacesOrganizer.selectLeftPaneQuery("UnfiledBookmarks");
+  ok(!library.PlacesOrganizer._places.selectedNode.containerOpen,
+     "Unfiled container is closed");
+
+  let folderNode = library.ContentTree.view.view.nodeForTreeIndex(0);
+  is(folderNode.itemId, folder,
+     "Found the expected folder in the right pane");
+  // Select the folder node in the right pane.
+  library.ContentTree.view.selectNode(folderNode);
+
+  synthesizeClickOnSelectedTreeCell(library.ContentTree.view,
+                                    { clickCount: 2 });
+
+  is(library.ContentTree.view.view.nodeForTreeIndex(0).itemId, bookmark,
+     "Found the expected bookmark in the right pane");
+});
--- a/browser/components/places/tests/browser/browser_sidebarpanels_click.js
+++ b/browser/components/places/tests/browser/browser_sidebarpanels_click.js
@@ -114,37 +114,16 @@ function test() {
         // Note that for the history sidebar, the URL itself is not opened,
         // and Places will show the load-js-data-url-error prompt as an alert
         // box, which means that the click actually worked, so it's good enough
         // for the purpose of this test.
       });
     }, true);
   }
 
-  function synthesizeClickOnSelectedTreeCell(aTree) {
-    let tbo = aTree.treeBoxObject;
-    is(tbo.view.selection.count, 1,
-       "The test node should be successfully selected");
-    // Get selection rowID.
-    let min = {}, max = {};
-    tbo.view.selection.getRangeAt(0, min, max);
-    let rowID = min.value;
-    tbo.ensureRowIsVisible(rowID);
-
-    // Calculate the click coordinates.
-    let x = {}, y = {}, width = {}, height = {};
-    tbo.getCoordsForCellItem(rowID, aTree.columns[0], "text",
-                             x, y, width, height);
-    x = x.value + width.value / 2;
-    y = y.value + height.value / 2;
-    // Simulate the click.
-    EventUtils.synthesizeMouse(aTree.body, x, y, {},
-                               aTree.ownerDocument.defaultView);
-  }
-
   function changeSidebarDirection(aDirection) {
     sidebar.contentDocument.documentElement.style.direction = aDirection;
   }
 
   function runNextTest() {
     // Remove eventual tabs created by previous sub-tests.
     while (gBrowser.tabs.length > 1) {
       gBrowser.removeTab(gBrowser.tabContainer.lastChild);
--- a/browser/components/places/tests/browser/head.js
+++ b/browser/components/places/tests/browser/head.js
@@ -1,12 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-Components.utils.import("resource://gre/modules/NetUtil.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
+  "resource://gre/modules/NetUtil.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Promise",
+  "resource://gre/modules/commonjs/sdk/core/promise.js");
 
 // We need to cache this before test runs...
 let cachedLeftPaneFolderIdGetter;
 let (getter = PlacesUIUtils.__lookupGetter__("leftPaneFolderId")) {
   if (!cachedLeftPaneFolderIdGetter && typeof(getter) == "function")
     cachedLeftPaneFolderIdGetter = getter;
 }
 // ...And restore it when test ends.
@@ -177,11 +181,27 @@ function addVisits(aPlaceInfo, aWindow, 
       handleCompletion: function UP_handleCompletion() {
         if (aCallback)
           aCallback();
       }
     }
   );
 }
 
-XPCOMUtils.defineLazyModuleGetter(this, "Promise",
-  "resource://gre/modules/commonjs/sdk/core/promise.js");
-
+function synthesizeClickOnSelectedTreeCell(aTree, aOptions) {
+  let tbo = aTree.treeBoxObject;
+  if (tbo.view.selection.count != 1)
+     throw new Error("The test node should be successfully selected");
+  // Get selection rowID.
+  let min = {}, max = {};
+  tbo.view.selection.getRangeAt(0, min, max);
+  let rowID = min.value;
+  tbo.ensureRowIsVisible(rowID);
+  // Calculate the click coordinates.
+  let x = {}, y = {}, width = {}, height = {};
+  tbo.getCoordsForCellItem(rowID, aTree.columns[0], "text",
+                           x, y, width, height);
+  x = x.value + width.value / 2;
+  y = y.value + height.value / 2;
+  // Simulate the click.
+  EventUtils.synthesizeMouse(aTree.body, x, y, aOptions || {},
+                             aTree.ownerDocument.defaultView);
+}