browser_library_left_pane_commands.js
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et: */
3 /* ***** BEGIN LICENSE BLOCK *****
4  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is Places test code.
17  *
18  * The Initial Developer of the Original Code is Mozilla Corp.
19  * Portions created by the Initial Developer are Copyright (C) 2009
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  * Marco Bonardo <mak77@bonardo.net> (Original Author)
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by devaring the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not devare
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38 
43 const TEST_URI = "http://www.mozilla.org/";
44 
45 var gTests = [];
47 
48 //------------------------------------------------------------------------------
49 
50 gTests.push({
51  desc: "Bug 489351 - Date containers under History in Library cannot be deleted/cut",
52  run: function() {
53  var bhist = PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
54  // Add a visit.
55  PlacesUtils.history.addVisit(PlacesUtils._uri(TEST_URI), Date.now() * 1000,
56  null, PlacesUtils.history.TRANSITION_TYPED,
57  false, 0);
58  ok(bhist.isVisited(PlacesUtils._uri(TEST_URI)), "Visit has been added");
59 
60  // Select and open the left pane "History" query.
61  var PO = gLibrary.PlacesOrganizer;
62  PO.selectLeftPaneQuery('History');
63  isnot(PO._places.selectedNode, null, "We correctly selected History");
64 
65  // Check that both delete and cut commands are disabled.
66  ok(!PO._places.controller.isCommandEnabled("cmd_cut"),
67  "Cut command is disabled");
68  ok(!PO._places.controller.isCommandEnabled("cmd_delete"),
69  "Delete command is disabled");
70  var historyNode = PO._places.selectedNode
71  .QueryInterface(Ci.nsINavHistoryContainerResultNode);
72  historyNode.containerOpen = true;
73 
74  // Check that we have a child container. It is "Today" container.
75  is(historyNode.childCount, 1, "History node has one child");
76  var todayNode = historyNode.getChild(0);
77  var todayNodeExpectedTitle = PlacesUtils.getString("finduri-AgeInDays-is-0");
78  is(todayNode.title, todayNodeExpectedTitle,
79  "History child is the expected container");
80 
81  // Select "Today" container.
82  PO._places.selectNode(todayNode);
83  is(PO._places.selectedNode, todayNode,
84  "We correctly selected Today container");
85  // Check that delete command is enabled but cut command is disabled.
86  ok(!PO._places.controller.isCommandEnabled("cmd_cut"),
87  "Cut command is disabled");
88  ok(PO._places.controller.isCommandEnabled("cmd_delete"),
89  "Delete command is enabled");
90 
91  // Execute the delete command and check visit has been removed.
92  PO._places.controller.doCommand("cmd_delete");
93  ok(!bhist.isVisited(PlacesUtils._uri(TEST_URI)), "Visit has been removed");
94 
95  // Test live update of "History" query.
96  is(historyNode.childCount, 0, "History node has no more children");
97 
98  historyNode.containerOpen = false;
99  nextTest();
100  }
101 });
102 
103 //------------------------------------------------------------------------------
104 
105 gTests.push({
106  desc: "Bug 490156 - Can't delete smart bookmark containers",
107  run: function() {
108  // Select and open the left pane "Bookmarks Toolbar" folder.
109  var PO = gLibrary.PlacesOrganizer;
110  PO.selectLeftPaneQuery('BookmarksToolbar');
111  isnot(PO._places.selectedNode, null, "We have a valid selection");
112  is(PlacesUtils.getConcreteItemId(PO._places.selectedNode),
113  PlacesUtils.toolbarFolderId,
114  "We have correctly selected bookmarks toolbar node.");
115 
116  // Check that both cut and delete commands are disabled.
117  ok(!PO._places.controller.isCommandEnabled("cmd_cut"),
118  "Cut command is disabled");
119  ok(!PO._places.controller.isCommandEnabled("cmd_delete"),
120  "Delete command is disabled");
121 
122  var toolbarNode = PO._places.selectedNode
123  .QueryInterface(Ci.nsINavHistoryContainerResultNode);
124  toolbarNode.containerOpen = true;
125 
126  // Add an History query to the toolbar.
127  PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId,
128  PlacesUtils._uri("place:sort=4"),
129  0, // Insert at start.
130  "special_query");
131  // Get first child and check it is the "Most Visited" smart bookmark.
132  ok(toolbarNode.childCount > 0, "Toolbar node has children");
133  var queryNode = toolbarNode.getChild(0);
134  is(queryNode.title, "special_query", "Query node is correctly selected");
135 
136  // Select query node.
137  PO._places.selectNode(queryNode);
138  is(PO._places.selectedNode, queryNode, "We correctly selected query node");
139 
140  // Check that both cut and delete commands are enabled.
141  ok(PO._places.controller.isCommandEnabled("cmd_cut"),
142  "Cut command is enabled");
143  ok(PO._places.controller.isCommandEnabled("cmd_delete"),
144  "Delete command is enabled");
145 
146  // Execute the delete command and check bookmark has been removed.
147  PO._places.controller.doCommand("cmd_delete");
148  try {
149  PlacesUtils.bookmarks.getFolderIdForItem(queryNode.itemId);
150  ok(false, "Unable to remove query node bookmark");
151  } catch(ex) {
152  ok(true, "Query node bookmark has been correctly removed");
153  }
154 
155  toolbarNode.containerOpen = false;
156  nextTest();
157  }
158 });
159 
160 //------------------------------------------------------------------------------
161 
162 function nextTest() {
163  if (gTests.length) {
164  var test = gTests.shift();
165  info("Start of test: " + test.desc);
166  test.run();
167  }
168  else {
169  // Close Library window.
170  gLibrary.close();
171  // No need to cleanup anything, we have a correct left pane now.
172  finish();
173  }
174 }
175 
176 var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
177  getService(Ci.nsIWindowWatcher);
178 
180  observe: function(aSubject, aTopic, aData) {
181  if (aTopic === "domwindowopened") {
182  ww.unregisterNotification(this);
183  gLibrary = aSubject.QueryInterface(Ci.nsIDOMWindow);
184  gLibrary.addEventListener("load", function onLoad(event) {
185  gLibrary.removeEventListener("load", onLoad, false);
186  executeSoon(function () {
187  // Execute tests.
188  nextTest();
189  });
190  }, false);
191  }
192  }
193 };
194 
195 function test() {
197  // Sanity checks.
198  ok(PlacesUtils, "PlacesUtils is running in chrome context");
199  ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
200 
201  // Open Library.
202  ww.registerNotification(windowObserver);
203  ww.openWindow(null,
204  "chrome://browser/content/places/places.xul",
205  "",
206  "chrome,toolbar=yes,dialog=no,resizable",
207  null);
208 }
var PlacesUIUtils
Definition: utils.js:85
const Cc
var event
getService(Ci.sbIFaceplateManager)
Lastfm onLoad
Definition: mini.js:36
waitForExplicitFinish()
return null
Definition: FeedWriter.js:1143
const Ci
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe