browser_library_left_pane_fixnames.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 var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
44  getService(Ci.nsIWindowWatcher);
45 
46 // Array of left pane queries objects, each one has the following properties:
47 // name: query's identifier got from annotations,
48 // itemId: query's itemId,
49 // correctTitle: original and correct query's title.
50 var leftPaneQueries = [];
51 
53  observe: function(aSubject, aTopic, aData) {
54  if (aTopic === "domwindowopened") {
55  ww.unregisterNotification(this);
56  var organizer = aSubject.QueryInterface(Ci.nsIDOMWindow);
57  organizer.addEventListener("load", function onLoad(event) {
58  organizer.removeEventListener("load", onLoad, false);
59  executeSoon(function () {
60  // Check titles have been fixed.
61  for (var i = 0; i < leftPaneQueries.length; i++) {
62  var query = leftPaneQueries[i];
63  is(PlacesUtils.bookmarks.getItemTitle(query.itemId),
64  query.correctTitle, "Title is correct for query " + query.name);
65  }
66 
67  // Close Library window.
68  organizer.close();
69  // No need to cleanup anything, we have a correct left pane now.
70  finish();
71  });
72  }, false);
73  }
74  }
75 };
76 
77 function test() {
79  // Sanity checks.
80  ok(PlacesUtils, "PlacesUtils is running in chrome context");
81  ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
83  "Left pane version in chrome context, current version is: " + ORGANIZER_LEFTPANE_VERSION );
84 
85  // Ensure left pane is initialized.
86  ok(PlacesUIUtils.leftPaneFolderId > 0, "left pane folder is initialized");
87 
88  // Get the left pane folder.
89  var leftPaneItems = PlacesUtils.annotations
90  .getItemsWithAnnotation(ORGANIZER_FOLDER_ANNO, {});
91 
92  is(leftPaneItems.length, 1, "We correctly have only 1 left pane folder");
93  // Check version.
94  var version = PlacesUtils.annotations
95  .getItemAnnotation(leftPaneItems[0],
97  is(version, ORGANIZER_LEFTPANE_VERSION, "Left pane version is actual");
98 
99  // Get all left pane queries.
100  var items = PlacesUtils.annotations
101  .getItemsWithAnnotation(ORGANIZER_QUERY_ANNO, {});
102  // Get current queries names.
103  for (var i = 0; i < items.length; i++) {
104  var itemId = items[i];
105  var queryName = PlacesUtils.annotations
106  .getItemAnnotation(items[i],
108  leftPaneQueries.push({ name: queryName,
109  itemId: itemId,
110  correctTitle: PlacesUtils.bookmarks
111  .getItemTitle(itemId) });
112  // Rename to a bad title.
113  PlacesUtils.bookmarks.setItemTitle(itemId, "badName");
114  }
115 
116  // Open Library, this will kick-off left pane code.
117  ww.registerNotification(windowObserver);
118  ww.openWindow(null,
119  "chrome://browser/content/places/places.xul",
120  "",
121  "chrome,toolbar=yes,dialog=no,resizable",
122  null);
123 }
var PlacesUIUtils
Definition: utils.js:85
const ORGANIZER_QUERY_ANNO
Definition: utils.js:64
const ORGANIZER_LEFTPANE_VERSION
Definition: utils.js:65
const Cc
var event
version(170)
getService(Ci.sbIFaceplateManager)
Lastfm onLoad
Definition: mini.js:36
waitForExplicitFinish()
return null
Definition: FeedWriter.js:1143
const ORGANIZER_FOLDER_ANNO
Definition: utils.js:63
const Ci
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe