test_browserGlue_restore.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 function run_test() {
45  // Create our bookmarks.html copying bookmarks.glue.html to the profile
46  // folder. It will be ignored.
47  create_bookmarks_html("bookmarks.glue.html");
48 
49  // Create our JSON backup copying bookmarks.glue.json to the profile
50  // folder. It will be ignored.
51  create_JSON_backup("bookmarks.glue.json");
52 
53  // Remove current database file.
54  let db = gProfD.clone();
55  db.append("places.sqlite");
56  if (db.exists()) {
57  db.remove(false);
58  do_check_false(db.exists());
59  }
60 
61  // Initialize nsBrowserGlue before Places.
62  Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
63 
64  // Initialize Places through the History Service.
65  let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
66  getService(Ci.nsINavHistoryService);
67  // Check a new database has been created.
68  // nsBrowserGlue uses databaseStatus to manage initialization.
69  do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE);
70 
71  // Restore could take some time, usually less than 1s.
72  // We will poll later in continue_test() to be sure restore has finished.
73  do_test_pending();
74  do_timeout(1000, "continue_test();");
75 }
76 
77 function continue_test() {
78  let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
79  getService(Ci.nsINavBookmarksService);
80 
81  if (bs.getIdForItemAt(bs.toolbarFolder, 0) == -1) {
82  // Not enough time to complete restore, poll again later.
83  do_timeout(1000, "continue_test();");
84  return;
85  }
86 
87  // Check that JSON backup has been restored.
88  let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
89  do_check_eq(bs.getItemTitle(itemId), "examplejson");
90 
91  do_test_finished();
92 }
const Cc
do_check_eq(typeof PlacesUtils,"object")
function create_bookmarks_html(aFilename)
const SMART_BOOKMARKS_ON_TOOLBAR
getService(Ci.sbIFaceplateManager)
function continue_test()
function run_test()
function create_JSON_backup(aFilename)
const Ci
var gProfD