Bug 538765 - cleanup Places browserGlue tests, r=dietrich

This commit is contained in:
Marco Bonardo 2010-02-04 15:56:10 +01:00
Родитель deeaace276
Коммит 32407addb6
7 изменённых файлов: 171 добавлений и 137 удалений

Просмотреть файл

@ -15,7 +15,7 @@
*
* The Original Code is Places Unit Test code.
*
* The Initial Developer of the Original Code is Mozilla Corp.
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
@ -42,12 +42,13 @@
*/
function run_test() {
do_test_pending();
// Create our bookmarks.html copying bookmarks.glue.html to the profile
// folder. It will be ignored.
// folder. It should be ignored.
create_bookmarks_html("bookmarks.glue.html");
// Create our JSON backup copying bookmarks.glue.json to the profile
// folder. It will be ignored.
// Create our JSON backup copying bookmarks.glue.json to the profile folder.
create_JSON_backup("bookmarks.glue.json");
// Remove current database file.
@ -73,25 +74,34 @@ function run_test() {
// nsBrowserGlue uses databaseStatus to manage initialization.
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT);
// Restore could take some time, usually less than 1s.
// We will poll later in continue_test to be sure restore has finished.
do_test_pending();
do_timeout(1000, continue_test);
// Wait for restore to finish.
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let observer = {
observe: function(aSubject, aTopic, aData) {
os.removeObserver(observer, "bookmarks-restore-success");
os.removeObserver(observer, "bookmarks-restore-failed");
do_check_eq(aTopic, "bookmarks-restore-success");
do_check_eq(aData, "json");
continue_test();
}
}
os.addObserver(observer, "bookmarks-restore-success", false);
os.addObserver(observer, "bookmarks-restore-failed", false);
}
function continue_test() {
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
if (bs.getIdForItemAt(bs.toolbarFolder, 0) == -1) {
// Not enough time to complete restore, poll again later.
do_timeout(1000, continue_test);
return;
}
// Check that JSON backup has been restored.
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
// Notice restore from JSON notification is fired before smart bookmarks creation.
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
do_check_neq(itemId, -1);
do_check_eq(bs.getItemTitle(itemId), "examplejson");
remove_bookmarks_html();
remove_all_JSON_backups();
do_test_finished();
}

Просмотреть файл

@ -15,7 +15,7 @@
*
* The Original Code is Places Unit Test code.
*
* The Initial Developer of the Original Code is Mozilla Corp.
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
@ -41,49 +41,23 @@
* is corrupt but a JSON backup is not available.
*/
const NS_PLACES_INIT_COMPLETE_TOPIC = "places-init-complete";
// Create an observer for the Places notifications
var os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
var observer = {
observe: function thn_observe(aSubject, aTopic, aData) {
if (aTopic == NS_PLACES_INIT_COMPLETE_TOPIC) {
os.removeObserver(this, NS_PLACES_INIT_COMPLETE_TOPIC);
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
// Check the database was corrupt.
// nsBrowserGlue uses databaseStatus to manage initialization.
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT);
// Enqueue next part of the test.
var tm = Cc["@mozilla.org/thread-manager;1"].
getService(Ci.nsIThreadManager);
tm.mainThread.dispatch({
run: function() {
continue_test();
}
}, Ci.nsIThread.DISPATCH_NORMAL);
}
}
};
os.addObserver(observer, NS_PLACES_INIT_COMPLETE_TOPIC, false);
function run_test() {
do_test_pending();
// Create bookmarks.html in the profile.
create_bookmarks_html("bookmarks.glue.html");
// Remove JSON backup from profile.
remove_all_JSON_backups();
// Remove current database file.
var db = gProfD.clone();
let db = gProfD.clone();
db.append("places.sqlite");
if (db.exists()) {
db.remove(false);
do_check_false(db.exists());
}
// Create a corrupt database.
var corruptDB = gTestDir.clone();
let corruptDB = gTestDir.clone();
corruptDB.append("corruptDB.sqlite");
corruptDB.copyTo(gProfD, "places.sqlite");
do_check_true(db.exists());
@ -92,20 +66,39 @@ function run_test() {
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
// Initialize Places through the History Service.
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
// Check the database was corrupt.
// nsBrowserGlue uses databaseStatus to manage initialization.
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT);
// Wait for init-complete notification before going on.
do_test_pending();
// Wait for restore to finish.
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let observer = {
observe: function(aSubject, aTopic, aData) {
os.removeObserver(observer, "bookmarks-restore-success");
os.removeObserver(observer, "bookmarks-restore-failed");
do_check_eq(aTopic, "bookmarks-restore-success");
do_check_eq(aData, "html-initial");
continue_test();
}
}
os.addObserver(observer, "bookmarks-restore-success", false);
os.addObserver(observer, "bookmarks-restore-failed", false);
}
function continue_test() {
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
var itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
// Check that bookmarks html has been restored.
// Notice restore from HTML notification is fired after smart bookmarks creation.
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
do_check_neq(itemId, -1);
do_check_eq(bs.getItemTitle(itemId), "example");
remove_bookmarks_html();
do_test_finished();
}

Просмотреть файл

@ -15,7 +15,7 @@
*
* The Original Code is Places Unit Test code.
*
* The Initial Developer of the Original Code is Mozilla Corp.
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
@ -41,49 +41,23 @@
* corrupt, nor a JSON backup nor bookmarks.html are available.
*/
const NS_PLACES_INIT_COMPLETE_TOPIC = "places-init-complete";
// Create an observer for the Places notifications
var os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
var observer = {
observe: function thn_observe(aSubject, aTopic, aData) {
if (aTopic == NS_PLACES_INIT_COMPLETE_TOPIC) {
os.removeObserver(this, NS_PLACES_INIT_COMPLETE_TOPIC);
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
// Check the database was corrupt.
// nsBrowserGlue uses databaseStatus to manage initialization.
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT);
// Enqueue next part of the test.
var tm = Cc["@mozilla.org/thread-manager;1"].
getService(Ci.nsIThreadManager);
tm.mainThread.dispatch({
run: function() {
continue_test();
}
}, Ci.nsIThread.DISPATCH_NORMAL);
}
}
};
os.addObserver(observer, NS_PLACES_INIT_COMPLETE_TOPIC, false);
function run_test() {
do_test_pending();
// Remove bookmarks.html from profile.
remove_bookmarks_html();
// Remove JSON backup from profile.
remove_all_JSON_backups();
// Remove current database file.
var db = gProfD.clone();
let db = gProfD.clone();
db.append("places.sqlite");
if (db.exists()) {
db.remove(false);
do_check_false(db.exists());
}
// Create a corrupt database.
var corruptDB = gTestDir.clone();
let corruptDB = gTestDir.clone();
corruptDB.append("corruptDB.sqlite");
corruptDB.copyTo(gProfD, "places.sqlite");
do_check_true(db.exists());
@ -92,20 +66,36 @@ function run_test() {
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
// Initialize Places through the History Service.
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
// Check the database was corrupt.
// nsBrowserGlue uses databaseStatus to manage initialization.
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT);
// Wait for init-complete notification before going on.
do_test_pending();
// Wait for restore to finish.
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let observer = {
observe: function(aSubject, aTopic, aData) {
os.removeObserver(observer, "bookmarks-restore-success");
os.removeObserver(observer, "bookmarks-restore-failed");
do_check_eq(aTopic, "bookmarks-restore-success");
do_check_eq(aData, "html-initial");
continue_test();
}
}
os.addObserver(observer, "bookmarks-restore-success", false);
os.addObserver(observer, "bookmarks-restore-failed", false);
}
function continue_test() {
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
// Check that default bookmarks have been restored.
var itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR + 1);
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
do_check_true(itemId > 0);
do_check_eq(bs.getItemTitle(itemId), "Getting Started");
do_test_finished();
}

Просмотреть файл

@ -47,22 +47,12 @@ const PREF_BMPROCESSED = "distribution.516444.bookmarksProcessed";
const PREF_DISTRIBUTION_ID = "distribution.id";
const TOPIC_FINAL_UI_STARTUP = "final-ui-startup";
const TOPIC_PLACES_INIT_COMPLETE = "places-init-complete";
const TOPIC_CUSTOMIZATION_COMPLETE = "distribution-customization-complete";
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let observer = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == TOPIC_CUSTOMIZATION_COMPLETE) {
os.removeObserver(this, TOPIC_CUSTOMIZATION_COMPLETE);
do_timeout(0, continue_test);
}
}
}
os.addObserver(observer, TOPIC_CUSTOMIZATION_COMPLETE, false);
function run_test() {
do_test_pending();
// Copy distribution.ini file to our app dir.
let distroDir = dirSvc.get("XCurProcD", Ci.nsIFile);
distroDir.append("distribution");
@ -82,9 +72,10 @@ function run_test() {
let ps = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
// Avoid migrateUI, we are just simulating a partial startup.
ps.setIntPref("browser.migration.version", 1);
// Initialize Places through the History Service, so it won't trigger
// browserGlue::_initPlaces since browserGlue is not yet in context.
// Initialize Places through the History Service.
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
// Check a new database has been created.
@ -92,14 +83,30 @@ function run_test() {
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE);
// Initialize nsBrowserGlue.
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
let bg = Cc["@mozilla.org/browser/browserglue;1"].
getService(Ci.nsIBrowserGlue);
os.notifyObservers(null, TOPIC_FINAL_UI_STARTUP, null);
// places-init-complete is an enqueued notification so it will be notified
// when exiting from this scope.
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let observer = {
observe: function(aSubject, aTopic, aData) {
os.removeObserver(this, TOPIC_PLACES_INIT_COMPLETE);
do_test_pending();
// Test will continue on customization complete notification.
// Simulate browser startup.
bg.QueryInterface(Ci.nsIObserver).observe(null,
TOPIC_FINAL_UI_STARTUP,
null);
// Test will continue on customization complete notification.
let observer = {
observe: function(aSubject, aTopic, aData) {
os.removeObserver(this, TOPIC_CUSTOMIZATION_COMPLETE);
continue_test();
}
}
os.addObserver(observer, TOPIC_CUSTOMIZATION_COMPLETE, false);
}
}
os.addObserver(observer, TOPIC_PLACES_INIT_COMPLETE, false);
}
function continue_test() {

Просмотреть файл

@ -15,7 +15,7 @@
*
* The Original Code is Places Unit Test code.
*
* The Initial Developer of the Original Code is Mozilla Corp.
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
@ -44,8 +44,6 @@
const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion";
const TOPIC_PLACES_INIT_COMPLETE = "places-init-complete";
function run_test() {
// Create our bookmarks.html copying bookmarks.glue.html to the profile
// folder. It will be ignored.
@ -79,13 +77,8 @@ function run_test() {
bs.DEFAULT_INDEX, "migrated");
// Initialize nsBrowserGlue.
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
// Places initialization has already happened, so we need to simulate
// it. This will force browserGlue::_initPlaces().
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
os.notifyObservers(null, TOPIC_PLACES_INIT_COMPLETE, null);
let bg = Cc["@mozilla.org/browser/browserglue;1"].
getService(Ci.nsIBrowserGlue);
// Import could take some time, usually less than 1s, but to be sure we will
// check after 3s.
@ -105,5 +98,7 @@ function continue_test() {
do_check_eq(bs.getIdForItemAt(bs.bookmarksMenuFolder, 1), -1);
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
remove_bookmarks_html();
do_test_finished();
}

Просмотреть файл

@ -15,7 +15,7 @@
*
* The Original Code is Places Unit Test code.
*
* The Initial Developer of the Original Code is Mozilla Corp.
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
@ -42,6 +42,8 @@
*/
function run_test() {
do_test_pending();
// Create our bookmarks.html copying bookmarks.glue.html to the profile
// folder. It will be ignored.
create_bookmarks_html("bookmarks.glue.html");
@ -68,25 +70,33 @@ function run_test() {
// nsBrowserGlue uses databaseStatus to manage initialization.
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE);
// Restore could take some time, usually less than 1s.
// We will poll later in continue_test() to be sure restore has finished.
do_test_pending();
do_timeout(1000, continue_test);
// Wait for restore to finish.
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let observer = {
observe: function(aSubject, aTopic, aData) {
os.removeObserver(observer, "bookmarks-restore-success");
os.removeObserver(observer, "bookmarks-restore-failed");
do_check_eq(aTopic, "bookmarks-restore-success");
do_check_eq(aData, "json");
continue_test();
}
}
os.addObserver(observer, "bookmarks-restore-success", false);
os.addObserver(observer, "bookmarks-restore-failed", false);
}
function continue_test() {
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
if (bs.getIdForItemAt(bs.toolbarFolder, 0) == -1) {
// Not enough time to complete restore, poll again later.
do_timeout(1000, continue_test);
return;
}
// Check that JSON backup has been restored.
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
// Notice restore from JSON notification is fired before smart bookmarks creation.
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
do_check_eq(bs.getItemTitle(itemId), "examplejson");
remove_bookmarks_html();
remove_all_JSON_backups();
do_test_finished();
}

Просмотреть файл

@ -15,7 +15,7 @@
*
* The Original Code is Places Unit Test code.
*
* The Initial Developer of the Original Code is Mozilla Corp.
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
@ -41,7 +41,7 @@
* and creating bookmarks backup if one does not exist for today.
*/
// Initialize nsBrowserGlue.
// Initialize nsBrowserGlue after Places.
let bg = Cc["@mozilla.org/browser/browserglue;1"].
getService(Ci.nsIBrowserGlue);
@ -68,10 +68,19 @@ tests.push({
exec: function() {
// Sanity check: we should have bookmarks on the toolbar.
do_check_true(bs.getIdForItemAt(bs.toolbarFolder, 0) > 0);
// Set preferences.
ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
// Force nsBrowserGlue::_shutdownPlaces().
os.notifyObservers(null, TOPIC_QUIT_APPLICATION_GRANTED, null);
try {
bg.QueryInterface(Ci.nsIObserver).observe(null,
TOPIC_QUIT_APPLICATION_GRANTED,
null);
}
catch(ex) {
// This throws due to idle observer, we can ignore that.
}
// Check bookmarks.html has been created.
check_bookmarks_html();
@ -94,15 +103,25 @@ tests.push({
exec: function() {
// Sanity check: we should have bookmarks on the toolbar.
do_check_true(bs.getIdForItemAt(bs.toolbarFolder, 0) > 0);
// Setpreferences.
// Set preferences.
ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
// Create a bookmarks.html in the profile.
let profileBookmarksHTMLFile = create_bookmarks_html("bookmarks.glue.html");
// Get file lastModified and size.
let lastMod = profileBookmarksHTMLFile.lastModifiedTime;
let fileSize = profileBookmarksHTMLFile.fileSize;
// Force nsBrowserGlue::_shutdownPlaces().
os.notifyObservers(null, TOPIC_QUIT_APPLICATION_GRANTED, null);
try {
bg.QueryInterface(Ci.nsIObserver).observe(null,
TOPIC_QUIT_APPLICATION_GRANTED,
null);
}
catch(ex) {
// This throws due to idle observer, we can ignore that.
}
// Check a new bookmarks.html has been created.
let profileBookmarksHTMLFile = check_bookmarks_html();
@ -126,13 +145,22 @@ tests.push({
exec: function() {
// Sanity check: we should have bookmarks on the toolbar.
do_check_true(bs.getIdForItemAt(bs.toolbarFolder, 0) > 0);
// Create a JSON backup in the profile.
let profileBookmarksJSONFile = create_JSON_backup("bookmarks.glue.json");
// Get file lastModified and size.
let lastMod = profileBookmarksJSONFile.lastModifiedTime;
let fileSize = profileBookmarksJSONFile.fileSize;
// Force nsBrowserGlue::_shutdownPlaces().
os.notifyObservers(null, TOPIC_QUIT_APPLICATION_GRANTED, null);
try {
bg.QueryInterface(Ci.nsIObserver).observe(null,
TOPIC_QUIT_APPLICATION_GRANTED,
null);
}
catch(ex) {
// This throws due to idle observer, we can ignore that.
}
// Check a new JSON backup has not been created.
do_check_true(profileBookmarksJSONFile.exists());
@ -163,6 +191,8 @@ function next_test() {
}
function run_test() {
do_test_pending();
// Clean up bookmarks.
remove_all_bookmarks();
@ -173,6 +203,5 @@ function run_test() {
bs.DEFAULT_INDEX, "bookmark-on-toolbar");
// Kick-off tests.
do_test_pending();
next_test();
}