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 // Store the page info for each uri
let gPages = []; 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 * Adds a page, and creates various properties for it depending on the
* parameters passed in. This function will also add one visit, unless * parameters passed in. This function will also add one visit, unless
@ -190,6 +193,11 @@ let gPages = [];
* visit is added. * visit is added.
*/ */
function addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aNoVisit) 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 // Add a page entry for the current uri
gPages[aURI] = [aURI, aBook != undefined ? aBook : aTitle, aTags]; 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 // Add the page and a visit if we need to
if (!aNoVisit) { if (!aNoVisit) {
let tt = aTransitionType || TRANSITION_LINK; yield promiseAddVisits({
let isRedirect = tt == TRANSITION_REDIRECT_PERMANENT || uri: uri,
tt == TRANSITION_REDIRECT_TEMPORARY; transition: aTransitionType || TRANSITION_LINK,
histsvc.addVisit(uri, gDate, null, tt, isRedirect, 0); visitDate: gDate,
setPageTitle(uri, title); title: title
});
out.push("\nwith visit"); out.push("\nwith visit");
} }
@ -254,24 +263,49 @@ function run_test() {
if (func) if (func)
func(); func();
// At this point frecency could still be updating due to latest pages updates. Task.spawn(function () {
// This is not a problem in real life, but autocomplete tests should return // Iterate over all tasks and execute them
// reliable resultsets, thus we have to wait. for (let [, [fn, args]] in Iterator(gNextTestSetupTasks)) {
promiseAsyncUpdates().then(function () ensure_results(search, expected)); 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 // Utility function to remove history pages
function removePages(aURIs) function removePages(aURIs)
{
gNextTestSetupTasks.push([do_removePages, arguments]);
}
function do_removePages(aURIs)
{ {
for each (let uri in aURIs) for each (let uri in aURIs)
histsvc.removePage(toURI(kURIs[uri])); histsvc.removePage(toURI(kURIs[uri]));
} }
// Utility function to mark pages as typed // Utility function to mark pages as typed
function markTyped(aURIs) function markTyped(aURIs, aTitle)
{ {
for each (let uri in aURIs) gNextTestSetupTasks.push([task_markTyped, arguments]);
histsvc.addVisit(toURI(kURIs[uri]), Date.now() * 1000, null,
histsvc.TRANSITION_TYPED, false, 0);
} }
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 * 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"]. var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService); getService(Ci.nsINavHistoryService);
function run_test() function run_test()
{
run_next_test();
}
add_task(function test_autocomplete_on_value_removed()
{ {
// QI to nsIAutoCompleteSimpleResultListener // QI to nsIAutoCompleteSimpleResultListener
var listener = Cc["@mozilla.org/autocomplete/search;1?name=history"]. var listener = Cc["@mozilla.org/autocomplete/search;1?name=history"].
getService(Components.interfaces.nsIAutoCompleteSimpleResultListener); getService(Components.interfaces.nsIAutoCompleteSimpleResultListener);
// add history visit // add history visit
var now = Date.now() * 1000; var testUri = uri("http://foo.mozilla.com/");
var uri = ios.newURI("http://foo.mozilla.com/", null, null); yield promiseAddVisits({
var ref = ios.newURI("http://mozilla.com/", null, null); uri: testUri,
var visit = histsvc.addVisit(uri, now, ref, 1, false, 0); referrer: uri("http://mozilla.com/")
});
// create a query object // create a query object
var query = histsvc.getNewQuery(); var query = histsvc.getNewQuery();
// create the options object we will never use // create the options object we will never use
var options = histsvc.getNewQueryOptions(); var options = histsvc.getNewQueryOptions();
// look for this uri only // look for this uri only
query.uri = uri; query.uri = testUri;
// execute // execute
var queryRes = histsvc.executeQuery(query, options); var queryRes = histsvc.executeQuery(query, options);
// open the result container // open the result container
@ -43,10 +46,9 @@ function run_test()
// dump_table("moz_places"); // dump_table("moz_places");
do_check_eq(queryRes.root.childCount, 1); do_check_eq(queryRes.root.childCount, 1);
// call the untested code path // 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 // make sure it is GONE from the DB
do_check_eq(queryRes.root.childCount, 0); do_check_eq(queryRes.root.childCount, 0);
// close the container // close the container
queryRes.root.containerOpen = false; queryRes.root.containerOpen = false;
} });

View File

@ -31,7 +31,7 @@ addPageBook(4, 0, 0); // bookmark
addPageBook(5, 0, 0); // bookmark typed addPageBook(5, 0, 0); // bookmark typed
// Set some pages as typed // Set some pages as typed
markTyped([2,3,5]); markTyped([2,3,5], 0);
// Remove pages from history to treat them as unvisited // Remove pages from history to treat them as unvisited
removePages([4,5]); 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 // visits are 0,1,2,3,5,10
removePages([4,6,7,8,9,11]); removePages([4,6,7,8,9,11]);
// Set some pages as typed // 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 // Provide for each test: description; search terms; array of gPages indices of
// pages that should match; optional function to be run before the test // pages that should match; optional function to be run before the test