test_browserGlue_corrupt_nobackup_default.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 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>
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 
44 const NS_PLACES_INIT_COMPLETE_TOPIC = "places-init-complete";
45 
46 // Create an observer for the Places notifications
47 var os = Cc["@mozilla.org/observer-service;1"].
48  getService(Ci.nsIObserverService);
49 var observer = {
50  observe: function thn_observe(aSubject, aTopic, aData) {
51  if (aTopic == NS_PLACES_INIT_COMPLETE_TOPIC) {
52  os.removeObserver(this, NS_PLACES_INIT_COMPLETE_TOPIC);
53  var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
54  getService(Ci.nsINavHistoryService);
55  // Check the database was corrupt.
56  // nsBrowserGlue uses databaseStatus to manage initialization.
57  do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT);
58 
59  // Enqueue next part of the test.
60  var tm = Cc["@mozilla.org/thread-manager;1"].
61  getService(Ci.nsIThreadManager);
62  tm.mainThread.dispatch({
63  run: function() {
64  continue_test();
65  }
66  }, Ci.nsIThread.DISPATCH_NORMAL);
67  }
68  }
69 };
70 
71 function run_test() {
72  // XXX bug 507199
73  // This test is temporarily disabled!
74  return;
75 
76  os.addObserver(observer, NS_PLACES_INIT_COMPLETE_TOPIC, false);
77 
78  // Remove bookmarks.html from profile.
80  // Remove JSON backup from profile.
82 
83  // Remove current database file.
84  var db = gProfD.clone();
85  db.append("places.sqlite");
86  if (db.exists()) {
87  db.remove(false);
88  do_check_false(db.exists());
89  }
90  // Create a corrupt database.
91  corruptDB = gTestDir.clone();
92  corruptDB.append("corruptDB.sqlite");
93  corruptDB.copyTo(gProfD, "places.sqlite");
94  do_check_true(db.exists());
95 
96  // Initialize nsBrowserGlue before Places.
97  Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
98 
99  // Initialize Places through the History Service.
100  var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
101  getService(Ci.nsINavHistoryService);
102 
103  // Wait for init-complete notification before going on.
104  do_test_pending();
105 }
106 
107 function continue_test() {
108  var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
109  getService(Ci.nsINavBookmarksService);
110 
111  // Check that default bookmarks have been restored.
112  var itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR + 1);
113  do_check_true(itemId > 0);
114 
115  do_test_finished();
116 }
const Cc
do_check_eq(typeof PlacesUtils,"object")
const SMART_BOOKMARKS_ON_TOOLBAR
getService(Ci.sbIFaceplateManager)
let gTestDir
function remove_all_JSON_backups()
function remove_bookmarks_html()
const Ci
_updateTextAndScrollDataForFrame aData
var gProfD
sbDeviceFirmwareAutoCheckForUpdate prototype observe