Bug 776863 - Remove calls to addVisit from the "autocomplete" folder. r=mak

This commit is contained in:
Paolo Amadini 2012-12-08 20:51:07 +01:00
parent ba40458f8d
commit cb16c5c3db
4 changed files with 63 additions and 26 deletions

View File

@ -160,6 +160,9 @@ let gDate = new Date(Date.now() - 1000 * 60 * 60) * 1000;
// Store the page info for each uri
let gPages = [];
// Initialization tasks to be run before the next test
let gNextTestSetupTasks = [];
/**
* Adds a page, and creates various properties for it depending on the
* parameters passed in. This function will also add one visit, unless
@ -190,6 +193,11 @@ let gPages = [];
* visit is added.
*/
function addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aNoVisit)
{
gNextTestSetupTasks.push([task_addPageBook, arguments]);
}
function task_addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aNoVisit)
{
// Add a page entry for the current uri
gPages[aURI] = [aURI, aBook != undefined ? aBook : aTitle, aTags];
@ -203,11 +211,12 @@ function addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aNoVisit
// Add the page and a visit if we need to
if (!aNoVisit) {
let tt = aTransitionType || TRANSITION_LINK;
let isRedirect = tt == TRANSITION_REDIRECT_PERMANENT ||
tt == TRANSITION_REDIRECT_TEMPORARY;
histsvc.addVisit(uri, gDate, null, tt, isRedirect, 0);
setPageTitle(uri, title);
yield promiseAddVisits({
uri: uri,
transition: aTransitionType || TRANSITION_LINK,
visitDate: gDate,
title: title
});
out.push("\nwith visit");
}
@ -254,24 +263,49 @@ function run_test() {
if (func)
func();
// At this point frecency could still be updating due to latest pages updates.
// This is not a problem in real life, but autocomplete tests should return
// reliable resultsets, thus we have to wait.
promiseAsyncUpdates().then(function () ensure_results(search, expected));
Task.spawn(function () {
// Iterate over all tasks and execute them
for (let [, [fn, args]] in Iterator(gNextTestSetupTasks)) {
yield fn.apply(this, args);
};
// Clean up to allow tests to register more functions.
gNextTestSetupTasks = [];
// At this point frecency could still be updating due to latest pages
// updates. This is not a problem in real life, but autocomplete tests
// should return reliable resultsets, thus we have to wait.
yield promiseAsyncUpdates();
}).then(function () ensure_results(search, expected),
do_report_unexpected_exception);
}
// Utility function to remove history pages
function removePages(aURIs)
{
gNextTestSetupTasks.push([do_removePages, arguments]);
}
function do_removePages(aURIs)
{
for each (let uri in aURIs)
histsvc.removePage(toURI(kURIs[uri]));
}
// Utility function to mark pages as typed
function markTyped(aURIs)
function markTyped(aURIs, aTitle)
{
for each (let uri in aURIs)
histsvc.addVisit(toURI(kURIs[uri]), Date.now() * 1000, null,
histsvc.TRANSITION_TYPED, false, 0);
gNextTestSetupTasks.push([task_markTyped, arguments]);
}
function task_markTyped(aURIs, aTitle)
{
for (let uri of aURIs) {
yield promiseAddVisits({
uri: toURI(kURIs[uri]),
transition: TRANSITION_TYPED,
title: kTitles[aTitle]
});
}
}

View File

@ -12,29 +12,32 @@
* Bug 479089
*/
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
function run_test()
{
run_next_test();
}
add_task(function test_autocomplete_on_value_removed()
{
// QI to nsIAutoCompleteSimpleResultListener
var listener = Cc["@mozilla.org/autocomplete/search;1?name=history"].
getService(Components.interfaces.nsIAutoCompleteSimpleResultListener);
// add history visit
var now = Date.now() * 1000;
var uri = ios.newURI("http://foo.mozilla.com/", null, null);
var ref = ios.newURI("http://mozilla.com/", null, null);
var visit = histsvc.addVisit(uri, now, ref, 1, false, 0);
var testUri = uri("http://foo.mozilla.com/");
yield promiseAddVisits({
uri: testUri,
referrer: uri("http://mozilla.com/")
});
// create a query object
var query = histsvc.getNewQuery();
// create the options object we will never use
var options = histsvc.getNewQueryOptions();
// look for this uri only
query.uri = uri;
query.uri = testUri;
// execute
var queryRes = histsvc.executeQuery(query, options);
// open the result container
@ -43,10 +46,9 @@ function run_test()
// dump_table("moz_places");
do_check_eq(queryRes.root.childCount, 1);
// call the untested code path
listener.onValueRemoved(null, uri.spec, true);
listener.onValueRemoved(null, testUri.spec, true);
// make sure it is GONE from the DB
do_check_eq(queryRes.root.childCount, 0);
// close the container
queryRes.root.containerOpen = false;
}
});

View File

@ -31,7 +31,7 @@ addPageBook(4, 0, 0); // bookmark
addPageBook(5, 0, 0); // bookmark typed
// Set some pages as typed
markTyped([2,3,5]);
markTyped([2,3,5], 0);
// Remove pages from history to treat them as unvisited
removePages([4,5]);

View File

@ -52,7 +52,8 @@ addPageBook(11, 1, 1, [1]); // title and url
// visits are 0,1,2,3,5,10
removePages([4,6,7,8,9,11]);
// Set some pages as typed
markTyped([0,3,10]);
markTyped([0,10], 0);
markTyped([3], 1);
// Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test