browser_0_library_left_pane_migration.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 
45 const TEST_URI = "http://www.mozilla.org/";
46 
47 var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
48  getService(Ci.nsIWindowWatcher);
49 
51  observe: function(aSubject, aTopic, aData) {
52  if (aTopic === "domwindowopened") {
53  ww.unregisterNotification(this);
54  var organizer = aSubject.QueryInterface(Ci.nsIDOMWindow);
55  organizer.addEventListener("load", function onLoad(event) {
56  organizer.removeEventListener("load", onLoad, false);
57  executeSoon(function () {
58  // Check left pane.
59  ok(PlacesUIUtils.leftPaneFolderId > 0,
60  "Left pane folder correctly created");
61  var leftPaneItems =
62  PlacesUtils.annotations
63  .getItemsWithAnnotation(ORGANIZER_FOLDER_ANNO, {});
64  is(leftPaneItems.length, 1,
65  "We correctly have only 1 left pane folder");
66  var leftPaneRoot = leftPaneItems[0];
67  is(leftPaneRoot, PlacesUIUtils.leftPaneFolderId,
68  "leftPaneFolderId getter has correct value");
69  // Check version has been upgraded.
70  var version =
71  PlacesUtils.annotations.getItemAnnotation(leftPaneRoot,
73  is(version, ORGANIZER_LEFTPANE_VERSION,
74  "Left pane version has been correctly upgraded");
75 
76  // Check left pane is populated.
77  organizer.PlacesOrganizer.selectLeftPaneQuery('History');
78  is(organizer.PlacesOrganizer._places.selectedNode.itemId,
79  PlacesUIUtils.leftPaneQueries["History"],
80  "Library left pane is populated and working");
81 
82  // Close Library window.
83  organizer.close();
84  // No need to cleanup anything, we have a correct left pane now.
85  finish();
86  });
87  }, false);
88  }
89  }
90 };
91 
92 function test() {
94  // Sanity checks.
95  ok(PlacesUtils, "PlacesUtils is running in chrome context");
96  ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context");
98  "Left pane version in chrome context, current version is: " + ORGANIZER_LEFTPANE_VERSION );
99 
100  // Check if we have any left pane folder already set, remove it eventually.
101  var leftPaneItems = PlacesUtils.annotations
102  .getItemsWithAnnotation(ORGANIZER_FOLDER_ANNO, {});
103  if (leftPaneItems.length > 0) {
104  // The left pane has already been created, touching it now would cause
105  // next tests to rely on wrong values (and possibly crash)
106  is(leftPaneItems.length, 1, "We correctly have only 1 left pane folder");
107  // Check version.
108  var version = PlacesUtils.annotations.getItemAnnotation(leftPaneItems[0],
110  is(version, ORGANIZER_LEFTPANE_VERSION, "Left pane version is actual");
111  ok(true, "left pane has already been created, skipping test");
112  finish();
113  return;
114  }
115 
116  // Create a fake left pane folder with an old version (current version - 1).
117  var fakeLeftPaneRoot =
118  PlacesUtils.bookmarks.createFolder(PlacesUtils.placesRootId, "",
119  PlacesUtils.bookmarks.DEFAULT_INDEX);
120  PlacesUtils.annotations.setItemAnnotation(fakeLeftPaneRoot,
123  0,
124  PlacesUtils.annotations.EXPIRE_NEVER);
125 
126  // Check fake left pane root has been correctly created.
127  var leftPaneItems =
128  PlacesUtils.annotations.getItemsWithAnnotation(ORGANIZER_FOLDER_ANNO, {});
129  is(leftPaneItems.length, 1, "We correctly have only 1 left pane folder");
130  is(leftPaneItems[0], fakeLeftPaneRoot, "left pane root itemId is correct");
131 
132  // Check version.
133  var version = PlacesUtils.annotations.getItemAnnotation(fakeLeftPaneRoot,
135  is(version, ORGANIZER_LEFTPANE_VERSION - 1, "Left pane version correctly set");
136 
137  // Open Library, this will upgrade our left pane version.
138  ww.registerNotification(windowObserver);
139  ww.openWindow(null,
140  "chrome://browser/content/places/places.xul",
141  "",
142  "chrome,toolbar=yes,dialog=no,resizable",
143  null);
144 }
var PlacesUIUtils
Definition: utils.js:85
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
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe