--- a/toolkit/components/places/tests/unit/test_000_frecency.js
+++ b/toolkit/components/places/tests/unit/test_000_frecency.js
@@ -13,20 +13,16 @@ Autocomplete Frecency Tests
- test number of matches
- test each item's location in results
*/
try {
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
- var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
- getService(Ci.nsINavBookmarksService);
- var prefs = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefBranch);
} catch (ex) {
do_throw("Could not get services\n");
}
var bucketPrefs = [
[ "firstBucketCutoff", "firstBucketWeight"],
[ "secondBucketCutoff", "secondBucketWeight"],
[ "thirdBucketCutoff", "thirdBucketWeight"],
@@ -50,41 +46,45 @@ var bonusPrefs = {
var searchTerm = "frecency";
var results = [];
var now = Date.now();
var prefPrefix = "places.frecency.";
async function task_initializeBucket(bucket) {
let [cutoffName, weightName] = bucket;
// get pref values
- var weight = prefs.getIntPref(prefPrefix + weightName, 0);
- var cutoff = prefs.getIntPref(prefPrefix + cutoffName, 0);
+ var weight = Services.prefs.getIntPref(prefPrefix + weightName, 0);
+ var cutoff = Services.prefs.getIntPref(prefPrefix + cutoffName, 0);
if (cutoff < 1)
return;
// generate a date within the cutoff period
var dateInPeriod = (now - ((cutoff - 1) * 86400 * 1000)) * 1000;
for (let [bonusName, visitType] of Object.entries(bonusPrefs)) {
var frecency = -1;
var calculatedURI = null;
var matchTitle = "";
- var bonusValue = prefs.getIntPref(prefPrefix + bonusName);
+ var bonusValue = Services.prefs.getIntPref(prefPrefix + bonusName);
// unvisited (only for first cutoff date bucket)
if (bonusName == "unvisitedBookmarkBonus" || bonusName == "unvisitedTypedBonus") {
if (cutoffName == "firstBucketCutoff") {
let points = Math.ceil(bonusValue / parseFloat(100.0) * weight);
var visitCount = 1; // bonusName == "unvisitedBookmarkBonus" ? 1 : 0;
frecency = Math.ceil(visitCount * points);
calculatedURI = uri("http://" + searchTerm + ".com/" +
bonusName + ":" + bonusValue + "/cutoff:" + cutoff +
"/weight:" + weight + "/frecency:" + frecency);
if (bonusName == "unvisitedBookmarkBonus") {
matchTitle = searchTerm + "UnvisitedBookmark";
- bmsvc.insertBookmark(bmsvc.unfiledBookmarksFolder, calculatedURI, bmsvc.DEFAULT_INDEX, matchTitle);
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ url: calculatedURI,
+ title: matchTitle
+ });
} else {
matchTitle = searchTerm + "UnvisitedTyped";
await PlacesTestUtils.addVisits({
uri: calculatedURI,
title: matchTitle,
transition: visitType,
visitDate: now
});
@@ -109,17 +109,21 @@ async function task_initializeBucket(buc
frecency = -1;
} else
frecency = points;
calculatedURI = uri("http://" + searchTerm + ".com/" +
bonusName + ":" + bonusValue + "/cutoff:" + cutoff +
"/weight:" + weight + "/frecency:" + frecency);
if (visitType == Ci.nsINavHistoryService.TRANSITION_BOOKMARK) {
matchTitle = searchTerm + "Bookmarked";
- bmsvc.insertBookmark(bmsvc.unfiledBookmarksFolder, calculatedURI, bmsvc.DEFAULT_INDEX, matchTitle);
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ url: calculatedURI,
+ title: matchTitle
+ });
} else
matchTitle = calculatedURI.spec.substr(calculatedURI.spec.lastIndexOf("/") + 1);
await PlacesTestUtils.addVisits({
uri: calculatedURI,
transition: visitType,
visitDate: dateInPeriod
});
}
@@ -194,35 +198,35 @@ add_task(async function test_frecency()
do_register_cleanup(() => Services.prefs.clearUserPref("browser.urlbar.autoFill"));
for (let bucket of bucketPrefs) {
await task_initializeBucket(bucket);
}
// sort results by frecency
results.sort((a, b) => b[1] - a[1]);
// Make sure there's enough results returned
- prefs.setIntPref("browser.urlbar.maxRichResults", results.length);
+ Services.prefs.setIntPref("browser.urlbar.maxRichResults", results.length);
// DEBUG
// results.every(function(el) { dump("result: " + el[1] + ": " + el[0].spec + " (" + el[2] + ")\n"); return true; })
await PlacesTestUtils.promiseAsyncUpdates();
var controller = Components.classes["@mozilla.org/autocomplete/controller;1"].
getService(Components.interfaces.nsIAutoCompleteController);
// Make an AutoCompleteInput that uses our searches
// and confirms results on search complete
var input = new AutoCompleteInput(["unifiedcomplete"]);
controller.input = input;
// always search in history + bookmarks, no matter what the default is
- prefs.setIntPref("browser.urlbar.search.sources", 3);
- prefs.setIntPref("browser.urlbar.default.behavior", 0);
+ Services.prefs.setIntPref("browser.urlbar.search.sources", 3);
+ Services.prefs.setIntPref("browser.urlbar.default.behavior", 0);
var numSearchesStarted = 0;
input.onSearchBegin = function() {
numSearchesStarted++;
do_check_eq(numSearchesStarted, 1);
};
await new Promise(resolve => {
--- a/toolkit/components/places/tests/unit/test_1085291.js
+++ b/toolkit/components/places/tests/unit/test_1085291.js
@@ -31,12 +31,8 @@ add_task(async function() {
title: "Test Folder" });
// separator
await insertAndTest({ parentGuid: root.bookmarkGuid,
type: PlacesUtils.bookmarks.TYPE_SEPARATOR });
root.containerOpen = false;
});
-
-function run_test() {
- run_next_test();
-}
--- a/toolkit/components/places/tests/unit/test_1105208.js
+++ b/toolkit/components/places/tests/unit/test_1105208.js
@@ -13,12 +13,8 @@ add_task(async function() {
Assert.equal(shortcutNode.bookmarkGuid, shortcutInfo.guid);
let toolbarInfo =
await PlacesUtils.bookmarks.fetch(PlacesUtils.bookmarks.toolbarGuid);
Assert.equal(shortcutNode.title, toolbarInfo.title);
unfiledRoot.containerOpen = false;
});
-
-function run_test() {
- run_next_test();
-}
--- a/toolkit/components/places/tests/unit/test_1105866.js
+++ b/toolkit/components/places/tests/unit/test_1105866.js
@@ -52,12 +52,8 @@ add_task(async function test_non_item_qu
let options = PlacesUtils.history.getNewQueryOptions();
let root = PlacesUtils.history.executeQuery(
PlacesUtils.history.getNewQuery(), options).root;
Assert.strictEqual(root.itemId, -1);
Assert.strictEqual(PlacesUtils.asQuery(root).folderItemId, -1);
Assert.strictEqual(root.bookmarkGuid, "");
Assert.strictEqual(PlacesUtils.asQuery(root).targetFolderGuid, "");
});
-
-function run_test() {
- run_next_test();
-}
--- a/toolkit/components/places/tests/unit/test_317472.js
+++ b/toolkit/components/places/tests/unit/test_317472.js
@@ -5,34 +5,32 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const charset = "UTF-8";
const CHARSET_ANNO = "URIProperties/characterSet";
const TEST_URI = uri("http://foo.com");
const TEST_BOOKMARKED_URI = uri("http://bar.com");
-function run_test() {
- run_next_test();
-}
-
add_task(async function test_execute() {
// add pages to history
await PlacesTestUtils.addVisits(TEST_URI);
await PlacesTestUtils.addVisits(TEST_BOOKMARKED_URI);
// create bookmarks on TEST_BOOKMARKED_URI
- PlacesUtils.bookmarks.insertBookmark(
- PlacesUtils.unfiledBookmarksFolderId,
- TEST_BOOKMARKED_URI, PlacesUtils.bookmarks.DEFAULT_INDEX,
- TEST_BOOKMARKED_URI.spec);
- PlacesUtils.bookmarks.insertBookmark(
- PlacesUtils.toolbarFolderId,
- TEST_BOOKMARKED_URI, PlacesUtils.bookmarks.DEFAULT_INDEX,
- TEST_BOOKMARKED_URI.spec);
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ url: TEST_BOOKMARKED_URI,
+ title: TEST_BOOKMARKED_URI.spec,
+ });
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ url: TEST_BOOKMARKED_URI,
+ title: TEST_BOOKMARKED_URI.spec,
+ });
// set charset on not-bookmarked page
await PlacesUtils.setCharsetForURI(TEST_URI, charset);
// set charset on bookmarked page
await PlacesUtils.setCharsetForURI(TEST_BOOKMARKED_URI, charset);
// check that we have created a page annotation
do_check_eq(PlacesUtils.annotations.getPageAnnotation(TEST_URI, CHARSET_ANNO), charset);
--- a/toolkit/components/places/tests/unit/test_331487.js
+++ b/toolkit/components/places/tests/unit/test_331487.js
@@ -6,90 +6,96 @@
// Get history service
try {
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
} catch (ex) {
do_throw("Could not get history service\n");
}
-var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
- getService(Ci.nsINavBookmarksService);
-
-// main
-function run_test() {
- // add a folder
- var folder = bmsvc.createFolder(bmsvc.placesRoot, "test folder", bmsvc.DEFAULT_INDEX);
+add_task(async function test_hierarchical_query() {
+ let bookmarks = await PlacesUtils.bookmarks.insertTree({
+ guid: PlacesUtils.bookmarks.unfiledGuid,
+ children: [{
+ title: "test folder",
+ type: PlacesUtils.bookmarks.TYPE_FOLDER,
+ children: [{
+ title: "1 title",
+ url: "http://a1.com/",
+ }, {
+ title: "subfolder 1",
+ type: PlacesUtils.bookmarks.TYPE_FOLDER,
+ children: [{
+ title: "2 title",
+ url: "http://a2.com/",
+ }, {
+ title: "subfolder 2",
+ type: PlacesUtils.bookmarks.TYPE_FOLDER,
+ children: [{
+ title: "3 title",
+ url: "http://a3.com/",
+ }]
+ }]
+ }]
+ }]
+ });
- // add a bookmark to the folder
- var b1 = bmsvc.insertBookmark(folder, uri("http://a1.com/"),
- bmsvc.DEFAULT_INDEX, "1 title");
- // add a subfolder
- var sf1 = bmsvc.createFolder(folder, "subfolder 1", bmsvc.DEFAULT_INDEX);
+ let [folderGuid, b1, sf1, b2, sf2, b3] = bookmarks.map((bookmark) => bookmark.guid);
- // add a bookmark to the subfolder
- var b2 = bmsvc.insertBookmark(sf1, uri("http://a2.com/"),
- bmsvc.DEFAULT_INDEX, "2 title");
-
- // add a subfolder to the subfolder
- var sf2 = bmsvc.createFolder(sf1, "subfolder 2", bmsvc.DEFAULT_INDEX);
-
- // add a bookmark to the subfolder of the subfolder
- var b3 = bmsvc.insertBookmark(sf2, uri("http://a3.com/"),
- bmsvc.DEFAULT_INDEX, "3 title");
+ let testFolderId = await PlacesUtils.promiseItemId(folderGuid);
// bookmark query that should result in the "hierarchical" result
// because there is one query, one folder,
// no begin time, no end time, no domain, no uri, no search term
// and no max results. See GetSimpleBookmarksQueryFolder()
// for more details.
var options = histsvc.getNewQueryOptions();
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
var query = histsvc.getNewQuery();
- query.setFolders([folder], 1);
+ query.setFolders([testFolderId], 1);
var result = histsvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
do_check_eq(root.childCount, 2);
- do_check_eq(root.getChild(0).itemId, b1);
- do_check_eq(root.getChild(1).itemId, sf1);
+ do_check_eq(root.getChild(0).bookmarkGuid, b1);
+ do_check_eq(root.getChild(1).bookmarkGuid, sf1);
// check the contents of the subfolder
var sf1Node = root.getChild(1);
sf1Node = sf1Node.QueryInterface(Ci.nsINavHistoryContainerResultNode);
sf1Node.containerOpen = true;
do_check_eq(sf1Node.childCount, 2);
- do_check_eq(sf1Node.getChild(0).itemId, b2);
- do_check_eq(sf1Node.getChild(1).itemId, sf2);
+ do_check_eq(sf1Node.getChild(0).bookmarkGuid, b2);
+ do_check_eq(sf1Node.getChild(1).bookmarkGuid, sf2);
// check the contents of the subfolder's subfolder
var sf2Node = sf1Node.getChild(1);
sf2Node = sf2Node.QueryInterface(Ci.nsINavHistoryContainerResultNode);
sf2Node.containerOpen = true;
do_check_eq(sf2Node.childCount, 1);
- do_check_eq(sf2Node.getChild(0).itemId, b3);
+ do_check_eq(sf2Node.getChild(0).bookmarkGuid, b3);
sf2Node.containerOpen = false;
sf1Node.containerOpen = false;
root.containerOpen = false;
// bookmark query that should result in a flat list
// because we specified max results
options = histsvc.getNewQueryOptions();
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
options.maxResults = 10;
query = histsvc.getNewQuery();
- query.setFolders([folder], 1);
+ query.setFolders([testFolderId], 1);
result = histsvc.executeQuery(query, options);
root = result.root;
root.containerOpen = true;
do_check_eq(root.childCount, 3);
- do_check_eq(root.getChild(0).itemId, b1);
- do_check_eq(root.getChild(1).itemId, b2);
- do_check_eq(root.getChild(2).itemId, b3);
+ do_check_eq(root.getChild(0).bookmarkGuid, b1);
+ do_check_eq(root.getChild(1).bookmarkGuid, b2);
+ do_check_eq(root.getChild(2).bookmarkGuid, b3);
root.containerOpen = false;
// XXX TODO
// test that if we have: more than one query,
// multiple folders, a begin time, an end time, a domain, a uri
// or a search term, that we get the (correct) flat list results
// (like we do when specified maxResults)
-}
+});
--- a/toolkit/components/places/tests/unit/test_385397.js
+++ b/toolkit/components/places/tests/unit/test_385397.js
@@ -1,20 +1,16 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const TOTAL_SITES = 20;
-function run_test() {
- run_next_test();
-}
-
add_task(async function test_execute() {
let now = (Date.now() - 10000) * 1000;
for (let i = 0; i < TOTAL_SITES; i++) {
let site = "http://www.test-" + i + ".com/";
let testURI = uri(site);
let testImageURI = uri(site + "blank.gif");
let when = now + (i * TOTAL_SITES * 1000);
--- a/toolkit/components/places/tests/unit/test_399264_query_to_string.js
+++ b/toolkit/components/places/tests/unit/test_399264_query_to_string.js
@@ -17,33 +17,29 @@ function query_string(aFolderID) {
var query = hs.getNewQuery();
query.setFolders([aFolderID], 1);
var options = hs.getNewQueryOptions();
return hs.queriesToQueryString([query], 1, options);
}
function run_test() {
- var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
- getService(Ci.nsINavBookmarksService);
-
const QUERIES = [
"folder=PLACES_ROOT",
"folder=BOOKMARKS_MENU",
"folder=TAGS",
"folder=UNFILED_BOOKMARKS",
"folder=TOOLBAR"
];
const FOLDER_IDS = [
- bs.placesRoot,
- bs.bookmarksMenuFolder,
- bs.tagsFolder,
- bs.unfiledBookmarksFolder,
- bs.toolbarFolder
+ PlacesUtils.placesRootId,
+ PlacesUtils.bookmarksMenuFolderId,
+ PlacesUtils.tagsFolderId,
+ PlacesUtils.unfiledBookmarksFolderId,
+ PlacesUtils.toolbarFolderId,
];
-
for (var i = 0; i < QUERIES.length; i++) {
var result = query_string(FOLDER_IDS[i]);
dump("Looking for '" + QUERIES[i] + "' in '" + result + "'\n");
do_check_neq(-1, result.indexOf(QUERIES[i]));
}
}
--- a/toolkit/components/places/tests/unit/test_399264_string_to_query.js
+++ b/toolkit/components/places/tests/unit/test_399264_string_to_query.js
@@ -24,50 +24,56 @@ function folder_id(aQuery) {
var root = result.root;
root.containerOpen = true;
do_check_true(root.hasChildren);
var folderID = root.getChild(0).parent.itemId;
root.containerOpen = false;
return folderID;
}
-function run_test() {
- var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
- getService(Ci.nsINavBookmarksService);
-
+add_task(async function test_history_string_to_query() {
const QUERIES = [
"place:folder=PLACES_ROOT",
"place:folder=BOOKMARKS_MENU",
"place:folder=TAGS",
"place:folder=UNFILED_BOOKMARKS",
"place:folder=TOOLBAR"
];
const FOLDER_IDS = [
- bs.placesRoot,
- bs.bookmarksMenuFolder,
- bs.tagsFolder,
- bs.unfiledBookmarksFolder,
- bs.toolbarFolder
+ PlacesUtils.placesRootId,
+ PlacesUtils.bookmarksMenuFolderId,
+ PlacesUtils.tagsFolderId,
+ PlacesUtils.unfiledBookmarksFolderId,
+ PlacesUtils.toolbarFolderId,
];
// add something in the bookmarks menu folder so a query to it returns results
- bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://example.com/bmf/"),
- Ci.nsINavBookmarksService.DEFAULT_INDEX, "bmf");
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.menuGuid,
+ title: "bmf",
+ url: "http://example.com/bmf/",
+ });
// add something to the tags folder
var ts = Cc["@mozilla.org/browser/tagging-service;1"].
getService(Ci.nsITaggingService);
ts.tagURI(uri("http://www.example.com/"), ["tag"]);
// add something to the unfiled bookmarks folder
- bs.insertBookmark(bs.unfiledBookmarksFolder, uri("http://example.com/ubf/"),
- Ci.nsINavBookmarksService.DEFAULT_INDEX, "ubf");
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ title: "ubf",
+ url: "http://example.com/ubf/",
+ });
// add something to the toolbar folder
- bs.insertBookmark(bs.toolbarFolder, uri("http://example.com/tf/"),
- Ci.nsINavBookmarksService.DEFAULT_INDEX, "tf");
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ title: "tf",
+ url: "http://example.com/tf/",
+ });
for (var i = 0; i < QUERIES.length; i++) {
var result = folder_id(QUERIES[i]);
dump("expected " + FOLDER_IDS[i] + ", got " + result + "\n");
do_check_eq(FOLDER_IDS[i], result);
}
-}
+});
--- a/toolkit/components/places/tests/unit/test_399266.js
+++ b/toolkit/components/places/tests/unit/test_399266.js
@@ -1,20 +1,16 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const TOTAL_SITES = 20;
-function run_test() {
- run_next_test();
-}
-
add_task(async function test_execute() {
let places = [];
for (let i = 0; i < TOTAL_SITES; i++) {
for (let j = 0; j <= i; j++) {
places.push({ uri: uri("http://www.test-" + i + ".com/"),
transition: TRANSITION_TYPED });
// because these are embedded visits, they should not show up on our
// query results. If they do, we have a problem.
--- a/toolkit/components/places/tests/unit/test_402799.js
+++ b/toolkit/components/places/tests/unit/test_402799.js
@@ -7,54 +7,52 @@
// Get history services
try {
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
} catch (ex) {
do_throw("Could not get history services\n");
}
-// Get bookmark service
-try {
- var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
- getService(Ci.nsINavBookmarksService);
-} catch (ex) {
- do_throw("Could not get the nav-bookmarks-service\n");
-}
-
// Get tagging service
try {
var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].
getService(Ci.nsITaggingService);
} catch (ex) {
do_throw("Could not get tagging service\n");
}
-
-// main
-function run_test() {
- var uri1 = uri("http://foo.bar/");
+add_task(async function test_query_only_returns_bookmarks_not_tags() {
+ const url = "http://foo.bar/";
// create 2 bookmarks on the same uri
- bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, uri1,
- bmsvc.DEFAULT_INDEX, "title 1");
- bmsvc.insertBookmark(bmsvc.toolbarFolder, uri1,
- bmsvc.DEFAULT_INDEX, "title 2");
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.menuGuid,
+ title: "title 1",
+ url,
+ });
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ title: "title 2",
+ url,
+ });
// add some tags
- tagssvc.tagURI(uri1, ["foo", "bar", "foobar", "foo bar"]);
+ tagssvc.tagURI(uri(url), ["foo", "bar", "foobar", "foo bar"]);
// check that a generic bookmark query returns only real bookmarks
- var options = histsvc.getNewQueryOptions();
+ let options = histsvc.getNewQueryOptions();
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
- var query = histsvc.getNewQuery();
- var result = histsvc.executeQuery(query, options);
- var root = result.root;
+ let query = histsvc.getNewQuery();
+ let result = histsvc.executeQuery(query, options);
+ let root = result.root;
root.containerOpen = true;
- var cc = root.childCount;
+ let cc = root.childCount;
do_check_eq(cc, 2);
- var node1 = root.getChild(0);
- do_check_eq(bmsvc.getFolderIdForItem(node1.itemId), bmsvc.bookmarksMenuFolder);
- var node2 = root.getChild(1);
- do_check_eq(bmsvc.getFolderIdForItem(node2.itemId), bmsvc.toolbarFolder);
+ let node1 = root.getChild(0);
+ node1 = await PlacesUtils.bookmarks.fetch(node1.bookmarkGuid);
+ do_check_eq(node1.parentGuid, PlacesUtils.bookmarks.menuGuid);
+ let node2 = root.getChild(1);
+ node2 = await PlacesUtils.bookmarks.fetch(node2.bookmarkGuid);
+ do_check_eq(node2.parentGuid, PlacesUtils.bookmarks.toolbarGuid);
root.containerOpen = false;
-}
+});
--- a/toolkit/components/places/tests/unit/test_405497.js
+++ b/toolkit/components/places/tests/unit/test_405497.js
@@ -3,18 +3,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
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);
/**
* The callback object for runInBatchMode.
*
* @param aService
* Takes a reference to the history service or the bookmark service.
* This determines which service should be called when calling the second
* runInBatchMode the second time.
@@ -46,10 +44,10 @@ callback.prototype = {
function run_test() {
// checking the history service
do_test_pending();
hs.runInBatchMode(new callback(hs), null);
// checking the bookmark service
do_test_pending();
- bs.runInBatchMode(new callback(bs), null);
+ PlacesUtils.bookmarks.runInBatchMode(new callback(PlacesUtils.bookmarks), null);
}
--- a/toolkit/components/places/tests/unit/test_408221.js
+++ b/toolkit/components/places/tests/unit/test_408221.js
@@ -1,16 +1,14 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-var current_test = 0;
-
function AutoCompleteInput(aSearches) {
this.searches = aSearches;
}
AutoCompleteInput.prototype = {
constructor: AutoCompleteInput,
searches: null,
@@ -71,94 +69,86 @@ function ensure_tag_results(uris, search
getService(Components.interfaces.nsIAutoCompleteController);
// Make an AutoCompleteInput that uses our searches
// and confirms results on search complete
var input = new AutoCompleteInput(["unifiedcomplete"]);
controller.input = input;
- // Search is asynchronous, so don't let the test finish immediately
- do_test_pending();
-
- var numSearchesStarted = 0;
- input.onSearchBegin = function() {
- numSearchesStarted++;
- do_check_eq(numSearchesStarted, 1);
- };
+ return new Promise(resolve => {
+ var numSearchesStarted = 0;
+ input.onSearchBegin = function() {
+ numSearchesStarted++;
+ do_check_eq(numSearchesStarted, 1);
+ };
- input.onSearchComplete = function() {
- do_check_eq(numSearchesStarted, 1);
- do_check_eq(controller.searchStatus,
- Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
- do_check_eq(controller.matchCount, uris.length);
- let vals = [];
- for (let i = 0; i < controller.matchCount; i++) {
- // Keep the URL for later because order of tag results is undefined
- vals.push(controller.getValueAt(i));
- do_check_eq(controller.getStyleAt(i), "bookmark-tag");
- }
- // Sort the results then check if we have the right items
- vals.sort().forEach((val, i) => do_check_eq(val, uris[i].spec))
+ input.onSearchComplete = function() {
+ do_check_eq(numSearchesStarted, 1);
+ do_check_eq(controller.searchStatus,
+ Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
+ do_check_eq(controller.matchCount, uris.length);
+ let vals = [];
+ for (let i = 0; i < controller.matchCount; i++) {
+ // Keep the URL for later because order of tag results is undefined
+ vals.push(controller.getValueAt(i));
+ do_check_eq(controller.getStyleAt(i), "bookmark-tag");
+ }
+ // Sort the results then check if we have the right items
+ vals.sort().forEach((val, i) => do_check_eq(val, uris[i]))
- if (current_test < (tests.length - 1)) {
- current_test++;
- tests[current_test]();
- }
+ resolve();
+ };
- do_test_finished();
- };
-
- controller.startSearch(searchTerm);
+ controller.startSearch(searchTerm);
+ });
}
-var uri1 = uri("http://site.tld/1");
-var uri2 = uri("http://site.tld/2");
-var uri3 = uri("http://site.tld/3");
-var uri4 = uri("http://site.tld/4");
-var uri5 = uri("http://site.tld/5");
-var uri6 = uri("http://site.tld/6");
-
-var tests = [function() { ensure_tag_results([uri1, uri2, uri3], "foo"); },
- function() { ensure_tag_results([uri1, uri2, uri3], "Foo"); },
- function() { ensure_tag_results([uri1, uri2, uri3], "foO"); },
- function() { ensure_tag_results([uri4, uri5, uri6], "bar mud"); },
- function() { ensure_tag_results([uri4, uri5, uri6], "BAR MUD"); },
- function() { ensure_tag_results([uri4, uri5, uri6], "Bar Mud"); }];
+const uri1 = "http://site.tld/1";
+const uri2 = "http://site.tld/2";
+const uri3 = "http://site.tld/3";
+const uri4 = "http://site.tld/4";
+const uri5 = "http://site.tld/5";
+const uri6 = "http://site.tld/6";
/**
* Properly tags a uri adding it to bookmarks.
*
* @param aURI
* The nsIURI to tag.
* @param aTags
* The tags to add.
*/
-function tagURI(aURI, aTags) {
- PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
- aURI,
- PlacesUtils.bookmarks.DEFAULT_INDEX,
- "A title");
- tagssvc.tagURI(aURI, aTags);
+async function tagURI(url, aTags) {
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ title: "A title",
+ url,
+ });
+
+ tagssvc.tagURI(uri(url), aTags);
}
/**
* Test bug #408221
*/
-function run_test() {
+add_task(async function test_tags_search_case_insensitivity() {
// always search in history + bookmarks, no matter what the default is
- var prefs = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefBranch);
- prefs.setIntPref("browser.urlbar.search.sources", 3);
- prefs.setIntPref("browser.urlbar.default.behavior", 0);
+ Services.prefs.setIntPref("browser.urlbar.search.sources", 3);
+ Services.prefs.setIntPref("browser.urlbar.default.behavior", 0);
- tagURI(uri1, ["Foo"]);
- tagURI(uri2, ["FOO"]);
- tagURI(uri3, ["foO"]);
- tagURI(uri4, ["BAR"]);
- tagURI(uri4, ["MUD"]);
- tagURI(uri5, ["bar"]);
- tagURI(uri5, ["mud"]);
- tagURI(uri6, ["baR"]);
- tagURI(uri6, ["muD"]);
+ await tagURI(uri1, ["Foo"]);
+ await tagURI(uri2, ["FOO"]);
+ await tagURI(uri3, ["foO"]);
+ await tagURI(uri4, ["BAR"]);
+ await tagURI(uri4, ["MUD"]);
+ await tagURI(uri5, ["bar"]);
+ await tagURI(uri5, ["mud"]);
+ await tagURI(uri6, ["baR"]);
+ await tagURI(uri6, ["muD"]);
- tests[0]();
-}
+ await ensure_tag_results([uri1, uri2, uri3], "foo");
+ await ensure_tag_results([uri1, uri2, uri3], "Foo");
+ await ensure_tag_results([uri1, uri2, uri3], "foO");
+ await ensure_tag_results([uri4, uri5, uri6], "bar mud");
+ await ensure_tag_results([uri4, uri5, uri6], "BAR MUD");
+ await ensure_tag_results([uri4, uri5, uri6], "Bar Mud");
+});
--- a/toolkit/components/places/tests/unit/test_412132.js
+++ b/toolkit/components/places/tests/unit/test_412132.js
@@ -6,124 +6,134 @@
/*
* TEST DESCRIPTION:
*
* Tests patch to Bug 412132:
* https://bugzilla.mozilla.org/show_bug.cgi?id=412132
*/
+const TEST_URL0 = "http://example.com/";
+const TEST_URL1 = "http://example.com/1";
+const TEST_URL2 = "http://example.com/2";
+
add_task(async function changeuri_unvisited_bookmark() {
do_print("After changing URI of bookmark, frecency of bookmark's " +
"original URI should be zero if original URI is unvisited and " +
"no longer bookmarked.");
- const TEST_URI = NetUtil.newURI("http://example.com/1");
- let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
- TEST_URI,
- PlacesUtils.bookmarks.DEFAULT_INDEX,
- "bookmark title");
- await PlacesTestUtils.promiseAsyncUpdates();
-
- do_print("Bookmarked => frecency of URI should be != 0");
- do_check_neq(frecencyForUrl(TEST_URI), 0);
-
- PlacesUtils.bookmarks.changeBookmarkURI(id, uri("http://example.com/2"));
+ let bookmark = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ title: "bookmark title",
+ url: TEST_URL1,
+ });
await PlacesTestUtils.promiseAsyncUpdates();
- do_print("Unvisited URI no longer bookmarked => frecency should = 0");
- do_check_eq(frecencyForUrl(TEST_URI), 0);
+ Assert.notEqual(frecencyForUrl(TEST_URL1), 0,
+ "Bookmarked => frecency of URI should be != 0");
+
+ await PlacesUtils.bookmarks.update({
+ guid: bookmark.guid,
+ url: TEST_URL2
+ });
+
+ await PlacesTestUtils.promiseAsyncUpdates();
+
+ Assert.equal(frecencyForUrl(TEST_URL1), 0,
+ "Unvisited URI no longer bookmarked => frecency should = 0");
await PlacesUtils.bookmarks.eraseEverything();
await PlacesTestUtils.clearHistory();
});
add_task(async function changeuri_visited_bookmark() {
do_print("After changing URI of bookmark, frecency of bookmark's " +
"original URI should not be zero if original URI is visited.");
- const TEST_URI = NetUtil.newURI("http://example.com/1");
- let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
- TEST_URI,
- PlacesUtils.bookmarks.DEFAULT_INDEX,
- "bookmark title");
+ let bookmark = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ title: "bookmark title",
+ url: TEST_URL1,
+ });
await PlacesTestUtils.promiseAsyncUpdates();
- do_print("Bookmarked => frecency of URI should be != 0");
- do_check_neq(frecencyForUrl(TEST_URI), 0);
+ Assert.notEqual(frecencyForUrl(TEST_URL1), 0,
+ "Bookmarked => frecency of URI should be != 0");
- await PlacesTestUtils.addVisits(TEST_URI);
+ await PlacesTestUtils.addVisits(TEST_URL1);
await PlacesTestUtils.promiseAsyncUpdates();
- PlacesUtils.bookmarks.changeBookmarkURI(id, uri("http://example.com/2"));
+ await PlacesUtils.bookmarks.update({
+ guid: bookmark.guid,
+ url: TEST_URL2,
+ })
await PlacesTestUtils.promiseAsyncUpdates();
- do_print("*Visited* URI no longer bookmarked => frecency should != 0");
- do_check_neq(frecencyForUrl(TEST_URI), 0);
+ Assert.notEqual(frecencyForUrl(TEST_URL1), 0,
+ "*Visited* URI no longer bookmarked => frecency should != 0");
await PlacesUtils.bookmarks.eraseEverything();
await PlacesTestUtils.clearHistory();
});
add_task(async function changeuri_bookmark_still_bookmarked() {
do_print("After changing URI of bookmark, frecency of bookmark's " +
"original URI should not be zero if original URI is still " +
"bookmarked.");
- const TEST_URI = NetUtil.newURI("http://example.com/1");
- let id1 = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
- TEST_URI,
- PlacesUtils.bookmarks.DEFAULT_INDEX,
- "bookmark 1 title");
- PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
- TEST_URI,
- PlacesUtils.bookmarks.DEFAULT_INDEX,
- "bookmark 2 title");
+ let bookmark = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ title: "bookmark 1 title",
+ url: TEST_URL1,
+ });
+
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ title: "bookmark 2 title",
+ url: TEST_URL1,
+ });
await PlacesTestUtils.promiseAsyncUpdates();
- do_print("Bookmarked => frecency of URI should be != 0");
- do_check_neq(frecencyForUrl(TEST_URI), 0);
+ Assert.notEqual(frecencyForUrl(TEST_URL1), 0,
+ "Bookmarked => frecency of URI should be != 0");
- PlacesUtils.bookmarks.changeBookmarkURI(id1, uri("http://example.com/2"));
+ await PlacesUtils.bookmarks.update({
+ guid: bookmark.guid,
+ url: TEST_URL2
+ })
await PlacesTestUtils.promiseAsyncUpdates();
do_print("URI still bookmarked => frecency should != 0");
- do_check_neq(frecencyForUrl(TEST_URI), 0);
+ do_check_neq(frecencyForUrl(TEST_URL2), 0);
await PlacesUtils.bookmarks.eraseEverything();
await PlacesTestUtils.clearHistory();
});
add_task(async function changeuri_nonexistent_bookmark() {
- do_print("Changing the URI of a nonexistent bookmark should fail.");
- function tryChange(itemId) {
- try {
- PlacesUtils.bookmarks.changeBookmarkURI(itemId + 1, uri("http://example.com/2"));
- do_throw("Nonexistent bookmark should throw.");
- } catch (ex) {}
- }
-
- // First try a straight-up bogus item ID, one greater than the current max
- // ID.
- let stmt = DBConn().createStatement("SELECT MAX(id) FROM moz_bookmarks");
- stmt.executeStep();
- let maxId = stmt.getInt32(0);
- stmt.finalize();
- tryChange(maxId + 1);
+ // Try a bogus guid.
+ await Assert.rejects(PlacesUtils.bookmarks.update({
+ guid: "ABCDEDFGHIJK",
+ url: TEST_URL2
+ }), /No bookmarks found for the provided GUID/,
+ "Changing the URI of a non-existent bookmark should fail.");
// Now add a bookmark, delete it, and check.
- let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
- uri("http://example.com/"),
- PlacesUtils.bookmarks.DEFAULT_INDEX,
- "bookmark title");
- PlacesUtils.bookmarks.removeItem(id);
- tryChange(id);
+ let bookmark = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ title: "bookmark title",
+ url: TEST_URL0,
+ })
+
+ await PlacesUtils.bookmarks.remove(bookmark.guid);
+
+ await Assert.rejects(PlacesUtils.bookmarks.update({
+ guid: bookmark.guid,
+ url: TEST_URL2
+ }), /No bookmarks found for the provided GUID/,
+ "Changing the URI of a non-existent bookmark should fail.");
await PlacesUtils.bookmarks.eraseEverything();
await PlacesTestUtils.clearHistory();
});
-
-function run_test() {
- run_next_test();
-}
--- a/toolkit/components/places/tests/unit/test_413784.js
+++ b/toolkit/components/places/tests/unit/test_413784.js
@@ -67,45 +67,44 @@ AutoCompleteInput.prototype = {
if (iid.equals(Ci.nsISupports) ||
iid.equals(Ci.nsIAutoCompleteInput))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
}
}
-function run_test() {
- do_test_pending();
- PlacesTestUtils.addVisits(url).then(continue_test);
-}
+add_task(async function test_autocomplete_non_english() {
+ await PlacesTestUtils.addVisits(url);
-function continue_test() {
var controller = Components.classes["@mozilla.org/autocomplete/controller;1"].
getService(Components.interfaces.nsIAutoCompleteController);
// Make an AutoCompleteInput that uses our searches
// and confirms results on search complete
var input = new AutoCompleteInput(["unifiedcomplete"]);
controller.input = input;
- var numSearchesStarted = 0;
- input.onSearchBegin = function() {
- numSearchesStarted++;
- do_check_eq(numSearchesStarted, 1);
- };
+ return new Promise(resolve => {
+ var numSearchesStarted = 0;
+ input.onSearchBegin = function() {
+ numSearchesStarted++;
+ do_check_eq(numSearchesStarted, 1);
+ };
- input.onSearchComplete = function() {
- do_check_eq(numSearchesStarted, 1);
- do_check_eq(controller.searchStatus,
- Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
+ input.onSearchComplete = function() {
+ do_check_eq(numSearchesStarted, 1);
+ do_check_eq(controller.searchStatus,
+ Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
- // test that we found the entry we added
- do_check_eq(controller.matchCount, 1);
+ // test that we found the entry we added
+ do_check_eq(controller.matchCount, 1);
- // Make sure the url is the same according to spec, so it can be deleted
- do_check_eq(controller.getValueAt(0), url.spec);
+ // Make sure the url is the same according to spec, so it can be deleted
+ do_check_eq(controller.getValueAt(0), url.spec);
- do_test_finished();
- };
+ resolve();
+ };
- controller.startSearch(searchTerm);
-}
+ controller.startSearch(searchTerm);
+ });
+});
--- a/toolkit/components/places/tests/unit/test_415460.js
+++ b/toolkit/components/places/tests/unit/test_415460.js
@@ -23,18 +23,14 @@ function search_has_result(aTerms) {
var result = hs.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
var cc = root.childCount;
root.containerOpen = false;
return (cc == 1);
}
-function run_test() {
- run_next_test();
-}
-
add_task(async function test_execute() {
const SEARCH_TERM = "ユニコード";
const TEST_URL = "http://example.com/" + SEARCH_TERM + "/";
await PlacesTestUtils.addVisits(uri(TEST_URL));
do_check_true(search_has_result(SEARCH_TERM));
});
--- a/toolkit/components/places/tests/unit/test_415757.js
+++ b/toolkit/components/places/tests/unit/test_415757.js
@@ -23,20 +23,16 @@ function uri_in_db(aURI) {
var cc = root.childCount;
root.containerOpen = false;
return (cc == 1);
}
const TOTAL_SITES = 20;
// main
-function run_test() {
- run_next_test();
-}
-
add_task(async function test_execute() {
// add pages to global history
for (let i = 0; i < TOTAL_SITES; i++) {
let site = "http://www.test-" + i + ".com/";
let testURI = uri(site);
let when = Date.now() * 1000 + (i * TOTAL_SITES);
await PlacesTestUtils.addVisits({ uri: testURI, visitDate: when });
}
--- a/toolkit/components/places/tests/unit/test_418643_removeFolderChildren.js
+++ b/toolkit/components/places/tests/unit/test_418643_removeFolderChildren.js
@@ -3,141 +3,175 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Get services.
try {
var histSvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
- var bmSvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
- getService(Ci.nsINavBookmarksService);
var annoSvc = Cc["@mozilla.org/browser/annotation-service;1"]
.getService(Ci.nsIAnnotationService);
} catch (ex) {
do_throw("Could not get services\n");
}
var validAnnoName = "validAnno";
var validItemName = "validItem";
var deletedAnnoName = "deletedAnno";
var deletedItemName = "deletedItem";
-var bookmarkedURI = uri("http://www.mozilla.org/");
+var bookmarkedURI = "http://www.mozilla.org/";
// set lastModified to the past to prevent VM timing bugs
-var pastDate = Date.now() * 1000 - 1;
-var deletedBookmarkIds = [];
+var pastDate = new Date(Date.now() - 1000);
+var deletedBookmarkGuids = [];
// bookmarks observer
var observer = {
// cached ordered array of notified items
- _onItemRemovedItemIds: [],
- onItemRemoved(aItemId, aParentId, aIndex) {
+ _onItemRemovedItemGuids: [],
+ onItemRemoved(itemId, parentId, index, type, uri, guid, parentGuid) {
// We should first get notifications for children, then for their parent
- do_check_eq(this._onItemRemovedItemIds.indexOf(aParentId), -1);
+ Assert.equal(this._onItemRemovedItemGuids.indexOf(parentGuid), -1,
+ "should first get notifications for children, then their parents.");
// Ensure we are not wrongly removing 1 level up
- do_check_neq(aParentId, bmSvc.toolbarFolder);
+ Assert.notEqual(parentGuid, PlacesUtils.bookmarks.toolbarGuid,
+ "should not be removing from the level above");
// Removed item must be one of those we have manually deleted
- do_check_neq(deletedBookmarkIds.indexOf(aItemId), -1);
- this._onItemRemovedItemIds.push(aItemId);
+ Assert.notEqual(deletedBookmarkGuids.indexOf(guid), -1,
+ "should be one of the deleted items.");
+ this._onItemRemovedItemGuids.push(itemId);
},
- QueryInterface(aIID) {
- if (aIID.equals(Ci.nsINavBookmarkObserver) ||
- aIID.equals(Ci.nsISupports)) {
- return this;
- }
- throw Cr.NS_ERROR_NO_INTERFACE;
- }
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
};
-bmSvc.addObserver(observer);
+PlacesUtils.bookmarks.addObserver(observer);
-function add_bookmarks() {
+async function add_bookmarks() {
// This is the folder we will cleanup
- var validFolderId = bmSvc.createFolder(bmSvc.toolbarFolder,
- validItemName,
- bmSvc.DEFAULT_INDEX);
+ let validFolder = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ title: validItemName,
+ type: PlacesUtils.bookmarks.TYPE_FOLDER
+ });
+
+ let validFolderId = await PlacesUtils.promiseItemId(validFolder.guid);
+
annoSvc.setItemAnnotation(validFolderId, validAnnoName,
"annotation", 0,
annoSvc.EXPIRE_NEVER);
- bmSvc.setItemLastModified(validFolderId, pastDate);
+ await PlacesUtils.bookmarks.update({
+ guid: validFolder.guid,
+ dateAdded: pastDate,
+ lastModified: pastDate,
+ });
// This bookmark should not be deleted
- var validItemId = bmSvc.insertBookmark(bmSvc.toolbarFolder,
- bookmarkedURI,
- bmSvc.DEFAULT_INDEX,
- validItemName);
+ let bookmark = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ title: validItemName,
+ url: bookmarkedURI,
+ });
+
+ let validItemId = await PlacesUtils.promiseItemId(bookmark.guid);
annoSvc.setItemAnnotation(validItemId, validAnnoName,
"annotation", 0, annoSvc.EXPIRE_NEVER);
// The following contents should be deleted
- var deletedItemId = bmSvc.insertBookmark(validFolderId,
- bookmarkedURI,
- bmSvc.DEFAULT_INDEX,
- deletedItemName);
+ bookmark = await PlacesUtils.bookmarks.insert({
+ parentGuid: validFolder.guid,
+ title: deletedItemName,
+ url: bookmarkedURI,
+ });
+
+ let deletedItemId = await PlacesUtils.promiseItemId(bookmark.guid);
+
annoSvc.setItemAnnotation(deletedItemId, deletedAnnoName,
"annotation", 0, annoSvc.EXPIRE_NEVER);
- deletedBookmarkIds.push(deletedItemId);
+ deletedBookmarkGuids.push(bookmark.guid);
- var internalFolderId = bmSvc.createFolder(validFolderId,
- deletedItemName,
- bmSvc.DEFAULT_INDEX);
+ let internalFolder = await PlacesUtils.bookmarks.insert({
+ parentGuid: validFolder.guid,
+ title: deletedItemName,
+ type: PlacesUtils.bookmarks.TYPE_FOLDER,
+ });
+
+ let internalFolderId = await PlacesUtils.promiseItemId(internalFolder.guid);
+
annoSvc.setItemAnnotation(internalFolderId, deletedAnnoName,
"annotation", 0, annoSvc.EXPIRE_NEVER);
- deletedBookmarkIds.push(internalFolderId);
+ deletedBookmarkGuids.push(internalFolder.guid);
- deletedItemId = bmSvc.insertBookmark(internalFolderId,
- bookmarkedURI,
- bmSvc.DEFAULT_INDEX,
- deletedItemName);
+ bookmark = await PlacesUtils.bookmarks.insert({
+ parentGuid: internalFolder.guid,
+ title: deletedItemName,
+ url: bookmarkedURI,
+ });
+
+ deletedItemId = await PlacesUtils.promiseItemId(bookmark.guid);
+
annoSvc.setItemAnnotation(deletedItemId, deletedAnnoName,
"annotation", 0, annoSvc.EXPIRE_NEVER);
- deletedBookmarkIds.push(deletedItemId);
+ deletedBookmarkGuids.push(bookmark.guid);
- return validFolderId;
+ return [validFolder.guid, validFolderId];
}
-function check_bookmarks(aFolderId) {
+async function check_bookmarks(folderGuid) {
// check that we still have valid bookmarks
- var bookmarks = bmSvc.getBookmarkIdsForURI(bookmarkedURI);
- for (var i = 0; i < bookmarks.length; i++) {
- do_check_eq(bmSvc.getItemTitle(bookmarks[i]), validItemName);
- do_check_true(annoSvc.itemHasAnnotation(bookmarks[i], validAnnoName));
- }
+ let bookmarks = [];
+ await PlacesUtils.bookmarks.fetch({url: bookmarkedURI}, bookmark => bookmarks.push(bookmark));
+
+ Assert.equal(bookmarks.length, 1, "Should have the correct amount of bookmarks.");
+
+ Assert.equal(bookmarks[0].title, validItemName);
+ let id = await PlacesUtils.promiseItemId(bookmarks[0].guid);
+ Assert.ok(annoSvc.itemHasAnnotation(id, validAnnoName));
// check that folder exists and has still its annotation
- do_check_eq(bmSvc.getItemTitle(aFolderId), validItemName);
- do_check_true(annoSvc.itemHasAnnotation(aFolderId, validAnnoName));
+ let folder = await PlacesUtils.bookmarks.fetch(folderGuid);
+ Assert.equal(folder.title, validItemName, "should have the correct name");
+ let folderId = await PlacesUtils.promiseItemId(folderGuid);
+ Assert.ok(annoSvc.itemHasAnnotation(folderId, validAnnoName),
+ "should still have an annotation");
+
+ // test that lastModified got updated
+ Assert.ok(pastDate < folder.lastModified, "lastModified date should have been updated");
// check that folder is empty
var options = histSvc.getNewQueryOptions();
var query = histSvc.getNewQuery();
- query.setFolders([aFolderId], 1);
+ query.setFolders([folderId], 1);
var result = histSvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
do_check_eq(root.childCount, 0);
root.containerOpen = false;
- // test that lastModified got updated
- do_check_true(pastDate < bmSvc.getItemLastModified(aFolderId));
-
// test that all children have been deleted, we use annos for that
var deletedItems = annoSvc.getItemsWithAnnotation(deletedAnnoName);
- do_check_eq(deletedItems.length, 0);
+ Assert.equal(deletedItems.length, 0);
// test that observer has been called for (and only for) deleted items
- do_check_eq(observer._onItemRemovedItemIds.length, deletedBookmarkIds.length);
+ Assert.equal(observer._onItemRemovedItemGuids.length, deletedBookmarkGuids.length);
- // Sanity check: all roots should be intact
- do_check_eq(bmSvc.getFolderIdForItem(bmSvc.placesRoot), 0);
- do_check_eq(bmSvc.getFolderIdForItem(bmSvc.bookmarksMenuFolder), bmSvc.placesRoot);
- do_check_eq(bmSvc.getFolderIdForItem(bmSvc.tagsFolder), bmSvc.placesRoot);
- do_check_eq(bmSvc.getFolderIdForItem(bmSvc.unfiledBookmarksFolder), bmSvc.placesRoot);
- do_check_eq(bmSvc.getFolderIdForItem(bmSvc.toolbarFolder), bmSvc.placesRoot);
+ // Sanity check: all roots should be intact.
+ folder = await PlacesUtils.bookmarks.fetch(PlacesUtils.bookmarks.rootGuid);
+ Assert.equal(folder.parentGuid, undefined, "root shouldn't have a parent.");
+ folder = await PlacesUtils.bookmarks.fetch(PlacesUtils.bookmarks.menuGuid);
+ Assert.equal(folder.parentGuid, PlacesUtils.bookmarks.rootGuid,
+ "bookmarks menu should still be a child of root.");
+ folder = await PlacesUtils.bookmarks.fetch(PlacesUtils.bookmarks.tagsGuid);
+ Assert.equal(folder.parentGuid, PlacesUtils.bookmarks.rootGuid,
+ "tags folder should still be a child of root.");
+ folder = await PlacesUtils.bookmarks.fetch(PlacesUtils.bookmarks.unfiledGuid);
+ Assert.equal(folder.parentGuid, PlacesUtils.bookmarks.rootGuid,
+ "unfiled folder should still be a child of root.");
+ folder = await PlacesUtils.bookmarks.fetch(PlacesUtils.bookmarks.toolbarGuid);
+ Assert.equal(folder.parentGuid, PlacesUtils.bookmarks.rootGuid,
+ "toolbar folder should still be a child of root.");
}
-// main
-function run_test() {
- var folderId = add_bookmarks();
- bmSvc.removeFolderChildren(folderId);
- check_bookmarks(folderId);
-}
+add_task(async function test_removing_folder_children() {
+ let [folderGuid, folderId] = await add_bookmarks();
+ PlacesUtils.bookmarks.removeFolderChildren(folderId);
+ await check_bookmarks(folderGuid);
+});
--- a/toolkit/components/places/tests/unit/test_419731.js
+++ b/toolkit/components/places/tests/unit/test_419731.js
@@ -1,96 +1,123 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-function run_test() {
- let uri1 = NetUtil.newURI("http://foo.bar/");
+add_task(async function test_tag_updates() {
+ const url = "http://foo.bar/";
+ let lastModified = new Date(Date.now() - 10000);
// create 2 bookmarks
- let bookmark1id = PlacesUtils.bookmarks
- .insertBookmark(PlacesUtils.bookmarksMenuFolderId,
- uri1,
- PlacesUtils.bookmarks.DEFAULT_INDEX,
- "title 1");
- let bookmark2id = PlacesUtils.bookmarks
- .insertBookmark(PlacesUtils.toolbarFolderId,
- uri1,
- PlacesUtils.bookmarks.DEFAULT_INDEX,
- "title 2");
+ let bm1 = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.menuGuid,
+ dateAdded: lastModified,
+ lastModified: new Date(),
+ title: "title 1",
+ url,
+ });
+ let bm2 = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.menuGuid,
+ dateAdded: lastModified,
+ lastModified,
+ title: "title 2",
+ url,
+ });
+
// add a new tag
- PlacesUtils.tagging.tagURI(uri1, ["foo"]);
+ PlacesUtils.tagging.tagURI(uri(url), ["foo"]);
// get tag folder id
let options = PlacesUtils.history.getNewQueryOptions();
let query = PlacesUtils.history.getNewQuery();
query.setFolders([PlacesUtils.tagsFolderId], 1);
let result = PlacesUtils.history.executeQuery(query, options);
let tagRoot = result.root;
tagRoot.containerOpen = true;
let tagNode = tagRoot.getChild(0)
.QueryInterface(Ci.nsINavHistoryContainerResultNode);
+ let tagItemGuid = tagNode.bookmarkGuid;
let tagItemId = tagNode.itemId;
tagRoot.containerOpen = false;
// change bookmark 1 title
- PlacesUtils.bookmarks.setItemTitle(bookmark1id, "new title 1");
+ await PlacesUtils.bookmarks.update({
+ guid: bm1.guid,
+ title: "new title 1",
+ });
// Workaround timers resolution and time skews.
- let bookmark2LastMod = PlacesUtils.bookmarks.getItemLastModified(bookmark2id);
- PlacesUtils.bookmarks.setItemLastModified(bookmark1id, bookmark2LastMod + 1000);
+ bm2 = await PlacesUtils.bookmarks.fetch(bm2.guid);
+
+ lastModified = new Date(lastModified.getTime() + 1000);
+
+ await PlacesUtils.bookmarks.update({
+ guid: bm1.guid,
+ lastModified,
+ });
// Query the tag.
options = PlacesUtils.history.getNewQueryOptions();
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
options.resultType = options.RESULTS_AS_TAG_QUERY;
query = PlacesUtils.history.getNewQuery();
result = PlacesUtils.history.executeQuery(query, options);
let root = result.root;
root.containerOpen = true;
do_check_eq(root.childCount, 1);
let theTag = root.getChild(0)
.QueryInterface(Ci.nsINavHistoryContainerResultNode);
// Bug 524219: Check that renaming the tag shows up in the result.
- do_check_eq(theTag.title, "foo")
- PlacesUtils.bookmarks.setItemTitle(tagItemId, "bar");
+ do_check_eq(theTag.title, "foo");
+
+ await PlacesUtils.bookmarks.update({
+ guid: tagItemGuid,
+ title: "bar",
+ });
// Check that the item has been replaced
do_check_neq(theTag, root.getChild(0));
theTag = root.getChild(0)
.QueryInterface(Ci.nsINavHistoryContainerResultNode);
do_check_eq(theTag.title, "bar");
// Check that tag container contains new title
theTag.containerOpen = true;
do_check_eq(theTag.childCount, 1);
let node = theTag.getChild(0);
do_check_eq(node.title, "new title 1");
theTag.containerOpen = false;
root.containerOpen = false;
// Change bookmark 2 title.
- PlacesUtils.bookmarks.setItemTitle(bookmark2id, "new title 2");
+ PlacesUtils.bookmarks.update({
+ guid: bm2.guid,
+ title: "new title 2"
+ });
// Workaround timers resolution and time skews.
- let bookmark1LastMod = PlacesUtils.bookmarks.getItemLastModified(bookmark1id);
- PlacesUtils.bookmarks.setItemLastModified(bookmark2id, bookmark1LastMod + 1000);
+ lastModified = new Date(lastModified.getTime() + 1000);
+
+ await PlacesUtils.bookmarks.update({
+ guid: bm2.guid,
+ lastModified,
+ });
// Check that tag container contains new title
options = PlacesUtils.history.getNewQueryOptions();
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
options.resultType = options.RESULTS_AS_TAG_CONTENTS;
query = PlacesUtils.history.getNewQuery();
query.setFolders([tagItemId], 1);
result = PlacesUtils.history.executeQuery(query, options);
root = result.root;
root.containerOpen = true;
do_check_eq(root.childCount, 1);
node = root.getChild(0);
do_check_eq(node.title, "new title 2");
root.containerOpen = false;
-}
+});
--- a/toolkit/components/places/tests/unit/test_419792_node_tags_property.js
+++ b/toolkit/components/places/tests/unit/test_419792_node_tags_property.js
@@ -2,38 +2,39 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// get services
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
-var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
- getService(Ci.nsINavBookmarksService);
var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].
getService(Ci.nsITaggingService);
-function run_test() {
+add_task(async function test_query_node_tags_property() {
// get toolbar node
var options = histsvc.getNewQueryOptions();
var query = histsvc.getNewQuery();
- query.setFolders([bmsvc.toolbarFolder], 1);
+ query.setFolders([PlacesUtils.toolbarFolderId], 1);
var result = histsvc.executeQuery(query, options);
var toolbarNode = result.root;
toolbarNode.containerOpen = true;
// add a bookmark
var bookmarkURI = uri("http://foo.com");
- var bookmarkId = bmsvc.insertBookmark(bmsvc.toolbarFolder, bookmarkURI,
- bmsvc.DEFAULT_INDEX, "");
+ let bookmark = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ title: "",
+ url: bookmarkURI,
+ });
// get the node for the new bookmark
var node = toolbarNode.getChild(toolbarNode.childCount - 1);
- do_check_eq(node.itemId, bookmarkId);
+ do_check_eq(node.bookmarkGuid, bookmark.guid);
// confirm there's no tags via the .tags property
do_check_eq(node.tags, null);
// add a tag
tagssvc.tagURI(bookmarkURI, ["foo"]);
do_check_eq(node.tags, "foo");
@@ -41,9 +42,9 @@ function run_test() {
tagssvc.tagURI(bookmarkURI, ["bar"]);
do_check_eq(node.tags, "bar, foo");
// remove the tags, confirming the property is cleared
tagssvc.untagURI(bookmarkURI, null);
do_check_eq(node.tags, null);
toolbarNode.containerOpen = false;
-}
+});
--- a/toolkit/components/places/tests/unit/test_425563.js
+++ b/toolkit/components/places/tests/unit/test_425563.js
@@ -1,18 +1,14 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-function run_test() {
- run_next_test();
-}
-
add_task(async function test_execute() {
let count_visited_URIs = ["http://www.test-link.com/",
"http://www.test-typed.com/",
"http://www.test-bookmark.com/",
"http://www.test-redirect-permanent.com/",
"http://www.test-redirect-temporary.com/"];
let notcount_visited_URIs = ["http://www.test-embed.com/",
--- a/toolkit/components/places/tests/unit/test_429505_remove_shortcuts.js
+++ b/toolkit/components/places/tests/unit/test_429505_remove_shortcuts.js
@@ -9,27 +9,35 @@
- add a folder
- add a folder-shortcut to the new folder
- query for the shortcut
- remove the folder-shortcut
- confirm the shortcut is removed from the query results
*/
-function run_test() {
- const IDX = PlacesUtils.bookmarks.DEFAULT_INDEX;
- var folderId =
- PlacesUtils.bookmarks.createFolder(PlacesUtils.toolbarFolderId, "", IDX);
+add_task(async function test_query_with_remove_shortcut() {
+ let folder = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ title: "",
+ type: PlacesUtils.bookmarks.TYPE_FOLDER,
+ });
- var queryId =
- PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId,
- uri("place:folder=" + folderId), IDX, "");
+ let folderId = await PlacesUtils.promiseItemId(folder.guid);
- var root = PlacesUtils.getFolderContents(PlacesUtils.toolbarFolderId, false, true).root;
+ let query = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ title: "",
+ url: `place:folder=${folderId}`,
+ });
- var oldCount = root.childCount;
+ var root = PlacesUtils.getFolderContents(PlacesUtils.toolbarFolderId, false, true).root;
- PlacesUtils.bookmarks.removeItem(queryId);
+ var oldCount = root.childCount;
+
+ await PlacesUtils.bookmarks.remove(query.guid);
- do_check_eq(root.childCount, oldCount - 1);
+ do_check_eq(root.childCount, oldCount - 1);
- root.containerOpen = false;
-}
+ root.containerOpen = false;
+
+ await PlacesTestUtils.promiseAsyncUpdates();
+});
--- a/toolkit/components/places/tests/unit/test_433317_query_title_update.js
+++ b/toolkit/components/places/tests/unit/test_433317_query_title_update.js
@@ -1,38 +1,42 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-function run_test() {
+add_task(async function test_query_title_update() {
try {
- var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
- getService(Ci.nsINavHistoryService);
- var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
- getService(Ci.nsINavBookmarksService);
+ var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
+ getService(Ci.nsINavHistoryService);
} catch (ex) {
do_throw("Unable to initialize Places services");
}
// create a query bookmark
- var queryId = bmsvc.insertBookmark(bmsvc.toolbarFolder, uri("place:"),
- 0 /* first item */, "test query");
+ let bmQuery = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ title: "test query",
+ url: "place:",
+ });
// query for that query
var options = histsvc.getNewQueryOptions();
- var query = histsvc.getNewQuery();
- query.setFolders([bmsvc.toolbarFolder], 1);
+ let query = histsvc.getNewQuery();
+ query.setFolders([PlacesUtils.toolbarFolderId], 1);
var result = histsvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
var queryNode = root.getChild(0);
do_check_eq(queryNode.title, "test query");
// change the title
- bmsvc.setItemTitle(queryId, "foo");
+ await PlacesUtils.bookmarks.update({
+ guid: bmQuery.guid,
+ title: "foo",
+ });
// confirm the node was updated
do_check_eq(queryNode.title, "foo");
root.containerOpen = false;
-}
+});
--- a/toolkit/components/places/tests/unit/test_433525_hasChildren_crash.js
+++ b/toolkit/components/places/tests/unit/test_433525_hasChildren_crash.js
@@ -1,24 +1,18 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-function run_test() {
- run_next_test();
-}
-
add_task(async function test_execute() {
try {
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
- var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
- getService(Ci.nsINavBookmarksService);
} catch (ex) {
do_throw("Unable to initialize Places services");
}
// add a visit
var testURI = uri("http://test");
await PlacesTestUtils.addVisits(testURI);
@@ -31,23 +25,26 @@ add_task(async function test_execute() {
var result = histsvc.executeQuery(query, options);
var root = result.root;
// check hasChildren while the container is closed
do_check_eq(root.hasChildren, true);
// now check via the saved search path
var queryURI = histsvc.queriesToQueryString([query], 1, options);
- bmsvc.insertBookmark(bmsvc.toolbarFolder, uri(queryURI),
- 0 /* first item */, "test query");
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ title: "test query",
+ url: queryURI,
+ });
// query for that query
options = histsvc.getNewQueryOptions();
query = histsvc.getNewQuery();
- query.setFolders([bmsvc.toolbarFolder], 1);
+ query.setFolders([PlacesUtils.toolbarFolderId], 1);
result = histsvc.executeQuery(query, options);
root = result.root;
root.containerOpen = true;
var queryNode = root.getChild(0);
do_check_eq(queryNode.title, "test query");
queryNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
do_check_eq(queryNode.hasChildren, true);
root.containerOpen = false;
--- a/toolkit/components/places/tests/unit/test_452777.js
+++ b/toolkit/components/places/tests/unit/test_452777.js
@@ -4,31 +4,40 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* This test ensures that when removing a folder within a transaction, undoing
* the transaction restores it with the same id (as received by the observers).
*/
-var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
- getService(Ci.nsINavBookmarksService);
-
-function run_test() {
+add_task(async function test_undo_folder_remove_within_transaction() {
const TITLE = "test folder";
// Create two test folders; remove the first one. This ensures that undoing
// the removal will not get the same id by chance (the insert id's can be
// reused in SQLite).
- let id = bs.createFolder(bs.placesRoot, TITLE, -1);
- bs.createFolder(bs.placesRoot, "test folder 2", -1);
- let transaction = bs.getRemoveFolderTransaction(id);
+ let folder = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ title: TITLE,
+ type: PlacesUtils.bookmarks.TYPE_FOLDER,
+ });
+
+ let id = await PlacesUtils.promiseItemId(folder.guid);
+
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ title: "test folder 2",
+ type: PlacesUtils.bookmarks.TYPE_FOLDER,
+ });
+
+ let transaction = PlacesUtils.bookmarks.getRemoveFolderTransaction(id);
transaction.doTransaction();
// Now check to make sure it gets added with the right id
- bs.addObserver({
+ PlacesUtils.bookmarks.addObserver({
onItemAdded(aItemId, aFolder, aIndex, aItemType, aURI, aTitle) {
do_check_eq(aItemId, id);
do_check_eq(aTitle, TITLE);
}
});
transaction.undoTransaction();
-}
+});
--- a/toolkit/components/places/tests/unit/test_adaptive.js
+++ b/toolkit/components/places/tests/unit/test_adaptive.js
@@ -126,20 +126,21 @@ async function task_setCountRank(aURI, a
// Bump up the instrumentation feedback.
for (let i = 0; i < aRank; i++) {
Services.obs.notifyObservers(thing, "autocomplete-will-enter-text");
}
// If this is supposed to be a bookmark, add it.
if (aBookmark) {
- PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
- aURI,
- PlacesUtils.bookmarks.DEFAULT_INDEX,
- "test_book");
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ title: "test_book",
+ url: aURI,
+ });
// And add the tag if we need to.
if (aBookmark == "tag") {
PlacesUtils.tagging.tagURI(aURI, ["test_tag"]);
}
}
}
--- a/toolkit/components/places/tests/unit/test_adaptive_bug527311.js
+++ b/toolkit/components/places/tests/unit/test_adaptive_bug527311.js
@@ -5,18 +5,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const TEST_URL = "http://adapt.mozilla.org/";
const SEARCH_STRING = "adapt";
const SUGGEST_TYPES = ["history", "bookmark", "openpage"];
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
- getService(Ci.nsINavBookmarksService);
var os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
var ps = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
const PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC =
"places-autocomplete-feedback-updated";
@@ -72,68 +70,78 @@ AutoCompleteInput.prototype = {
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
}
}
function check_results() {
- let controller = Cc["@mozilla.org/autocomplete/controller;1"].
- getService(Ci.nsIAutoCompleteController);
- let input = new AutoCompleteInput(["unifiedcomplete"]);
- controller.input = input;
+ return new Promise(resolve => {
+ let controller = Cc["@mozilla.org/autocomplete/controller;1"].
+ getService(Ci.nsIAutoCompleteController);
+ let input = new AutoCompleteInput(["unifiedcomplete"]);
+ controller.input = input;
- input.onSearchComplete = function() {
- do_check_eq(controller.searchStatus,
- Ci.nsIAutoCompleteController.STATUS_COMPLETE_NO_MATCH);
- do_check_eq(controller.matchCount, 0);
+ input.onSearchComplete = function() {
+ do_check_eq(controller.searchStatus,
+ Ci.nsIAutoCompleteController.STATUS_COMPLETE_NO_MATCH);
+ do_check_eq(controller.matchCount, 0);
- PlacesUtils.bookmarks.eraseEverything().then(() => {
- cleanup();
- do_test_finished();
- });
- };
+ PlacesUtils.bookmarks.eraseEverything().then(() => {
+ cleanup();
+ resolve();
+ });
+ };
- controller.startSearch(SEARCH_STRING);
+ controller.startSearch(SEARCH_STRING);
+ });
}
-function addAdaptiveFeedback(aUrl, aSearch, aCallback) {
- let observer = {
- observe(aSubject, aTopic, aData) {
- os.removeObserver(observer, PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC);
- do_timeout(0, aCallback);
- }
- };
- os.addObserver(observer, PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC);
+function addAdaptiveFeedback(aUrl, aSearch) {
+ return new Promise(resolve => {
+ let observer = {
+ observe(aSubject, aTopic, aData) {
+ os.removeObserver(observer, PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC);
+ do_timeout(0, resolve);
+ }
+ };
+ os.addObserver(observer, PLACES_AUTOCOMPLETE_FEEDBACK_UPDATED_TOPIC);
- let thing = {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput,
- Ci.nsIAutoCompletePopup,
- Ci.nsIAutoCompleteController]),
- get popup() { return thing; },
- get controller() { return thing; },
- popupOpen: true,
- selectedIndex: 0,
- getValueAt: () => aUrl,
- searchString: aSearch
- };
+ let thing = {
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput,
+ Ci.nsIAutoCompletePopup,
+ Ci.nsIAutoCompleteController]),
+ get popup() { return thing; },
+ get controller() { return thing; },
+ popupOpen: true,
+ selectedIndex: 0,
+ getValueAt: () => aUrl,
+ searchString: aSearch
+ };
- os.notifyObservers(thing, "autocomplete-will-enter-text");
+ os.notifyObservers(thing, "autocomplete-will-enter-text");
+ });
}
-function run_test() {
- do_test_pending();
+add_task(async function test_adaptive_search_specific() {
+ // Add a bookmark to our url.
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ title: "test_book",
+ url: TEST_URL,
+ });
- // Add a bookmark to our url.
- bs.insertBookmark(bs.unfiledBookmarksFolder, uri(TEST_URL),
- bs.DEFAULT_INDEX, "test_book");
// We want to search only history.
for (let type of SUGGEST_TYPES) {
type == "history" ? ps.setBoolPref("browser.urlbar.suggest." + type, true)
: ps.setBoolPref("browser.urlbar.suggest." + type, false);
}
// Add an adaptive entry.
- addAdaptiveFeedback(TEST_URL, SEARCH_STRING, check_results);
-}
+ await addAdaptiveFeedback(TEST_URL, SEARCH_STRING);
+
+ await check_results();
+
+ await PlacesTestUtils.promiseAsyncUpdates();
+});
--- a/toolkit/components/places/tests/unit/test_annotations.js
+++ b/toolkit/components/places/tests/unit/test_annotations.js
@@ -1,21 +1,14 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-// Get bookmark service
-try {
- var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
-} catch (ex) {
- do_throw("Could not get nav-bookmarks-service\n");
-}
-
// Get annotation service
try {
var annosvc = Cc["@mozilla.org/browser/annotation-service;1"].getService(Ci.nsIAnnotationService);
} catch (ex) {
do_throw("Could not get annotation service\n");
}
var annoObserver = {
@@ -44,55 +37,64 @@ var annoObserver = {
ITEM_lastRemoved_Id: -1,
ITEM_lastRemoved_AnnoName: "",
onItemAnnotationRemoved(aItemId, aName) {
this.ITEM_lastRemoved_Id = aItemId;
this.ITEM_lastRemoved_AnnoName = aName;
}
};
-// main
-function run_test() {
- run_next_test();
-}
-
add_task(async function test_execute() {
- var testURI = uri("http://mozilla.com/");
- var testItemId = bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, testURI, -1, "");
- var testAnnoName = "moz-test-places/annotations";
- var testAnnoVal = "test";
+ let testURI = uri("http://mozilla.com/");
+ let testItem = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.menuGuid,
+ title: "",
+ url: testURI,
+ });
+ let testItemId = await PlacesUtils.promiseItemId(testItem.guid);
+ let testAnnoName = "moz-test-places/annotations";
+ let testAnnoVal = "test";
+ let earlierDate = new Date(Date.now() - 1000);
annosvc.addObserver(annoObserver);
// create new string annotation
try {
annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, 0);
} catch (ex) {
do_throw("unable to add page-annotation");
}
do_check_eq(annoObserver.PAGE_lastSet_URI, testURI.spec);
do_check_eq(annoObserver.PAGE_lastSet_AnnoName, testAnnoName);
// get string annotation
do_check_true(annosvc.pageHasAnnotation(testURI, testAnnoName));
var storedAnnoVal = annosvc.getPageAnnotation(testURI, testAnnoName);
do_check_true(testAnnoVal === storedAnnoVal);
// string item-annotation
+ let item = await PlacesUtils.bookmarks.fetch(testItem.guid);
+
+ // Verify that lastModified equals dateAdded before we set the annotation.
+ do_check_eq(item.lastModified.getTime(), item.dateAdded.getTime());
+ // Workaround possible VM timers issues moving last modified to the past.
+ await PlacesUtils.bookmarks.update({
+ guid: item.guid,
+ dateAdded: earlierDate,
+ lastModified: earlierDate,
+ });
+
try {
- var lastModified = bmsvc.getItemLastModified(testItemId);
- // Verify that lastModified equals dateAdded before we set the annotation.
- do_check_eq(lastModified, bmsvc.getItemDateAdded(testItemId));
- // Workaround possible VM timers issues moving last modified to the past.
- bmsvc.setItemLastModified(testItemId, --lastModified);
annosvc.setItemAnnotation(testItemId, testAnnoName, testAnnoVal, 0, 0);
- var lastModified2 = bmsvc.getItemLastModified(testItemId);
- // verify that setting the annotation updates the last modified time
- do_check_true(lastModified2 > lastModified);
} catch (ex) {
- do_throw("unable to add item annotation");
+ do_throw("unable to add item annotation " + ex);
}
+
+ let updatedItem = await PlacesUtils.bookmarks.fetch(testItem.guid);
+
+ // verify that setting the annotation updates the last modified time
+ do_check_true(updatedItem.lastModified > item.lastModified);
do_check_eq(annoObserver.ITEM_lastSet_Id, testItemId);
do_check_eq(annoObserver.ITEM_lastSet_AnnoName, testAnnoName);
try {
var annoVal = annosvc.getItemAnnotation(testItemId, testAnnoName);
// verify the anno value
do_check_true(testAnnoVal === annoVal);
} catch (ex) {
@@ -106,17 +108,22 @@ add_task(async function test_execute() {
var pages = annosvc.getPagesWithAnnotation(testAnnoName);
do_check_eq(pages.length, 2);
// Don't rely on the order
do_check_false(pages[0].equals(pages[1]));
do_check_true(pages[0].equals(testURI) || pages[1].equals(testURI));
do_check_true(pages[0].equals(uri2) || pages[1].equals(uri2));
// test getItemsWithAnnotation
- var testItemId2 = bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, uri2, -1, "");
+ let testItem2 = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.menuGuid,
+ title: "",
+ url: uri2,
+ });
+ let testItemId2 = await PlacesUtils.promiseItemId(testItem2.guid);
annosvc.setItemAnnotation(testItemId2, testAnnoName, testAnnoVal, 0, 0);
var items = annosvc.getItemsWithAnnotation(testAnnoName);
do_check_eq(items.length, 2);
// Don't rely on the order
do_check_true(items[0] != items[1]);
do_check_true(items[0] == testItemId || items[1] == testItemId);
do_check_true(items[0] == testItemId2 || items[1] == testItemId2);
@@ -174,18 +181,28 @@ add_task(async function test_execute() {
do_check_eq(newAnnoNames.length, 2);
do_check_true(annosvc.pageHasAnnotation(newURI, "oldAnno"));
do_check_true(annosvc.pageHasAnnotation(newURI, copiedAnno));
do_check_eq(annosvc.getPageAnnotation(newURI, "oldAnno"), "new");
// copy annotations to another item
newURI = uri("http://mozilla.org");
- var newItemId = bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, newURI, -1, "");
- var itemId = bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, testURI, -1, "");
+ let newItem = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.menuGuid,
+ title: "",
+ url: newURI,
+ });
+ let newItemId = await PlacesUtils.promiseItemId(newItem.guid);
+ item = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.menuGuid,
+ title: "",
+ url: testURI,
+ });
+ var itemId = await PlacesUtils.promiseItemId(item.guid);
annosvc.setItemAnnotation(itemId, "oldAnno", "new", 0, 0);
annosvc.setItemAnnotation(itemId, "testAnno", "test", 0, 0);
annosvc.setItemAnnotation(newItemId, "oldAnno", "old", 0, 0);
annoNames = annosvc.getItemAnnotationNames(newItemId);
do_check_eq(annoNames.length, 1);
do_check_eq(annoNames[0], "oldAnno");
oldAnnoNames = annosvc.getItemAnnotationNames(itemId);
do_check_eq(oldAnnoNames.length, 2);
@@ -259,21 +276,29 @@ add_task(async function test_execute() {
storedVal = annosvc.getItemAnnotation(testItemId, doubleKey);
do_check_true(doubleVal === storedVal);
// test annotation removal
annosvc.removePageAnnotation(testURI, int32Key);
annosvc.setItemAnnotation(testItemId, testAnnoName, testAnnoVal, 0, 0);
// verify that removing an annotation updates the last modified date
- var lastModified3 = bmsvc.getItemLastModified(testItemId);
+ testItem = await PlacesUtils.bookmarks.fetch(testItem.guid);
+
+ var lastModified3 = testItem.lastModified;
// Workaround possible VM timers issues moving last modified to the past.
- bmsvc.setItemLastModified(testItemId, --lastModified3);
+ await PlacesUtils.bookmarks.update({
+ guid: testItem.guid,
+ dateAdded: earlierDate,
+ lastModified: earlierDate,
+ });
annosvc.removeItemAnnotation(testItemId, int32Key);
- var lastModified4 = bmsvc.getItemLastModified(testItemId);
+
+ testItem = await PlacesUtils.bookmarks.fetch(testItem.guid);
+ var lastModified4 = testItem.lastModified;
do_print("verify that removing an annotation updates the last modified date");
do_print("lastModified3 = " + lastModified3);
do_print("lastModified4 = " + lastModified4);
do_check_true(lastModified4 > lastModified3);
do_check_eq(annoObserver.PAGE_lastRemoved_URI, testURI.spec);
do_check_eq(annoObserver.PAGE_lastRemoved_AnnoName, int32Key);
do_check_eq(annoObserver.ITEM_lastRemoved_Id, testItemId);
@@ -289,17 +314,22 @@ add_task(async function test_execute() {
for (var id of invalidIds) {
try {
annosvc.setItemAnnotation(id, "foo", "bar", 0, 0);
do_throw("setItemAnnotation* should throw for invalid item id: " + id)
} catch (ex) { }
}
// setting an annotation with EXPIRE_HISTORY for an item should throw
- itemId = bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, testURI, -1, "");
+ item = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.menuGuid,
+ title: "",
+ url: testURI,
+ });
+ itemId = await PlacesUtils.promiseItemId(item.guid);
try {
annosvc.setItemAnnotation(itemId, "foo", "bar", 0, annosvc.EXPIRE_WITH_HISTORY);
do_throw("setting an item annotation with EXPIRE_HISTORY should throw");
} catch (ex) {
}
annosvc.removeObserver(annoObserver);
});
--- a/toolkit/components/places/tests/unit/test_asyncExecuteLegacyQueries.js
+++ b/toolkit/components/places/tests/unit/test_asyncExecuteLegacyQueries.js
@@ -1,93 +1,81 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// This is a test for asyncExecuteLegacyQueries API.
-var tests = [
-
-function test_history_query() {
- let uri = NetUtil.newURI("http://test.visit.mozilla.com/");
+add_task(async function test_history_query() {
+ let uri = "http://test.visit.mozilla.com/";
let title = "Test visit";
- PlacesTestUtils.addVisits({ uri, title }).then(function() {
- let options = PlacesUtils.history.getNewQueryOptions();
- options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING;
- let query = PlacesUtils.history.getNewQuery();
+ await PlacesTestUtils.addVisits({ uri, title });
+ let options = PlacesUtils.history.getNewQueryOptions();
+ options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING;
+ let query = PlacesUtils.history.getNewQuery();
+
+ return new Promise(resolve => {
PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
.asyncExecuteLegacyQueries([query], 1, options, {
handleResult(aResultSet) {
for (let row; (row = aResultSet.getNextRow());) {
try {
- do_check_eq(row.getResultByIndex(1), uri.spec);
+ do_check_eq(row.getResultByIndex(1), uri);
do_check_eq(row.getResultByIndex(2), title);
} catch (e) {
do_throw("Error while fetching page data.");
}
}
},
handleError(aError) {
do_throw("Async execution error (" + aError.result + "): " + aError.message);
},
handleCompletion(aReason) {
- run_next_test();
+ cleanupTest().then(resolve);
},
});
});
-},
+});
-function test_bookmarks_query() {
- let uri = NetUtil.newURI("http://test.bookmark.mozilla.com/");
+add_task(async function test_bookmarks_query() {
+ let url = "http://test.bookmark.mozilla.com/";
let title = "Test bookmark";
- bookmark(uri, title);
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ title,
+ url,
+ });
+
let options = PlacesUtils.history.getNewQueryOptions();
options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_LASMODIFIED_DESCENDING;
options.queryType = options.QUERY_TYPE_BOOKMARKS;
let query = PlacesUtils.history.getNewQuery();
- PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
- .asyncExecuteLegacyQueries([query], 1, options, {
- handleResult(aResultSet) {
- for (let row; (row = aResultSet.getNextRow());) {
- try {
- do_check_eq(row.getResultByIndex(1), uri.spec);
- do_check_eq(row.getResultByIndex(2), title);
- } catch (e) {
- do_throw("Error while fetching page data.");
+ return new Promise(resolve => {
+ PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
+ .asyncExecuteLegacyQueries([query], 1, options, {
+ handleResult(aResultSet) {
+ for (let row; (row = aResultSet.getNextRow());) {
+ try {
+ do_check_eq(row.getResultByIndex(1), url);
+ do_check_eq(row.getResultByIndex(2), title);
+ } catch (e) {
+ do_throw("Error while fetching page data.");
+ }
}
- }
- },
- handleError(aError) {
- do_throw("Async execution error (" + aError.result + "): " + aError.message);
- },
- handleCompletion(aReason) {
- run_next_test();
- },
+ },
+ handleError(aError) {
+ do_throw("Async execution error (" + aError.result + "): " + aError.message);
+ },
+ handleCompletion(aReason) {
+ cleanupTest().then(resolve);
+ },
+ });
});
-},
+});
-];
-
-function bookmark(aURI, aTitle) {
- PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
- aURI,
- PlacesUtils.bookmarks.DEFAULT_INDEX,
- aTitle);
-}
-
-function run_test() {
- do_test_pending();
- run_next_test();
-}
-
-function run_next_test() {
- if (tests.length == 0) {
- do_test_finished();
- return;
- }
-
- Promise.all([
+function cleanupTest() {
+ return Promise.all([
PlacesTestUtils.clearHistory(),
PlacesUtils.bookmarks.eraseEverything()
- ]).then(tests.shift());
+ ]);
}
--- a/toolkit/components/places/tests/unit/test_download_history.js
+++ b/toolkit/components/places/tests/unit/test_download_history.js
@@ -59,20 +59,16 @@ function waitForOnDeleteVisits(aCallback
onDeleteVisits: function HO_onDeleteVisits() {
PlacesUtils.history.removeObserver(this);
aCallback.apply(null, arguments);
}
};
PlacesUtils.history.addObserver(historyObserver);
}
-function run_test() {
- run_next_test();
-}
-
add_test(function test_dh_is_from_places() {
// Test that this nsIDownloadHistory is the one places implements.
do_check_true(gDownloadHistory instanceof Ci.mozIAsyncHistory);
run_next_test();
});
add_test(function test_dh_addRemoveDownload() {
@@ -113,35 +109,39 @@ add_test(function test_dh_addMultiRemove
});
gDownloadHistory.removeAllDownloads();
});
gDownloadHistory.addDownload(DOWNLOAD_URI, null, Date.now() * 1000);
});
});
-add_test(function test_dh_addBookmarkRemoveDownload() {
- PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
- DOWNLOAD_URI,
- PlacesUtils.bookmarks.DEFAULT_INDEX,
- "A bookmark");
- waitForOnVisit(function DHAD_onVisit(aURI) {
- do_check_true(aURI.equals(DOWNLOAD_URI));
- do_check_true(!!page_in_database(DOWNLOAD_URI));
+add_task(async function test_dh_addBookmarkRemoveDownload() {
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ url: DOWNLOAD_URI,
+ title: "A bookmark"
+ });
- waitForOnDeleteVisits(function DHRAD_onDeleteVisits(aDeletedURI) {
- do_check_true(aDeletedURI.equals(DOWNLOAD_URI));
+ await new Promise(resolve => {
+ waitForOnVisit(function DHAD_onVisit(aURI) {
+ do_check_true(aURI.equals(DOWNLOAD_URI));
do_check_true(!!page_in_database(DOWNLOAD_URI));
- PlacesTestUtils.clearHistory().then(run_next_test);
+ waitForOnDeleteVisits(function DHRAD_onDeleteVisits(aDeletedURI) {
+ do_check_true(aDeletedURI.equals(DOWNLOAD_URI));
+ do_check_true(!!page_in_database(DOWNLOAD_URI));
+
+ PlacesTestUtils.clearHistory().then(resolve);
+ });
+ gDownloadHistory.removeAllDownloads();
});
- gDownloadHistory.removeAllDownloads();
+
+ gDownloadHistory.addDownload(DOWNLOAD_URI, null, Date.now() * 1000);
});
-
- gDownloadHistory.addDownload(DOWNLOAD_URI, null, Date.now() * 1000);
});
add_test(function test_dh_addDownload_referrer() {
waitForOnVisit(function DHAD_prepareReferrer(aURI, aVisitID) {
do_check_true(aURI.equals(REFERRER_URI));
let referrerVisitId = aVisitID;
waitForOnVisit(function DHAD_onVisit(aVisitedURI, unused, unused2, unused3,
--- a/toolkit/components/places/tests/unit/test_frecency.js
+++ b/toolkit/components/places/tests/unit/test_frecency.js
@@ -109,38 +109,43 @@ async function ensure_results_internal(u
controller.startSearch(searchTerm);
await promise;
}
// Get history service
try {
var tagssvc = Cc["@mozilla.org/browser/tagging-service;1"].
getService(Ci.nsITaggingService);
- var bmksvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
- getService(Ci.nsINavBookmarksService);
} catch (ex) {
do_throw("Could not get history service\n");
}
async function task_setCountDate(aURI, aCount, aDate) {
// We need visits so that frecency can be computed over multiple visits
let visits = [];
for (let i = 0; i < aCount; i++) {
visits.push({ uri: aURI, visitDate: aDate, transition: TRANSITION_TYPED });
}
await PlacesTestUtils.addVisits(visits);
}
-function setBookmark(aURI) {
- bmksvc.insertBookmark(bmksvc.bookmarksMenuFolder, aURI, -1, "bleh");
+async function setBookmark(aURI) {
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.menuGuid,
+ url: aURI,
+ title: "bleh"
+ });
}
-function tagURI(aURI, aTags) {
- bmksvc.insertBookmark(bmksvc.unfiledBookmarksFolder, aURI,
- bmksvc.DEFAULT_INDEX, "bleh");
+async function tagURI(aURI, aTags) {
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ url: aURI,
+ title: "bleh",
+ });
tagssvc.tagURI(aURI, aTags);
}
var uri1 = uri("http://site.tld/1");
var uri2 = uri("http://site.tld/2");
var uri3 = uri("http://aaaaaaaaaa/1");
var uri4 = uri("http://aaaaaaaaaa/2");
@@ -153,112 +158,112 @@ var c1 = 10;
var c2 = 1;
var tests = [
// test things without a search term
async function() {
print("TEST-INFO | Test 0: same count, different date");
await task_setCountDate(uri1, c1, d1);
await task_setCountDate(uri2, c1, d2);
- tagURI(uri1, ["site"]);
+ await tagURI(uri1, ["site"]);
await ensure_results([uri1, uri2], "");
},
async function() {
print("TEST-INFO | Test 1: same count, different date");
await task_setCountDate(uri1, c1, d2);
await task_setCountDate(uri2, c1, d1);
- tagURI(uri1, ["site"]);
+ await tagURI(uri1, ["site"]);
await ensure_results([uri2, uri1], "");
},
async function() {
print("TEST-INFO | Test 2: different count, same date");
await task_setCountDate(uri1, c1, d1);
await task_setCountDate(uri2, c2, d1);
- tagURI(uri1, ["site"]);
+ await tagURI(uri1, ["site"]);
await ensure_results([uri1, uri2], "");
},
async function() {
print("TEST-INFO | Test 3: different count, same date");
await task_setCountDate(uri1, c2, d1);
await task_setCountDate(uri2, c1, d1);
- tagURI(uri1, ["site"]);
+ await tagURI(uri1, ["site"]);
await ensure_results([uri2, uri1], "");
},
// test things with a search term
async function() {
print("TEST-INFO | Test 4: same count, different date");
await task_setCountDate(uri1, c1, d1);
await task_setCountDate(uri2, c1, d2);
- tagURI(uri1, ["site"]);
+ await tagURI(uri1, ["site"]);
await ensure_results([uri1, uri2], "site");
},
async function() {
print("TEST-INFO | Test 5: same count, different date");
await task_setCountDate(uri1, c1, d2);
await task_setCountDate(uri2, c1, d1);
- tagURI(uri1, ["site"]);
+ await tagURI(uri1, ["site"]);
await ensure_results([uri2, uri1], "site");
},
async function() {
print("TEST-INFO | Test 6: different count, same date");
await task_setCountDate(uri1, c1, d1);
await task_setCountDate(uri2, c2, d1);
- tagURI(uri1, ["site"]);
+ await tagURI(uri1, ["site"]);
await ensure_results([uri1, uri2], "site");
},
async function() {
print("TEST-INFO | Test 7: different count, same date");
await task_setCountDate(uri1, c2, d1);
await task_setCountDate(uri2, c1, d1);
- tagURI(uri1, ["site"]);
+ await tagURI(uri1, ["site"]);
await ensure_results([uri2, uri1], "site");
},
// There are multiple tests for 8, hence the multiple functions
// Bug 426166 section
async function() {
print("TEST-INFO | Test 8.1a: same count, same date");
- setBookmark(uri3);
- setBookmark(uri4);
+ await setBookmark(uri3);
+ await setBookmark(uri4);
await ensure_results([uri4, uri3], "a");
},
async function() {
print("TEST-INFO | Test 8.1b: same count, same date");
- setBookmark(uri3);
- setBookmark(uri4);
+ await setBookmark(uri3);
+ await setBookmark(uri4);
await ensure_results([uri4, uri3], "aa");
},
async function() {
print("TEST-INFO | Test 8.2: same count, same date");
- setBookmark(uri3);
- setBookmark(uri4);
+ await setBookmark(uri3);
+ await setBookmark(uri4);
await ensure_results([uri4, uri3], "aaa");
},
async function() {
print("TEST-INFO | Test 8.3: same count, same date");
- setBookmark(uri3);
- setBookmark(uri4);
+ await setBookmark(uri3);
+ await setBookmark(uri4);
await ensure_results([uri4, uri3], "aaaa");
},
async function() {
print("TEST-INFO | Test 8.4: same count, same date");
- setBookmark(uri3);
- setBookmark(uri4);
+ await setBookmark(uri3);
+ await setBookmark(uri4);
await ensure_results([uri4, uri3], "aaa");
},
async function() {
print("TEST-INFO | Test 8.5: same count, same date");
- setBookmark(uri3);
- setBookmark(uri4);
+ await setBookmark(uri3);
+ await setBookmark(uri4);
await ensure_results([uri4, uri3], "aa");
},
async function() {
print("TEST-INFO | Test 8.6: same count, same date");
- setBookmark(uri3);
- setBookmark(uri4);
+ await setBookmark(uri3);
+ await setBookmark(uri4);
await ensure_results([uri4, uri3], "a");
}
];
add_task(async function test_frecency() {
// Disable autoFill for this test.
Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
do_register_cleanup(() => Services.prefs.clearUserPref("browser.urlbar.autoFill"));
--- a/toolkit/components/places/tests/unit/test_history_sidebar.js
+++ b/toolkit/components/places/tests/unit/test_history_sidebar.js
@@ -2,18 +2,16 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Get history service
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);
/**
* Adds a test URI visit to the database.
*
* @param aURI
* The URI to add a visit for.
* @param aTime
* Reference "now" time.
@@ -73,17 +71,17 @@ var containers = [
/* eslint-enable comma-spacing */
var visibleContainers = containers.filter(
function(aContainer) { return aContainer.visible });
/**
* Asynchronous task that fills history and checks containers' labels.
*/
-async function task_fill_history() {
+add_task(async function task_fill_history() {
print("\n\n*** TEST Fill History\n");
// We can't use "now" because our hardcoded offsets would be invalid for some
// date. So we hardcode a date.
for (let i = 0; i < containers.length; i++) {
let container = containers[i];
var testURI = uri("http://mirror" + i + ".mozilla.com/b");
await task_add_normalized_visit(testURI, nowObj.getTime(), container.offset);
testURI = uri("http://mirror" + i + ".mozilla.com/a");
@@ -116,17 +114,17 @@ async function task_fill_history() {
if (container.label)
do_check_eq(node.title, container.label);
// Check labels are not repeated.
do_check_eq(previousLabels.indexOf(node.title), -1);
previousLabels.push(node.title);
}
do_check_eq(cc, visibleContainers.length);
root.containerOpen = false;
-}
+});
/**
* Bug 485703 - Hide date containers not containing additional entries compared
* to previous ones.
*/
function check_visit(aOffset) {
var options = hs.getNewQueryOptions();
options.resultType = options.RESULTS_AS_DATE_SITE_QUERY;
@@ -160,17 +158,17 @@ function check_visit(aOffset) {
root.containerOpen = false;
}
/**
* Queries history grouped by date and site, checking containers' labels and
* children.
*/
-function test_RESULTS_AS_DATE_SITE_QUERY() {
+add_task(async function test_RESULTS_AS_DATE_SITE_QUERY() {
print("\n\n*** TEST RESULTS_AS_DATE_SITE_QUERY\n");
var options = hs.getNewQueryOptions();
options.resultType = options.RESULTS_AS_DATE_SITE_QUERY;
var query = hs.getNewQuery();
var result = hs.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
@@ -219,22 +217,22 @@ function test_RESULTS_AS_DATE_SITE_QUERY
// But URLs are now sorted by title descending
site1visit = site1.getChild(0);
do_check_eq(site1visit.uri, "http://mirror0.google.com/b");
site1.containerOpen = false;
dayNode.containerOpen = false;
root.containerOpen = false;
-}
+});
/**
* Queries history grouped by date, checking containers' labels and children.
*/
-function test_RESULTS_AS_DATE_QUERY() {
+add_task(async function test_RESULTS_AS_DATE_QUERY() {
print("\n\n*** TEST RESULTS_AS_DATE_QUERY\n");
var options = hs.getNewQueryOptions();
options.resultType = options.RESULTS_AS_DATE_QUERY;
var query = hs.getNewQuery();
var result = hs.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
@@ -275,26 +273,29 @@ function test_RESULTS_AS_DATE_QUERY() {
visit1 = dayNode.getChild(0);
do_check_eq(visit1.uri, "http://mirror0.mozilla.com/b");
visit2 = dayNode.getChild(3);
do_check_eq(visit2.uri, "http://mirror0.google.com/a");
dayNode.containerOpen = false;
root.containerOpen = false;
-}
+});
/**
* Queries history grouped by site, checking containers' labels and children.
*/
-function test_RESULTS_AS_SITE_QUERY() {
+add_task(async function test_RESULTS_AS_SITE_QUERY() {
print("\n\n*** TEST RESULTS_AS_SITE_QUERY\n");
// add a bookmark with a domain not in the set of visits in the db
- var itemId = bs.insertBookmark(bs.toolbarFolder, uri("http://foobar"),
- bs.DEFAULT_INDEX, "");
+ let bookmark = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ url: "http://foobar",
+ title: ""
+ });
var options = hs.getNewQueryOptions();
options.resultType = options.RESULTS_AS_SITE_QUERY;
options.sortingMode = options.SORT_BY_TITLE_ASCENDING;
var query = hs.getNewQuery();
var result = hs.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
@@ -340,18 +341,18 @@ function test_RESULTS_AS_SITE_QUERY() {
// But URLs are now sorted by title descending
var visit = siteNode.getChild(0);
do_check_eq(visit.uri, "http://mirror3.google.com/b");
siteNode.containerOpen = false;
root.containerOpen = false;
// Cleanup.
- bs.removeItem(itemId);
-}
+ await PlacesUtils.bookmarks.remove(bookmark.guid);
+});
/**
* Checks that queries grouped by date do liveupdate correctly.
*/
async function task_test_date_liveupdate(aResultType) {
var midnight = nowObj;
midnight.setHours(0);
midnight.setMinutes(0);
@@ -381,24 +382,26 @@ async function task_test_date_liveupdate
// container.
await task_add_normalized_visit(uri("http://www.mozilla.org/"), nowObj.getTime(), 0);
do_check_eq(root.childCount, visibleContainers.length);
last7Days.containerOpen = false;
root.containerOpen = false;
// TEST 2. Test that the query correctly updates even if it is not root.
- var itemId = bs.insertBookmark(bs.toolbarFolder,
- uri("place:type=" + aResultType),
- bs.DEFAULT_INDEX, "");
+ var bookmark = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ url: "place:type=" + aResultType,
+ title: "",
+ });
// Query toolbar and open our query container, then check again liveupdate.
options = hs.getNewQueryOptions();
query = hs.getNewQuery();
- query.setFolders([bs.toolbarFolder], 1);
+ query.setFolders([PlacesUtils.toolbarFolderId], 1);
result = hs.executeQuery(query, options);
root = result.root;
root.containerOpen = true;
do_check_eq(root.childCount, 1);
var dateContainer = root.getChild(0).QueryInterface(Ci.nsINavHistoryContainerResultNode);
dateContainer.containerOpen = true;
do_check_eq(dateContainer.childCount, visibleContainers.length);
@@ -408,34 +411,29 @@ async function task_test_date_liveupdate
// Add a visit for "Today".
await task_add_normalized_visit(uri("http://www.mozilla.org/"), nowObj.getTime(), 0);
do_check_eq(dateContainer.childCount, visibleContainers.length);
dateContainer.containerOpen = false;
root.containerOpen = false;
// Cleanup.
- bs.removeItem(itemId);
+ await PlacesUtils.bookmarks.remove(bookmark.guid);
}
function run_test() {
- run_next_test();
-}
-
-add_task(async function test_history_sidebar() {
// If we're dangerously close to a date change, just bail out.
if (nowObj.getHours() == 23 && nowObj.getMinutes() >= 50) {
return;
}
- await task_fill_history();
- test_RESULTS_AS_DATE_SITE_QUERY();
- test_RESULTS_AS_DATE_QUERY();
- test_RESULTS_AS_SITE_QUERY();
+ run_next_test();
+}
+add_task(async function test_history_sidebar() {
await task_test_date_liveupdate(Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_SITE_QUERY);
await task_test_date_liveupdate(Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_QUERY);
// The remaining views are
// RESULTS_AS_URI + SORT_BY_VISITCOUNT_DESCENDING
// -> test_399266.js
// RESULTS_AS_URI + SORT_BY_DATE_DESCENDING
// -> test_385397.js