browser_library_infoBox.js
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Places test code.
15  *
16  * The Initial Developer of the Original Code is Mozilla Corp.
17  * Portions created by the Initial Developer are Copyright (C) 2009
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Margaret Leibovic <mleibovic@mozilla.com> (Original Author)
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPL"), or
25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26  * in which case the provisions of the GPL or the LGPL are applicable instead
27  * of those above. If you wish to allow use of your version of this file only
28  * under the terms of either the GPL or the LGPL, and not to allow others to
29  * use your version of this file under the terms of the MPL, indicate your
30  * decision by devaring the provisions above and replace them with the notice
31  * and other provisions required by the GPL or the LGPL. If you do not devare
32  * the provisions above, a recipient may use your version of this file under
33  * the terms of any one of the MPL, the GPL or the LGPL.
34  *
35  * ***** END LICENSE BLOCK ***** */
36 
42 const TEST_URI = "http://www.mozilla.org/";
43 
44 var gTests = [];
46 
47 //------------------------------------------------------------------------------
48 
49 gTests.push({
50  desc: "Bug 430148 - Remove or hide the more/less button in details pane...",
51  run: function() {
52  var PO = gLibrary.PlacesOrganizer;
53  var infoBoxExpanderWrapper = getAndCheckElmtById("infoBoxExpanderWrapper");
54 
55  // add a visit to browser history
56  var bhist = PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
57  PlacesUtils.history.addVisit(PlacesUtils._uri(TEST_URI), Date.now() * 1000,
58  null, PlacesUtils.history.TRANSITION_TYPED,
59  false, 0);
60  ok(bhist.isVisited(PlacesUtils._uri(TEST_URI)), "Visit has been added.");
61 
62  // open all bookmarks node
63  PO.selectLeftPaneQuery("AllBookmarks");
64  isnot(PO._places.selectedNode, null,
65  "Correctly selected all bookmarks node.");
67  ok(infoBoxExpanderWrapper.hidden,
68  "Expander button is hidden for all bookmarks node.");
70 
71  // open history node
72  PO.selectLeftPaneQuery("History");
73  isnot(PO._places.selectedNode, null, "Correctly selected history node.");
75  ok(infoBoxExpanderWrapper.hidden,
76  "Expander button is hidden for history node.");
78 
79  // open history child node
80  var historyNode = PO._places.selectedNode.
81  QueryInterface(Ci.nsINavHistoryContainerResultNode);
82  historyNode.containerOpen = true;
83  var childNode = historyNode.getChild(0);
84  isnot(childNode, null, "History node first child is not null.");
85  PO._places.selectNode(childNode);
87  ok(infoBoxExpanderWrapper.hidden,
88  "Expander button is hidden for history child node.");
90 
91  // open history item
92  var view = PO._content.treeBoxObject.view;
93  ok(view.rowCount > 0, "History item exists.");
94  view.selection.select(0);
95  ok(infoBoxExpanderWrapper.hidden,
96  "Expander button is hidden for history item.");
98 
99  historyNode.containerOpen = false;
100 
101  // open bookmarks menu node
102  PO.selectLeftPaneQuery("BookmarksMenu");
103  isnot(PO._places.selectedNode, null,
104  "Correctly selected bookmarks menu node.");
106  ok(infoBoxExpanderWrapper.hidden,
107  "Expander button is hidden for bookmarks menu node.");
109 
110  // open recently bookmarked node
111  var menuNode = PO._places.selectedNode.
112  QueryInterface(Ci.nsINavHistoryContainerResultNode);
113  menuNode.containerOpen = true;
114  childNode = menuNode.getChild(0);
115  isnot(childNode, null, "Bookmarks menu child node exists.");
116  var recentlyBookmarkedTitle = PlacesUIUtils.
117  getString("recentlyBookmarkedTitle");
118  isnot(recentlyBookmarkedTitle, null,
119  "Correctly got the recently bookmarked title locale string.");
120  is(childNode.title, recentlyBookmarkedTitle,
121  "Correctly selected recently bookmarked node.");
122  PO._places.selectNode(childNode);
124  ok(!infoBoxExpanderWrapper.hidden,
125  "Expander button is not hidden for recently bookmarked node.");
127 
128  // open first bookmark
129  var view = PO._content.treeBoxObject.view;
130  ok(view.rowCount > 0, "Bookmark item exists.");
131  view.selection.select(0);
133  ok(!infoBoxExpanderWrapper.hidden,
134  "Expander button is not hidden for bookmark item.");
136  checkAddInfoFields(PO, "bookmark item");
137 
138  // make sure additional fields are still hidden in second bookmark item
139  ok(view.rowCount > 1, "Second bookmark item exists.");
140  view.selection.select(1);
142  ok(!infoBoxExpanderWrapper.hidden,
143  "Expander button is not hidden for second bookmark item.");
145  checkAddInfoFields(PO, "second bookmark item");
146 
147  menuNode.containerOpen = false;
148 
149  bhist.removeAllPages();
150  nextTest();
151  }
152 });
153 
154 function checkInfoBoxSelected(PO) {
155  PO._places.focus();
156  is(getAndCheckElmtById("detailsDeck").selectedIndex, 1,
157  "Selected element in detailsDeck is infoBox.");
158 }
159 
161  PO._additionalInfoFields.forEach(function (id) {
162  ok(getAndCheckElmtById(id).collapsed,
163  "Additional info field correctly collapsed: #" + id);
164  });
165 }
166 
168  ok(PO._additionalInfoFields.some(function (id) {
169  return !getAndCheckElmtById(id).collapsed;
170  }), "Some additional info field correctly not collapsed");
171 }
172 
174  ok(true, "Checking additional info fields visibiity for node: " + nodeName);
175  var expanderButton = getAndCheckElmtById("infoBoxExpander");
176 
177  // make sure additional fields are hidden by default
178  PO._additionalInfoFields.forEach(function (id) {
180  "Additional info field correctly hidden by default: #" + id);
181  });
182 
183  // toggle fields and make sure they are hidden/unhidden as expected
184  expanderButton.click();
185  PO._additionalInfoFields.forEach(function (id) {
186  ok(!getAndCheckElmtById(id).hidden,
187  "Additional info field correctly unhidden after toggle: #" + id);
188  });
189  expanderButton.click();
190  PO._additionalInfoFields.forEach(function (id) {
192  "Additional info field correctly hidden after toggle: #" + id);
193  });
194 }
195 
196 function getAndCheckElmtById(id) {
197  var elmt = gLibrary.document.getElementById(id);
198  isnot(elmt, null, "Correctly got element: #" + id);
199  return elmt;
200 }
201 
202 //------------------------------------------------------------------------------
203 
204 function nextTest() {
205  if (gTests.length) {
206  var test = gTests.shift();
207  ok(true, "TEST: " + test.desc);
208  dump("TEST: " + test.desc + "\n");
209  test.run();
210  }
211  else {
212  // Close Library window.
213  gLibrary.close();
214  // No need to cleanup anything, we have a correct left pane now.
215  finish();
216  }
217 }
218 
219 var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
220  getService(Ci.nsIWindowWatcher);
221 
223  observe: function(aSubject, aTopic, aData) {
224  if (aTopic === "domwindowopened") {
225  ww.unregisterNotification(this);
226  gLibrary = aSubject.QueryInterface(Ci.nsIDOMWindow);
227  gLibrary.addEventListener("load", function onLoad(event) {
228  gLibrary.removeEventListener("load", onLoad, false);
229  executeSoon(function () {
230  // Execute tests.
231  nextTest();
232  });
233  }, false);
234  }
235  }
236 };
237 
238 function test() {
239  dump("Starting test browser_library_infoBox.js\n");
241  // Sanity checks.
242  ok(PlacesUtils, "PlacesUtils is running in chrome context");
243  ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
244 
245  // Open Library.
246  ww.registerNotification(windowObserver);
247  ww.openWindow(null,
248  "chrome://browser/content/places/places.xul",
249  "",
250  "chrome,toolbar=yes,dialog=no,resizable",
251  null);
252 }
var PlacesUIUtils
Definition: utils.js:85
function checkAddInfoFields(PO, nodeName)
const Cc
function checkAddInfoFieldsNotCollapsed(PO)
var event
function getAndCheckElmtById(id)
sbOSDControlService prototype QueryInterface
getService(Ci.sbIFaceplateManager)
function checkInfoBoxSelected(PO)
const TEST_URI
Lastfm onLoad
Definition: mini.js:36
waitForExplicitFinish()
var windowObserver
return null
Definition: FeedWriter.js:1143
function test()
const Ci
var hidden
function nextTest()
function checkAddInfoFieldsCollapsed(PO)
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe