зеркало из https://github.com/mozilla/pjs.git
Bug 474582 - With initial migration Shiretoko doesn't import favorites from Internet Explorer 7 anymore, r=dietrich
This commit is contained in:
Родитель
8225820f73
Коммит
a87fbe4503
|
@ -1335,14 +1335,6 @@ nsIEProfileMigrator::CopyFavorites(PRBool aReplace) {
|
||||||
// read Favorites folder if it exists on the machine.
|
// read Favorites folder if it exists on the machine.
|
||||||
if (favoritesDirectory) {
|
if (favoritesDirectory) {
|
||||||
rv = ParseFavoritesFolder(favoritesDirectory, folder, bms, personalToolbarFolderName, PR_TRUE);
|
rv = ParseFavoritesFolder(favoritesDirectory, folder, bms, personalToolbarFolderName, PR_TRUE);
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
// after importing the favorites,
|
|
||||||
// we need to set this pref so that on startup
|
|
||||||
// we don't blow away what we just imported
|
|
||||||
nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
|
||||||
NS_ENSURE_TRUE(pref, NS_ERROR_FAILURE);
|
|
||||||
rv = pref->SetBoolPref("browser.places.importBookmarksHTML", PR_FALSE);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1098,13 +1098,6 @@ nsOperaProfileMigrator::CopyBookmarks(PRBool aReplace)
|
||||||
rv = ParseBookmarksFolder(lineInputStream, parentFolder, toolbar, bms);
|
rv = ParseBookmarksFolder(lineInputStream, parentFolder, toolbar, bms);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
// after importing the favorites,
|
|
||||||
// we need to set this pref so that on startup
|
|
||||||
// we don't blow away what we just imported
|
|
||||||
nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
|
||||||
NS_ENSURE_TRUE(pref, NS_ERROR_FAILURE);
|
|
||||||
rv = pref->SetBoolPref("browser.places.importBookmarksHTML", PR_FALSE);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -942,15 +942,6 @@ nsSafariProfileMigrator::CopyBookmarks(PRBool aReplace)
|
||||||
(CFArrayRef)::CFDictionaryGetValue(safariBookmarks, CFSTR("Children"));
|
(CFArrayRef)::CFDictionaryGetValue(safariBookmarks, CFSTR("Children"));
|
||||||
if (children) {
|
if (children) {
|
||||||
rv = ParseBookmarksFolder(children, folder, bms, PR_TRUE);
|
rv = ParseBookmarksFolder(children, folder, bms, PR_TRUE);
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
// after importing the favorites,
|
|
||||||
// we need to set this pref so that on startup
|
|
||||||
// we don't blow away what we just imported
|
|
||||||
nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
|
||||||
NS_ENSURE_TRUE(pref, NS_ERROR_FAILURE);
|
|
||||||
rv = pref->SetBoolPref("browser.places.importBookmarksHTML", PR_FALSE);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -732,9 +732,10 @@ nsSeamonkeyProfileMigrator::CopyPasswords(PRBool aReplace)
|
||||||
nsresult
|
nsresult
|
||||||
nsSeamonkeyProfileMigrator::CopyBookmarks(PRBool aReplace)
|
nsSeamonkeyProfileMigrator::CopyBookmarks(PRBool aReplace)
|
||||||
{
|
{
|
||||||
|
nsresult rv;
|
||||||
if (aReplace) {
|
if (aReplace) {
|
||||||
// Initialize the default bookmarks
|
// Initialize the default bookmarks
|
||||||
nsresult rv = InitializeBookmarks(mTargetProfile);
|
rv = InitializeBookmarks(mTargetProfile);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
// Merge in the bookmarks from the source profile
|
// Merge in the bookmarks from the source profile
|
||||||
|
@ -743,17 +744,13 @@ nsSeamonkeyProfileMigrator::CopyBookmarks(PRBool aReplace)
|
||||||
sourceFile->Append(FILE_NAME_BOOKMARKS);
|
sourceFile->Append(FILE_NAME_BOOKMARKS);
|
||||||
rv = ImportBookmarksHTML(sourceFile, PR_TRUE, PR_FALSE, EmptyString().get());
|
rv = ImportBookmarksHTML(sourceFile, PR_TRUE, PR_FALSE, EmptyString().get());
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
// we need to set this pref so that on startup
|
|
||||||
// we don't blow away what we just imported
|
|
||||||
nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
return pref->SetBoolPref("browser.places.importBookmarksHTML", PR_FALSE);
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
return ImportNetscapeBookmarks(FILE_NAME_BOOKMARKS,
|
rv = ImportNetscapeBookmarks(FILE_NAME_BOOKMARKS,
|
||||||
NS_LITERAL_STRING("sourceNameSeamonkey").get());
|
NS_LITERAL_STRING("sourceNameSeamonkey").get());
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
|
|
|
@ -509,6 +509,18 @@ BrowserGlue.prototype = {
|
||||||
var importBookmarks = databaseStatus == histsvc.DATABASE_STATUS_CREATE ||
|
var importBookmarks = databaseStatus == histsvc.DATABASE_STATUS_CREATE ||
|
||||||
databaseStatus == histsvc.DATABASE_STATUS_CORRUPT;
|
databaseStatus == histsvc.DATABASE_STATUS_CORRUPT;
|
||||||
|
|
||||||
|
if (databaseStatus == histsvc.DATABASE_STATUS_CREATE) {
|
||||||
|
// If the database has just been created, but we already have any
|
||||||
|
// bookmark, this is not the initial import. This can happen after a
|
||||||
|
// migration from a different browser since migrators run before us.
|
||||||
|
// In such a case we should not import, unless some pref has been set.
|
||||||
|
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||||
|
getService(Ci.nsINavBookmarksService);
|
||||||
|
if (bmsvc.getIdForItemAt(bmsvc.bookmarksMenuFolder, 0) != -1 ||
|
||||||
|
bmsvc.getIdForItemAt(bmsvc.toolbarFolder, 0) != -1)
|
||||||
|
importBookmarks = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if user or an extension has required to import bookmarks.html
|
// Check if user or an extension has required to import bookmarks.html
|
||||||
var importBookmarksHTML = false;
|
var importBookmarksHTML = false;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
||||||
|
<!-- This is an automatically generated file.
|
||||||
|
It will be read and overwritten.
|
||||||
|
DO NOT EDIT! -->
|
||||||
|
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
||||||
|
<TITLE>Bookmarks</TITLE>
|
||||||
|
<H1>Bookmarks Menu</H1>
|
||||||
|
|
||||||
|
<DL><p>
|
||||||
|
<DT><A HREF="http://example.com/" ADD_DATE="1233157972" LAST_MODIFIED="1233157984">example</A>
|
||||||
|
<DT><H3 ADD_DATE="1233157910" LAST_MODIFIED="1233157972" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks Toolbar</H3>
|
||||||
|
<DD>Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar
|
||||||
|
<DL><p>
|
||||||
|
<DT><A HREF="http://example.com/" ADD_DATE="1233157972" LAST_MODIFIED="1233157984">example</A>
|
||||||
|
</DL><p>
|
||||||
|
</DL><p>
|
|
@ -0,0 +1 @@
|
||||||
|
{"title":"","id":1,"dateAdded":1233157910552624,"lastModified":1233157955206833,"type":"text/x-moz-place-container","root":"placesRoot","children":[{"title":"Bookmarks Menu","id":2,"parent":1,"dateAdded":1233157910552624,"lastModified":1233157993171424,"type":"text/x-moz-place-container","root":"bookmarksMenuFolder","children":[{"title":"examplejson","id":27,"parent":2,"dateAdded":1233157972101126,"lastModified":1233157984999673,"type":"text/x-moz-place","uri":"http://example.com/"}]},{"index":1,"title":"Bookmarks Toolbar","id":3,"parent":1,"dateAdded":1233157910552624,"lastModified":1233157972101126,"annos":[{"name":"bookmarkProperties/description","flags":0,"expires":4,"mimeType":null,"type":3,"value":"Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar"}],"type":"text/x-moz-place-container","root":"toolbarFolder","children":[{"title":"examplejson","id":26,"parent":3,"dateAdded":1233157972101126,"lastModified":1233157984999673,"type":"text/x-moz-place","uri":"http://example.com/"}]},{"index":2,"title":"Tags","id":4,"parent":1,"dateAdded":1233157910552624,"lastModified":1233157910582667,"type":"text/x-moz-place-container","root":"tagsFolder","children":[]},{"index":3,"title":"Unsorted Bookmarks","id":5,"parent":1,"dateAdded":1233157910552624,"lastModified":1233157911033315,"type":"text/x-moz-place-container","root":"unfiledBookmarksFolder","children":[]},]}
|
Двоичный файл не отображается.
|
@ -41,6 +41,8 @@ version(170);
|
||||||
|
|
||||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||||
const NS_APP_PROFILE_DIR_STARTUP = "ProfDS";
|
const NS_APP_PROFILE_DIR_STARTUP = "ProfDS";
|
||||||
|
const NS_APP_BOOKMARKS_50_FILE = "BMarks";
|
||||||
|
|
||||||
var Ci = Components.interfaces;
|
var Ci = Components.interfaces;
|
||||||
var Cc = Components.classes;
|
var Cc = Components.classes;
|
||||||
var Cr = Components.results;
|
var Cr = Components.results;
|
||||||
|
@ -74,6 +76,11 @@ var dirProvider = {
|
||||||
if (prop == NS_APP_USER_PROFILE_50_DIR ||
|
if (prop == NS_APP_USER_PROFILE_50_DIR ||
|
||||||
prop == NS_APP_PROFILE_DIR_STARTUP)
|
prop == NS_APP_PROFILE_DIR_STARTUP)
|
||||||
return gProfD.clone();
|
return gProfD.clone();
|
||||||
|
else if (prop == NS_APP_BOOKMARKS_50_FILE) {
|
||||||
|
var bmarks = gProfD.clone();
|
||||||
|
bmarks.append("bookmarks.html");
|
||||||
|
return bmarks;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
QueryInterface: function(iid) {
|
QueryInterface: function(iid) {
|
||||||
|
@ -126,11 +133,6 @@ var updateSvc = Cc["@mozilla.org/updates/update-service;1"].
|
||||||
|
|
||||||
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||||
|
|
||||||
// The following components need to be initialized to perform tests without
|
|
||||||
// asserting in debug builds (Bug 448804).
|
|
||||||
Cc["@mozilla.org/browser/livemark-service;2"].getService(Ci.nsILivemarkService);
|
|
||||||
Cc["@mozilla.org/feed-processor;1"].createInstance(Ci.nsIFeedProcessor);
|
|
||||||
|
|
||||||
function uri(spec) {
|
function uri(spec) {
|
||||||
return iosvc.newURI(spec, null, null);
|
return iosvc.newURI(spec, null, null);
|
||||||
}
|
}
|
||||||
|
@ -167,3 +169,107 @@ function check_no_bookmarks() {
|
||||||
do_check_eq(root.childCount, 0);
|
do_check_eq(root.childCount, 0);
|
||||||
root.containerOpen = false;
|
root.containerOpen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let gTestDir = do_get_file("browser/components/places/tests/unit/");
|
||||||
|
const FILENAME_BOOKMARKS_HTML = "bookmarks.html";
|
||||||
|
let backup_date = new Date().toLocaleFormat("%Y-%m-%d");
|
||||||
|
const FILENAME_BOOKMARKS_JSON = "bookmarks-" + backup_date + ".json";
|
||||||
|
// Number of smart bookmarks we have on the toolbar
|
||||||
|
const SMART_BOOKMARKS_ON_TOOLBAR = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a bookmarks.html file in the profile folder from a given source file.
|
||||||
|
*
|
||||||
|
* @param aFilename
|
||||||
|
* Name of the file to copy to the profile folder. This file must
|
||||||
|
* exist in the directory that contains the test files.
|
||||||
|
*
|
||||||
|
* @return nsIFile object for the file.
|
||||||
|
*/
|
||||||
|
function create_bookmarks_html(aFilename) {
|
||||||
|
remove_bookmarks_html();
|
||||||
|
let bookmarksHTMLFile = gTestDir.clone();
|
||||||
|
bookmarksHTMLFile.append(aFilename);
|
||||||
|
do_check_true(bookmarksHTMLFile.exists());
|
||||||
|
bookmarksHTMLFile.copyTo(gProfD, FILENAME_BOOKMARKS_HTML);
|
||||||
|
let profileBookmarksHTMLFile = gProfD.clone();
|
||||||
|
profileBookmarksHTMLFile.append(FILENAME_BOOKMARKS_HTML);
|
||||||
|
do_check_true(profileBookmarksHTMLFile.exists());
|
||||||
|
return profileBookmarksHTMLFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove bookmarks.html file from the profile folder.
|
||||||
|
*/
|
||||||
|
function remove_bookmarks_html() {
|
||||||
|
let profileBookmarksHTMLFile = gProfD.clone();
|
||||||
|
profileBookmarksHTMLFile.append(FILENAME_BOOKMARKS_HTML);
|
||||||
|
if (profileBookmarksHTMLFile.exists()) {
|
||||||
|
profileBookmarksHTMLFile.remove(false);
|
||||||
|
do_check_false(profileBookmarksHTMLFile.exists());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check bookmarks.html file exists in the profile folder.
|
||||||
|
*
|
||||||
|
* @return nsIFile object for the file.
|
||||||
|
*/
|
||||||
|
function check_bookmarks_html() {
|
||||||
|
let profileBookmarksHTMLFile = gProfD.clone();
|
||||||
|
profileBookmarksHTMLFile.append(FILENAME_BOOKMARKS_HTML);
|
||||||
|
do_check_true(profileBookmarksHTMLFile.exists());
|
||||||
|
return profileBookmarksHTMLFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a JSON backup in the profile folder folder from a given source file.
|
||||||
|
*
|
||||||
|
* @param aFilename
|
||||||
|
* Name of the file to copy to the profile folder. This file must
|
||||||
|
* exist in the directory that contains the test files.
|
||||||
|
*
|
||||||
|
* @return nsIFile object for the file.
|
||||||
|
*/
|
||||||
|
function create_JSON_backup(aFilename) {
|
||||||
|
remove_all_JSON_backups();
|
||||||
|
let bookmarksBackupDir = gProfD.clone();
|
||||||
|
bookmarksBackupDir.append("bookmarkbackups");
|
||||||
|
if (!bookmarksBackupDir.exists()) {
|
||||||
|
bookmarksBackupDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0777);
|
||||||
|
do_check_true(bookmarksBackupDir.exists());
|
||||||
|
}
|
||||||
|
let bookmarksJSONFile = gTestDir.clone();
|
||||||
|
bookmarksJSONFile.append(aFilename);
|
||||||
|
do_check_true(bookmarksJSONFile.exists());
|
||||||
|
bookmarksJSONFile.copyTo(bookmarksBackupDir, FILENAME_BOOKMARKS_JSON);
|
||||||
|
let profileBookmarksJSONFile = bookmarksBackupDir.clone();
|
||||||
|
profileBookmarksJSONFile.append(FILENAME_BOOKMARKS_JSON);
|
||||||
|
do_check_true(profileBookmarksJSONFile.exists());
|
||||||
|
return profileBookmarksJSONFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove bookmarksbackup dir and all backups from the profile folder.
|
||||||
|
*/
|
||||||
|
function remove_all_JSON_backups() {
|
||||||
|
let bookmarksBackupDir = gProfD.clone();
|
||||||
|
bookmarksBackupDir.append("bookmarkbackups");
|
||||||
|
if (bookmarksBackupDir.exists()) {
|
||||||
|
bookmarksBackupDir.remove(true);
|
||||||
|
do_check_false(bookmarksBackupDir.exists());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check a JSON backup file for today exists in the profile folder.
|
||||||
|
*
|
||||||
|
* @return nsIFile object for the file.
|
||||||
|
*/
|
||||||
|
function check_JSON_backup() {
|
||||||
|
let profileBookmarksJSONFile = gProfD.clone();
|
||||||
|
profileBookmarksJSONFile.append("bookmarkbackups");
|
||||||
|
profileBookmarksJSONFile.append(FILENAME_BOOKMARKS_JSON);
|
||||||
|
do_check_true(profileBookmarksJSONFile.exists());
|
||||||
|
return profileBookmarksJSONFile;
|
||||||
|
}
|
||||||
|
|
|
@ -43,3 +43,14 @@ var os = Cc['@mozilla.org/observer-service;1'].
|
||||||
getService(Ci.nsIObserverService);
|
getService(Ci.nsIObserverService);
|
||||||
os.notifyObservers(null, "quit-application-granted", null);
|
os.notifyObservers(null, "quit-application-granted", null);
|
||||||
os.notifyObservers(null, "quit-application", null);
|
os.notifyObservers(null, "quit-application", null);
|
||||||
|
|
||||||
|
// try to close the connection so we can remove places.sqlite
|
||||||
|
var pip = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||||
|
getService(Ci.nsINavHistoryService).
|
||||||
|
QueryInterface(Ci.nsPIPlacesDatabase);
|
||||||
|
if (pip.DBConnection.connectionReady) {
|
||||||
|
pip.commitPendingChanges();
|
||||||
|
pip.finalizeInternalStatements();
|
||||||
|
pip.DBConnection.close();
|
||||||
|
do_check_false(pip.DBConnection.connectionReady);
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,11 @@
|
||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
// The following components need to be initialized to perform tests without
|
||||||
|
// asserting in debug builds (Bug 448804).
|
||||||
|
Cc["@mozilla.org/browser/livemark-service;2"].getService(Ci.nsILivemarkService);
|
||||||
|
Cc["@mozilla.org/feed-processor;1"].createInstance(Ci.nsIFeedProcessor);
|
||||||
|
|
||||||
const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar";
|
const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar";
|
||||||
const DESCRIPTION_ANNO = "bookmarkProperties/description";
|
const DESCRIPTION_ANNO = "bookmarkProperties/description";
|
||||||
const POST_DATA_ANNO = "bookmarkProperties/POSTData";
|
const POST_DATA_ANNO = "bookmarkProperties/POSTData";
|
||||||
|
|
|
@ -87,6 +87,7 @@ function run_test() {
|
||||||
var stmt = dbConn.createStatement("UPDATE moz_bookmarks SET fk = NULL WHERE id = :itemId");
|
var stmt = dbConn.createStatement("UPDATE moz_bookmarks SET fk = NULL WHERE id = :itemId");
|
||||||
stmt.params.itemId = corruptItemId;
|
stmt.params.itemId = corruptItemId;
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
|
stmt.finalize();
|
||||||
|
|
||||||
// Export bookmarks
|
// Export bookmarks
|
||||||
var bookmarksFile = dirSvc.get("ProfD", Ci.nsILocalFile);
|
var bookmarksFile = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Places Unit Test code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Mozilla Corp.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Marco Bonardo <mak77@bonardo.net>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that nsBrowserGlue correctly restores bookmarks from a JSON backup if
|
||||||
|
* database is corrupt and one backup is available.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function run_test() {
|
||||||
|
// Create our bookmarks.html copying bookmarks.glue.html to the profile
|
||||||
|
// folder. It will 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_JSON_backup("bookmarks.glue.json");;
|
||||||
|
|
||||||
|
// Remove current database file.
|
||||||
|
let db = gProfD.clone();
|
||||||
|
db.append("places.sqlite");
|
||||||
|
if (db.exists()) {
|
||||||
|
db.remove(false);
|
||||||
|
do_check_false(db.exists());
|
||||||
|
}
|
||||||
|
// Create a corrupt database.
|
||||||
|
corruptDB = gTestDir.clone();
|
||||||
|
corruptDB.append("corruptDB.sqlite");
|
||||||
|
corruptDB.copyTo(gProfD, "places.sqlite");
|
||||||
|
do_check_true(db.exists());
|
||||||
|
|
||||||
|
// Initialize nsBrowserGlue before Places.
|
||||||
|
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
|
||||||
|
|
||||||
|
// Initialize Places through the History Service.
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 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();");
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
do_check_eq(bs.getItemTitle(itemId), "examplejson");
|
||||||
|
|
||||||
|
do_test_finished();
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Places Unit Test code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Mozilla Corp.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Marco Bonardo <mak77@bonardo.net>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that nsBrowserGlue correctly imports from bookmarks.html if database
|
||||||
|
* is corrupt but a JSON backup is not available.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function run_test() {
|
||||||
|
// Create bookmarks.html in the profile.
|
||||||
|
create_bookmarks_html();
|
||||||
|
// Remove JSON backup from profile.
|
||||||
|
remove_all_JSON_backups();
|
||||||
|
|
||||||
|
// Remove current database file.
|
||||||
|
let db = gProfD.clone();
|
||||||
|
db.append("places.sqlite");
|
||||||
|
if (db.exists()) {
|
||||||
|
db.remove(false);
|
||||||
|
do_check_false(db.exists());
|
||||||
|
}
|
||||||
|
// Create a corrupt database.
|
||||||
|
corruptDB = gTestDir.clone();
|
||||||
|
corruptDB.append("corruptDB.sqlite");
|
||||||
|
corruptDB.copyTo(gProfD, "places.sqlite");
|
||||||
|
do_check_true(db.exists());
|
||||||
|
|
||||||
|
// Initialize nsBrowserGlue before Places.
|
||||||
|
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
|
||||||
|
|
||||||
|
// Initialize Places through the History Service.
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 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();");
|
||||||
|
}
|
||||||
|
|
||||||
|
function continue_test() {
|
||||||
|
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||||
|
getService(Ci.nsINavBookmarksService);
|
||||||
|
do_test_finished();
|
||||||
|
if (bs.getIdForItemAt(bs.toolbarFolder, 0) == -1) {
|
||||||
|
// Not enough time to complete restore, poll again later.
|
||||||
|
do_timeout(1000, "continue_test();");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that default bookmarks have been restored.
|
||||||
|
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
|
||||||
|
do_check_eq(bs.getItemTitle(itemId), "example");
|
||||||
|
|
||||||
|
do_test_finished();
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Places Unit Test code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Mozilla Corp.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Marco Bonardo <mak77@bonardo.net>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that nsBrowserGlue correctly restores default bookmarks if database is
|
||||||
|
* corrupt, nor a JSON backup nor bookmarks.html are available.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function run_test() {
|
||||||
|
// Remove bookmarks.html from profile.
|
||||||
|
remove_bookmarks_html();
|
||||||
|
// Remove JSON backup from profile.
|
||||||
|
remove_all_JSON_backups();
|
||||||
|
|
||||||
|
// Remove current database file.
|
||||||
|
let db = gProfD.clone();
|
||||||
|
db.append("places.sqlite");
|
||||||
|
if (db.exists()) {
|
||||||
|
db.remove(false);
|
||||||
|
do_check_false(db.exists());
|
||||||
|
}
|
||||||
|
// Create a corrupt database.
|
||||||
|
corruptDB = gTestDir.clone();
|
||||||
|
corruptDB.append("corruptDB.sqlite");
|
||||||
|
corruptDB.copyTo(gProfD, "places.sqlite");
|
||||||
|
do_check_true(db.exists());
|
||||||
|
|
||||||
|
// Initialize nsBrowserGlue before Places.
|
||||||
|
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
|
||||||
|
|
||||||
|
// Initialize Places through the History Service.
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 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();");
|
||||||
|
}
|
||||||
|
|
||||||
|
function continue_test() {
|
||||||
|
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||||
|
getService(Ci.nsINavBookmarksService);
|
||||||
|
|
||||||
|
if (bs.getIdForItemAt(bs.toolbarFolder, 1) == -1) {
|
||||||
|
// Not enough time to complete restore, poll again later.
|
||||||
|
do_timeout(1000, "continue_test();");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that default bookmarks have been restored.
|
||||||
|
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR + 1);
|
||||||
|
do_check_true(itemId > 0);
|
||||||
|
|
||||||
|
do_test_finished();
|
||||||
|
}
|
|
@ -0,0 +1,109 @@
|
||||||
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Places Unit Test code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Mozilla Corp.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Marco Bonardo <mak77@bonardo.net>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that nsBrowserGlue does not overwrite bookmarks imported from the
|
||||||
|
* migrators. They usually run before nsBrowserGlue, so if we find any
|
||||||
|
* bookmark on init, we should not try to import.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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.
|
||||||
|
create_bookmarks_html("bookmarks.glue.html");
|
||||||
|
|
||||||
|
// Remove current database file.
|
||||||
|
let db = gProfD.clone();
|
||||||
|
db.append("places.sqlite");
|
||||||
|
if (db.exists()) {
|
||||||
|
db.remove(false);
|
||||||
|
do_check_false(db.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable Smart Bookmarks creation.
|
||||||
|
let ps = Cc["@mozilla.org/preferences-service;1"].
|
||||||
|
getService(Ci.nsIPrefBranch);
|
||||||
|
ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
// nsBrowserGlue uses databaseStatus to manage initialization.
|
||||||
|
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE);
|
||||||
|
|
||||||
|
// A migrator would run before nsBrowserGlue, so we mimic that behavior
|
||||||
|
// adding a bookmark.
|
||||||
|
bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||||
|
getService(Ci.nsINavBookmarksService);
|
||||||
|
bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://mozilla.org/"),
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Import could take some time, usually less than 1s, but to be sure we will
|
||||||
|
// check after 3s.
|
||||||
|
do_test_pending();
|
||||||
|
do_timeout(3000, "continue_test();");
|
||||||
|
}
|
||||||
|
|
||||||
|
function continue_test() {
|
||||||
|
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||||
|
getService(Ci.nsINavBookmarksService);
|
||||||
|
|
||||||
|
// Check the created bookmarks still exist.
|
||||||
|
let itemId = bs.getIdForItemAt(bs.bookmarksMenuFolder, 0);
|
||||||
|
do_check_eq(bs.getItemTitle(itemId), "migrated");
|
||||||
|
|
||||||
|
// Check that we have not imported any new bookmark.
|
||||||
|
do_check_eq(bs.getIdForItemAt(bs.bookmarksMenuFolder, 1), -1);
|
||||||
|
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||||
|
|
||||||
|
do_test_finished();
|
||||||
|
}
|
|
@ -0,0 +1,243 @@
|
||||||
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Places Unit Test code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Mozilla Corp.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Marco Bonardo <mak77@bonardo.net>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that nsBrowserGlue is correctly interpreting the preferences settable
|
||||||
|
* by the user or by other components.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Initialize browserGlue.
|
||||||
|
let bg = Cc["@mozilla.org/browser/browserglue;1"].
|
||||||
|
getService(Ci.nsIBrowserGlue);
|
||||||
|
|
||||||
|
// Initialize Places through Bookmarks Service.
|
||||||
|
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||||
|
getService(Ci.nsINavBookmarksService);
|
||||||
|
|
||||||
|
// Get other services.
|
||||||
|
let ps = Cc["@mozilla.org/preferences-service;1"].
|
||||||
|
getService(Ci.nsIPrefBranch);
|
||||||
|
let os = Cc["@mozilla.org/observer-service;1"].
|
||||||
|
getService(Ci.nsIObserverService);
|
||||||
|
|
||||||
|
const PREF_IMPORT_BOOKMARKS_HTML = "browser.places.importBookmarksHTML";
|
||||||
|
const PREF_RESTORE_DEFAULT_BOOKMARKS = "browser.bookmarks.restore_default_bookmarks";
|
||||||
|
const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion";
|
||||||
|
const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML";
|
||||||
|
|
||||||
|
const TOPIC_PLACES_INIT_COMPLETE = "places-init-complete";
|
||||||
|
|
||||||
|
let tests = [];
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
tests.push({
|
||||||
|
description: "Import from bookmarks.html if importBookmarksHTML is true.",
|
||||||
|
exec: function() {
|
||||||
|
// Sanity check: we should not have any bookmark on the toolbar.
|
||||||
|
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||||
|
// Set preferences.
|
||||||
|
ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||||
|
// Force nsBrowserGlue::_initPlaces().
|
||||||
|
os.notifyObservers(null, TOPIC_PLACES_INIT_COMPLETE, null);
|
||||||
|
|
||||||
|
// Check bookmarks.html has been imported, and a smart bookmark has been
|
||||||
|
// created.
|
||||||
|
let itemId = bs.getIdForItemAt(bs.toolbarFolder,
|
||||||
|
SMART_BOOKMARKS_ON_TOOLBAR);
|
||||||
|
do_check_eq(bs.getItemTitle(itemId), "example");
|
||||||
|
// Check preferences have been reverted.
|
||||||
|
do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||||
|
|
||||||
|
next_test();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
tests.push({
|
||||||
|
description: "import from bookmarks.html, but don't create smart bookmarks if they are disabled",
|
||||||
|
exec: function() {
|
||||||
|
// Sanity check: we should not have any bookmark on the toolbar.
|
||||||
|
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||||
|
// Set preferences.
|
||||||
|
ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
|
||||||
|
ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||||
|
// Force nsBrowserGlue::_initPlaces().
|
||||||
|
os.notifyObservers(null, TOPIC_PLACES_INIT_COMPLETE, null);
|
||||||
|
|
||||||
|
// Check bookmarks.html has been imported, but smart bookmarks have not
|
||||||
|
// been created.
|
||||||
|
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||||
|
do_check_eq(bs.getItemTitle(itemId), "example");
|
||||||
|
// Check preferences have been reverted.
|
||||||
|
do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||||
|
|
||||||
|
next_test();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
tests.push({
|
||||||
|
description: "Import from bookmarks.html, but don't create smart bookmarks if autoExportHTML is true and they are at latest version",
|
||||||
|
exec: function() {
|
||||||
|
// Sanity check: we should not have any bookmark on the toolbar.
|
||||||
|
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||||
|
// Set preferences.
|
||||||
|
ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 999);
|
||||||
|
ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
|
||||||
|
ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||||
|
// Force nsBrowserGlue::_initPlaces()
|
||||||
|
os.notifyObservers(null, TOPIC_PLACES_INIT_COMPLETE, null);
|
||||||
|
|
||||||
|
// Check bookmarks.html has been imported, but smart bookmarks have not
|
||||||
|
// been created.
|
||||||
|
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||||
|
do_check_eq(bs.getItemTitle(itemId), "example");
|
||||||
|
do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||||
|
// Check preferences have been reverted.
|
||||||
|
ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
|
||||||
|
|
||||||
|
next_test();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
tests.push({
|
||||||
|
description: "Import from bookmarks.html, and create smart bookmarks if autoExportHTML is true and they are not at latest version.",
|
||||||
|
exec: function() {
|
||||||
|
// Sanity check: we should not have any bookmark on the toolbar.
|
||||||
|
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||||
|
// Set preferences.
|
||||||
|
ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0);
|
||||||
|
ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
|
||||||
|
ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||||
|
// Force nsBrowserGlue::_initPlaces()
|
||||||
|
os.notifyObservers(null, TOPIC_PLACES_INIT_COMPLETE, null);
|
||||||
|
|
||||||
|
// Check bookmarks.html has been imported, but smart bookmarks have not
|
||||||
|
// been created.
|
||||||
|
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
|
||||||
|
do_check_eq(bs.getItemTitle(itemId), "example");
|
||||||
|
do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||||
|
// Check preferences have been reverted.
|
||||||
|
ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
|
||||||
|
|
||||||
|
next_test();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
tests.push({
|
||||||
|
description: "restore from default bookmarks.html if restore_default_bookmarks is true.",
|
||||||
|
exec: function() {
|
||||||
|
// Sanity check: we should not have any bookmark on the toolbar.
|
||||||
|
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||||
|
// Set preferences.
|
||||||
|
ps.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
|
||||||
|
// Force nsBrowserGlue::_initPlaces()
|
||||||
|
os.notifyObservers(null, TOPIC_PLACES_INIT_COMPLETE, null);
|
||||||
|
|
||||||
|
// Check bookmarks.html has been restored.
|
||||||
|
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR + 1);
|
||||||
|
do_check_true(itemId > 0);
|
||||||
|
// Check preferences have been reverted.
|
||||||
|
do_check_false(ps.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||||
|
|
||||||
|
next_test();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
tests.push({
|
||||||
|
description: "setting both importBookmarksHTML and restore_default_bookmarks should restore defaults.",
|
||||||
|
exec: function() {
|
||||||
|
// Sanity check: we should not have any bookmark on the toolbar.
|
||||||
|
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||||
|
// Set preferences.
|
||||||
|
ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||||
|
ps.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
|
||||||
|
// Force nsBrowserGlue::_initPlaces()
|
||||||
|
os.notifyObservers(null, TOPIC_PLACES_INIT_COMPLETE, null);
|
||||||
|
|
||||||
|
// Check bookmarks.html has been restored.
|
||||||
|
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR + 1);
|
||||||
|
do_check_true(itemId > 0);
|
||||||
|
// Check preferences have been reverted.
|
||||||
|
do_check_false(ps.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||||
|
do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||||
|
|
||||||
|
finish_test();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function finish_test() {
|
||||||
|
do_test_finished();
|
||||||
|
}
|
||||||
|
|
||||||
|
var testIndex = 0;
|
||||||
|
function next_test() {
|
||||||
|
// Clean up database from all bookmarks.
|
||||||
|
remove_all_bookmarks();
|
||||||
|
|
||||||
|
// nsBrowserGlue stops observing topics after first notification,
|
||||||
|
// so we add back the observer to test additional runs.
|
||||||
|
os.addObserver(bg, TOPIC_PLACES_INIT_COMPLETE, false);
|
||||||
|
|
||||||
|
// Execute next test.
|
||||||
|
let test = tests.shift();
|
||||||
|
dump("\nTEST " + (++testIndex) + ": " + test.description);
|
||||||
|
test.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_test() {
|
||||||
|
// Create our bookmarks.html from bookmarks.glue.html.
|
||||||
|
create_bookmarks_html("bookmarks.glue.html");
|
||||||
|
|
||||||
|
// Create our JSON backup from bookmarks.glue.json.
|
||||||
|
create_JSON_backup("bookmarks.glue.json");
|
||||||
|
|
||||||
|
// Kick-off tests.
|
||||||
|
do_test_pending();
|
||||||
|
next_test();
|
||||||
|
}
|
|
@ -0,0 +1,92 @@
|
||||||
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Places Unit Test code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Mozilla Corp.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Marco Bonardo <mak77@bonardo.net>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that nsBrowserGlue correctly restores bookmarks from a JSON backup if
|
||||||
|
* database has been created and one backup is available.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function run_test() {
|
||||||
|
// Create our bookmarks.html copying bookmarks.glue.html to the profile
|
||||||
|
// folder. It will 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_JSON_backup("bookmarks.glue.json");
|
||||||
|
|
||||||
|
// Remove current database file.
|
||||||
|
let db = gProfD.clone();
|
||||||
|
db.append("places.sqlite");
|
||||||
|
if (db.exists()) {
|
||||||
|
db.remove(false);
|
||||||
|
do_check_false(db.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize nsBrowserGlue before Places.
|
||||||
|
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
// 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();");
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
do_check_eq(bs.getItemTitle(itemId), "examplejson");
|
||||||
|
|
||||||
|
do_test_finished();
|
||||||
|
}
|
|
@ -0,0 +1,177 @@
|
||||||
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Places Unit Test code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Mozilla Corp.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Marco Bonardo <mak77@bonardo.net>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that nsBrowserGlue is correctly exporting based on preferences values,
|
||||||
|
* and creating bookmarks backup if one does not exist for today.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Initialize nsBrowserGlue.
|
||||||
|
let bg = Cc["@mozilla.org/browser/browserglue;1"].
|
||||||
|
getService(Ci.nsIBrowserGlue);
|
||||||
|
|
||||||
|
// Initialize Places through Bookmarks Service.
|
||||||
|
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||||
|
getService(Ci.nsINavBookmarksService);
|
||||||
|
|
||||||
|
// Get other services.
|
||||||
|
let ps = Cc["@mozilla.org/preferences-service;1"].
|
||||||
|
getService(Ci.nsIPrefBranch);
|
||||||
|
let os = Cc["@mozilla.org/observer-service;1"].
|
||||||
|
getService(Ci.nsIObserverService);
|
||||||
|
|
||||||
|
const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML";
|
||||||
|
|
||||||
|
const TOPIC_QUIT_APPLICATION_GRANTED = "quit-application-granted";
|
||||||
|
|
||||||
|
let tests = [];
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
tests.push({
|
||||||
|
description: "Export to bookmarks.html if autoExportHTML is true.",
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Check bookmarks.html has been created.
|
||||||
|
check_bookmarks_html();
|
||||||
|
// Check JSON backup has been created.
|
||||||
|
check_JSON_backup();
|
||||||
|
|
||||||
|
// Check preferences have not been reverted.
|
||||||
|
do_check_true(ps.getBoolPref(PREF_AUTO_EXPORT_HTML));
|
||||||
|
// Reset preferences.
|
||||||
|
ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
|
||||||
|
|
||||||
|
next_test();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
tests.push({
|
||||||
|
description: "Export to bookmarks.html if autoExportHTML is true and a bookmarks.html exists.",
|
||||||
|
exec: function() {
|
||||||
|
// Sanity check: we should have bookmarks on the toolbar.
|
||||||
|
do_check_true(bs.getIdForItemAt(bs.toolbarFolder, 0) > 0);
|
||||||
|
// Setpreferences.
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Check a new bookmarks.html has been created.
|
||||||
|
let profileBookmarksHTMLFile = check_bookmarks_html();
|
||||||
|
do_check_true(profileBookmarksHTMLFile.lastModifiedTime > lastMod);
|
||||||
|
do_check_neq(profileBookmarksHTMLFile.fileSize > fileSize);
|
||||||
|
|
||||||
|
// Check preferences have not been reverted.
|
||||||
|
do_check_true(ps.getBoolPref(PREF_AUTO_EXPORT_HTML));
|
||||||
|
// Reset preferences.
|
||||||
|
ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
|
||||||
|
|
||||||
|
next_test();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
tests.push({
|
||||||
|
description: "Backup to JSON should be a no-op if a backup for today already exists.",
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Check a new JSON backup has not been created.
|
||||||
|
do_check_true(profileBookmarksJSONFile.exists());
|
||||||
|
do_check_eq(profileBookmarksJSONFile.lastModifiedTime, lastMod);
|
||||||
|
do_check_eq(profileBookmarksJSONFile.fileSize, fileSize);
|
||||||
|
|
||||||
|
finish_test();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function finish_test() {
|
||||||
|
do_test_finished();
|
||||||
|
}
|
||||||
|
|
||||||
|
var testIndex = 0;
|
||||||
|
function next_test() {
|
||||||
|
// Remove bookmarks.html from profile.
|
||||||
|
remove_bookmarks_html();
|
||||||
|
// Remove JSON backups from profile.
|
||||||
|
remove_all_JSON_backups();
|
||||||
|
|
||||||
|
// Execute next test.
|
||||||
|
let test = tests.shift();
|
||||||
|
dump("\nTEST " + (++testIndex) + ": " + test.description);
|
||||||
|
test.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_test() {
|
||||||
|
// Clean up bookmarks.
|
||||||
|
remove_all_bookmarks();
|
||||||
|
|
||||||
|
// Create some bookmarks.
|
||||||
|
bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://mozilla.org/"),
|
||||||
|
bs.DEFAULT_INDEX, "bookmark-on-menu");
|
||||||
|
bs.insertBookmark(bs.toolbarFolder, uri("http://mozilla.org/"),
|
||||||
|
bs.DEFAULT_INDEX, "bookmark-on-toolbar");
|
||||||
|
|
||||||
|
// Kick-off tests.
|
||||||
|
do_test_pending();
|
||||||
|
next_test();
|
||||||
|
}
|
|
@ -351,8 +351,7 @@ interface nsINavBookmarksService : nsISupports
|
||||||
* The direct parent folder of the item
|
* The direct parent folder of the item
|
||||||
* @param aIndex
|
* @param aIndex
|
||||||
* The index of the item within aFolder, DEFAULT_INDEX for the last item
|
* The index of the item within aFolder, DEFAULT_INDEX for the last item
|
||||||
* @returns the id of the found item
|
* @returns the id of the found item, -1 if the item does not exists
|
||||||
* @throws if the item does not exist
|
|
||||||
*/
|
*/
|
||||||
long long getIdForItemAt(in long long aFolder, in long aIndex);
|
long long getIdForItemAt(in long long aFolder, in long aIndex);
|
||||||
|
|
||||||
|
|
|
@ -1490,10 +1490,11 @@ nsNavBookmarks::GetLastChildId(PRInt64 aFolder, PRInt64* aItemId)
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
if (!hasMore) {
|
if (!hasMore) {
|
||||||
// Item doesn't exist
|
// Item doesn't exist
|
||||||
return NS_ERROR_INVALID_ARG;
|
*aItemId = -1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
*aItemId = statement->AsInt64(0);
|
||||||
|
|
||||||
*aItemId = statement->AsInt64(0);
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1503,7 +1504,8 @@ nsNavBookmarks::GetIdForItemAt(PRInt64 aFolder, PRInt32 aIndex, PRInt64* aItemId
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
if (aIndex == nsINavBookmarksService::DEFAULT_INDEX) {
|
if (aIndex == nsINavBookmarksService::DEFAULT_INDEX) {
|
||||||
// we want the last item within aFolder
|
// we want the last item within aFolder
|
||||||
return GetLastChildId(aFolder, aItemId);
|
rv = GetLastChildId(aFolder, aItemId);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
} else {
|
} else {
|
||||||
{
|
{
|
||||||
// get the item in aFolder with position aIndex
|
// get the item in aFolder with position aIndex
|
||||||
|
@ -1519,10 +1521,10 @@ nsNavBookmarks::GetIdForItemAt(PRInt64 aFolder, PRInt32 aIndex, PRInt64* aItemId
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
if (!hasMore) {
|
if (!hasMore) {
|
||||||
// Item doesn't exist
|
// Item doesn't exist
|
||||||
return NS_ERROR_INVALID_ARG;
|
*aItemId = -1;
|
||||||
}
|
}
|
||||||
// actually found an item
|
else
|
||||||
*aItemId = mDBGetChildAt->AsInt64(0);
|
*aItemId = mDBGetChildAt->AsInt64(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
|
@ -295,6 +295,12 @@ function run_test() {
|
||||||
|
|
||||||
// test getIdForItemAt
|
// test getIdForItemAt
|
||||||
do_check_eq(bmsvc.getIdForItemAt(testRoot, 0), workFolder);
|
do_check_eq(bmsvc.getIdForItemAt(testRoot, 0), workFolder);
|
||||||
|
// wrong parent, should return -1
|
||||||
|
do_check_eq(bmsvc.getIdForItemAt(1337, 0), -1);
|
||||||
|
// wrong index, should return -1
|
||||||
|
do_check_eq(bmsvc.getIdForItemAt(testRoot, 1337), -1);
|
||||||
|
// wrong parent and index, should return -1
|
||||||
|
do_check_eq(bmsvc.getIdForItemAt(1337, 1337), -1);
|
||||||
|
|
||||||
// move folder, appending, to different folder
|
// move folder, appending, to different folder
|
||||||
var oldParentCC = getChildCount(testRoot);
|
var oldParentCC = getChildCount(testRoot);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче