mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-11 10:08:41 +00:00
Bug 556376 - Provide a common head for Places xpcshell-tests.
r=dietrich on code changes, blanket-rs=places-team for test changes
This commit is contained in:
parent
9d61d8ef06
commit
c92ceba9fd
@ -37,48 +37,24 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
version(170);
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
const NS_APP_PROFILE_DIR_STARTUP = "ProfDS";
|
||||
const NS_APP_BOOKMARKS_50_FILE = "BMarks";
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var Ci = Components.interfaces;
|
||||
var Cc = Components.classes;
|
||||
var Cr = Components.results;
|
||||
|
||||
function LOG(aMsg) {
|
||||
aMsg = ("*** PLACES TESTS: " + aMsg);
|
||||
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
|
||||
logStringMessage(aMsg);
|
||||
print(aMsg);
|
||||
// Import common head.
|
||||
let (commonFile = do_get_file("../../test_places/head_common.js", false)) {
|
||||
let uri = Services.io.newFileURI(commonFile);
|
||||
Services.scriptloader.loadSubScript(uri.spec, this);
|
||||
}
|
||||
|
||||
var gProfD = do_get_profile();
|
||||
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties);
|
||||
// Put any other stuff relative to this test folder below.
|
||||
|
||||
var dirProvider = {
|
||||
getFile: function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_BOOKMARKS_50_FILE) {
|
||||
var bmarks = gProfD.clone();
|
||||
bmarks.append("bookmarks.html");
|
||||
return bmarks;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(dirProvider);
|
||||
|
||||
var XULAppInfo = {
|
||||
// Needed by some test that relies on having an app registered.
|
||||
let (XULAppInfo = {
|
||||
vendor: "Mozilla",
|
||||
name: "PlacesTest",
|
||||
ID: "{230de50e-4cd1-11dc-8314-0800200c9a66}",
|
||||
@ -91,80 +67,29 @@ var XULAppInfo = {
|
||||
OS: "XPCShell",
|
||||
XPCOMABI: "noarch-spidermonkey",
|
||||
|
||||
QueryInterface: function QueryInterface(iid) {
|
||||
if (iid.equals(Ci.nsIXULAppInfo) ||
|
||||
iid.equals(Ci.nsIXULRuntime) ||
|
||||
iid.equals(Ci.nsISupports))
|
||||
return this;
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
var XULAppInfoFactory = {
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||
return XULAppInfo.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
|
||||
var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"),
|
||||
"XULAppInfo", "@mozilla.org/xre/app-info;1",
|
||||
XULAppInfoFactory);
|
||||
|
||||
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
|
||||
function uri(spec) {
|
||||
return iosvc.newURI(spec, null, null);
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Ci.nsIXULAppInfo,
|
||||
Ci.nsIXULRuntime,
|
||||
])
|
||||
}) {
|
||||
let XULAppInfoFactory = {
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||
return XULAppInfo.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"),
|
||||
"XULAppInfo", "@mozilla.org/xre/app-info;1",
|
||||
XULAppInfoFactory);
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes all bookmarks and checks for correct cleanup
|
||||
*/
|
||||
function remove_all_bookmarks() {
|
||||
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
// Clear all bookmarks.
|
||||
bs.removeFolderChildren(bs.bookmarksMenuFolder);
|
||||
bs.removeFolderChildren(bs.toolbarFolder);
|
||||
bs.removeFolderChildren(bs.unfiledBookmarksFolder);
|
||||
|
||||
// Check for correct cleanup.
|
||||
dump_table("moz_bookmarks");
|
||||
dump_table("moz_places");
|
||||
check_no_bookmarks()
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks that we don't have any bookmark
|
||||
*/
|
||||
function check_no_bookmarks() {
|
||||
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
var query = hs.getNewQuery();
|
||||
query.setFolders([bs.toolbarFolder, bs.bookmarksMenuFolder, bs.unfiledBookmarksFolder], 3);
|
||||
var options = hs.getNewQueryOptions();
|
||||
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
|
||||
var result = hs.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
var cc = root.childCount;
|
||||
// Dump contents if found.
|
||||
for (var i = 0; i < cc ; i++) {
|
||||
var node = root.getChild(i);
|
||||
print("Found unexpected child at " + i + ": " + node.title);
|
||||
}
|
||||
do_check_eq(cc, 0);
|
||||
root.containerOpen = false;
|
||||
}
|
||||
|
||||
let gTestDir = do_get_cwd();
|
||||
const FILENAME_BOOKMARKS_HTML = "bookmarks.html";
|
||||
let backup_date = new Date().toLocaleFormat("%Y-%m-%d");
|
||||
const FILENAME_BOOKMARKS_JSON = "bookmarks-" + backup_date + ".json";
|
||||
let (backup_date = new Date().toLocaleFormat("%Y-%m-%d")) {
|
||||
const FILENAME_BOOKMARKS_JSON = "bookmarks-" + backup_date + ".json";
|
||||
}
|
||||
|
||||
// Smart bookmarks constants.
|
||||
const SMART_BOOKMARKS_VERSION = 2;
|
||||
@ -174,179 +99,3 @@ const SMART_BOOKMARKS_ON_MENU = 3; // Takes in count the additional separator.
|
||||
// Default bookmarks constants.
|
||||
const DEFAULT_BOOKMARKS_ON_TOOLBAR = 2;
|
||||
const DEFAULT_BOOKMARKS_ON_MENU = 3;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (!aFilename)
|
||||
do_throw("you must pass a filename to create_bookmarks_html function");
|
||||
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) {
|
||||
if (!aFilename)
|
||||
do_throw("you must pass a filename to create_JSON_backup function");
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the rows of a table out to the console.
|
||||
*
|
||||
* @param aName
|
||||
* The name of the table or view to output.
|
||||
*/
|
||||
function dump_table(aName)
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
let stmt = db.createStatement("SELECT * FROM " + aName);
|
||||
|
||||
dump("\n*** Printing data from " + aName + ":\n");
|
||||
let count = 0;
|
||||
while (stmt.executeStep()) {
|
||||
let columns = stmt.numEntries;
|
||||
|
||||
if (count == 0) {
|
||||
// print the column names
|
||||
for (let i = 0; i < columns; i++)
|
||||
dump(stmt.getColumnName(i) + "\t");
|
||||
dump("\n");
|
||||
}
|
||||
|
||||
// print the row
|
||||
for (let i = 0; i < columns; i++) {
|
||||
switch (stmt.getTypeOfIndex(i)) {
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_NULL:
|
||||
dump("NULL\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_INTEGER:
|
||||
dump(stmt.getInt64(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_FLOAT:
|
||||
dump(stmt.getDouble(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_TEXT:
|
||||
dump(stmt.getString(i) + "\t");
|
||||
break;
|
||||
}
|
||||
}
|
||||
dump("\n");
|
||||
|
||||
count++;
|
||||
}
|
||||
dump("*** There were a total of " + count + " rows of data.\n\n");
|
||||
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes any events in the event loop of the main thread.
|
||||
*/
|
||||
function flush_main_thread_events()
|
||||
{
|
||||
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
||||
while (tm.mainThread.hasPendingEvents())
|
||||
tm.mainThread.processNextEvent(false);
|
||||
}
|
||||
|
||||
// These tests are known to randomly fail due to bug 507790 when database
|
||||
// flushes are active, so we turn off syncing for them.
|
||||
let randomFailingSyncTests = [
|
||||
"test_browserGlue_smartBookmarks.js",
|
||||
];
|
||||
let currentTestFilename = do_get_file(_TEST_FILE[0], true).leafName;
|
||||
if (randomFailingSyncTests.indexOf(currentTestFilename) != -1) {
|
||||
print("Test " + currentTestFilename + " is known random due to bug 507790, disabling PlacesDBFlush component.");
|
||||
let sync = Cc["@mozilla.org/places/sync;1"].getService(Ci.nsIObserver);
|
||||
sync.observe(null, "places-debug-stop-sync", null);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ function run_test() {
|
||||
//var bookmarksFileOld = do_get_file("bookmarks.large.html");
|
||||
var bookmarksFileOld = do_get_file("bookmarks.preplaces.html");
|
||||
// file pointer to a new places-exported json file
|
||||
var jsonFile = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
var jsonFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
jsonFile.append("bookmarks.exported.json");
|
||||
|
||||
// create bookmarks.exported.json
|
||||
|
@ -90,7 +90,7 @@ function run_test() {
|
||||
stmt.finalize();
|
||||
|
||||
// Export bookmarks
|
||||
var bookmarksFile = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
var bookmarksFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
bookmarksFile.append("bookmarks.exported.html");
|
||||
if (bookmarksFile.exists())
|
||||
bookmarksFile.remove(false);
|
||||
|
@ -115,7 +115,7 @@ var tests = [
|
||||
data: NSIOBSERVER_DATA_JSON,
|
||||
folderId: null,
|
||||
run: function () {
|
||||
this.file = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
this.file = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
this.file.append("this file doesn't exist because nobody created it");
|
||||
try {
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(this.file);
|
||||
@ -169,7 +169,7 @@ var tests = [
|
||||
data: NSIOBSERVER_DATA_HTML,
|
||||
folderId: null,
|
||||
run: function () {
|
||||
this.file = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
this.file = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
this.file.append("this file doesn't exist because nobody created it");
|
||||
try {
|
||||
importer.importHTMLFromFile(this.file, false);
|
||||
@ -223,7 +223,7 @@ var tests = [
|
||||
data: NSIOBSERVER_DATA_HTML_INIT,
|
||||
folderId: null,
|
||||
run: function () {
|
||||
this.file = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
this.file = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
this.file.append("this file doesn't exist because nobody created it");
|
||||
try {
|
||||
importer.importHTMLFromFile(this.file, true);
|
||||
@ -284,7 +284,7 @@ var tests = [
|
||||
finalTopic: NSIOBSERVER_TOPIC_FAILED,
|
||||
data: NSIOBSERVER_DATA_HTML,
|
||||
run: function () {
|
||||
this.file = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
this.file = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
this.file.append("this file doesn't exist because nobody created it");
|
||||
this.folderId = bmsvc.createFolder(bmsvc.unfiledBookmarksFolder,
|
||||
"test folder",
|
||||
@ -407,7 +407,7 @@ function checkBookmarksExist() {
|
||||
* @return The nsILocalFile
|
||||
*/
|
||||
function createFile(aBasename) {
|
||||
var file = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
var file = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
file.append(aBasename);
|
||||
if (file.exists())
|
||||
file.remove(false);
|
||||
|
@ -104,7 +104,7 @@ function run_test() {
|
||||
// file pointer to legacy bookmarks file
|
||||
var bookmarksFileOld = do_get_file("bookmarks.preplaces.html");
|
||||
// file pointer to a new places-exported bookmarks file
|
||||
var bookmarksFileNew = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
var bookmarksFileNew = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
bookmarksFileNew.append("bookmarks.exported.html");
|
||||
|
||||
// create bookmarks.exported.html
|
||||
|
@ -47,14 +47,13 @@ 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";
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
// Copy distribution.ini file to our app dir.
|
||||
let distroDir = dirSvc.get("XCurProcD", Ci.nsIFile);
|
||||
let distroDir = Services.dirsvc.get("XCurProcD", Ci.nsIFile);
|
||||
distroDir.append("distribution");
|
||||
let iniFile = distroDir.clone();
|
||||
iniFile.append("distribution.ini");
|
||||
@ -97,13 +96,13 @@ function run_test() {
|
||||
TOPIC_FINAL_UI_STARTUP,
|
||||
null);
|
||||
// Test will continue on customization complete notification.
|
||||
let observer = {
|
||||
let cObserver = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
os.removeObserver(this, TOPIC_CUSTOMIZATION_COMPLETE);
|
||||
continue_test();
|
||||
do_execute_soon(continue_test);
|
||||
}
|
||||
}
|
||||
os.addObserver(observer, TOPIC_CUSTOMIZATION_COMPLETE, false);
|
||||
os.addObserver(cObserver, TOPIC_CUSTOMIZATION_COMPLETE, false);
|
||||
}
|
||||
}
|
||||
os.addObserver(observer, TOPIC_PLACES_INIT_COMPLETE, false);
|
||||
@ -145,7 +144,7 @@ function continue_test() {
|
||||
do_register_cleanup(function() {
|
||||
// Remove the distribution file, even if the test failed, otherwise all
|
||||
// next tests will import it.
|
||||
let iniFile = dirSvc.get("XCurProcD", Ci.nsIFile);
|
||||
let iniFile = Services.dirsvc.get("XCurProcD", Ci.nsIFile);
|
||||
iniFile.append("distribution");
|
||||
iniFile.append("distribution.ini");
|
||||
iniFile.remove(false);
|
||||
|
@ -63,8 +63,7 @@ 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";
|
||||
const TOPIC_PLACES_DATABASE_LOCKED = "places-database-locked";
|
||||
|
||||
let tests = [];
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
@ -40,10 +40,6 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
function LOG(str) {
|
||||
dump("*** " + str + "\n");
|
||||
}
|
||||
|
||||
var EXPORTED_SYMBOLS = ["PlacesUtils"];
|
||||
|
||||
var Ci = Components.interfaces;
|
||||
@ -52,6 +48,8 @@ var Cr = Components.results;
|
||||
var Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
const EXCLUDE_FROM_BACKUP_ANNO = "places/excludeFromBackup";
|
||||
const POST_DATA_ANNO = "bookmarkProperties/POSTData";
|
||||
@ -106,66 +104,6 @@ var PlacesUtils = {
|
||||
// Place entries as raw URL text
|
||||
TYPE_UNICODE: "text/unicode",
|
||||
|
||||
/**
|
||||
* The Bookmarks Service.
|
||||
*/
|
||||
get bookmarks() {
|
||||
delete this.bookmarks;
|
||||
return this.bookmarks = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
},
|
||||
|
||||
/**
|
||||
* The Nav History Service.
|
||||
*/
|
||||
get history() {
|
||||
delete this.history;
|
||||
return this.history = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
},
|
||||
|
||||
/**
|
||||
* The Live Bookmark Service.
|
||||
*/
|
||||
get livemarks() {
|
||||
delete this.livemarks;
|
||||
return this.livemarks = Cc["@mozilla.org/browser/livemark-service;2"].
|
||||
getService(Ci.nsILivemarkService);
|
||||
},
|
||||
|
||||
/**
|
||||
* The Annotations Service.
|
||||
*/
|
||||
get annotations() {
|
||||
delete this.annotations;
|
||||
return this.annotations = Cc["@mozilla.org/browser/annotation-service;1"].
|
||||
getService(Ci.nsIAnnotationService);
|
||||
},
|
||||
|
||||
/**
|
||||
* The Favicons Service
|
||||
*/
|
||||
get favicons() {
|
||||
delete this.favicons;
|
||||
return this.favicons = Cc["@mozilla.org/browser/favicon-service;1"].
|
||||
getService(Ci.nsIFaviconService);
|
||||
},
|
||||
|
||||
/**
|
||||
* The Places Tagging Service
|
||||
*/
|
||||
get tagging() {
|
||||
delete this.tagging;
|
||||
return this.tagging = Cc["@mozilla.org/browser/tagging-service;1"].
|
||||
getService(Ci.nsITaggingService);
|
||||
},
|
||||
|
||||
get observerSvc() {
|
||||
delete this.observerSvc;
|
||||
return this.observerSvc = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
},
|
||||
|
||||
/**
|
||||
* Makes a URI from a spec.
|
||||
* @param aSpec
|
||||
@ -173,21 +111,7 @@ var PlacesUtils = {
|
||||
* @returns A URI object for the spec.
|
||||
*/
|
||||
_uri: function PU__uri(aSpec) {
|
||||
return Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService).
|
||||
newURI(aSpec, null, null);
|
||||
},
|
||||
|
||||
/**
|
||||
* String bundle helpers
|
||||
*/
|
||||
get _bundle() {
|
||||
const PLACES_STRING_BUNDLE_URI =
|
||||
"chrome://places/locale/places.properties";
|
||||
delete this._bundle;
|
||||
return this._bundle = Cc["@mozilla.org/intl/stringbundle;1"].
|
||||
getService(Ci.nsIStringBundleService).
|
||||
createBundle(PLACES_STRING_BUNDLE_URI);
|
||||
return NetUtil.newURI(aSpec);
|
||||
},
|
||||
|
||||
getFormattedString: function PU_getFormattedString(key, params) {
|
||||
@ -298,7 +222,7 @@ var PlacesUtils = {
|
||||
this.annotations.addObserver(this, false);
|
||||
|
||||
// observe shutdown, so we can remove the anno observer
|
||||
this.observerSvc.addObserver(this, "xpcom-shutdown", false);
|
||||
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
||||
|
||||
var readOnly = this.annotations.getItemsWithAnnotation(READ_ONLY_ANNO);
|
||||
this.__defineGetter__("_readOnly", function() readOnly);
|
||||
@ -312,7 +236,7 @@ var PlacesUtils = {
|
||||
observe: function PU_observe(aSubject, aTopic, aData) {
|
||||
if (aTopic == "xpcom-shutdown") {
|
||||
this.annotations.removeObserver(this);
|
||||
this.observerSvc.removeObserver(this, "xpcom-shutdown");
|
||||
Services.obs.removeObserver(this, "xpcom-shutdown");
|
||||
}
|
||||
},
|
||||
|
||||
@ -717,7 +641,6 @@ var PlacesUtils = {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG("Cannot unwrap data of type " + type);
|
||||
throw Cr.NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
return nodes;
|
||||
@ -1495,9 +1418,7 @@ var PlacesUtils = {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
} catch(ex) {
|
||||
LOG(ex);
|
||||
}
|
||||
} catch(ex) {}
|
||||
if (annos.length != 0)
|
||||
aJSNode.annos = annos;
|
||||
}
|
||||
@ -1682,9 +1603,9 @@ var PlacesUtils = {
|
||||
restoreBookmarksFromJSONFile:
|
||||
function PU_restoreBookmarksFromJSONFile(aFile) {
|
||||
let failed = false;
|
||||
this.observerSvc.notifyObservers(null,
|
||||
RESTORE_BEGIN_NSIOBSERVER_TOPIC,
|
||||
RESTORE_NSIOBSERVER_DATA);
|
||||
Services.obs.notifyObservers(null,
|
||||
RESTORE_BEGIN_NSIOBSERVER_TOPIC,
|
||||
RESTORE_NSIOBSERVER_DATA);
|
||||
|
||||
try {
|
||||
// open file stream
|
||||
@ -1710,17 +1631,17 @@ var PlacesUtils = {
|
||||
}
|
||||
catch (exc) {
|
||||
failed = true;
|
||||
this.observerSvc.notifyObservers(null,
|
||||
RESTORE_FAILED_NSIOBSERVER_TOPIC,
|
||||
RESTORE_NSIOBSERVER_DATA);
|
||||
Services.obs.notifyObservers(null,
|
||||
RESTORE_FAILED_NSIOBSERVER_TOPIC,
|
||||
RESTORE_NSIOBSERVER_DATA);
|
||||
Cu.reportError("Bookmarks JSON restore failed: " + exc);
|
||||
throw exc;
|
||||
}
|
||||
finally {
|
||||
if (!failed) {
|
||||
this.observerSvc.notifyObservers(null,
|
||||
RESTORE_SUCCESS_NSIOBSERVER_TOPIC,
|
||||
RESTORE_NSIOBSERVER_DATA);
|
||||
Services.obs.notifyObservers(null,
|
||||
RESTORE_SUCCESS_NSIOBSERVER_TOPIC,
|
||||
RESTORE_NSIOBSERVER_DATA);
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -1763,9 +1684,7 @@ var PlacesUtils = {
|
||||
},
|
||||
|
||||
get folder() {
|
||||
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties);
|
||||
let bookmarksBackupDir = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
let bookmarksBackupDir = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
bookmarksBackupDir.append("bookmarkbackups");
|
||||
if (!bookmarksBackupDir.exists()) {
|
||||
bookmarksBackupDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0700);
|
||||
@ -2014,3 +1933,46 @@ var PlacesUtils = {
|
||||
Cu.import("resource://gre/modules/PlacesDBUtils.jsm");
|
||||
}
|
||||
};
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "history",
|
||||
"@mozilla.org/browser/nav-history-service;1",
|
||||
"nsINavHistoryService");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(PlacesUtils, "bhistory", function() {
|
||||
return PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(PlacesUtils, "ghistory2", function() {
|
||||
return PlacesUtils.history.QueryInterface(Ci.nsIGlobalHistory2);
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(PlacesUtils, "ghistory3", function() {
|
||||
return PlacesUtils.history.QueryInterface(Ci.nsIGlobalHistory3);
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "favicons",
|
||||
"@mozilla.org/browser/favicon-service;1",
|
||||
"nsIFaviconService");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "bookmarks",
|
||||
"@mozilla.org/browser/nav-bookmarks-service;1",
|
||||
"nsINavBookmarksService");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "annotations",
|
||||
"@mozilla.org/browser/annotation-service;1",
|
||||
"nsIAnnotationService");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "tagging",
|
||||
"@mozilla.org/browser/tagging-service;1",
|
||||
"nsITaggingService");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(PlacesUtils, "livemarks",
|
||||
"@mozilla.org/browser/livemark-service;2",
|
||||
"nsILivemarkService");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(PlacesUtils, "_bundle", function() {
|
||||
const PLACES_STRING_BUNDLE_URI = "chrome://places/locale/places.properties";
|
||||
return Cc["@mozilla.org/intl/stringbundle;1"].
|
||||
getService(Ci.nsIStringBundleService).
|
||||
createBundle(PLACES_STRING_BUNDLE_URI);
|
||||
});
|
||||
|
@ -56,6 +56,11 @@ XPCSHELL_TESTS = \
|
||||
network \
|
||||
$(NULL)
|
||||
|
||||
# Files in the main "tests" folder.
|
||||
XPCSHELL_TESTS_COMMON = \
|
||||
head_common.js \
|
||||
$(NULL)
|
||||
|
||||
# Simple MochiTests
|
||||
MOCHI_TESTS = \
|
||||
mochitest/test_bug_411966.html \
|
||||
@ -77,3 +82,6 @@ include $(topsrcdir)/config/rules.mk
|
||||
|
||||
libs:: $(MOCHI_TESTS)
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
|
||||
|
||||
libs:: $(XPCSHELL_TESTS_COMMON)
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/xpcshell/$(MODULE)
|
||||
|
@ -1,141 +0,0 @@
|
||||
/* ***** 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.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Google Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
* Dietrich Ayala <dietrich@mozilla.com>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
const NS_APP_HISTORY_50_FILE = "UHist";
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
|
||||
var profDir = do_get_profile();
|
||||
|
||||
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
let provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_HISTORY_50_FILE) {
|
||||
let histFile = profDir.clone();
|
||||
histFile.append("history.dat");
|
||||
return histFile;
|
||||
}
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
},
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
|
||||
// Delete a previously created sqlite file
|
||||
function clearDB() {
|
||||
try {
|
||||
let file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
if (file.exists())
|
||||
file.remove(false);
|
||||
} catch(ex) { dump("Exception: " + ex); }
|
||||
}
|
||||
clearDB();
|
||||
|
||||
/**
|
||||
* Dumps the rows of a table out to the console.
|
||||
*
|
||||
* @param aName
|
||||
* The name of the table or view to output.
|
||||
*/
|
||||
function dump_table(aName)
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
let stmt = db.createStatement("SELECT * FROM " + aName);
|
||||
|
||||
dump("\n*** Printing data from " + aName + ":\n");
|
||||
let count = 0;
|
||||
while (stmt.executeStep()) {
|
||||
let columns = stmt.numEntries;
|
||||
|
||||
if (count == 0) {
|
||||
// print the column names
|
||||
for (let i = 0; i < columns; i++)
|
||||
dump(stmt.getColumnName(i) + "\t");
|
||||
dump("\n");
|
||||
}
|
||||
|
||||
// print the row
|
||||
for (let i = 0; i < columns; i++) {
|
||||
switch (stmt.getTypeOfIndex(i)) {
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_NULL:
|
||||
dump("NULL\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_INTEGER:
|
||||
dump(stmt.getInt64(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_FLOAT:
|
||||
dump(stmt.getDouble(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_TEXT:
|
||||
dump(stmt.getString(i) + "\t");
|
||||
break;
|
||||
}
|
||||
}
|
||||
dump("\n");
|
||||
|
||||
count++;
|
||||
}
|
||||
dump("*** There were a total of " + count + " rows of data.\n\n");
|
||||
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes any events in the event loop of the main thread.
|
||||
*/
|
||||
function flush_main_thread_events()
|
||||
{
|
||||
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
||||
while (tm.mainThread.hasPendingEvents())
|
||||
tm.mainThread.processNextEvent(false);
|
||||
}
|
@ -35,22 +35,27 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Import common head.
|
||||
let (commonFile = do_get_file("../head_common.js", false)) {
|
||||
let uri = Services.io.newFileURI(commonFile);
|
||||
Services.scriptloader.loadSubScript(uri.spec, this);
|
||||
}
|
||||
|
||||
// Put any other stuff relative to this test folder below.
|
||||
|
||||
|
||||
/**
|
||||
* Header file for autocomplete testcases that create a set of pages with uris,
|
||||
* titles, tags and tests that a given search term matches certain pages.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
const TRANSITION_LINK = Ci.nsINavHistoryService.TRANSITION_LINK;
|
||||
const TRANSITION_TYPED = Ci.nsINavHistoryService.TRANSITION_TYPED;
|
||||
const TRANSITION_BOOKMARK = Ci.nsINavHistoryService.TRANSITION_BOOKMARK;
|
||||
const TRANSITION_EMBED = Ci.nsINavHistoryService.TRANSITION_EMBED;
|
||||
const TRANSITION_FRAMED_LINK = Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK;
|
||||
const TRANSITION_REDIRECT_PERMANENT = Ci.nsINavHistoryService.TRANSITION_REDIRECT_PERMANENT;
|
||||
const TRANSITION_REDIRECT_TEMPORARY = Ci.nsINavHistoryService.TRANSITION_REDIRECT_TEMPORARY;
|
||||
const TRANSITION_DOWNLOAD = Ci.nsINavHistoryService.TRANSITION_DOWNLOAD;
|
||||
|
||||
let current_test = 0;
|
||||
|
||||
function AutoCompleteInput(aSearches) {
|
||||
@ -72,12 +77,14 @@ AutoCompleteInput.prototype = {
|
||||
setSelectedIndex: function() {},
|
||||
get searchCount() { return this.searches.length; },
|
||||
getSearchAt: function(aIndex) this.searches[aIndex],
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput, Ci.nsIAutoCompletePopup])
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Ci.nsIAutoCompleteInput,
|
||||
Ci.nsIAutoCompletePopup,
|
||||
])
|
||||
};
|
||||
|
||||
function toURI(aSpec)
|
||||
{
|
||||
return iosvc.newURI(aSpec, null, null);
|
||||
function toURI(aSpec) {
|
||||
return uri(aSpec);
|
||||
}
|
||||
|
||||
let appendTags = true;
|
||||
@ -188,72 +195,6 @@ let gDate = new Date(Date.now() - 1000 * 60 * 60) * 1000;
|
||||
// Store the page info for each uri
|
||||
let gPages = [];
|
||||
|
||||
/**
|
||||
* Function gets current database connection, if the connection has been closed
|
||||
* it will try to reconnect to the places.sqlite database.
|
||||
*/
|
||||
function DBConn()
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
if (db.connectionReady)
|
||||
return db;
|
||||
|
||||
// open a new connection if needed
|
||||
let file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
let storageService = Cc["@mozilla.org/storage/service;1"].
|
||||
getService(Ci.mozIStorageService);
|
||||
try {
|
||||
var dbConn = storageService.openDatabase(file);
|
||||
} catch (ex) {
|
||||
return null;
|
||||
}
|
||||
return dbConn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets title synchronously for a page in moz_places synchronously.
|
||||
* History.SetPageTitle uses LAZY_ADD so we can't rely on it.
|
||||
*
|
||||
* @param aURI
|
||||
* An nsIURI to set the title for.
|
||||
* @param aTitle
|
||||
* The title to set the page to.
|
||||
* @throws if the page is not found in the database.
|
||||
*
|
||||
* @note this function only exists because we have no API to do this. It should
|
||||
* be added in bug 421897.
|
||||
*/
|
||||
function setPageTitle(aURI, aTitle) {
|
||||
let dbConn = DBConn();
|
||||
// Check that the page exists.
|
||||
let stmt = dbConn.createStatement(
|
||||
"SELECT id FROM moz_places_view WHERE url = :url");
|
||||
stmt.params.url = aURI.spec;
|
||||
try {
|
||||
if (!stmt.executeStep()) {
|
||||
do_throw("Unable to find page " + aURIString);
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
stmt.finalize();
|
||||
}
|
||||
|
||||
// Update the title
|
||||
stmt = dbConn.createStatement(
|
||||
"UPDATE moz_places_view SET title = :title WHERE url = :url");
|
||||
stmt.params.title = aTitle;
|
||||
stmt.params.url = aURI.spec;
|
||||
try {
|
||||
stmt.execute();
|
||||
}
|
||||
finally {
|
||||
stmt.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a livemark container with a single child, and creates various properties
|
||||
|
@ -37,169 +37,17 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
|
||||
function LOG(aMsg) {
|
||||
aMsg = ("*** PLACES TESTS: " + aMsg);
|
||||
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
|
||||
logStringMessage(aMsg);
|
||||
print(aMsg);
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Import common head.
|
||||
let (commonFile = do_get_file("../head_common.js", false)) {
|
||||
let uri = Services.io.newFileURI(commonFile);
|
||||
Services.scriptloader.loadSubScript(uri.spec, this);
|
||||
}
|
||||
|
||||
do_get_profile();
|
||||
|
||||
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
|
||||
function uri(spec) {
|
||||
return iosvc.newURI(spec, null, null);
|
||||
}
|
||||
|
||||
// Delete a previously created sqlite file
|
||||
function clearDB() {
|
||||
try {
|
||||
var file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
if (file.exists())
|
||||
file.remove(false);
|
||||
} catch(ex) { dump("Exception: " + ex); }
|
||||
}
|
||||
clearDB();
|
||||
|
||||
/**
|
||||
* Dumps the rows of a table out to the console.
|
||||
*
|
||||
* @param aName
|
||||
* The name of the table or view to output.
|
||||
*/
|
||||
function dump_table(aName)
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
let stmt = db.createStatement("SELECT * FROM " + aName);
|
||||
|
||||
dump("\n*** Printing data from " + aName + ":\n");
|
||||
let count = 0;
|
||||
while (stmt.executeStep()) {
|
||||
let columns = stmt.numEntries;
|
||||
|
||||
if (count == 0) {
|
||||
// print the column names
|
||||
for (let i = 0; i < columns; i++)
|
||||
dump(stmt.getColumnName(i) + "\t");
|
||||
dump("\n");
|
||||
}
|
||||
|
||||
// print the row
|
||||
for (let i = 0; i < columns; i++) {
|
||||
switch (stmt.getTypeOfIndex(i)) {
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_NULL:
|
||||
dump("NULL\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_INTEGER:
|
||||
dump(stmt.getInt64(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_FLOAT:
|
||||
dump(stmt.getDouble(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_TEXT:
|
||||
dump(stmt.getString(i) + "\t");
|
||||
break;
|
||||
}
|
||||
}
|
||||
dump("\n");
|
||||
|
||||
count++;
|
||||
}
|
||||
dump("*** There were a total of " + count + " rows of data.\n\n");
|
||||
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes all bookmarks and checks for correct cleanup
|
||||
*/
|
||||
function remove_all_bookmarks() {
|
||||
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
// Clear all bookmarks
|
||||
bs.removeFolderChildren(bs.bookmarksMenuFolder);
|
||||
bs.removeFolderChildren(bs.toolbarFolder);
|
||||
bs.removeFolderChildren(bs.unfiledBookmarksFolder);
|
||||
// Check for correct cleanup
|
||||
check_no_bookmarks()
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks that we don't have any bookmark
|
||||
*/
|
||||
function check_no_bookmarks() {
|
||||
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
var query = hs.getNewQuery();
|
||||
query.setFolders([bs.toolbarFolder, bs.bookmarksMenuFolder, bs.unfiledBookmarksFolder], 3);
|
||||
var options = hs.getNewQueryOptions();
|
||||
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
|
||||
var result = hs.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
do_check_eq(root.childCount, 0);
|
||||
root.containerOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function gets current database connection, if the connection has been closed
|
||||
* it will try to reconnect to the places.sqlite database.
|
||||
*/
|
||||
function DBConn()
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
if (db.connectionReady)
|
||||
return db;
|
||||
|
||||
// open a new connection if needed
|
||||
let file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
let storageService = Cc["@mozilla.org/storage/service;1"].
|
||||
getService(Ci.mozIStorageService);
|
||||
|
||||
try {
|
||||
return dbConn = storageService.openDatabase(file);
|
||||
}
|
||||
catch(ex) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes any events in the event loop of the main thread.
|
||||
*/
|
||||
function flush_main_thread_events()
|
||||
{
|
||||
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
||||
while (tm.mainThread.hasPendingEvents())
|
||||
tm.mainThread.processNextEvent(false);
|
||||
}
|
||||
|
||||
// These tests are known to randomly fail due to bug 507790 when database
|
||||
// flushes are active, so we turn off syncing for them.
|
||||
let randomFailingSyncTests = [
|
||||
"test_384228.js",
|
||||
"test_395593.js",
|
||||
];
|
||||
let currentTestFilename = do_get_file(_TEST_FILE[0], true).leafName;
|
||||
if (randomFailingSyncTests.indexOf(currentTestFilename) != -1) {
|
||||
print("Test " + currentTestFilename + " is known random due to bug 507790, disabling PlacesDBFlush component.");
|
||||
let sync = Cc["@mozilla.org/places/sync;1"].getService(Ci.nsIObserver);
|
||||
sync.observe(null, "places-debug-stop-sync", null);
|
||||
}
|
||||
// Put any other stuff relative to this test folder below.
|
||||
|
@ -222,7 +222,7 @@ function run_test() {
|
||||
do_check_eq(typeof PlacesUtils, "object");
|
||||
|
||||
// make json file
|
||||
var jsonFile = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
var jsonFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
jsonFile.append("bookmarks.json");
|
||||
if (jsonFile.exists())
|
||||
jsonFile.remove(false);
|
||||
|
@ -145,7 +145,7 @@ function run_test() {
|
||||
do_check_eq(typeof PlacesUtils, "object");
|
||||
|
||||
// make json file
|
||||
var jsonFile = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
var jsonFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
jsonFile.append("bookmarks.json");
|
||||
if (jsonFile.exists())
|
||||
jsonFile.remove(false);
|
||||
|
@ -157,7 +157,7 @@ function run_test() {
|
||||
do_check_eq(typeof PlacesUtils, "object");
|
||||
|
||||
// make json file
|
||||
var jsonFile = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
var jsonFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
jsonFile.append("bookmarks.json");
|
||||
if (jsonFile.exists())
|
||||
jsonFile.remove(false);
|
||||
|
@ -91,7 +91,7 @@ function run_test() {
|
||||
do_check_eq(typeof PlacesUtils, "object");
|
||||
|
||||
// make json file
|
||||
var jsonFile = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
var jsonFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
jsonFile.append("bookmarks.json");
|
||||
if (jsonFile.exists())
|
||||
jsonFile.remove(false);
|
||||
|
@ -103,7 +103,7 @@ function run_test() {
|
||||
do_check_eq(typeof PlacesUtils, "object");
|
||||
|
||||
// make json file
|
||||
var jsonFile = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
var jsonFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
jsonFile.append("bookmarks.json");
|
||||
if (jsonFile.exists())
|
||||
jsonFile.remove(false);
|
||||
|
@ -134,7 +134,7 @@ function run_test() {
|
||||
do_check_eq(typeof PlacesUtils, "object");
|
||||
|
||||
// make json file
|
||||
var jsonFile = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
var jsonFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
jsonFile.append("bookmarks.json");
|
||||
if (jsonFile.exists())
|
||||
jsonFile.remove(false);
|
||||
|
@ -79,7 +79,7 @@ function run_test() {
|
||||
do_check_eq(typeof PlacesUtils, "object");
|
||||
|
||||
// make json file
|
||||
var jsonFile = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
var jsonFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
|
||||
jsonFile.append("bookmarks.json");
|
||||
if (jsonFile.exists())
|
||||
jsonFile.remove(false);
|
||||
|
@ -37,245 +37,21 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
const NS_APP_HISTORY_50_FILE = "UHist";
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
|
||||
function LOG(aMsg) {
|
||||
aMsg = ("*** PLACES TESTS: " + aMsg);
|
||||
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
|
||||
logStringMessage(aMsg);
|
||||
print(aMsg);
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Import common head.
|
||||
let (commonFile = do_get_file("../head_common.js", false)) {
|
||||
let uri = Services.io.newFileURI(commonFile);
|
||||
Services.scriptloader.loadSubScript(uri.spec, this);
|
||||
}
|
||||
|
||||
// If there's no location registered for the profile direcotry, register one now.
|
||||
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
var profileDir = null;
|
||||
try {
|
||||
profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
|
||||
} catch (e) {}
|
||||
if (!profileDir) {
|
||||
// Register our own provider for the profile directory.
|
||||
// It will simply return the current directory.
|
||||
var provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_USER_PROFILE_50_DIR)
|
||||
return dirSvc.get("CurProcD", Ci.nsIFile);
|
||||
if (prop == NS_APP_HISTORY_50_FILE) {
|
||||
var histFile = dirSvc.get("CurProcD", Ci.nsIFile);
|
||||
histFile.append("history.dat");
|
||||
return histFile;
|
||||
}
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
},
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
}
|
||||
// Put any other stuff relative to this test folder below.
|
||||
|
||||
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
|
||||
function uri(spec) {
|
||||
return iosvc.newURI(spec, null, null);
|
||||
}
|
||||
|
||||
// Delete a previously created sqlite file
|
||||
function clearDB() {
|
||||
try {
|
||||
var file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
if (file.exists())
|
||||
file.remove(false);
|
||||
} catch(ex) { dump("Exception: " + ex); }
|
||||
}
|
||||
clearDB();
|
||||
|
||||
/**
|
||||
* Dumps the rows of a table out to the console.
|
||||
*
|
||||
* @param aName
|
||||
* The name of the table or view to output.
|
||||
*/
|
||||
function dump_table(aName)
|
||||
{
|
||||
let db = DBConn()
|
||||
let stmt = db.createStatement("SELECT * FROM " + aName);
|
||||
|
||||
dump("\n*** Printing data from " + aName + ":\n");
|
||||
let count = 0;
|
||||
while (stmt.executeStep()) {
|
||||
let columns = stmt.numEntries;
|
||||
|
||||
if (count == 0) {
|
||||
// Print the column names.
|
||||
for (let i = 0; i < columns; i++)
|
||||
dump(stmt.getColumnName(i) + "\t");
|
||||
dump("\n");
|
||||
}
|
||||
|
||||
// Print the row.
|
||||
for (let i = 0; i < columns; i++) {
|
||||
switch (stmt.getTypeOfIndex(i)) {
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_NULL:
|
||||
dump("NULL\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_INTEGER:
|
||||
dump(stmt.getInt64(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_FLOAT:
|
||||
dump(stmt.getDouble(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_TEXT:
|
||||
dump(stmt.getString(i) + "\t");
|
||||
break;
|
||||
}
|
||||
}
|
||||
dump("\n");
|
||||
|
||||
count++;
|
||||
}
|
||||
dump("*** There were a total of " + count + " rows of data.\n\n");
|
||||
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function tests to see if the place associated with the bookmark with id
|
||||
* aBookmarkId has the uri aExpectedURI. The event will call do_test_finished()
|
||||
* if aFinish is true.
|
||||
*
|
||||
* @param aBookmarkId
|
||||
* The bookmark to check against.
|
||||
* @param aExpectedURI
|
||||
* The URI we expect to be in moz_places.
|
||||
* @param aExpected
|
||||
* Indicates if we expect to get a result or not.
|
||||
* @param [optional] aFinish
|
||||
* Indicates if the test should be completed or not.
|
||||
*/
|
||||
function new_test_bookmark_uri_event(aBookmarkId, aExpectedURI, aExpected, aFinish)
|
||||
{
|
||||
let db = DBConn();
|
||||
let stmt = db.createStatement(
|
||||
"SELECT moz_places.url " +
|
||||
"FROM moz_bookmarks INNER JOIN moz_places " +
|
||||
"ON moz_bookmarks.fk = moz_places.id " +
|
||||
"WHERE moz_bookmarks.id = ?1"
|
||||
);
|
||||
stmt.bindInt64Parameter(0, aBookmarkId);
|
||||
|
||||
if (aExpected) {
|
||||
do_check_true(stmt.executeStep());
|
||||
do_check_eq(stmt.getUTF8String(0), aExpectedURI);
|
||||
}
|
||||
else {
|
||||
do_check_false(stmt.executeStep());
|
||||
}
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
|
||||
if (aFinish)
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function tests to see if the place associated with the visit with id aVisitId
|
||||
* has the uri aExpectedURI. The event will call do_test_finished() if aFinish is
|
||||
* true.
|
||||
*
|
||||
* @param aVisitId
|
||||
* The visit to check against.
|
||||
* @param aExpectedURI
|
||||
* The URI we expect to be in moz_places.
|
||||
* @param aExpected
|
||||
* Indicates if we expect to get a result or not.
|
||||
* @param [optional] aFinish
|
||||
* Indicates if the test should be completed or not.
|
||||
*/
|
||||
function new_test_visit_uri_event(aVisitId, aExpectedURI, aExpected, aFinish)
|
||||
{
|
||||
let db = DBConn();
|
||||
let stmt = db.createStatement(
|
||||
"SELECT moz_places.url " +
|
||||
"FROM moz_historyvisits INNER JOIN moz_places " +
|
||||
"ON moz_historyvisits.place_id = moz_places.id " +
|
||||
"WHERE moz_historyvisits.id = ?1"
|
||||
);
|
||||
stmt.bindInt64Parameter(0, aVisitId);
|
||||
|
||||
if (aExpected) {
|
||||
do_check_true(stmt.executeStep());
|
||||
do_check_eq(stmt.getUTF8String(0), aExpectedURI);
|
||||
}
|
||||
else {
|
||||
do_check_false(stmt.executeStep());
|
||||
}
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
|
||||
if (aFinish)
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function gets current database connection, if the connection has been closed
|
||||
* it will try to reconnect to the places.sqlite database.
|
||||
*/
|
||||
function DBConn()
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
if (db.connectionReady)
|
||||
return db;
|
||||
|
||||
// open a new connection if needed
|
||||
let file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
let storageService = Cc["@mozilla.org/storage/service;1"].
|
||||
getService(Ci.mozIStorageService);
|
||||
|
||||
try {
|
||||
return dbConn = storageService.openDatabase(file);
|
||||
}
|
||||
catch(ex) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes any events in the event loop of the main thread.
|
||||
*/
|
||||
function flush_main_thread_events()
|
||||
{
|
||||
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
||||
while (tm.mainThread.hasPendingEvents())
|
||||
tm.mainThread.processNextEvent(false);
|
||||
}
|
||||
|
||||
// Simulates a Places shutdown.
|
||||
function shutdownPlaces()
|
||||
{
|
||||
const TOPIC_XPCOM_SHUTDOWN = "xpcom-shutdown";
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsIObserver);
|
||||
hs.observe(null, TOPIC_XPCOM_SHUTDOWN, null);
|
||||
let sync = Cc["@mozilla.org/places/sync;1"].getService(Ci.nsIObserver);
|
||||
sync.observe(null, TOPIC_XPCOM_SHUTDOWN, null);
|
||||
let expire = Cc["@mozilla.org/places/expiration;1"].getService(Ci.nsIObserver);
|
||||
expire.observe(null, TOPIC_XPCOM_SHUTDOWN, null);
|
||||
}
|
||||
|
||||
// Simulates an expiration at shutdown.
|
||||
function shutdownExpiration()
|
||||
@ -285,6 +61,7 @@ function shutdownExpiration()
|
||||
expire.observe(null, TOPIC_XPCOM_SHUTDOWN, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Causes expiration component to start, otherwise it would wait for the first
|
||||
* history notification.
|
||||
@ -293,6 +70,7 @@ function force_expiration_start() {
|
||||
Cc["@mozilla.org/places/expiration;1"].getService(Ci.nsISupports);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Forces an expiration run.
|
||||
*/
|
||||
@ -304,66 +82,48 @@ function force_expiration_step(aLimit) {
|
||||
expire.observe(null, TOPIC_DEBUG_START_EXPIRATION, aLimit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears history invoking callback when done.
|
||||
*/
|
||||
function waitForClearHistory(aCallback) {
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let observer = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
os.removeObserver(this, TOPIC_EXPIRATION_FINISHED);
|
||||
aCallback();
|
||||
}
|
||||
};
|
||||
os.addObserver(observer, TOPIC_EXPIRATION_FINISHED, false);
|
||||
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Expiration preferences helpers.
|
||||
*/
|
||||
let prefs = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
|
||||
function setInterval(aNewInterval) {
|
||||
prefs.setIntPref("places.history.expiration.interval_seconds", aNewInterval);
|
||||
Services.prefs.setIntPref("places.history.expiration.interval_seconds", aNewInterval);
|
||||
}
|
||||
function getInterval() {
|
||||
return prefs.getIntPref("places.history.expiration.interval_seconds");
|
||||
return Services.prefs.getIntPref("places.history.expiration.interval_seconds");
|
||||
}
|
||||
function clearInterval() {
|
||||
try {
|
||||
prefs.clearUserPref("places.history.expiration.interval_seconds");
|
||||
Services.prefs.clearUserPref("places.history.expiration.interval_seconds");
|
||||
}
|
||||
catch(ex) {}
|
||||
}
|
||||
|
||||
|
||||
function setMaxPages(aNewMaxPages) {
|
||||
prefs.setIntPref("places.history.expiration.max_pages", aNewMaxPages);
|
||||
Services.prefs.setIntPref("places.history.expiration.max_pages", aNewMaxPages);
|
||||
}
|
||||
function getMaxPages() {
|
||||
return prefs.getIntPref("places.history.expiration.max_pages");
|
||||
return Services.prefs.getIntPref("places.history.expiration.max_pages");
|
||||
}
|
||||
function clearMaxPages() {
|
||||
try {
|
||||
prefs.clearUserPref("places.history.expiration.max_pages");
|
||||
Services.prefs.clearUserPref("places.history.expiration.max_pages");
|
||||
}
|
||||
catch(ex) {}
|
||||
}
|
||||
|
||||
|
||||
function setHistoryEnabled(aHistoryEnabled) {
|
||||
prefs.setBoolPref("places.history.enabled", aHistoryEnabled);
|
||||
Services.prefs.setBoolPref("places.history.enabled", aHistoryEnabled);
|
||||
}
|
||||
function getHistoryEnabled() {
|
||||
return prefs.getBoolPref("places.history.enabled");
|
||||
return Services.prefs.getBoolPref("places.history.enabled");
|
||||
}
|
||||
function clearHistoryEnabled() {
|
||||
try {
|
||||
prefs.clearUserPref("places.history.enabled");
|
||||
Services.prefs.clearUserPref("places.history.enabled");
|
||||
}
|
||||
catch(ex) {}
|
||||
}
|
||||
|
@ -45,8 +45,6 @@
|
||||
* This expiration policy is only valid for page annotations.
|
||||
*/
|
||||
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
|
@ -48,8 +48,6 @@
|
||||
* the item is removed, thus expiration won't handle this case at all.
|
||||
*/
|
||||
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
|
@ -47,8 +47,6 @@
|
||||
* - EXPIRE_MONTHS: annotation would be expired after 180 days
|
||||
*/
|
||||
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
@ -76,7 +74,6 @@ function add_old_anno(aIdentifier, aName, aValue, aExpirePolicy,
|
||||
if (aLastModifiedAgeInDays)
|
||||
lastModifiedDate = (now - (aLastModifiedAgeInDays * 86400 * 1000)) * 1000;
|
||||
|
||||
let dbConn = DBConn();
|
||||
let sql;
|
||||
if (typeof(aIdentifier) == "number") {
|
||||
// Item annotation.
|
||||
@ -100,7 +97,7 @@ function add_old_anno(aIdentifier, aName, aValue, aExpirePolicy,
|
||||
else
|
||||
do_throw("Wrong identifier type");
|
||||
|
||||
let stmt = dbConn.createStatement(sql);
|
||||
let stmt = DBConn().createStatement(sql);
|
||||
stmt.params.id = (typeof(aIdentifier) == "number") ? aIdentifier
|
||||
: aIdentifier.spec;
|
||||
stmt.params.expire_date = expireDate;
|
||||
|
@ -43,8 +43,6 @@
|
||||
* Session annotations should be expired when browsing session ends.
|
||||
*/
|
||||
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
|
@ -43,8 +43,6 @@
|
||||
* Ensure that History (through category cache) notifies us just once.
|
||||
*/
|
||||
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
|
@ -43,8 +43,6 @@
|
||||
* Expiring a full page should fire an onDeleteURI notification.
|
||||
*/
|
||||
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
|
@ -44,8 +44,6 @@
|
||||
* onDeleteVisits notification.
|
||||
*/
|
||||
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
|
@ -47,7 +47,6 @@
|
||||
* If the pref is set to a number <= 0 we will use the default value.
|
||||
*/
|
||||
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
const MAX_WAIT_SECONDS = 4;
|
||||
const INTERVAL_CUSHION = 2;
|
||||
|
||||
|
@ -47,8 +47,6 @@
|
||||
* If the pref is set to a number < 0 we will use the default value.
|
||||
*/
|
||||
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
|
@ -44,8 +44,6 @@
|
||||
* annos.
|
||||
*/
|
||||
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
@ -73,7 +71,6 @@ function add_old_anno(aIdentifier, aName, aValue, aExpirePolicy,
|
||||
if (aLastModifiedAgeInDays)
|
||||
lastModifiedDate = (now - (aLastModifiedAgeInDays * 86400 * 1000)) * 1000;
|
||||
|
||||
let dbConn = DBConn();
|
||||
let sql;
|
||||
if (typeof(aIdentifier) == "number") {
|
||||
// Item annotation.
|
||||
@ -97,7 +94,7 @@ function add_old_anno(aIdentifier, aName, aValue, aExpirePolicy,
|
||||
else
|
||||
do_throw("Wrong identifier type");
|
||||
|
||||
let stmt = dbConn.createStatement(sql);
|
||||
let stmt = DBConn().createStatement(sql);
|
||||
stmt.params.id = (typeof(aIdentifier) == "number") ? aIdentifier
|
||||
: aIdentifier.spec;
|
||||
stmt.params.expire_date = expireDate;
|
||||
|
504
toolkit/components/places/tests/head_common.js
Normal file
504
toolkit/components/places/tests/head_common.js
Normal file
@ -0,0 +1,504 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* ***** 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 Tests Code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is the Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* 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 ***** */
|
||||
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
const NS_APP_PROFILE_DIR_STARTUP = "ProfDS";
|
||||
const NS_APP_HISTORY_50_FILE = "UHist";
|
||||
const NS_APP_BOOKMARKS_50_FILE = "BMarks";
|
||||
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
const TOPIC_SHUTDOWN = "xpcom-shutdown";
|
||||
const TOPIC_PLACES_INIT_COMPLETE = "places-init-complete";
|
||||
const TOPIC_PLACES_DATABASE_LOCKED = "places-database-locked";
|
||||
|
||||
// Shortcuts to transactions type.
|
||||
const TRANSITION_LINK = Ci.nsINavHistoryService.TRANSITION_LINK;
|
||||
const TRANSITION_TYPED = Ci.nsINavHistoryService.TRANSITION_TYPED;
|
||||
const TRANSITION_BOOKMARK = Ci.nsINavHistoryService.TRANSITION_BOOKMARK;
|
||||
const TRANSITION_EMBED = Ci.nsINavHistoryService.TRANSITION_EMBED;
|
||||
const TRANSITION_FRAMED_LINK = Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK;
|
||||
const TRANSITION_REDIRECT_PERMANENT = Ci.nsINavHistoryService.TRANSITION_REDIRECT_PERMANENT;
|
||||
const TRANSITION_REDIRECT_TEMPORARY = Ci.nsINavHistoryService.TRANSITION_REDIRECT_TEMPORARY;
|
||||
const TRANSITION_DOWNLOAD = Ci.nsINavHistoryService.TRANSITION_DOWNLOAD;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "Services", function() {
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
return Services;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "NetUtil", function() {
|
||||
Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||
return NetUtil;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "PlacesUtils", function() {
|
||||
Cu.import("resource://gre/modules/utils.js");
|
||||
return PlacesUtils;
|
||||
});
|
||||
|
||||
|
||||
function LOG(aMsg) {
|
||||
aMsg = ("*** PLACES TESTS: " + aMsg);
|
||||
Services.console.logStringMessage(aMsg);
|
||||
print(aMsg);
|
||||
}
|
||||
|
||||
|
||||
let gTestDir = do_get_cwd();
|
||||
|
||||
|
||||
// Initialize profile.
|
||||
let gProfD = do_get_profile();
|
||||
|
||||
// Add our own dirprovider for old history.dat.
|
||||
let (provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_HISTORY_50_FILE) {
|
||||
let histFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
||||
histFile.append("history.dat");
|
||||
return histFile;
|
||||
}
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider])
|
||||
})
|
||||
{
|
||||
Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIDirectoryService).
|
||||
QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
}
|
||||
|
||||
|
||||
// Remove any old database.
|
||||
clearDB();
|
||||
|
||||
|
||||
/**
|
||||
* Shortcut to create a nsIURI.
|
||||
*
|
||||
* @param aSpec
|
||||
* URLString of the uri.
|
||||
*/
|
||||
function uri(aSpec) NetUtil.newURI(aSpec);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the database connection. If the Places connection is invalid it will
|
||||
* try to create a new connection.
|
||||
*
|
||||
* @return The database connection or null if unable to get one.
|
||||
*/
|
||||
function DBConn() {
|
||||
let db = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
|
||||
.DBConnection;
|
||||
if (db.connectionReady)
|
||||
return db;
|
||||
|
||||
// If the database has been closed, then we need to open a new connection.
|
||||
let file = Services.dirsvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
return Services.storage.openDatabase(file);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Reads the data from the specified nsIFile, and returns an array of bytes.
|
||||
*
|
||||
* @param aFile
|
||||
* The nsIFile to read from.
|
||||
*/
|
||||
function readFileData(aFile) {
|
||||
let inputStream = Cc["@mozilla.org/network/file-input-stream;1"].
|
||||
createInstance(Ci.nsIFileInputStream);
|
||||
// init the stream as RD_ONLY, -1 == default permissions.
|
||||
inputStream.init(aFile, 0x01, -1, null);
|
||||
let size = inputStream.available();
|
||||
|
||||
// use a binary input stream to grab the bytes.
|
||||
let bis = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
bis.setInputStream(inputStream);
|
||||
|
||||
let bytes = bis.readByteArray(size);
|
||||
|
||||
if (size != bytes.length)
|
||||
throw "Didn't read expected number of bytes";
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compares two arrays, and returns true if they are equal.
|
||||
*
|
||||
* @param aArray1
|
||||
* First array to compare.
|
||||
* @param aArray2
|
||||
* Second array to compare.
|
||||
*/
|
||||
function compareArrays(aArray1, aArray2) {
|
||||
if (aArray1.length != aArray2.length) {
|
||||
print("compareArrays: array lengths differ\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < aArray1.length; i++) {
|
||||
if (aArray1[i] != aArray2[i]) {
|
||||
print("compareArrays: arrays differ at index " + i + ": " +
|
||||
"(" + aArray1[i] + ") != (" + aArray2[i] +")\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deletes a previously created sqlite file from the profile folder.
|
||||
*/
|
||||
function clearDB() {
|
||||
try {
|
||||
let file = Services.dirsvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
if (file.exists())
|
||||
file.remove(false);
|
||||
} catch(ex) { dump("Exception: " + ex); }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dumps the rows of a table out to the console.
|
||||
*
|
||||
* @param aName
|
||||
* The name of the table or view to output.
|
||||
*/
|
||||
function dump_table(aName)
|
||||
{
|
||||
let stmt = DBConn().createStatement("SELECT * FROM " + aName);
|
||||
|
||||
print("\n*** Printing data from " + aName);
|
||||
let count = 0;
|
||||
while (stmt.executeStep()) {
|
||||
let columns = stmt.numEntries;
|
||||
|
||||
if (count == 0) {
|
||||
// Print the column names.
|
||||
for (let i = 0; i < columns; i++)
|
||||
dump(stmt.getColumnName(i) + "\t");
|
||||
dump("\n");
|
||||
}
|
||||
|
||||
// Print the rows.
|
||||
for (let i = 0; i < columns; i++) {
|
||||
switch (stmt.getTypeOfIndex(i)) {
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_NULL:
|
||||
dump("NULL\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_INTEGER:
|
||||
dump(stmt.getInt64(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_FLOAT:
|
||||
dump(stmt.getDouble(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_TEXT:
|
||||
dump(stmt.getString(i) + "\t");
|
||||
break;
|
||||
}
|
||||
}
|
||||
dump("\n");
|
||||
|
||||
count++;
|
||||
}
|
||||
print("*** There were a total of " + count + " rows of data.\n");
|
||||
|
||||
stmt.finalize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes all bookmarks and checks for correct cleanup
|
||||
*/
|
||||
function remove_all_bookmarks() {
|
||||
let PU = PlacesUtils;
|
||||
// Clear all bookmarks
|
||||
PU.bookmarks.removeFolderChildren(PU.bookmarks.bookmarksMenuFolder);
|
||||
PU.bookmarks.removeFolderChildren(PU.bookmarks.toolbarFolder);
|
||||
PU.bookmarks.removeFolderChildren(PU.bookmarks.unfiledBookmarksFolder);
|
||||
// Check for correct cleanup
|
||||
check_no_bookmarks();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks that we don't have any bookmark
|
||||
*/
|
||||
function check_no_bookmarks() {
|
||||
let query = PlacesUtils.history.getNewQuery();
|
||||
let folders = [
|
||||
PlacesUtils.bookmarks.toolbarFolder,
|
||||
PlacesUtils.bookmarks.bookmarksMenuFolder,
|
||||
PlacesUtils.bookmarks.unfiledBookmarksFolder,
|
||||
];
|
||||
query.setFolders(folders, 3);
|
||||
let options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
|
||||
let root = PlacesUtils.history.executeQuery(query, options).root;
|
||||
root.containerOpen = true;
|
||||
do_check_eq(root.childCount, 0);
|
||||
root.containerOpen = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets title synchronously for a page in moz_places synchronously.
|
||||
* History.SetPageTitle uses LAZY_ADD so we can't rely on it.
|
||||
*
|
||||
* @param aURI
|
||||
* An nsIURI to set the title for.
|
||||
* @param aTitle
|
||||
* The title to set the page to.
|
||||
* @throws if the page is not found in the database.
|
||||
*
|
||||
* @note this function only exists because we have no API to do this. It should
|
||||
* be added in bug 421897.
|
||||
*/
|
||||
function setPageTitle(aURI, aTitle) {
|
||||
// Check that the page exists.
|
||||
let stmt = DBConn().createStatement(
|
||||
"SELECT id FROM moz_places_view WHERE url = :url"
|
||||
);
|
||||
stmt.params.url = aURI.spec;
|
||||
try {
|
||||
if (!stmt.executeStep()) {
|
||||
do_throw("Unable to find page " + aURI.spec);
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
stmt.finalize();
|
||||
}
|
||||
|
||||
// Update the title
|
||||
stmt = DBConn().createStatement(
|
||||
"UPDATE moz_places_view SET title = :title WHERE url = :url"
|
||||
);
|
||||
stmt.params.title = aTitle;
|
||||
stmt.params.url = aURI.spec;
|
||||
try {
|
||||
stmt.execute();
|
||||
}
|
||||
finally {
|
||||
stmt.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clears history invoking callback when done.
|
||||
*
|
||||
* @param aCallback
|
||||
* Callback function to be called once clear history has finished.
|
||||
*/
|
||||
function waitForClearHistory(aCallback) {
|
||||
let observer = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(this, TOPIC_EXPIRATION_FINISHED);
|
||||
aCallback();
|
||||
}
|
||||
};
|
||||
Services.obs.addObserver(observer, TOPIC_EXPIRATION_FINISHED, false);
|
||||
|
||||
PlacesUtils.bhistory.removeAllPages();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simulates a Places shutdown.
|
||||
*/
|
||||
function shutdownPlaces()
|
||||
{
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsIObserver);
|
||||
hs.observe(null, TOPIC_SHUTDOWN, null);
|
||||
|
||||
let sync = Cc["@mozilla.org/places/sync;1"].
|
||||
getService(Ci.nsIObserver);
|
||||
sync.observe(null, TOPIC_SHUTDOWN, null);
|
||||
|
||||
let expire = Cc["@mozilla.org/places/expiration;1"].
|
||||
getService(Ci.nsIObserver);
|
||||
expire.observe(null, TOPIC_SHUTDOWN, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (!aFilename)
|
||||
do_throw("you must pass a filename to create_bookmarks_html function");
|
||||
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) {
|
||||
if (!aFilename)
|
||||
do_throw("you must pass a filename to create_JSON_backup function");
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
// These tests are known to randomly fail due to bug 507790 when database
|
||||
// flushes are active, so we turn off syncing for them.
|
||||
let (randomFailingSyncTests = [
|
||||
"test_multi_word_tags.js",
|
||||
"test_removeVisitsByTimeframe.js",
|
||||
"test_utils_getURLsForContainerNode.js",
|
||||
"test_exclude_livemarks.js",
|
||||
"test_402799.js",
|
||||
"test_results-as-visit.js",
|
||||
"test_sorting.js",
|
||||
"test_redirectsMode.js",
|
||||
"test_384228.js",
|
||||
"test_395593.js",
|
||||
"test_containersQueries_sorting.js",
|
||||
"test_browserGlue_smartBookmarks.js",
|
||||
"test_browserGlue_distribution.js",
|
||||
]) {
|
||||
let currentTestFilename = do_get_file(_TEST_FILE[0], true).leafName;
|
||||
if (randomFailingSyncTests.indexOf(currentTestFilename) != -1) {
|
||||
print("Test " + currentTestFilename +
|
||||
" is known random due to bug 507790, disabling PlacesDBFlush.");
|
||||
let sync = Cc["@mozilla.org/places/sync;1"].getService(Ci.nsIObserver);
|
||||
sync.observe(null, "places-debug-stop-sync", null);
|
||||
}
|
||||
}
|
@ -37,292 +37,16 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
const NS_APP_HISTORY_50_FILE = "UHist";
|
||||
|
||||
// This will also define Cc, Ci.
|
||||
// This will also define Cc, Ci, Cr, Cu.
|
||||
do_load_httpd_js();
|
||||
|
||||
function LOG(aMsg) {
|
||||
aMsg = ("*** PLACES TESTS: " + aMsg);
|
||||
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
|
||||
logStringMessage(aMsg);
|
||||
print(aMsg);
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Import common head.
|
||||
let (commonFile = do_get_file("../head_common.js", false)) {
|
||||
let uri = Services.io.newFileURI(commonFile);
|
||||
Services.scriptloader.loadSubScript(uri.spec, this);
|
||||
}
|
||||
|
||||
do_get_profile();
|
||||
// Put any other stuff relative to this test folder below.
|
||||
|
||||
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
var provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_HISTORY_50_FILE) {
|
||||
var histFile = dirSvc.get("ProfD", Ci.nsIFile);
|
||||
histFile.append("history.dat");
|
||||
return histFile;
|
||||
}
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
},
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
|
||||
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
|
||||
function uri(spec) {
|
||||
return iosvc.newURI(spec, null, null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads the data from the specified nsIFile, and returns an array of bytes.
|
||||
*/
|
||||
function readFileData(aFile) {
|
||||
var inputStream = Cc["@mozilla.org/network/file-input-stream;1"].
|
||||
createInstance(Ci.nsIFileInputStream);
|
||||
// init the stream as RD_ONLY, -1 == default permissions.
|
||||
inputStream.init(aFile, 0x01, -1, null);
|
||||
var size = inputStream.available();
|
||||
|
||||
// use a binary input stream to grab the bytes.
|
||||
var bis = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
bis.setInputStream(inputStream);
|
||||
|
||||
var bytes = bis.readByteArray(size);
|
||||
|
||||
if (size != bytes.length)
|
||||
throw "Didn't read expected number of bytes";
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compares two arrays, and returns true if they are equal.
|
||||
*/
|
||||
function compareArrays(aArray1, aArray2) {
|
||||
if (aArray1.length != aArray2.length) {
|
||||
print("compareArrays: array lengths differ\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < aArray1.length; i++) {
|
||||
if (aArray1[i] != aArray2[i]) {
|
||||
print("compareArrays: arrays differ at index " + i + ": " +
|
||||
"(" + aArray1[i] + ") != (" + aArray2[i] +")\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Delete a previously created sqlite file
|
||||
function clearDB() {
|
||||
try {
|
||||
var file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
if (file.exists())
|
||||
file.remove(false);
|
||||
} catch(ex) { dump("Exception: " + ex); }
|
||||
}
|
||||
clearDB();
|
||||
|
||||
/**
|
||||
* Dumps the rows of a table out to the console.
|
||||
*
|
||||
* @param aName
|
||||
* The name of the table or view to output.
|
||||
*/
|
||||
function dump_table(aName)
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
let stmt = db.createStatement("SELECT * FROM " + aName);
|
||||
|
||||
dump("\n*** Printing data from " + aName + ":\n");
|
||||
let count = 0;
|
||||
while (stmt.executeStep()) {
|
||||
let columns = stmt.numEntries;
|
||||
|
||||
if (count == 0) {
|
||||
// print the column names
|
||||
for (let i = 0; i < columns; i++)
|
||||
dump(stmt.getColumnName(i) + "\t");
|
||||
dump("\n");
|
||||
}
|
||||
|
||||
// print the row
|
||||
for (let i = 0; i < columns; i++) {
|
||||
switch (stmt.getTypeOfIndex(i)) {
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_NULL:
|
||||
dump("NULL\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_INTEGER:
|
||||
dump(stmt.getInt64(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_FLOAT:
|
||||
dump(stmt.getDouble(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_TEXT:
|
||||
dump(stmt.getString(i) + "\t");
|
||||
break;
|
||||
}
|
||||
}
|
||||
dump("\n");
|
||||
|
||||
count++;
|
||||
}
|
||||
dump("*** There were a total of " + count + " rows of data.\n\n");
|
||||
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes all bookmarks and checks for correct cleanup
|
||||
*/
|
||||
function remove_all_bookmarks() {
|
||||
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
// Clear all bookmarks
|
||||
bs.removeFolderChildren(bs.bookmarksMenuFolder);
|
||||
bs.removeFolderChildren(bs.toolbarFolder);
|
||||
bs.removeFolderChildren(bs.unfiledBookmarksFolder);
|
||||
// Check for correct cleanup
|
||||
check_no_bookmarks()
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks that we don't have any bookmark
|
||||
*/
|
||||
function check_no_bookmarks() {
|
||||
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
var query = hs.getNewQuery();
|
||||
query.setFolders([bs.toolbarFolder, bs.bookmarksMenuFolder, bs.unfiledBookmarksFolder], 3);
|
||||
var options = hs.getNewQueryOptions();
|
||||
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
|
||||
var result = hs.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
do_check_eq(root.childCount, 0);
|
||||
root.containerOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function gets current database connection, if the connection has been closed
|
||||
* it will try to reconnect to the places.sqlite database.
|
||||
*/
|
||||
function DBConn()
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
if (db.connectionReady)
|
||||
return db;
|
||||
|
||||
// open a new connection if needed
|
||||
let file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
let storageService = Cc["@mozilla.org/storage/service;1"].
|
||||
getService(Ci.mozIStorageService);
|
||||
try {
|
||||
var dbConn = storageService.openDatabase(file);
|
||||
} catch (ex) {
|
||||
return null;
|
||||
}
|
||||
return dbConn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets title synchronously for a page in moz_places synchronously.
|
||||
* History.SetPageTitle uses LAZY_ADD so we can't rely on it.
|
||||
*
|
||||
* @param aURI
|
||||
* An nsIURI to set the title for.
|
||||
* @param aTitle
|
||||
* The title to set the page to.
|
||||
* @throws if the page is not found in the database.
|
||||
*
|
||||
* @note this function only exists because we have no API to do this. It should
|
||||
* be added in bug 421897.
|
||||
*/
|
||||
function setPageTitle(aURI, aTitle) {
|
||||
let dbConn = DBConn();
|
||||
// Check that the page exists.
|
||||
let stmt = dbConn.createStatement(
|
||||
"SELECT id FROM moz_places_view WHERE url = :url");
|
||||
stmt.params.url = aURI.spec;
|
||||
try {
|
||||
if (!stmt.executeStep()) {
|
||||
do_throw("Unable to find page " + aURIString);
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
stmt.finalize();
|
||||
}
|
||||
|
||||
// Update the title
|
||||
stmt = dbConn.createStatement(
|
||||
"UPDATE moz_places_view SET title = :title WHERE url = :url");
|
||||
stmt.params.title = aTitle;
|
||||
stmt.params.url = aURI.spec;
|
||||
try {
|
||||
stmt.execute();
|
||||
}
|
||||
finally {
|
||||
stmt.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes any events in the event loop of the main thread.
|
||||
*/
|
||||
function flush_main_thread_events()
|
||||
{
|
||||
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
||||
while (tm.mainThread.hasPendingEvents())
|
||||
tm.mainThread.processNextEvent(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears history invoking callback when done.
|
||||
*/
|
||||
function waitForClearHistory(aCallback) {
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let observer = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
os.removeObserver(this, TOPIC_EXPIRATION_FINISHED);
|
||||
aCallback();
|
||||
}
|
||||
};
|
||||
os.addObserver(observer, TOPIC_EXPIRATION_FINISHED, false);
|
||||
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
|
||||
}
|
||||
|
||||
// These tests are known to randomly fail due to bug 507790 when database
|
||||
// flushes are active, so we turn off syncing for them.
|
||||
let randomFailingSyncTests = [
|
||||
];
|
||||
let currentTestFilename = do_get_file(_TEST_FILE[0], true).leafName;
|
||||
if (randomFailingSyncTests.indexOf(currentTestFilename) != -1) {
|
||||
print("Test " + currentTestFilename + " is known random due to bug 507790, disabling PlacesDBFlush component.");
|
||||
let sync = Cc["@mozilla.org/places/sync;1"].getService(Ci.nsIObserver);
|
||||
sync.observe(null, "places-debug-stop-sync", null);
|
||||
}
|
||||
|
@ -44,9 +44,6 @@ let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
let bh = hs.QueryInterface(Ci.nsIBrowserHistory);
|
||||
let ghist3 = hs.QueryInterface(Ci.nsIGlobalHistory3);
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
const PERMA_REDIR_PATH = "/permaredir";
|
||||
const TEMP_REDIR_PATH = "/tempredir";
|
||||
const FOUND_PATH = "/found";
|
||||
@ -110,8 +107,7 @@ function run_test() {
|
||||
}
|
||||
|
||||
function continue_test() {
|
||||
let dbConn = DBConn();
|
||||
let stmt = dbConn.createStatement(
|
||||
let stmt = DBConn().createStatement(
|
||||
"SELECT v.id, h.url, v.from_visit, v.visit_date, v.visit_type, v.session " +
|
||||
"FROM moz_historyvisits_view v " +
|
||||
"JOIN moz_places_view h on h.id = v.place_id " +
|
||||
|
@ -35,12 +35,22 @@
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
const NS_APP_HISTORY_50_FILE = "UHist";
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Import common head.
|
||||
let (commonFile = do_get_file("../head_common.js", false)) {
|
||||
let uri = Services.io.newFileURI(commonFile);
|
||||
Services.scriptloader.loadSubScript(uri.spec, this);
|
||||
}
|
||||
|
||||
// Put any other stuff relative to this test folder below.
|
||||
|
||||
|
||||
// Some Useful Date constants - PRTime uses microseconds, so convert
|
||||
const DAY_MICROSEC = 86400000000;
|
||||
@ -52,100 +62,6 @@ const tomorrow = today + DAY_MICROSEC;
|
||||
const old = today - (DAY_MICROSEC * 3);
|
||||
const futureday = today + (DAY_MICROSEC * 3);
|
||||
|
||||
function LOG(aMsg) {
|
||||
aMsg = ("*** PLACES TESTS: " + aMsg);
|
||||
print(aMsg);
|
||||
}
|
||||
|
||||
// If there's no location registered for the profile directory, register one now.
|
||||
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
var profileDir = do_get_profile();
|
||||
|
||||
var provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_HISTORY_50_FILE) {
|
||||
var histFile = profileDir.clone();
|
||||
histFile.append("history.dat");
|
||||
return histFile;
|
||||
}
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
},
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
|
||||
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
|
||||
function uri(spec) {
|
||||
return iosvc.newURI(spec, null, null);
|
||||
}
|
||||
|
||||
// Delete a previously created sqlite file
|
||||
function clearDB() {
|
||||
try {
|
||||
var file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
if (file.exists())
|
||||
file.remove(false);
|
||||
} catch(ex) { dump("Exception: " + ex); }
|
||||
}
|
||||
clearDB();
|
||||
|
||||
// Get our interfaces
|
||||
try {
|
||||
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
} catch(ex) {
|
||||
do_throw("Could not get history service\n");
|
||||
}
|
||||
|
||||
try {
|
||||
var bhistsvc = histsvc.QueryInterface(Ci.nsIBrowserHistory);
|
||||
} catch(ex) {
|
||||
do_throw("Could not get browser history service\n");
|
||||
}
|
||||
|
||||
try {
|
||||
var annosvc = Cc["@mozilla.org/browser/annotation-service;1"].
|
||||
getService(Ci.nsIAnnotationService);
|
||||
} catch(ex) {
|
||||
do_throw("Could not get annotation service\n");
|
||||
}
|
||||
|
||||
try {
|
||||
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
} catch (ex) {
|
||||
do_throw("Could not get bookmark service\n");
|
||||
}
|
||||
|
||||
try {
|
||||
var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].
|
||||
getService(Ci.nsITaggingService);
|
||||
} catch(ex) {
|
||||
do_throw("Could not get tagging service\n");
|
||||
}
|
||||
|
||||
try {
|
||||
var faviconsvc = Cc["@mozilla.org/browser/favicon-service;1"].
|
||||
getService(Ci.nsIFaviconService);
|
||||
} catch(ex) {
|
||||
do_throw("Could not get favicon service\n");
|
||||
}
|
||||
|
||||
try {
|
||||
var lmsvc = Cc["@mozilla.org/browser/livemark-service;2"].
|
||||
getService(Ci.nsILivemarkService);
|
||||
} catch(ex) {
|
||||
do_throw("Could not get livemark service\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generalized function to pull in an array of objects of data and push it into
|
||||
@ -154,6 +70,7 @@ try {
|
||||
*/
|
||||
function populateDB(aArray) {
|
||||
aArray.forEach(function(data) {
|
||||
dump_table("moz_bookmarks");
|
||||
try {
|
||||
// make the data object into a query data object in order to create proper
|
||||
// default values for anything left unspecified
|
||||
@ -161,23 +78,21 @@ function populateDB(aArray) {
|
||||
if (qdata.isVisit) {
|
||||
// Then we should add a visit for this node
|
||||
var referrer = qdata.referrer ? uri(qdata.referrer) : null;
|
||||
var visitId = histsvc.addVisit(uri(qdata.uri), qdata.lastVisit,
|
||||
referrer, qdata.transType,
|
||||
qdata.isRedirect, qdata.sessionID);
|
||||
var visitId = PlacesUtils.history.addVisit(uri(qdata.uri), qdata.lastVisit,
|
||||
referrer, qdata.transType,
|
||||
qdata.isRedirect, qdata.sessionID);
|
||||
do_check_true(visitId > 0);
|
||||
if (qdata.title && !qdata.isDetails) {
|
||||
// Set the page title synchronously, otherwise setPageTitle is LAZY.
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
let stmt = db.createStatement("UPDATE moz_places_view " +
|
||||
"SET title = :title WHERE url = :url");
|
||||
let stmt = DBConn().createStatement(
|
||||
"UPDATE moz_places_view SET title = :title WHERE url = :url"
|
||||
);
|
||||
stmt.params.title = qdata.title;
|
||||
stmt.params.url = qdata.uri;
|
||||
try {
|
||||
stmt.execute();
|
||||
// Force a notification so results are updated.
|
||||
histsvc.runInBatchMode({runBatched: function(){}}, null);
|
||||
PlacesUtils.history.runInBatchMode({runBatched: function(){}}, null);
|
||||
}
|
||||
finally {
|
||||
stmt.finalize();
|
||||
@ -186,17 +101,14 @@ function populateDB(aArray) {
|
||||
if (qdata.visitCount && !qdata.isDetails) {
|
||||
// Set a fake visit_count, this is not a real count but can be used
|
||||
// to test sorting by visit_count.
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
let stmt = db.createStatement("UPDATE moz_places_view " +
|
||||
"SET visit_count = :vc WHERE url = :url");
|
||||
let stmt = DBConn().createStatement(
|
||||
"UPDATE moz_places_view SET visit_count = :vc WHERE url = :url");
|
||||
stmt.params.vc = qdata.visitCount;
|
||||
stmt.params.url = qdata.uri;
|
||||
try {
|
||||
stmt.execute();
|
||||
// Force a notification so results are updated.
|
||||
histsvc.runInBatchMode({runBatched: function(){}}, null);
|
||||
PlacesUtils.history.runInBatchMode({runBatched: function(){}}, null);
|
||||
}
|
||||
finally {
|
||||
stmt.finalize();
|
||||
@ -206,57 +118,71 @@ function populateDB(aArray) {
|
||||
|
||||
if (qdata.isDetails) {
|
||||
// Then we add extraneous page details for testing
|
||||
bhistsvc.addPageWithDetails(uri(qdata.uri), qdata.title, qdata.lastVisit);
|
||||
PlacesUtils.history.addPageWithDetails(uri(qdata.uri),
|
||||
qdata.title, qdata.lastVisit);
|
||||
}
|
||||
|
||||
if (qdata.markPageAsTyped){
|
||||
bhistsvc.markPageAsTyped(uri(qdata.uri));
|
||||
PlacesUtils.bhistory.markPageAsTyped(uri(qdata.uri));
|
||||
}
|
||||
|
||||
if (qdata.hidePage){
|
||||
bhistsvc.hidePage(uri(qdata.uri));
|
||||
PlacesUtils.bhistory.hidePage(uri(qdata.uri));
|
||||
}
|
||||
|
||||
if (qdata.isPageAnnotation) {
|
||||
if (qdata.removeAnnotation)
|
||||
annosvc.removePageAnnotation(uri(qdata.uri), qdata.annoName);
|
||||
PlacesUtils.annotations.removePageAnnotation(uri(qdata.uri),
|
||||
qdata.annoName);
|
||||
else {
|
||||
annosvc.setPageAnnotation(uri(qdata.uri),
|
||||
qdata.annoName, qdata.annoVal,
|
||||
qdata.annoFlags, qdata.annoExpiration);
|
||||
PlacesUtils.annotations.setPageAnnotation(uri(qdata.uri),
|
||||
qdata.annoName,
|
||||
qdata.annoVal,
|
||||
qdata.annoFlags,
|
||||
qdata.annoExpiration);
|
||||
}
|
||||
}
|
||||
|
||||
if (qdata.isItemAnnotation) {
|
||||
if (qdata.removeAnnotation)
|
||||
annosvc.removeItemAnnotation(qdata.itemId, qdata.annoName);
|
||||
PlacesUtils.annotations.removeItemAnnotation(qdata.itemId,
|
||||
qdata.annoName);
|
||||
else {
|
||||
annosvc.setItemAnnotation(qdata.itemId, qdata.annoName, qdata.annoVal,
|
||||
qdata.annoFlags, qdata.annoExpiration);
|
||||
PlacesUtils.annotations.setItemAnnotation(qdata.itemId,
|
||||
qdata.annoName,
|
||||
qdata.annoVal,
|
||||
qdata.annoFlags,
|
||||
qdata.annoExpiration);
|
||||
}
|
||||
}
|
||||
|
||||
if (qdata.isPageBinaryAnnotation) {
|
||||
if (qdata.removeAnnotation)
|
||||
annosvc.removePageAnnotation(uri(qdata.uri), qdata.annoName);
|
||||
PlacesUtils.annotations.removePageAnnotation(uri(qdata.uri),
|
||||
qdata.annoName);
|
||||
else {
|
||||
annosvc.setPageAnnotationBinary(uri(qdata.uri), qdata.annoName,
|
||||
qdata.binarydata,
|
||||
qdata.binaryDataLength,
|
||||
qdata.annoMimeType, qdata.annoFlags,
|
||||
qdata.annoExpiration);
|
||||
PlacesUtils.annotations.setPageAnnotationBinary(uri(qdata.uri),
|
||||
qdata.annoName,
|
||||
qdata.binarydata,
|
||||
qdata.binaryDataLength,
|
||||
qdata.annoMimeType,
|
||||
qdata.annoFlags,
|
||||
qdata.annoExpiration);
|
||||
}
|
||||
}
|
||||
|
||||
if (qdata.isItemBinaryAnnotation) {
|
||||
if (qdata.removeAnnotation)
|
||||
annosvc.removeItemAnnotation(qdata.itemId, qdata.annoName);
|
||||
PlacesUtils.annotations.removeItemAnnotation(qdata.itemId,
|
||||
qdata.annoName);
|
||||
else {
|
||||
annosvc.setItemAnnotationBinary(qdata.itemId, qdata.annoName,
|
||||
qdata.binaryData,
|
||||
qdata.binaryDataLength,
|
||||
qdata.annoMimeType, qdata.annoFlags,
|
||||
qdata.annoExpiration);
|
||||
PlacesUtils.annotations.setItemAnnotationBinary(qdata.itemId,
|
||||
qdata.annoName,
|
||||
qdata.binaryData,
|
||||
qdata.binaryDataLength,
|
||||
qdata.annoMimeType,
|
||||
qdata.annoFlags,
|
||||
qdata.annoExpiration);
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,42 +190,54 @@ function populateDB(aArray) {
|
||||
// Not planning on doing deep testing of favIcon service so these two
|
||||
// calls should be sufficient to get favicons into the database
|
||||
try {
|
||||
faviconsvc.setFaviconData(uri(qdata.faviconURI), qdata.favicon,
|
||||
qdata.faviconLen, qdata.faviconMimeType,
|
||||
qdata.faviconExpiration);
|
||||
PlacesUtils.favicons.setFaviconData(uri(qdata.faviconURI),
|
||||
qdata.favicon,
|
||||
qdata.faviconLen,
|
||||
qdata.faviconMimeType,
|
||||
qdata.faviconExpiration);
|
||||
} catch (ex) {}
|
||||
faviconsvc.setFaviconUrlForPage(uri(qdata.uri), uri(qdata.faviconURI));
|
||||
PlacesUtils.favicons.setFaviconUrlForPage(uri(qdata.uri),
|
||||
uri(qdata.faviconURI));
|
||||
}
|
||||
|
||||
if (qdata.isFolder) {
|
||||
let folderId = bmsvc.createFolder(qdata.parentFolder, qdata.title, qdata.index);
|
||||
let folderId = PlacesUtils.bookmarks.createFolder(qdata.parentFolder,
|
||||
qdata.title,
|
||||
qdata.index);
|
||||
if (qdata.readOnly)
|
||||
bmsvc.setFolderReadonly(folderId, true);
|
||||
PlacesUtils.bookmarks.setFolderReadonly(folderId, true);
|
||||
}
|
||||
|
||||
if (qdata.isLivemark) {
|
||||
lmsvc.createLivemark(qdata.parentFolder, qdata.title, uri(qdata.uri),
|
||||
uri(qdata.feedURI), qdata.index);
|
||||
PlacesUtils.livemarks.createLivemark(qdata.parentFolder,
|
||||
qdata.title,
|
||||
uri(qdata.uri),
|
||||
uri(qdata.feedURI),
|
||||
qdata.index);
|
||||
}
|
||||
|
||||
if (qdata.isBookmark) {
|
||||
let itemId = bmsvc.insertBookmark(qdata.parentFolder, uri(qdata.uri),
|
||||
qdata.index, qdata.title);
|
||||
let itemId = PlacesUtils.bookmarks.insertBookmark(qdata.parentFolder,
|
||||
uri(qdata.uri),
|
||||
qdata.index,
|
||||
qdata.title);
|
||||
if (qdata.keyword)
|
||||
bmsvc.setKeywordForBookmark(itemId, qdata.keyword);
|
||||
PlacesUtils.bookmarks.setKeywordForBookmark(itemId, qdata.keyword);
|
||||
if (qdata.dateAdded)
|
||||
bmsvc.setItemDateAdded(itemId, qdata.dateAdded);
|
||||
PlacesUtils.bookmarks.setItemDateAdded(itemId, qdata.dateAdded);
|
||||
if (qdata.lastModified)
|
||||
bmsvc.setItemLastModified(itemId, qdata.lastModified);
|
||||
PlacesUtils.bookmarks.setItemLastModified(itemId, qdata.lastModified);
|
||||
}
|
||||
|
||||
if (qdata.isTag) {
|
||||
tagssvc.tagURI(uri(qdata.uri), qdata.tagArray);
|
||||
PlacesUtils.tagging.tagURI(uri(qdata.uri), qdata.tagArray);
|
||||
}
|
||||
|
||||
if (qdata.isDynContainer) {
|
||||
bmsvc.createDynamicContainer(qdata.parentFolder, qdata.title,
|
||||
qdata.contractId, qdata.index);
|
||||
PlacesUtils.bookmarks.createDynamicContainer(qdata.parentFolder,
|
||||
qdata.title,
|
||||
qdata.contractId,
|
||||
qdata.index);
|
||||
}
|
||||
} catch (ex) {
|
||||
// use the data object here in case instantiation of qdata failed
|
||||
@ -309,6 +247,7 @@ function populateDB(aArray) {
|
||||
}); // End of function and array
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The Query Data Object - this object encapsulates data for our queries and is
|
||||
* used to parameterize our calls to the Places APIs to put data into the
|
||||
@ -326,7 +265,7 @@ function queryData(obj) {
|
||||
this.uri = obj.uri ? obj.uri : "";
|
||||
this.lastVisit = obj.lastVisit ? obj.lastVisit : today;
|
||||
this.referrer = obj.referrer ? obj.referrer : null;
|
||||
this.transType = obj.transType ? obj.transType : histsvc.TRANSITION_TYPED;
|
||||
this.transType = obj.transType ? obj.transType : Ci.nsINavHistoryService.TRANSITION_TYPED;
|
||||
this.isRedirect = obj.isRedirect ? obj.isRedirect : false;
|
||||
this.sessionID = obj.sessionID ? obj.sessionID : 0;
|
||||
this.isDetails = obj.isDetails ? obj.isDetails : false;
|
||||
@ -357,9 +296,10 @@ function queryData(obj) {
|
||||
this.faviconExpiration = obj.faviconExpiration ?
|
||||
obj.faviconExpiration : futureday;
|
||||
this.isLivemark = obj.isLivemark ? obj.isLivemark : false;
|
||||
this.parentFolder = obj.parentFolder ? obj.parentFolder : bmsvc.placesRoot;
|
||||
this.parentFolder = obj.parentFolder ? obj.parentFolder
|
||||
: PlacesUtils.placesRootId;
|
||||
this.feedURI = obj.feedURI ? obj.feedURI : "";
|
||||
this.index = obj.index ? obj.index : bmsvc.DEFAULT_INDEX;
|
||||
this.index = obj.index ? obj.index : PlacesUtils.bookmarks.DEFAULT_INDEX;
|
||||
this.isFolder = obj.isFolder ? obj.isFolder : false;
|
||||
this.contractId = obj.contractId ? obj.contractId : "";
|
||||
this.lastModified = obj.lastModified ? obj.lastModified : today;
|
||||
@ -376,6 +316,7 @@ function queryData(obj) {
|
||||
// All attributes are set in the constructor above
|
||||
queryData.prototype = { }
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to compare an array of query objects with a result set.
|
||||
* It assumes the array of query objects contains the SAME SORT as the result
|
||||
@ -409,7 +350,7 @@ function compareArrayToResult(aArray, aRoot) {
|
||||
aArray[i].lastVisit != child.time)
|
||||
do_throw("Expected " + aArray[i].lastVisit + " found " + child.time);
|
||||
if (aArray[i].hasOwnProperty("index") &&
|
||||
aArray[i].index != bmsvc.DEFAULT_INDEX &&
|
||||
aArray[i].index != PlacesUtils.bookmarks.DEFAULT_INDEX &&
|
||||
aArray[i].index != child.bookmarkIndex)
|
||||
do_throw("Expected " + aArray[i].index + " found " + child.bookmarkIndex);
|
||||
|
||||
@ -422,6 +363,7 @@ function compareArrayToResult(aArray, aRoot) {
|
||||
LOG("Comparing Array to Results passes");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to check to see if one object either is or is not in the
|
||||
* result set. It can accept either a queryData object or an array of queryData
|
||||
@ -454,6 +396,7 @@ function isInResult(aQueryData, aRoot) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A nice helper function for debugging things. It LOGs the contents of a
|
||||
* result set.
|
||||
@ -474,107 +417,3 @@ function displayResultSet(aRoot) {
|
||||
aRoot.getChild(i).title + " Visit Time: " + aRoot.getChild(i).time);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes all bookmarks and checks for correct cleanup
|
||||
*/
|
||||
function remove_all_bookmarks() {
|
||||
// Clear all bookmarks
|
||||
bmsvc.removeFolderChildren(bmsvc.bookmarksMenuFolder);
|
||||
bmsvc.removeFolderChildren(bmsvc.toolbarFolder);
|
||||
bmsvc.removeFolderChildren(bmsvc.unfiledBookmarksFolder);
|
||||
// Check for correct cleanup
|
||||
check_no_bookmarks()
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks that we don't have any bookmark
|
||||
*/
|
||||
function check_no_bookmarks() {
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.toolbarFolder, bmsvc.bookmarksMenuFolder, bmsvc.unfiledBookmarksFolder], 3);
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
do_check_eq(root.childCount, 0);
|
||||
root.containerOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the rows of a table out to the console.
|
||||
*
|
||||
* @param aName
|
||||
* The name of the table or view to output.
|
||||
*/
|
||||
function dump_table(aName)
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
let stmt = db.createStatement("SELECT * FROM " + aName);
|
||||
|
||||
dump("\n*** Printing data from " + aName + ":\n");
|
||||
let count = 0;
|
||||
while (stmt.executeStep()) {
|
||||
let columns = stmt.numEntries;
|
||||
|
||||
if (count == 0) {
|
||||
// print the column names
|
||||
for (let i = 0; i < columns; i++)
|
||||
dump(stmt.getColumnName(i) + "\t");
|
||||
dump("\n");
|
||||
}
|
||||
|
||||
// print the row
|
||||
for (let i = 0; i < columns; i++) {
|
||||
switch (stmt.getTypeOfIndex(i)) {
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_NULL:
|
||||
dump("NULL\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_INTEGER:
|
||||
dump(stmt.getInt64(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_FLOAT:
|
||||
dump(stmt.getDouble(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_TEXT:
|
||||
dump(stmt.getString(i) + "\t");
|
||||
break;
|
||||
}
|
||||
}
|
||||
dump("\n");
|
||||
|
||||
count++;
|
||||
}
|
||||
dump("*** There were a total of " + count + " rows of data.\n\n");
|
||||
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes any events in the event loop of the main thread.
|
||||
*/
|
||||
function flush_main_thread_events()
|
||||
{
|
||||
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
||||
while (tm.mainThread.hasPendingEvents())
|
||||
tm.mainThread.processNextEvent(false);
|
||||
}
|
||||
|
||||
// These tests are known to randomly fail due to bug 507790 when database
|
||||
// flushes are active, so we turn off syncing for them.
|
||||
let randomFailingSyncTests = [
|
||||
"test_results-as-visit.js",
|
||||
"test_sorting.js",
|
||||
"test_redirectsMode.js",
|
||||
];
|
||||
let currentTestFilename = do_get_file(_TEST_FILE[0], true).leafName;
|
||||
if (randomFailingSyncTests.indexOf(currentTestFilename) != -1) {
|
||||
print("Test " + currentTestFilename + " is known random due to bug 507790, disabling PlacesDBFlush component.");
|
||||
let sync = Cc["@mozilla.org/places/sync;1"].getService(Ci.nsIObserver);
|
||||
sync.observe(null, "places-debug-stop-sync", null);
|
||||
}
|
||||
|
@ -43,12 +43,15 @@
|
||||
* Here is an example of using these to create some bookmark folders:
|
||||
*/
|
||||
// Create Folder1 from root
|
||||
bmsvc.createFolder(bmsvc.placesRoot, "Folder 1", bmsvc.DEFAULT_INDEX);
|
||||
var folder1Id = bmsvc.getChildFolder(bmsvc.placesRoot, "Folder 1");
|
||||
PlacesUtils.bookmarks.createFolder(PlacesUtils.placesRootId, "Folder 1",
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX);
|
||||
var folder1Id = PlacesUtils.bookmarks.getChildFolder(PlacesUtils.placesRootId,
|
||||
"Folder 1");
|
||||
|
||||
// Make Folder 1a a child of Folder 1
|
||||
bmsvc.createFolder(folder1Id, "Folder 1a", bmsvc.DEFAULT_INDEX);
|
||||
var folder1aId = bmsvc.getChildFolder(folder1Id, "Folder 1a");
|
||||
PlacesUtils.bookmarks.createFolder(folder1Id, "Folder 1a",
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX);
|
||||
var folder1aId = PlacesUtils.bookmarks.getChildFolder(folder1Id, "Folder 1a");
|
||||
|
||||
/**
|
||||
* The next thing we do is create a test database for us. Each test runs with
|
||||
@ -90,15 +93,15 @@ function run_test() {
|
||||
populateDB(testData);
|
||||
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
// Set query attributes here...
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
// Set queryOptions attributes here
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
|
||||
@ -130,7 +133,7 @@ function run_test() {
|
||||
}
|
||||
};
|
||||
|
||||
histsvc.runInBatchMode(updateBatch, null);
|
||||
PlacesUtils.history.runInBatchMode(updateBatch, null);
|
||||
|
||||
// Close the container when finished
|
||||
root.containerOpen = false;
|
||||
|
@ -92,7 +92,7 @@ var testData = [
|
||||
// Test subdomain included with isRedirect=true, different transtype
|
||||
{isInQuery: true, isVisit: true, isDetails: true, title: "moz",
|
||||
isRedirect: true, uri: "http://mail.foo.com/redirect", lastVisit: jan11_800,
|
||||
transType: histsvc.TRANSITION_LINK},
|
||||
transType: PlacesUtils.history.TRANSITION_LINK},
|
||||
|
||||
// Test subdomain inclued at the leading time edge
|
||||
{isInQuery: true, isVisit: true, isDetails: true,
|
||||
@ -158,11 +158,11 @@ function run_test() {
|
||||
populateDB(testData);
|
||||
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.beginTime = beginTime;
|
||||
query.endTime = endTime;
|
||||
query.beginTimeReference = histsvc.TIME_RELATIVE_EPOCH;
|
||||
query.endTimeReference = histsvc.TIME_RELATIVE_EPOCH;
|
||||
query.beginTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH;
|
||||
query.endTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH;
|
||||
query.searchTerms = "moz";
|
||||
query.domain = "foo.com";
|
||||
query.domainIsHost = false;
|
||||
@ -170,7 +170,7 @@ function run_test() {
|
||||
query.annotationIsNot = true;
|
||||
|
||||
// Options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = options.SORT_BY_URI_ASCENDING;
|
||||
options.resultType = options.RESULTS_AS_URI;
|
||||
// The next two options should be ignored
|
||||
@ -178,7 +178,7 @@ function run_test() {
|
||||
// options.excludeItems = true;
|
||||
|
||||
// Results
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
|
||||
@ -246,7 +246,7 @@ function run_test() {
|
||||
}
|
||||
};
|
||||
|
||||
histsvc.runInBatchMode(updateBatch, null);
|
||||
PlacesUtils.history.runInBatchMode(updateBatch, null);
|
||||
LOG("LiveUpdate by updating title in batch mode");
|
||||
do_check_eq(isInResult({uri: "http://foo.com/changeme2"}, root), true);
|
||||
|
||||
|
@ -96,7 +96,7 @@ var testData = [
|
||||
// Test uri included with isRedirect=true, different transtype
|
||||
{isInQuery: true, isVisit: true, isDetails: true, title: "moz",
|
||||
isRedirect: true, uri: "http://foo.com/redirect", lastVisit: jan11_800,
|
||||
transType: histsvc.TRANSITION_LINK},
|
||||
transType: PlacesUtils.history.TRANSITION_LINK},
|
||||
|
||||
// Test leading time edge with tag string is included
|
||||
{isInQuery: true, isVisit: true, isDetails: true, title: "taggariffic",
|
||||
@ -156,11 +156,11 @@ function run_test() {
|
||||
populateDB(testData);
|
||||
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.beginTime = beginTime;
|
||||
query.endTime = endTime;
|
||||
query.beginTimeReference = histsvc.TIME_RELATIVE_EPOCH;
|
||||
query.endTimeReference = histsvc.TIME_RELATIVE_EPOCH;
|
||||
query.beginTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH;
|
||||
query.endTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH;
|
||||
query.searchTerms = "moz";
|
||||
query.uri = uri("http://foo.com");
|
||||
query.uriIsPrefix = true;
|
||||
@ -168,7 +168,7 @@ function run_test() {
|
||||
query.annotationIsNot = true;
|
||||
|
||||
// Options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = options.SORT_BY_URI_ASCENDING;
|
||||
options.resultType = options.RESULTS_AS_URI;
|
||||
// The next two options should be ignored
|
||||
@ -176,7 +176,7 @@ function run_test() {
|
||||
// options.excludeItems = true;
|
||||
|
||||
// Results
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
|
||||
@ -243,7 +243,7 @@ function run_test() {
|
||||
}
|
||||
};
|
||||
|
||||
histsvc.runInBatchMode(updateBatch, null);
|
||||
PlacesUtils.history.runInBatchMode(updateBatch, null);
|
||||
LOG("LiveUpdate by updating title in batch mode");
|
||||
do_check_eq(isInResult({uri: "http://foo.com/changeme2"}, root), true);
|
||||
|
||||
|
@ -199,13 +199,13 @@ function test_query_callback(aSequence) {
|
||||
}
|
||||
|
||||
// Create a new query with required options.
|
||||
var query = histsvc.getNewQuery();
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.resultType = resultType.value;
|
||||
options.sortingMode = sortingMode.value;
|
||||
|
||||
// Compare resultset with expectedData.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
|
||||
|
@ -1,74 +1,74 @@
|
||||
/* -*- 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 Test Code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Clint Talbert <ctalbert@mozilla.com>
|
||||
* 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 ***** */
|
||||
|
||||
// The test data for our database, note that the ordering of the results that
|
||||
// will be returned by the query (the isInQuery: true objects) is IMPORTANT.
|
||||
// see compareArrayToResult in head_queries.js for more info.
|
||||
var testData = [
|
||||
// Normal folder
|
||||
{ isInQuery: true, isFolder: true, title: "Folder 1",
|
||||
parentFolder: bmsvc.toolbarFolder },
|
||||
|
||||
// Read only folder
|
||||
{ isInQuery: false, isFolder: true, title: "Folder 2 RO",
|
||||
parentFolder: bmsvc.toolbarFolder, readOnly: true }
|
||||
];
|
||||
|
||||
function run_test() {
|
||||
populateDB(testData);
|
||||
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.toolbarFolder], 1);
|
||||
|
||||
// Options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
options.excludeQueries = true;
|
||||
options.excludeReadOnlyFolders = true;
|
||||
|
||||
// Results
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
displayResultSet(root);
|
||||
// The readonly folder should not be in our result set.
|
||||
do_check_eq(1, root.childCount);
|
||||
do_check_eq("Folder 1", root.getChild(0).title);
|
||||
|
||||
root.containerOpen = false;
|
||||
}
|
||||
/* -*- 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 Test Code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Clint Talbert <ctalbert@mozilla.com>
|
||||
* 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 ***** */
|
||||
|
||||
// The test data for our database, note that the ordering of the results that
|
||||
// will be returned by the query (the isInQuery: true objects) is IMPORTANT.
|
||||
// see compareArrayToResult in head_queries.js for more info.
|
||||
var testData = [
|
||||
// Normal folder
|
||||
{ isInQuery: true, isFolder: true, title: "Folder 1",
|
||||
parentFolder: PlacesUtils.toolbarFolderId },
|
||||
|
||||
// Read only folder
|
||||
{ isInQuery: false, isFolder: true, title: "Folder 2 RO",
|
||||
parentFolder: PlacesUtils.toolbarFolderId, readOnly: true }
|
||||
];
|
||||
|
||||
function run_test() {
|
||||
populateDB(testData);
|
||||
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([PlacesUtils.toolbarFolderId], 1);
|
||||
|
||||
// Options
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.excludeQueries = true;
|
||||
options.excludeReadOnlyFolders = true;
|
||||
|
||||
// Results
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
displayResultSet(root);
|
||||
// The readonly folder should not be in our result set.
|
||||
do_check_eq(1, root.childCount);
|
||||
do_check_eq("Folder 1", root.getChild(0).title);
|
||||
|
||||
root.containerOpen = false;
|
||||
}
|
||||
|
@ -52,16 +52,16 @@ var testData = [
|
||||
// Add a bookmark that should be in the results
|
||||
{ isBookmark: true,
|
||||
uri: "http://bookmarked.com/",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.toolbarFolderId,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "",
|
||||
isInQuery: true },
|
||||
|
||||
// Add a bookmark that should not be in the results
|
||||
{ isBookmark: true,
|
||||
uri: "http://bookmarked-elsewhere.com/",
|
||||
parentFolder: bmsvc.bookmarksMenuFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarksMenuFolderId,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "",
|
||||
isInQuery: false },
|
||||
|
||||
@ -83,16 +83,16 @@ function run_test() {
|
||||
populateDB(testData);
|
||||
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.toolbarFolder], 1);
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([PlacesUtils.toolbarFolderId], 1);
|
||||
query.onlyBookmarked = true;
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.queryType = options.QUERY_TYPE_HISTORY;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
|
||||
@ -111,16 +111,16 @@ function run_test() {
|
||||
//Add a bookmark that should show up
|
||||
{ isBookmark: true,
|
||||
uri: "http://bookmarked2.com/",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.toolbarFolderId,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "",
|
||||
isInQuery: true },
|
||||
|
||||
//Add a bookmark that should not show up
|
||||
{ isBookmark: true,
|
||||
uri: "http://bookmarked-elsewhere2.com/",
|
||||
parentFolder: bmsvc.bookmarksMenuFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarksMenuFolderId,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "",
|
||||
isInQuery: false }
|
||||
];
|
||||
@ -150,7 +150,7 @@ function run_test() {
|
||||
}
|
||||
};
|
||||
|
||||
histsvc.runInBatchMode(updateBatch, null);
|
||||
PlacesUtils.history.runInBatchMode(updateBatch, null);
|
||||
|
||||
// re-query and test
|
||||
LOG("begin batched test");
|
||||
|
@ -286,10 +286,10 @@ const querySwitches = [
|
||||
aQuery.setFolders([], 0);
|
||||
},
|
||||
function (aQuery, aQueryOptions) {
|
||||
aQuery.setFolders([bmsvc.placesRoot], 1);
|
||||
aQuery.setFolders([PlacesUtils.placesRootId], 1);
|
||||
},
|
||||
function (aQuery, aQueryOptions) {
|
||||
aQuery.setFolders([bmsvc.placesRoot, bmsvc.tagsFolder], 2);
|
||||
aQuery.setFolders([PlacesUtils.placesRootId, PlacesUtils.tagsFolderId], 2);
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -754,8 +754,8 @@ function runQuerySequences(aHowManyLo, aHowManyHi)
|
||||
// ]
|
||||
cartProd(runs, function (runSet) {
|
||||
// Create a new query, apply the switches in runSet, and test it.
|
||||
var query = histsvc.getNewQuery();
|
||||
var opts = histsvc.getNewQueryOptions();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
var opts = PlacesUtils.history.getNewQueryOptions();
|
||||
for (let i = 0; i < runSet.length; i++) {
|
||||
runSet[i](query, opts);
|
||||
}
|
||||
@ -793,13 +793,13 @@ function runQuerySequences(aHowManyLo, aHowManyHi)
|
||||
*/
|
||||
function serializeDeserialize(aQueryArr, aQueryOptions)
|
||||
{
|
||||
var queryStr = histsvc.queriesToQueryString(aQueryArr,
|
||||
aQueryArr.length,
|
||||
aQueryOptions);
|
||||
var queryStr = PlacesUtils.history.queriesToQueryString(aQueryArr,
|
||||
aQueryArr.length,
|
||||
aQueryOptions);
|
||||
print(" " + queryStr);
|
||||
var queryArr2 = {};
|
||||
var opts2 = {};
|
||||
histsvc.queryStringToQueries(queryStr, queryArr2, {}, opts2);
|
||||
PlacesUtils.history.queryStringToQueries(queryStr, queryArr2, {}, opts2);
|
||||
queryArr2 = queryArr2.value;
|
||||
opts2 = opts2.value;
|
||||
|
||||
|
@ -109,8 +109,8 @@ function check_results_callback(aSequence) {
|
||||
}
|
||||
|
||||
// Create a new query with required options.
|
||||
let query = histsvc.getNewQuery();
|
||||
let options = histsvc.getNewQueryOptions();
|
||||
let query = PlacesUtils.history.getNewQuery();
|
||||
let options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.includeHidden = includeHidden;
|
||||
options.redirectsMode = redirectsMode;
|
||||
options.sortingMode = sortingMode;
|
||||
@ -118,7 +118,7 @@ function check_results_callback(aSequence) {
|
||||
options.maxResults = maxResults;
|
||||
|
||||
// Compare resultset with expectedData.
|
||||
let result = histsvc.executeQuery(query, options);
|
||||
let result = PlacesUtils.history.executeQuery(query, options);
|
||||
let root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(expectedData, root);
|
||||
@ -212,7 +212,7 @@ function cartProd(aSequences, aCallback)
|
||||
*/
|
||||
function add_visits_to_database() {
|
||||
// Clean up the database.
|
||||
bhistsvc.removeAllPages();
|
||||
PlacesUtils.bhistory.removeAllPages();
|
||||
remove_all_bookmarks();
|
||||
|
||||
// We don't really bother on this, but we need a time to add visits.
|
||||
@ -271,8 +271,8 @@ function add_visits_to_database() {
|
||||
// Add an unvisited bookmark in the database, it should never appear.
|
||||
visits.push({ isBookmark: true,
|
||||
uri: "http://unvisited.bookmark.com/",
|
||||
parentFolder: bmsvc.bookmarksMenuFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarksMenuFolderId,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "Unvisited Bookmark",
|
||||
isInQuery: false });
|
||||
|
||||
@ -302,6 +302,6 @@ function run_test() {
|
||||
check_results_callback);
|
||||
|
||||
// Clean up so we can't pollute next tests.
|
||||
bhistsvc.removeAllPages();
|
||||
PlacesUtils.bhistory.removeAllPages();
|
||||
remove_all_bookmarks();
|
||||
}
|
||||
|
@ -72,10 +72,10 @@ var testData = [
|
||||
|
||||
function getIdForTag(aTagName) {
|
||||
var id = -1;
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.tagsFolder], 1);
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var root = histsvc.executeQuery(query, options).root;
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([PlacesUtils.tagsFolderId], 1);
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
var root = PlacesUtils.history.executeQuery(query, options).root;
|
||||
root.containerOpen = true;
|
||||
var cc = root.childCount;
|
||||
do_check_eq(root.childCount, 2);
|
||||
@ -100,12 +100,12 @@ function run_test() {
|
||||
let tagId = getIdForTag("bugzilla");
|
||||
do_check_true(tagId > 0);
|
||||
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.resultType = options.RESULTS_AS_TAG_CONTENTS;
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([tagId], 1);
|
||||
|
||||
var root = histsvc.executeQuery(query, options).root;
|
||||
var root = PlacesUtils.history.executeQuery(query, options).root;
|
||||
root.containerOpen = true;
|
||||
|
||||
displayResultSet(root);
|
||||
@ -148,13 +148,13 @@ function run_test() {
|
||||
populateDB(batchchange);
|
||||
}
|
||||
};
|
||||
histsvc.runInBatchMode(updateBatch, null);
|
||||
PlacesUtils.history.runInBatchMode(updateBatch, null);
|
||||
do_check_false(isInResult({uri: "http://fooz.com/"}, root));
|
||||
do_check_true(isInResult({uri: "http://foo.com/changeme2.html"}, root));
|
||||
|
||||
// Test removing a tag updates us.
|
||||
LOG("Delete item outside of batch");
|
||||
tagssvc.untagURI(uri("http://foo.com/changeme2.html"), ["bugzilla"]);
|
||||
PlacesUtils.tagging.untagURI(uri("http://foo.com/changeme2.html"), ["bugzilla"]);
|
||||
do_check_false(isInResult({uri: "http://foo.com/changeme2.html"}, root));
|
||||
|
||||
root.containerOpen = false;
|
||||
|
@ -66,17 +66,17 @@ function createTestData() {
|
||||
function run_test() {
|
||||
createTestData();
|
||||
populateDB(testData);
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.searchTerms = "moz";
|
||||
query.minVisits = 2;
|
||||
|
||||
// Options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = options.SORT_BY_VISITCOUNT_ASCENDING;
|
||||
options.resultType = options.RESULTS_AS_VISIT;
|
||||
|
||||
// Results
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
|
||||
@ -127,7 +127,7 @@ function createTestData() {
|
||||
populateDB(batchchange);
|
||||
}
|
||||
};
|
||||
histsvc.runInBatchMode(updateBatch, null);
|
||||
PlacesUtils.history.runInBatchMode(updateBatch, null);
|
||||
do_check_false(isInResult({uri: "http://foo.mail.com/changeme1.html"}, root));
|
||||
do_check_true(isInResult({uri: "http://foo.mail.com/changeme3.html"}, root));
|
||||
|
||||
|
@ -53,7 +53,7 @@
|
||||
// Test subdomain included with isRedirect=true, different transtype
|
||||
{isInQuery: true, isVisit: true, isDetails: true, title: "amozzie",
|
||||
isRedirect: true, uri: "http://mail.foo.com/redirect", lastVisit: old,
|
||||
referrer: "http://myreferrer.com", transType: histsvc.TRANSITION_LINK},
|
||||
referrer: "http://myreferrer.com", transType: PlacesUtils.history.TRANSITION_LINK},
|
||||
|
||||
// Test subdomain inclued, search term at end
|
||||
{isInQuery: true, isVisit: true, isDetails: true,
|
||||
@ -89,18 +89,18 @@
|
||||
*/
|
||||
function run_test() {
|
||||
populateDB(testData);
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.searchTerms = "moz";
|
||||
query.domain = "foo.com";
|
||||
query.domainIsHost = false;
|
||||
|
||||
// Options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = options.SORT_BY_DATE_ASCENDING;
|
||||
options.resultType = options.RESULTS_AS_URI;
|
||||
|
||||
// Results
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
|
||||
@ -116,7 +116,7 @@ function run_test() {
|
||||
// Add to the query set
|
||||
LOG("Adding item to query")
|
||||
var change1 = [{isVisit: true, isDetails: true, uri: "http://foo.com/added.htm",
|
||||
title: "moz", transType: histsvc.TRANSITION_LINK}];
|
||||
title: "moz", transType: PlacesUtils.history.TRANSITION_LINK}];
|
||||
populateDB(change1);
|
||||
do_check_true(isInResult(change1, root));
|
||||
|
||||
@ -140,7 +140,7 @@ function run_test() {
|
||||
populateDB(batchchange);
|
||||
}
|
||||
};
|
||||
histsvc.runInBatchMode(updateBatch, null);
|
||||
PlacesUtils.history.runInBatchMode(updateBatch, null);
|
||||
do_check_true(isInResult({uri: "http://foo.com/changeme2.htm"}, root));
|
||||
do_check_true(isInResult({uri: "http://mail.foo.com/yiihah"}, root));
|
||||
do_check_false(isInResult({uri: "ftp://foo.com/ftp"}, root));
|
||||
|
@ -48,7 +48,7 @@
|
||||
// Test subdomain included with isRedirect=true, different transtype
|
||||
{isInQuery: true, isVisit: true, isDetails: true, title: "amozzie",
|
||||
isRedirect: true, uri: "http://foo.com/redirect", lastVisit: old,
|
||||
referrer: "http://myreferrer.com", transType: histsvc.TRANSITION_LINK},
|
||||
referrer: "http://myreferrer.com", transType: PlacesUtils.history.TRANSITION_LINK},
|
||||
|
||||
// Test www. style URI is included, with a tag
|
||||
{isInQuery: true, isVisit: true, isDetails: true, isTag: true,
|
||||
@ -85,18 +85,18 @@
|
||||
*/
|
||||
function run_test() {
|
||||
populateDB(testData);
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.searchTerms = "moz";
|
||||
query.uri = uri("http://foo.com");
|
||||
query.uriIsPrefix = true;
|
||||
|
||||
// Options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = options.SORT_BY_DATE_ASCENDING;
|
||||
options.resultType = options.RESULTS_AS_URI;
|
||||
|
||||
// Results
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
|
||||
@ -112,7 +112,7 @@
|
||||
// Add to the query set
|
||||
LOG("Adding item to query")
|
||||
var change1 = [{isVisit: true, isDetails: true, uri: "http://foo.com/added.htm",
|
||||
title: "moz", transType: histsvc.TRANSITION_LINK}];
|
||||
title: "moz", transType: PlacesUtils.history.TRANSITION_LINK}];
|
||||
populateDB(change1);
|
||||
do_check_true(isInResult(change1, root));
|
||||
|
||||
@ -137,7 +137,7 @@
|
||||
populateDB(batchchange);
|
||||
}
|
||||
};
|
||||
histsvc.runInBatchMode(updateBatch, null);
|
||||
PlacesUtils.history.runInBatchMode(updateBatch, null);
|
||||
do_check_true(isInResult({uri: "http://foo.com/changeme2.htm"}, root));
|
||||
do_check_true(isInResult({uri: "http://foo.com/yiihah"}, root));
|
||||
do_check_false(isInResult({uri: "http://foo.com/redirect"}, root));
|
||||
|
@ -50,24 +50,24 @@ tests.push({
|
||||
this._unsortedData = [
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/b",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "y",
|
||||
keyword: "b",
|
||||
isInQuery: true },
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/a",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "z",
|
||||
keyword: "a",
|
||||
isInQuery: true },
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/c",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "x",
|
||||
keyword: "c",
|
||||
isInQuery: true },
|
||||
@ -81,16 +81,16 @@ tests.push({
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.toolbarFolder], 1);
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
|
||||
query.onlyBookmarked = true;
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -113,30 +113,30 @@ tests.push({
|
||||
this._unsortedData = [
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/b1",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "y",
|
||||
isInQuery: true },
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/a",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "z",
|
||||
isInQuery: true },
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/c",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "x",
|
||||
isInQuery: true },
|
||||
|
||||
// if titles are equal, should fall back to URI
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/b2",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "y",
|
||||
isInQuery: true },
|
||||
];
|
||||
@ -154,16 +154,16 @@ tests.push({
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.toolbarFolder], 1);
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
|
||||
query.onlyBookmarked = true;
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -190,7 +190,7 @@ tests.push({
|
||||
{ isVisit: true,
|
||||
isDetails: true,
|
||||
isBookmark: true,
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 0,
|
||||
uri: "http://example.com/c1",
|
||||
lastVisit: timeInMicroseconds - 2,
|
||||
@ -200,7 +200,7 @@ tests.push({
|
||||
{ isVisit: true,
|
||||
isDetails: true,
|
||||
isBookmark: true,
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 1,
|
||||
uri: "http://example.com/a",
|
||||
lastVisit: timeInMicroseconds - 1,
|
||||
@ -210,7 +210,7 @@ tests.push({
|
||||
{ isVisit: true,
|
||||
isDetails: true,
|
||||
isBookmark: true,
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 2,
|
||||
uri: "http://example.com/b",
|
||||
lastVisit: timeInMicroseconds - 3,
|
||||
@ -221,7 +221,7 @@ tests.push({
|
||||
{ isVisit: true,
|
||||
isDetails: true,
|
||||
isBookmark: true,
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 3,
|
||||
uri: "http://example.com/c2",
|
||||
lastVisit: timeInMicroseconds - 2,
|
||||
@ -232,7 +232,7 @@ tests.push({
|
||||
{ isVisit: true,
|
||||
isDetails: true,
|
||||
isBookmark: true,
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 4,
|
||||
uri: "http://example.com/c2",
|
||||
lastVisit: timeInMicroseconds - 2,
|
||||
@ -254,16 +254,16 @@ tests.push({
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.toolbarFolder], 1);
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
|
||||
query.onlyBookmarked = true;
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -291,21 +291,21 @@ tests.push({
|
||||
isDetails: true,
|
||||
lastVisit: timeInMicroseconds,
|
||||
uri: "http://example.com/b",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 0,
|
||||
title: "y",
|
||||
isInQuery: true },
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/c",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 1,
|
||||
title: "x",
|
||||
isInQuery: true },
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/a",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 2,
|
||||
title: "z",
|
||||
isInQuery: true },
|
||||
@ -315,14 +315,14 @@ tests.push({
|
||||
isDetails: true,
|
||||
lastVisit: timeInMicroseconds + 1,
|
||||
uri: "http://example.com/c",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 3,
|
||||
title: "x",
|
||||
isInQuery: true },
|
||||
|
||||
// if no URI (e.g., node is a folder), should fall back to title
|
||||
{ isFolder: true,
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 4,
|
||||
title: "a",
|
||||
isInQuery: true },
|
||||
@ -332,14 +332,14 @@ tests.push({
|
||||
isDetails: true,
|
||||
lastVisit: timeInMicroseconds + 1,
|
||||
uri: "http://example.com/c",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 5,
|
||||
title: "x",
|
||||
isInQuery: true },
|
||||
|
||||
// if no URI and titles are equal, should fall back to bookmark index
|
||||
{ isFolder: true,
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 6,
|
||||
title: "a",
|
||||
isInQuery: true },
|
||||
@ -361,15 +361,15 @@ tests.push({
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.toolbarFolder], 1);
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -397,7 +397,7 @@ tests.push({
|
||||
uri: "http://example.com/a",
|
||||
lastVisit: timeInMicroseconds,
|
||||
title: "z",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 0,
|
||||
isInQuery: true },
|
||||
|
||||
@ -405,7 +405,7 @@ tests.push({
|
||||
uri: "http://example.com/c",
|
||||
lastVisit: timeInMicroseconds,
|
||||
title: "x",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 1,
|
||||
isInQuery: true },
|
||||
|
||||
@ -413,7 +413,7 @@ tests.push({
|
||||
uri: "http://example.com/b1",
|
||||
lastVisit: timeInMicroseconds,
|
||||
title: "y1",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 2,
|
||||
isInQuery: true },
|
||||
|
||||
@ -422,7 +422,7 @@ tests.push({
|
||||
uri: "http://example.com/b2",
|
||||
lastVisit: timeInMicroseconds + 1,
|
||||
title: "y2a",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 3,
|
||||
isInQuery: true },
|
||||
|
||||
@ -431,7 +431,7 @@ tests.push({
|
||||
uri: "http://example.com/b2",
|
||||
lastVisit: timeInMicroseconds + 1,
|
||||
title: "y2b",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 4,
|
||||
isInQuery: true },
|
||||
];
|
||||
@ -447,36 +447,36 @@ tests.push({
|
||||
// This function in head_queries.js creates our database with the above data
|
||||
populateDB(this._unsortedData);
|
||||
// add visits to increase visit count
|
||||
histsvc.addVisit(uri("http://example.com/a"), timeInMicroseconds, null,
|
||||
histsvc.TRANSITION_TYPED, false, 0);
|
||||
histsvc.addVisit(uri("http://example.com/b1"), timeInMicroseconds, null,
|
||||
histsvc.TRANSITION_TYPED, false, 0);
|
||||
histsvc.addVisit(uri("http://example.com/b1"), timeInMicroseconds, null,
|
||||
histsvc.TRANSITION_TYPED, false, 0);
|
||||
histsvc.addVisit(uri("http://example.com/b2"), timeInMicroseconds + 1, null,
|
||||
histsvc.TRANSITION_TYPED, false, 0);
|
||||
histsvc.addVisit(uri("http://example.com/b2"), timeInMicroseconds + 1, null,
|
||||
histsvc.TRANSITION_TYPED, false, 0);
|
||||
histsvc.addVisit(uri("http://example.com/c"), timeInMicroseconds, null,
|
||||
histsvc.TRANSITION_TYPED, false, 0);
|
||||
histsvc.addVisit(uri("http://example.com/c"), timeInMicroseconds, null,
|
||||
histsvc.TRANSITION_TYPED, false, 0);
|
||||
histsvc.addVisit(uri("http://example.com/c"), timeInMicroseconds, null,
|
||||
histsvc.TRANSITION_TYPED, false, 0);
|
||||
PlacesUtils.history.addVisit(uri("http://example.com/a"), timeInMicroseconds, null,
|
||||
PlacesUtils.history.TRANSITION_TYPED, false, 0);
|
||||
PlacesUtils.history.addVisit(uri("http://example.com/b1"), timeInMicroseconds, null,
|
||||
PlacesUtils.history.TRANSITION_TYPED, false, 0);
|
||||
PlacesUtils.history.addVisit(uri("http://example.com/b1"), timeInMicroseconds, null,
|
||||
PlacesUtils.history.TRANSITION_TYPED, false, 0);
|
||||
PlacesUtils.history.addVisit(uri("http://example.com/b2"), timeInMicroseconds + 1, null,
|
||||
PlacesUtils.history.TRANSITION_TYPED, false, 0);
|
||||
PlacesUtils.history.addVisit(uri("http://example.com/b2"), timeInMicroseconds + 1, null,
|
||||
PlacesUtils.history.TRANSITION_TYPED, false, 0);
|
||||
PlacesUtils.history.addVisit(uri("http://example.com/c"), timeInMicroseconds, null,
|
||||
PlacesUtils.history.TRANSITION_TYPED, false, 0);
|
||||
PlacesUtils.history.addVisit(uri("http://example.com/c"), timeInMicroseconds, null,
|
||||
PlacesUtils.history.TRANSITION_TYPED, false, 0);
|
||||
PlacesUtils.history.addVisit(uri("http://example.com/c"), timeInMicroseconds, null,
|
||||
PlacesUtils.history.TRANSITION_TYPED, false, 0);
|
||||
},
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.toolbarFolder], 1);
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
|
||||
query.onlyBookmarked = true;
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -501,24 +501,24 @@ tests.push({
|
||||
this._unsortedData = [
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/a",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "z",
|
||||
keyword: "a",
|
||||
isInQuery: true },
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/c",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "x",
|
||||
keyword: "c",
|
||||
isInQuery: true },
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/b1",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "y9",
|
||||
keyword: "b",
|
||||
isInQuery: true },
|
||||
@ -526,8 +526,8 @@ tests.push({
|
||||
// without a keyword, should fall back to title
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/null2",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "null8",
|
||||
keyword: null,
|
||||
isInQuery: true },
|
||||
@ -535,8 +535,8 @@ tests.push({
|
||||
// without a keyword, should fall back to title
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/null1",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "null9",
|
||||
keyword: null,
|
||||
isInQuery: true },
|
||||
@ -544,8 +544,8 @@ tests.push({
|
||||
// if keywords are equal, should fall back to title
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/b2",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "y8",
|
||||
keyword: "b",
|
||||
isInQuery: true },
|
||||
@ -566,16 +566,16 @@ tests.push({
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.toolbarFolder], 1);
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
|
||||
query.onlyBookmarked = true;
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -601,7 +601,7 @@ tests.push({
|
||||
this._unsortedData = [
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/b1",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 0,
|
||||
title: "y1",
|
||||
dateAdded: timeInMicroseconds -1,
|
||||
@ -609,7 +609,7 @@ tests.push({
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/a",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 1,
|
||||
title: "z",
|
||||
dateAdded: timeInMicroseconds - 2,
|
||||
@ -617,7 +617,7 @@ tests.push({
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/c",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 2,
|
||||
title: "x",
|
||||
dateAdded: timeInMicroseconds,
|
||||
@ -626,7 +626,7 @@ tests.push({
|
||||
// if dateAddeds are equal, should fall back to title
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/b2",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 3,
|
||||
title: "y2",
|
||||
dateAdded: timeInMicroseconds - 1,
|
||||
@ -635,7 +635,7 @@ tests.push({
|
||||
// if dateAddeds and titles are equal, should fall back to bookmark index
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/b3",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 4,
|
||||
title: "y3",
|
||||
dateAdded: timeInMicroseconds - 1,
|
||||
@ -656,16 +656,16 @@ tests.push({
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.toolbarFolder], 1);
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
|
||||
query.onlyBookmarked = true;
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -691,7 +691,7 @@ tests.push({
|
||||
this._unsortedData = [
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/b1",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 0,
|
||||
title: "y1",
|
||||
lastModified: timeInMicroseconds -1,
|
||||
@ -699,7 +699,7 @@ tests.push({
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/a",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 1,
|
||||
title: "z",
|
||||
lastModified: timeInMicroseconds - 2,
|
||||
@ -707,7 +707,7 @@ tests.push({
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/c",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 2,
|
||||
title: "x",
|
||||
lastModified: timeInMicroseconds,
|
||||
@ -716,7 +716,7 @@ tests.push({
|
||||
// if lastModifieds are equal, should fall back to title
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/b2",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 3,
|
||||
title: "y2",
|
||||
lastModified: timeInMicroseconds - 1,
|
||||
@ -726,7 +726,7 @@ tests.push({
|
||||
// index
|
||||
{ isBookmark: true,
|
||||
uri: "http://example.com/b3",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: 4,
|
||||
title: "y3",
|
||||
lastModified: timeInMicroseconds - 1,
|
||||
@ -747,16 +747,16 @@ tests.push({
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.toolbarFolder], 1);
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
|
||||
query.onlyBookmarked = true;
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -781,8 +781,8 @@ tests.push({
|
||||
this._unsortedData = [
|
||||
{ isBookmark: true,
|
||||
uri: "http://url2.com/",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "title x",
|
||||
isTag: true,
|
||||
tagArray: ["x", "y", "z"],
|
||||
@ -790,8 +790,8 @@ tests.push({
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://url1a.com/",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "title y1",
|
||||
isTag: true,
|
||||
tagArray: ["a", "b"],
|
||||
@ -799,15 +799,15 @@ tests.push({
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://url3a.com/",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "title w1",
|
||||
isInQuery: true },
|
||||
|
||||
{ isBookmark: true,
|
||||
uri: "http://url0.com/",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "title z",
|
||||
isTag: true,
|
||||
tagArray: ["a", "y", "z"],
|
||||
@ -816,8 +816,8 @@ tests.push({
|
||||
// if tags are equal, should fall back to title
|
||||
{ isBookmark: true,
|
||||
uri: "http://url1b.com/",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "title y2",
|
||||
isTag: true,
|
||||
tagArray: ["b", "a"],
|
||||
@ -826,8 +826,8 @@ tests.push({
|
||||
// if tags are equal, should fall back to title
|
||||
{ isBookmark: true,
|
||||
uri: "http://url3b.com/",
|
||||
parentFolder: bmsvc.toolbarFolder,
|
||||
index: bmsvc.DEFAULT_INDEX,
|
||||
parentFolder: PlacesUtils.bookmarks.toolbarFolder,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "title w2",
|
||||
isInQuery: true },
|
||||
];
|
||||
@ -847,16 +847,16 @@ tests.push({
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
query.setFolders([bmsvc.toolbarFolder], 1);
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
|
||||
query.onlyBookmarked = true;
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -944,15 +944,15 @@ tests.push({
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingAnnotation = "sorting";
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -1026,15 +1026,15 @@ tests.push({
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingAnnotation = "sorting";
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -1108,15 +1108,15 @@ tests.push({
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingAnnotation = "sorting";
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -1190,15 +1190,15 @@ tests.push({
|
||||
|
||||
check: function() {
|
||||
// Query
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
|
||||
// query options
|
||||
var options = histsvc.getNewQueryOptions();
|
||||
var options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.sortingAnnotation = "sorting";
|
||||
options.sortingMode = this._sortingMode;
|
||||
|
||||
// Results - this gets the result set and opens it for reading and modification.
|
||||
var result = histsvc.executeQuery(query, options);
|
||||
var result = PlacesUtils.history.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
compareArrayToResult(this._sortedData, root);
|
||||
@ -1216,7 +1216,7 @@ tests.push({
|
||||
|
||||
function prepare_for_next_test() {
|
||||
// Execute cleanup tasks
|
||||
bhistsvc.removeAllPages();
|
||||
PlacesUtils.bhistory.removeAllPages();
|
||||
remove_all_bookmarks();
|
||||
}
|
||||
|
||||
|
@ -71,14 +71,14 @@ var gTests = [
|
||||
desc: "Invalid calls to tags setter should fail",
|
||||
run: function () {
|
||||
try {
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.tags = null;
|
||||
do_throw(" Passing null to SetTags should fail");
|
||||
}
|
||||
catch (exc) {}
|
||||
|
||||
try {
|
||||
query = histsvc.getNewQuery();
|
||||
query = PlacesUtils.history.getNewQuery();
|
||||
query.tags = "this should not work";
|
||||
do_throw(" Passing a string to SetTags should fail");
|
||||
}
|
||||
@ -126,7 +126,7 @@ var gTests = [
|
||||
var str = Cc["@mozilla.org/supports-string;1"].
|
||||
createInstance(Ci.nsISupportsString);
|
||||
str.data = "foo";
|
||||
query = histsvc.getNewQuery();
|
||||
query = PlacesUtils.history.getNewQuery();
|
||||
query.tags = str;
|
||||
do_throw(" Passing nsISupportsString to SetTags should fail");
|
||||
}
|
||||
@ -377,32 +377,32 @@ var gTests = [
|
||||
let nsiuri = uri(pURI);
|
||||
addVisit(nsiuri);
|
||||
if (tags)
|
||||
tagssvc.tagURI(nsiuri, tags);
|
||||
PlacesUtils.tagging.tagURI(nsiuri, tags);
|
||||
}
|
||||
|
||||
print(' Querying for "foo" should match only /2 and /3');
|
||||
var [query, opts] = makeQuery(["foo"], true);
|
||||
queryResultsAre(histsvc.executeQuery(query, opts).root,
|
||||
queryResultsAre(PlacesUtils.history.executeQuery(query, opts).root,
|
||||
["http://example.com/2", "http://example.com/3"]);
|
||||
|
||||
print(' Querying for "foo" and "bar" should match only /2 and /3');
|
||||
[query, opts] = makeQuery(["foo", "bar"], true);
|
||||
queryResultsAre(histsvc.executeQuery(query, opts).root,
|
||||
queryResultsAre(PlacesUtils.history.executeQuery(query, opts).root,
|
||||
["http://example.com/2", "http://example.com/3"]);
|
||||
|
||||
print(' Querying for "foo" and "bogus" should match only /2 and /3');
|
||||
[query, opts] = makeQuery(["foo", "bogus"], true);
|
||||
queryResultsAre(histsvc.executeQuery(query, opts).root,
|
||||
queryResultsAre(PlacesUtils.history.executeQuery(query, opts).root,
|
||||
["http://example.com/2", "http://example.com/3"]);
|
||||
|
||||
print(' Querying for "foo" and "baz" should match only /3');
|
||||
[query, opts] = makeQuery(["foo", "baz"], true);
|
||||
queryResultsAre(histsvc.executeQuery(query, opts).root,
|
||||
queryResultsAre(PlacesUtils.history.executeQuery(query, opts).root,
|
||||
["http://example.com/3"]);
|
||||
|
||||
print(' Querying for "bogus" should match all');
|
||||
[query, opts] = makeQuery(["bogus"], true);
|
||||
queryResultsAre(histsvc.executeQuery(query, opts).root,
|
||||
queryResultsAre(PlacesUtils.history.executeQuery(query, opts).root,
|
||||
["http://example.com/1",
|
||||
"http://example.com/2",
|
||||
"http://example.com/3"]);
|
||||
@ -411,7 +411,7 @@ var gTests = [
|
||||
for (let [pURI, tags] in Iterator(urisAndTags)) {
|
||||
let nsiuri = uri(pURI);
|
||||
if (tags)
|
||||
tagssvc.untagURI(nsiuri, tags);
|
||||
PlacesUtils.tagging.untagURI(nsiuri, tags);
|
||||
}
|
||||
cleanDatabase();
|
||||
}
|
||||
@ -431,37 +431,37 @@ var gTests = [
|
||||
let nsiuri = uri(pURI);
|
||||
addBookmark(nsiuri);
|
||||
if (tags)
|
||||
tagssvc.tagURI(nsiuri, tags);
|
||||
PlacesUtils.tagging.tagURI(nsiuri, tags);
|
||||
}
|
||||
|
||||
print(' Querying for "foo" should match only /2 and /3');
|
||||
var [query, opts] = makeQuery(["foo"], true);
|
||||
opts.queryType = opts.QUERY_TYPE_BOOKMARKS;
|
||||
queryResultsAre(histsvc.executeQuery(query, opts).root,
|
||||
queryResultsAre(PlacesUtils.history.executeQuery(query, opts).root,
|
||||
["http://example.com/2", "http://example.com/3"]);
|
||||
|
||||
print(' Querying for "foo" and "bar" should match only /2 and /3');
|
||||
[query, opts] = makeQuery(["foo", "bar"], true);
|
||||
opts.queryType = opts.QUERY_TYPE_BOOKMARKS;
|
||||
queryResultsAre(histsvc.executeQuery(query, opts).root,
|
||||
queryResultsAre(PlacesUtils.history.executeQuery(query, opts).root,
|
||||
["http://example.com/2", "http://example.com/3"]);
|
||||
|
||||
print(' Querying for "foo" and "bogus" should match only /2 and /3');
|
||||
[query, opts] = makeQuery(["foo", "bogus"], true);
|
||||
opts.queryType = opts.QUERY_TYPE_BOOKMARKS;
|
||||
queryResultsAre(histsvc.executeQuery(query, opts).root,
|
||||
queryResultsAre(PlacesUtils.history.executeQuery(query, opts).root,
|
||||
["http://example.com/2", "http://example.com/3"]);
|
||||
|
||||
print(' Querying for "foo" and "baz" should match only /3');
|
||||
[query, opts] = makeQuery(["foo", "baz"], true);
|
||||
opts.queryType = opts.QUERY_TYPE_BOOKMARKS;
|
||||
queryResultsAre(histsvc.executeQuery(query, opts).root,
|
||||
queryResultsAre(PlacesUtils.history.executeQuery(query, opts).root,
|
||||
["http://example.com/3"]);
|
||||
|
||||
print(' Querying for "bogus" should match all');
|
||||
[query, opts] = makeQuery(["bogus"], true);
|
||||
opts.queryType = opts.QUERY_TYPE_BOOKMARKS;
|
||||
queryResultsAre(histsvc.executeQuery(query, opts).root,
|
||||
queryResultsAre(PlacesUtils.history.executeQuery(query, opts).root,
|
||||
["http://example.com/1",
|
||||
"http://example.com/2",
|
||||
"http://example.com/3"]);
|
||||
@ -470,7 +470,7 @@ var gTests = [
|
||||
for (let [pURI, tags] in Iterator(urisAndTags)) {
|
||||
let nsiuri = uri(pURI);
|
||||
if (tags)
|
||||
tagssvc.untagURI(nsiuri, tags);
|
||||
PlacesUtils.tagging.untagURI(nsiuri, tags);
|
||||
}
|
||||
cleanDatabase();
|
||||
}
|
||||
@ -484,26 +484,26 @@ var gTests = [
|
||||
|
||||
print(" Add bookmark and tag it normally");
|
||||
addBookmark(TEST_URI);
|
||||
tagssvc.tagURI(TEST_URI, [tagName]);
|
||||
PlacesUtils.tagging.tagURI(TEST_URI, [tagName]);
|
||||
|
||||
print(" Manually create tag folder with same name as tag and insert " +
|
||||
"bookmark");
|
||||
var dupTagId = bmsvc.createFolder(bmsvc.tagsFolder,
|
||||
tagName,
|
||||
bmsvc.DEFAULT_INDEX);
|
||||
var dupTagId = PlacesUtils.bookmarks.createFolder(PlacesUtils.tagsFolderId,
|
||||
tagName,
|
||||
Ci.nsINavBookmarksService.DEFAULT_INDEX);
|
||||
do_check_true(dupTagId > 0);
|
||||
var bmId = bmsvc.insertBookmark(dupTagId,
|
||||
TEST_URI,
|
||||
bmsvc.DEFAULT_INDEX,
|
||||
"title");
|
||||
var bmId = PlacesUtils.bookmarks.insertBookmark(dupTagId,
|
||||
TEST_URI,
|
||||
Ci.nsINavBookmarksService.DEFAULT_INDEX,
|
||||
"title");
|
||||
do_check_true(bmId > 0);
|
||||
|
||||
print(" Querying for tag should match URI");
|
||||
var [query, opts] = makeQuery([tagName]);
|
||||
opts.queryType = opts.QUERY_TYPE_BOOKMARKS;
|
||||
queryResultsAre(histsvc.executeQuery(query, opts).root, [TEST_URI.spec]);
|
||||
queryResultsAre(PlacesUtils.history.executeQuery(query, opts).root, [TEST_URI.spec]);
|
||||
|
||||
tagssvc.untagURI(TEST_URI, [tagName]);
|
||||
PlacesUtils.tagging.untagURI(TEST_URI, [tagName]);
|
||||
cleanDatabase();
|
||||
}
|
||||
},
|
||||
@ -516,20 +516,20 @@ var gTests = [
|
||||
|
||||
print(" Add bookmark and tag it");
|
||||
addBookmark(TEST_URI);
|
||||
tagssvc.tagURI(TEST_URI, [tagName]);
|
||||
PlacesUtils.tagging.tagURI(TEST_URI, [tagName]);
|
||||
|
||||
print(" Create folder with same name as tag");
|
||||
var folderId = bmsvc.createFolder(bmsvc.unfiledBookmarksFolder,
|
||||
tagName,
|
||||
bmsvc.DEFAULT_INDEX);
|
||||
var folderId = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId,
|
||||
tagName,
|
||||
Ci.nsINavBookmarksService.DEFAULT_INDEX);
|
||||
do_check_true(folderId > 0);
|
||||
|
||||
print(" Querying for tag should match URI");
|
||||
var [query, opts] = makeQuery([tagName]);
|
||||
opts.queryType = opts.QUERY_TYPE_BOOKMARKS;
|
||||
queryResultsAre(histsvc.executeQuery(query, opts).root, [TEST_URI.spec]);
|
||||
queryResultsAre(PlacesUtils.history.executeQuery(query, opts).root, [TEST_URI.spec]);
|
||||
|
||||
tagssvc.untagURI(TEST_URI, [tagName]);
|
||||
PlacesUtils.tagging.untagURI(TEST_URI, [tagName]);
|
||||
cleanDatabase();
|
||||
}
|
||||
},
|
||||
@ -554,53 +554,53 @@ var gTests = [
|
||||
let nsiuri = uri(pURI);
|
||||
addVisit(nsiuri);
|
||||
if (tags)
|
||||
tagssvc.tagURI(nsiuri, tags);
|
||||
PlacesUtils.tagging.tagURI(nsiuri, tags);
|
||||
}
|
||||
|
||||
print(" Query for /1 OR query for /2 should match both /1 and /2");
|
||||
var [query1, opts] = makeQuery(urisAndTags["http://example.com/1"]);
|
||||
var [query2, dummy] = makeQuery(urisAndTags["http://example.com/2"]);
|
||||
var root = histsvc.executeQueries([query1, query2], 2, opts).root;
|
||||
var root = PlacesUtils.history.executeQueries([query1, query2], 2, opts).root;
|
||||
queryResultsAre(root, ["http://example.com/1", "http://example.com/2"]);
|
||||
|
||||
print(" Query for /1 OR query on bogus tag should match only /1");
|
||||
[query1, opts] = makeQuery(urisAndTags["http://example.com/1"]);
|
||||
[query2, dummy] = makeQuery(["bogus"]);
|
||||
root = histsvc.executeQueries([query1, query2], 2, opts).root;
|
||||
root = PlacesUtils.history.executeQueries([query1, query2], 2, opts).root;
|
||||
queryResultsAre(root, ["http://example.com/1"]);
|
||||
|
||||
print(" Query for /1 OR query for /1 should match only /1");
|
||||
[query1, opts] = makeQuery(urisAndTags["http://example.com/1"]);
|
||||
[query2, dummy] = makeQuery(urisAndTags["http://example.com/1"]);
|
||||
root = histsvc.executeQueries([query1, query2], 2, opts).root;
|
||||
root = PlacesUtils.history.executeQueries([query1, query2], 2, opts).root;
|
||||
queryResultsAre(root, ["http://example.com/1"]);
|
||||
|
||||
print(" Query for /1 with tagsAreNot OR query for /2 with tagsAreNot " +
|
||||
"should match both /1 and /2");
|
||||
[query1, opts] = makeQuery(urisAndTags["http://example.com/1"], true);
|
||||
[query2, dummy] = makeQuery(urisAndTags["http://example.com/2"], true);
|
||||
root = histsvc.executeQueries([query1, query2], 2, opts).root;
|
||||
root = PlacesUtils.history.executeQueries([query1, query2], 2, opts).root;
|
||||
queryResultsAre(root, ["http://example.com/1", "http://example.com/2"]);
|
||||
|
||||
print(" Query for /1 OR query for /2 with tagsAreNot should match " +
|
||||
"only /1");
|
||||
[query1, opts] = makeQuery(urisAndTags["http://example.com/1"]);
|
||||
[query2, dummy] = makeQuery(urisAndTags["http://example.com/2"], true);
|
||||
root = histsvc.executeQueries([query1, query2], 2, opts).root;
|
||||
root = PlacesUtils.history.executeQueries([query1, query2], 2, opts).root;
|
||||
queryResultsAre(root, ["http://example.com/1"]);
|
||||
|
||||
print(" Query for /1 OR query for /1 with tagsAreNot should match " +
|
||||
"both URIs");
|
||||
[query1, opts] = makeQuery(urisAndTags["http://example.com/1"]);
|
||||
[query2, dummy] = makeQuery(urisAndTags["http://example.com/1"], true);
|
||||
root = histsvc.executeQueries([query1, query2], 2, opts).root;
|
||||
root = PlacesUtils.history.executeQueries([query1, query2], 2, opts).root;
|
||||
queryResultsAre(root, ["http://example.com/1", "http://example.com/2"]);
|
||||
|
||||
// Clean up.
|
||||
for (let [pURI, tags] in Iterator(urisAndTags)) {
|
||||
let nsiuri = uri(pURI);
|
||||
if (tags)
|
||||
tagssvc.untagURI(nsiuri, tags);
|
||||
PlacesUtils.tagging.untagURI(nsiuri, tags);
|
||||
}
|
||||
cleanDatabase();
|
||||
}
|
||||
@ -623,10 +623,10 @@ const TEST_URI = uri("http://example.com/");
|
||||
* URI of the page (an nsIURI)
|
||||
*/
|
||||
function addBookmark(aURI) {
|
||||
var bmId = bmsvc.insertBookmark(bmsvc.unfiledBookmarksFolder,
|
||||
aURI,
|
||||
bmsvc.DEFAULT_INDEX,
|
||||
aURI.spec);
|
||||
var bmId = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
|
||||
aURI,
|
||||
Ci.nsINavBookmarksService.DEFAULT_INDEX,
|
||||
aURI.spec);
|
||||
print(" Sanity check: insertBookmark should not fail");
|
||||
do_check_true(bmId > 0);
|
||||
}
|
||||
@ -638,12 +638,12 @@ function addBookmark(aURI) {
|
||||
* URI of the page (an nsIURI)
|
||||
*/
|
||||
function addVisit(aURI) {
|
||||
var visitId = histsvc.addVisit(aURI,
|
||||
Date.now() * 1000,
|
||||
null,
|
||||
histsvc.TRANSITION_LINK,
|
||||
false,
|
||||
0);
|
||||
var visitId = PlacesUtils.history.addVisit(aURI,
|
||||
Date.now() * 1000,
|
||||
null,
|
||||
Ci.nsINavHistoryService.TRANSITION_LINK,
|
||||
false,
|
||||
0);
|
||||
print(" Sanity check: addVisit should not fail");
|
||||
do_check_true(visitId > 0);
|
||||
}
|
||||
@ -652,7 +652,7 @@ function addVisit(aURI) {
|
||||
* Removes all pages from history and bookmarks.
|
||||
*/
|
||||
function cleanDatabase() {
|
||||
bhistsvc.removeAllPages();
|
||||
PlacesUtils.bhistory.removeAllPages();
|
||||
remove_all_bookmarks();
|
||||
}
|
||||
|
||||
@ -688,9 +688,9 @@ function checkQueryURI(aTags, aTagsAreNot) {
|
||||
*/
|
||||
function doWithBookmark(aTags, aCallback) {
|
||||
addBookmark(TEST_URI);
|
||||
tagssvc.tagURI(TEST_URI, aTags);
|
||||
PlacesUtils.tagging.tagURI(TEST_URI, aTags);
|
||||
aCallback(TEST_URI);
|
||||
tagssvc.untagURI(TEST_URI, aTags);
|
||||
PlacesUtils.tagging.untagURI(TEST_URI, aTags);
|
||||
cleanDatabase();
|
||||
}
|
||||
|
||||
@ -706,9 +706,9 @@ function doWithBookmark(aTags, aCallback) {
|
||||
*/
|
||||
function doWithVisit(aTags, aCallback) {
|
||||
addVisit(TEST_URI);
|
||||
tagssvc.tagURI(TEST_URI, aTags);
|
||||
PlacesUtils.tagging.tagURI(TEST_URI, aTags);
|
||||
aCallback(TEST_URI);
|
||||
tagssvc.untagURI(TEST_URI, aTags);
|
||||
PlacesUtils.tagging.untagURI(TEST_URI, aTags);
|
||||
cleanDatabase();
|
||||
}
|
||||
|
||||
@ -740,7 +740,7 @@ function encodeTag(aTag) {
|
||||
* Array of URIs (as strings) that aResultRoot should contain
|
||||
*/
|
||||
function executeAndCheckQueryResults(aQuery, aQueryOpts, aExpectedURIs) {
|
||||
var root = histsvc.executeQuery(aQuery, aQueryOpts).root;
|
||||
var root = PlacesUtils.history.executeQuery(aQuery, aQueryOpts).root;
|
||||
root.containerOpen = true;
|
||||
queryResultsAre(root, aExpectedURIs);
|
||||
root.containerOpen = false;
|
||||
@ -765,7 +765,7 @@ function makeQuery(aTags, aTagsAreNot) {
|
||||
"without calling setTags() at all") +
|
||||
" and with tagsAreNot=" +
|
||||
aTagsAreNot);
|
||||
var query = histsvc.getNewQuery();
|
||||
var query = PlacesUtils.history.getNewQuery();
|
||||
query.tagsAreNot = aTagsAreNot;
|
||||
if (aTags) {
|
||||
query.tags = aTags;
|
||||
@ -784,7 +784,7 @@ function makeQuery(aTags, aTagsAreNot) {
|
||||
do_check_eq(query.tags.length, expCount);
|
||||
do_check_eq(query.tagsAreNot, aTagsAreNot);
|
||||
|
||||
return [query, histsvc.getNewQueryOptions()];
|
||||
return [query, PlacesUtils.history.getNewQueryOptions()];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -818,7 +818,7 @@ function queryResultsAre(aResultRoot, aExpectedURIs) {
|
||||
* @return The query's URI
|
||||
*/
|
||||
function queryURI(aQuery, aQueryOpts) {
|
||||
return histsvc.queriesToQueryString([aQuery], 1, aQueryOpts);
|
||||
return PlacesUtils.history.queriesToQueryString([aQuery], 1, aQueryOpts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,120 +39,21 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
const NS_APP_HISTORY_50_FILE = "UHist";
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
|
||||
function LOG(aMsg) {
|
||||
aMsg = ("*** PLACES TESTS: " + aMsg);
|
||||
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
|
||||
logStringMessage(aMsg);
|
||||
print(aMsg);
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Import common head.
|
||||
let (commonFile = do_get_file("../head_common.js", false)) {
|
||||
let uri = Services.io.newFileURI(commonFile);
|
||||
Services.scriptloader.loadSubScript(uri.spec, this);
|
||||
}
|
||||
|
||||
// If there's no location registered for the profile direcotry, register one now.
|
||||
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
var profileDir = null;
|
||||
try {
|
||||
profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
|
||||
} catch (e) {}
|
||||
if (!profileDir) {
|
||||
// Register our own provider for the profile directory.
|
||||
// It will simply return the current directory.
|
||||
var provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_USER_PROFILE_50_DIR) {
|
||||
return dirSvc.get("CurProcD", Ci.nsIFile);
|
||||
}
|
||||
if (prop == NS_APP_HISTORY_50_FILE) {
|
||||
var histFile = dirSvc.get("CurProcD", Ci.nsIFile);
|
||||
histFile.append("history.dat");
|
||||
return histFile;
|
||||
}
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
},
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
}
|
||||
// Put any other stuff relative to this test folder below.
|
||||
|
||||
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
|
||||
function uri(spec) {
|
||||
return iosvc.newURI(spec, null, null);
|
||||
}
|
||||
|
||||
// Delete a previously created sqlite file
|
||||
function clearDB() {
|
||||
try {
|
||||
var file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
if (file.exists())
|
||||
file.remove(false);
|
||||
} catch(ex) { dump("Exception: " + ex); }
|
||||
}
|
||||
clearDB();
|
||||
|
||||
/**
|
||||
* Dumps the rows of a table out to the console.
|
||||
*
|
||||
* @param aName
|
||||
* The name of the table or view to output.
|
||||
*/
|
||||
function dump_table(aName)
|
||||
{
|
||||
let db = DBConn()
|
||||
let stmt = db.createStatement("SELECT * FROM " + aName);
|
||||
|
||||
dump("\n*** Printing data from " + aName + ":\n");
|
||||
let count = 0;
|
||||
while (stmt.executeStep()) {
|
||||
let columns = stmt.numEntries;
|
||||
|
||||
if (count == 0) {
|
||||
// print the column names
|
||||
for (let i = 0; i < columns; i++)
|
||||
dump(stmt.getColumnName(i) + "\t");
|
||||
dump("\n");
|
||||
}
|
||||
|
||||
// print the row
|
||||
for (let i = 0; i < columns; i++) {
|
||||
switch (stmt.getTypeOfIndex(i)) {
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_NULL:
|
||||
dump("NULL\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_INTEGER:
|
||||
dump(stmt.getInt64(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_FLOAT:
|
||||
dump(stmt.getDouble(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_TEXT:
|
||||
dump(stmt.getString(i) + "\t");
|
||||
break;
|
||||
}
|
||||
}
|
||||
dump("\n");
|
||||
|
||||
count++;
|
||||
}
|
||||
dump("*** There were a total of " + count + " rows of data.\n\n");
|
||||
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function tests to see if the place associated with the bookmark with id
|
||||
@ -170,8 +71,7 @@ function dump_table(aName)
|
||||
*/
|
||||
function new_test_bookmark_uri_event(aBookmarkId, aExpectedURI, aExpected, aFinish)
|
||||
{
|
||||
let db = DBConn();
|
||||
let stmt = db.createStatement(
|
||||
let stmt = DBConn().createStatement(
|
||||
"SELECT moz_places.url " +
|
||||
"FROM moz_bookmarks INNER JOIN moz_places " +
|
||||
"ON moz_bookmarks.fk = moz_places.id " +
|
||||
@ -194,6 +94,7 @@ function new_test_bookmark_uri_event(aBookmarkId, aExpectedURI, aExpected, aFini
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function tests to see if the place associated with the visit with id aVisitId
|
||||
* has the uri aExpectedURI. The event will call do_test_finished() if aFinish is
|
||||
@ -210,8 +111,7 @@ function new_test_bookmark_uri_event(aBookmarkId, aExpectedURI, aExpected, aFini
|
||||
*/
|
||||
function new_test_visit_uri_event(aVisitId, aExpectedURI, aExpected, aFinish)
|
||||
{
|
||||
let db = DBConn();
|
||||
let stmt = db.createStatement(
|
||||
let stmt = DBConn().createStatement(
|
||||
"SELECT moz_places.url " +
|
||||
"FROM moz_historyvisits INNER JOIN moz_places " +
|
||||
"ON moz_historyvisits.place_id = moz_places.id " +
|
||||
@ -234,50 +134,3 @@ function new_test_visit_uri_event(aVisitId, aExpectedURI, aExpected, aFinish)
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function gets current database connection, if the connection has been closed
|
||||
* it will try to reconnect to the places.sqlite database.
|
||||
*/
|
||||
function DBConn()
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
if (db.connectionReady)
|
||||
return db;
|
||||
|
||||
// open a new connection if needed
|
||||
let file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
let storageService = Cc["@mozilla.org/storage/service;1"].
|
||||
getService(Ci.mozIStorageService);
|
||||
try {
|
||||
var dbConn = storageService.openDatabase(file);
|
||||
} catch (ex) {
|
||||
return null;
|
||||
}
|
||||
return dbConn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes any events in the event loop of the main thread.
|
||||
*/
|
||||
function flush_main_thread_events()
|
||||
{
|
||||
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
||||
while (tm.mainThread.hasPendingEvents())
|
||||
tm.mainThread.processNextEvent(false);
|
||||
}
|
||||
|
||||
// Simulates a Places shutdown.
|
||||
function shutdownPlaces()
|
||||
{
|
||||
const TOPIC_XPCOM_SHUTDOWN = "xpcom-shutdown";
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsIObserver);
|
||||
hs.observe(null, TOPIC_XPCOM_SHUTDOWN, null);
|
||||
let sync = Cc["@mozilla.org/places/sync;1"].getService(Ci.nsIObserver);
|
||||
sync.observe(null, TOPIC_XPCOM_SHUTDOWN, null);
|
||||
let expire = Cc["@mozilla.org/places/expiration;1"].getService(Ci.nsIObserver);
|
||||
expire.observe(null, TOPIC_XPCOM_SHUTDOWN, null);
|
||||
}
|
||||
|
@ -110,13 +110,13 @@ function check_results() {
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
if (hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection.connectionReady) {
|
||||
if (PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
|
||||
.DBConnection.connectionReady) {
|
||||
do_timeout(POLLING_TIMEOUT_MS, check_results);
|
||||
return;
|
||||
}
|
||||
|
||||
let dbConn = DBConn();
|
||||
do_check_neq(dbConn, null);
|
||||
do_check_true(dbConn.connectionReady);
|
||||
|
||||
// Check that frecency for not cleared items (bookmarks) has been
|
||||
@ -127,14 +127,14 @@ function check_results() {
|
||||
do_check_false(stmt.executeStep());
|
||||
stmt.finalize();
|
||||
|
||||
stmt = DBConn().createStatement(
|
||||
stmt = dbConn.createStatement(
|
||||
"SELECT h.id FROM moz_places h WHERE h.frecency = -2 " +
|
||||
"AND EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) LIMIT 1");
|
||||
do_check_true(stmt.executeStep());
|
||||
stmt.finalize();
|
||||
|
||||
// Check that all visit_counts have been brought to 0
|
||||
stmt = DBConn().createStatement(
|
||||
stmt = dbConn.createStatement(
|
||||
"SELECT id FROM moz_places WHERE visit_count <> 0 LIMIT 1");
|
||||
do_check_false(stmt.executeStep());
|
||||
stmt.finalize();
|
||||
|
@ -12,16 +12,14 @@
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Places.
|
||||
* The Original Code is Places Unit Tests.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Google Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* The Initial Developer of the Original Code is the Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
* Dietrich Ayala <dietrich@mozilla.com>
|
||||
* 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
|
||||
@ -37,298 +35,17 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
const NS_APP_HISTORY_50_FILE = "UHist";
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
|
||||
function LOG(aMsg) {
|
||||
aMsg = ("*** PLACES TESTS: " + aMsg);
|
||||
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
|
||||
logStringMessage(aMsg);
|
||||
print(aMsg);
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Import common head.
|
||||
let (commonFile = do_get_file("../head_common.js", false)) {
|
||||
let uri = Services.io.newFileURI(commonFile);
|
||||
Services.scriptloader.loadSubScript(uri.spec, this);
|
||||
}
|
||||
|
||||
do_get_profile();
|
||||
|
||||
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
var provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_HISTORY_50_FILE) {
|
||||
var histFile = dirSvc.get("ProfD", Ci.nsIFile);
|
||||
histFile.append("history.dat");
|
||||
return histFile;
|
||||
}
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
},
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
|
||||
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
|
||||
function uri(spec) {
|
||||
return iosvc.newURI(spec, null, null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads the data from the specified nsIFile, and returns an array of bytes.
|
||||
*/
|
||||
function readFileData(aFile) {
|
||||
var inputStream = Cc["@mozilla.org/network/file-input-stream;1"].
|
||||
createInstance(Ci.nsIFileInputStream);
|
||||
// init the stream as RD_ONLY, -1 == default permissions.
|
||||
inputStream.init(aFile, 0x01, -1, null);
|
||||
var size = inputStream.available();
|
||||
|
||||
// use a binary input stream to grab the bytes.
|
||||
var bis = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
bis.setInputStream(inputStream);
|
||||
|
||||
var bytes = bis.readByteArray(size);
|
||||
|
||||
if (size != bytes.length)
|
||||
throw "Didn't read expected number of bytes";
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compares two arrays, and returns true if they are equal.
|
||||
*/
|
||||
function compareArrays(aArray1, aArray2) {
|
||||
if (aArray1.length != aArray2.length) {
|
||||
print("compareArrays: array lengths differ\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < aArray1.length; i++) {
|
||||
if (aArray1[i] != aArray2[i]) {
|
||||
print("compareArrays: arrays differ at index " + i + ": " +
|
||||
"(" + aArray1[i] + ") != (" + aArray2[i] +")\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Delete a previously created sqlite file
|
||||
function clearDB() {
|
||||
try {
|
||||
var file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
if (file.exists())
|
||||
file.remove(false);
|
||||
} catch(ex) { dump("Exception: " + ex); }
|
||||
}
|
||||
clearDB();
|
||||
|
||||
/**
|
||||
* Dumps the rows of a table out to the console.
|
||||
*
|
||||
* @param aName
|
||||
* The name of the table or view to output.
|
||||
*/
|
||||
function dump_table(aName)
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
let stmt = db.createStatement("SELECT * FROM " + aName);
|
||||
|
||||
dump("\n*** Printing data from " + aName + ":\n");
|
||||
let count = 0;
|
||||
while (stmt.executeStep()) {
|
||||
let columns = stmt.numEntries;
|
||||
|
||||
if (count == 0) {
|
||||
// print the column names
|
||||
for (let i = 0; i < columns; i++)
|
||||
dump(stmt.getColumnName(i) + "\t");
|
||||
dump("\n");
|
||||
}
|
||||
|
||||
// print the row
|
||||
for (let i = 0; i < columns; i++) {
|
||||
switch (stmt.getTypeOfIndex(i)) {
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_NULL:
|
||||
dump("NULL\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_INTEGER:
|
||||
dump(stmt.getInt64(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_FLOAT:
|
||||
dump(stmt.getDouble(i) + "\t");
|
||||
break;
|
||||
case Ci.mozIStorageValueArray.VALUE_TYPE_TEXT:
|
||||
dump(stmt.getString(i) + "\t");
|
||||
break;
|
||||
}
|
||||
}
|
||||
dump("\n");
|
||||
|
||||
count++;
|
||||
}
|
||||
dump("*** There were a total of " + count + " rows of data.\n\n");
|
||||
|
||||
stmt.reset();
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes all bookmarks and checks for correct cleanup
|
||||
*/
|
||||
function remove_all_bookmarks() {
|
||||
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
// Clear all bookmarks
|
||||
bs.removeFolderChildren(bs.bookmarksMenuFolder);
|
||||
bs.removeFolderChildren(bs.toolbarFolder);
|
||||
bs.removeFolderChildren(bs.unfiledBookmarksFolder);
|
||||
// Check for correct cleanup
|
||||
check_no_bookmarks()
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks that we don't have any bookmark
|
||||
*/
|
||||
function check_no_bookmarks() {
|
||||
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
var query = hs.getNewQuery();
|
||||
query.setFolders([bs.toolbarFolder, bs.bookmarksMenuFolder, bs.unfiledBookmarksFolder], 3);
|
||||
var options = hs.getNewQueryOptions();
|
||||
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
|
||||
var result = hs.executeQuery(query, options);
|
||||
var root = result.root;
|
||||
root.containerOpen = true;
|
||||
do_check_eq(root.childCount, 0);
|
||||
root.containerOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function gets current database connection, if the connection has been closed
|
||||
* it will try to reconnect to the places.sqlite database.
|
||||
*/
|
||||
function DBConn()
|
||||
{
|
||||
let db = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsPIPlacesDatabase).
|
||||
DBConnection;
|
||||
if (db.connectionReady)
|
||||
return db;
|
||||
|
||||
// open a new connection if needed
|
||||
let file = dirSvc.get('ProfD', Ci.nsIFile);
|
||||
file.append("places.sqlite");
|
||||
let storageService = Cc["@mozilla.org/storage/service;1"].
|
||||
getService(Ci.mozIStorageService);
|
||||
try {
|
||||
var dbConn = storageService.openDatabase(file);
|
||||
} catch (ex) {
|
||||
return null;
|
||||
}
|
||||
return dbConn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets title synchronously for a page in moz_places synchronously.
|
||||
* History.SetPageTitle uses LAZY_ADD so we can't rely on it.
|
||||
*
|
||||
* @param aURI
|
||||
* An nsIURI to set the title for.
|
||||
* @param aTitle
|
||||
* The title to set the page to.
|
||||
* @throws if the page is not found in the database.
|
||||
*
|
||||
* @note this function only exists because we have no API to do this. It should
|
||||
* be added in bug 421897.
|
||||
*/
|
||||
function setPageTitle(aURI, aTitle) {
|
||||
let dbConn = DBConn();
|
||||
// Check that the page exists.
|
||||
let stmt = dbConn.createStatement(
|
||||
"SELECT id FROM moz_places_view WHERE url = :url");
|
||||
stmt.params.url = aURI.spec;
|
||||
try {
|
||||
if (!stmt.executeStep()) {
|
||||
do_throw("Unable to find page " + aURIString);
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
stmt.finalize();
|
||||
}
|
||||
|
||||
// Update the title
|
||||
stmt = dbConn.createStatement(
|
||||
"UPDATE moz_places_view SET title = :title WHERE url = :url");
|
||||
stmt.params.title = aTitle;
|
||||
stmt.params.url = aURI.spec;
|
||||
try {
|
||||
stmt.execute();
|
||||
}
|
||||
finally {
|
||||
stmt.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes any events in the event loop of the main thread.
|
||||
*/
|
||||
function flush_main_thread_events()
|
||||
{
|
||||
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
||||
while (tm.mainThread.hasPendingEvents())
|
||||
tm.mainThread.processNextEvent(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears history invoking callback when done.
|
||||
*/
|
||||
function waitForClearHistory(aCallback) {
|
||||
const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let observer = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
os.removeObserver(this, TOPIC_EXPIRATION_FINISHED);
|
||||
aCallback();
|
||||
}
|
||||
};
|
||||
os.addObserver(observer, TOPIC_EXPIRATION_FINISHED, false);
|
||||
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
|
||||
}
|
||||
|
||||
// These tests are known to randomly fail due to bug 507790 when database
|
||||
// flushes are active, so we turn off syncing for them.
|
||||
let randomFailingSyncTests = [
|
||||
"test_multi_word_tags.js",
|
||||
"test_removeVisitsByTimeframe.js",
|
||||
"test_utils_getURLsForContainerNode.js",
|
||||
"test_exclude_livemarks.js",
|
||||
"test_402799.js",
|
||||
];
|
||||
let currentTestFilename = do_get_file(_TEST_FILE[0], true).leafName;
|
||||
if (randomFailingSyncTests.indexOf(currentTestFilename) != -1) {
|
||||
print("Test " + currentTestFilename + " is known random due to bug 507790, disabling PlacesDBFlush component.");
|
||||
let sync = Cc["@mozilla.org/places/sync;1"].getService(Ci.nsIObserver);
|
||||
sync.observe(null, "places-debug-stop-sync", null);
|
||||
}
|
||||
// Put any other stuff relative to this test folder below.
|
||||
|
@ -303,14 +303,15 @@ function getFrecency(url)
|
||||
return frecency;
|
||||
}
|
||||
|
||||
function prepTest(testIndex, testName, callback)
|
||||
function prepTest(testName, callback)
|
||||
{
|
||||
print("Test " + testIndex + ": " + testName);
|
||||
print("Test: " + testName);
|
||||
waitForClearHistory(function() {
|
||||
dbConn.executeSimpleSQL("DELETE FROM moz_places_view");
|
||||
dbConn.executeSimpleSQL("DELETE FROM moz_bookmarks WHERE id > " +
|
||||
defaultBookmarksMaxId);
|
||||
callback();
|
||||
runNextTest();
|
||||
});
|
||||
}
|
||||
|
||||
@ -328,6 +329,7 @@ function visit(uri)
|
||||
|
||||
function run_test()
|
||||
{
|
||||
do_test_pending();
|
||||
var stmt;
|
||||
|
||||
dbConn =
|
||||
@ -341,8 +343,16 @@ function run_test()
|
||||
stmt.finalize();
|
||||
do_check_true(defaultBookmarksMaxId > 0);
|
||||
|
||||
for (let i= 0; i < tests.length; i++)
|
||||
{
|
||||
prepTest(i, tests[i].desc, tests[i].run);
|
||||
runNextTest();
|
||||
}
|
||||
|
||||
let currentTest;
|
||||
function runNextTest() {
|
||||
if (tests.length) {
|
||||
currentTest = tests.shift();
|
||||
prepTest(currentTest.desc, currentTest.run);
|
||||
}
|
||||
else {
|
||||
do_test_finished();
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ function checkAddSucceeded(pageURI, mimetype, data) {
|
||||
|
||||
var favicons = [
|
||||
{
|
||||
uri: iosvc.newFileURI(do_get_file("favicon-normal32.png")),
|
||||
uri: uri(do_get_file("favicon-normal32.png")),
|
||||
data: readFileData(do_get_file("favicon-normal32.png")),
|
||||
mimetype: "image/png"
|
||||
}
|
||||
|
@ -59,13 +59,13 @@ XPCOMUtils.defineLazyServiceGetter(this, "prefs",
|
||||
|
||||
let favicons = [
|
||||
{
|
||||
uri: iosvc.newFileURI(do_get_file("favicon-normal16.png")),
|
||||
uri: uri(do_get_file("favicon-normal16.png")),
|
||||
data: readFileData(do_get_file("favicon-normal16.png")),
|
||||
mimetype: "image/png",
|
||||
size: 286
|
||||
},
|
||||
{
|
||||
uri: iosvc.newFileURI(do_get_file("favicon-normal32.png")),
|
||||
uri: uri(do_get_file("favicon-normal32.png")),
|
||||
data: readFileData(do_get_file("favicon-normal32.png")),
|
||||
mimetype: "image/png",
|
||||
size: 344
|
||||
@ -154,7 +154,7 @@ let historyObserver = {
|
||||
do_check_true(pageURI.equals(uri("http://test4.bar/")));
|
||||
|
||||
// Ensure there is only one entry in favicons table.
|
||||
let stmt = DBConn().createStatement(
|
||||
let stmt = PlacesServices.DBConn.createStatement(
|
||||
"SELECT url FROM moz_favicons"
|
||||
);
|
||||
let c = 0;
|
||||
|
@ -226,7 +226,7 @@ function run_test() {
|
||||
|
||||
// test to ensure history.dat gets deleted if all history is being cleared
|
||||
var file = do_get_file("history.dat");
|
||||
var histFile = dirSvc.get("ProfD", Ci.nsIFile);
|
||||
var histFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
||||
file.copyTo(histFile, "history.dat");
|
||||
histFile.append("history.dat");
|
||||
do_check_true(histFile.exists());
|
||||
|
Loading…
x
Reference in New Issue
Block a user