test_browserGlue_distribution.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 Unit Test code.
17  *
18  * The Initial Developer of the Original Code is Mozilla Foundation.
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>
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 deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
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 PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion";
46 const PREF_BMPROCESSED = "distribution.516444.bookmarksProcessed";
47 const PREF_DISTRIBUTION_ID = "distribution.id";
48 
49 const TOPIC_FINAL_UI_STARTUP = "final-ui-startup";
50 const TOPIC_PLACES_INIT_COMPLETE = "places-init-complete";
51 const TOPIC_CUSTOMIZATION_COMPLETE = "distribution-customization-complete";
52 
53 let os = Cc["@mozilla.org/observer-service;1"].
54  getService(Ci.nsIObserverService);
55 
56 let observer = {
57  observe: function(aSubject, aTopic, aData) {
58  if (aTopic == TOPIC_CUSTOMIZATION_COMPLETE) {
59  os.removeObserver(this, TOPIC_CUSTOMIZATION_COMPLETE);
60  do_timeout(0, "continue_test();");
61  }
62  }
63 }
64 os.addObserver(observer, TOPIC_CUSTOMIZATION_COMPLETE, false);
65 
66 function run_test() {
67  // Copy distribution.ini file to our app dir.
68  let distroDir = dirSvc.get("XCurProcD", Ci.nsIFile);
69  distroDir.append("distribution");
70  let iniFile = distroDir.clone();
71  iniFile.append("distribution.ini");
72  if (iniFile.exists()) {
73  iniFile.remove(false);
74  print("distribution.ini already exists, did some test forget to cleanup?");
75  }
76 
77  let testDistributionFile = gTestDir.clone();
78  testDistributionFile.append("distribution.ini");
79  testDistributionFile.copyTo(distroDir, "distribution.ini");
80  do_check_true(testDistributionFile.exists());
81 
82  // Disable Smart Bookmarks creation.
83  let ps = Cc["@mozilla.org/preferences-service;1"].
84  getService(Ci.nsIPrefBranch);
85  ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
86 
87  // Initialize Places through the History Service, so it won't trigger
88  // browserGlue::_initPlaces since browserGlue is not yet in context.
89  let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
90  getService(Ci.nsINavHistoryService);
91  // Check a new database has been created.
92  // nsBrowserGlue will use databaseStatus to manage initialization.
93  do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE);
94 
95  // Initialize nsBrowserGlue.
96  Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
97 
98  // Places initialization has already happened, so we need to simulate a new
99  // one. This will force browserGlue::_initPlaces().
100  os.notifyObservers(null, TOPIC_FINAL_UI_STARTUP, null);
101  os.notifyObservers(null, TOPIC_PLACES_INIT_COMPLETE, null);
102 
103  do_test_pending();
104  // Test will continue on customization complete notification.
105 }
106 
107 function continue_test() {
108  let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
109  getService(Ci.nsINavBookmarksService);
110 
111  // Check the custom bookmarks exist on menu.
112  let menuItemId = bs.getIdForItemAt(bs.bookmarksMenuFolder, 0);
113  do_check_neq(menuItemId, -1);
114  do_check_eq(bs.getItemTitle(menuItemId), "Menu Link Before");
115  menuItemId = bs.getIdForItemAt(bs.bookmarksMenuFolder, 1 + DEFAULT_BOOKMARKS_ON_MENU);
116  do_check_neq(menuItemId, -1);
117  do_check_eq(bs.getItemTitle(menuItemId), "Menu Link After");
118 
119  // Check the custom bookmarks exist on toolbar.
120  let toolbarItemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
121  do_check_neq(toolbarItemId, -1);
122  do_check_eq(bs.getItemTitle(toolbarItemId), "Toolbar Link Before");
123  toolbarItemId = bs.getIdForItemAt(bs.toolbarFolder, 1 + DEFAULT_BOOKMARKS_ON_TOOLBAR);
124  do_check_neq(toolbarItemId, -1);
125  do_check_eq(bs.getItemTitle(toolbarItemId), "Toolbar Link After");
126 
127  // Check the bmprocessed pref has been created.
128  let ps = Cc["@mozilla.org/preferences-service;1"].
129  getService(Ci.nsIPrefBranch);
130  do_check_true(ps.getBoolPref(PREF_BMPROCESSED));
131 
132  // Check distribution prefs have been created.
133  do_check_eq(ps.getCharPref(PREF_DISTRIBUTION_ID), "516444");
134 
135  do_test_finished();
136 }
137 
138 do_register_cleanup(function() {
139  // Remove the distribution file, even if the test failed, otherwise all
140  // next tests will import it.
141  let iniFile = dirSvc.get("XCurProcD", Ci.nsIFile);
142  iniFile.append("distribution");
143  iniFile.append("distribution.ini");
144  iniFile.remove(false);
145  do_check_false(iniFile.exists());
146 });
const Cc
do_check_eq(typeof PlacesUtils,"object")
var dirSvc
function continue_test()
const PREF_SMART_BOOKMARKS_VERSION
const DEFAULT_BOOKMARKS_ON_TOOLBAR
const PREF_DISTRIBUTION_ID
do_register_cleanup(function(){let iniFile=dirSvc.get("XCurProcD", Ci.nsIFile);iniFile.append("distribution");iniFile.append("distribution.ini");iniFile.remove(false);do_check_false(iniFile.exists());})
const DEFAULT_BOOKMARKS_ON_MENU
getService(Ci.sbIFaceplateManager)
const TOPIC_CUSTOMIZATION_COMPLETE
let gTestDir
const TOPIC_PLACES_INIT_COMPLETE
return null
Definition: FeedWriter.js:1143
const Ci
const PREF_BMPROCESSED
function run_test()
const TOPIC_FINAL_UI_STARTUP
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe