Bug 832133 - Stop using addvisit() in toolkit cpp tests.

r=Mano
This commit is contained in:
Marco Bonardo 2013-01-25 11:16:24 +01:00
parent 252ceff4bb
commit f5c101fb07

View File

@ -24,7 +24,6 @@
#include "prinrval.h"
#include "mozilla/Attributes.h"
#define TOPIC_FRECENCY_UPDATED "places-frecency-updated"
#define WAITFORTOPIC_TIMEOUT_SECONDS 5
@ -201,30 +200,6 @@ void AsyncStatementSpinner::SpinUntilCompleted()
}
}
/**
* Adds a URI to the database.
*
* @param aURI
* The URI to add to the database.
*/
void
addURI(nsIURI* aURI)
{
nsRefPtr<WaitForTopicSpinner> spinner =
new WaitForTopicSpinner(TOPIC_FRECENCY_UPDATED);
nsCOMPtr<nsINavHistoryService> hist =
do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID);
int64_t id;
nsresult rv = hist->AddVisit(aURI, PR_Now(), nullptr,
nsINavHistoryService::TRANSITION_LINK, false,
0, &id);
do_check_success(rv);
// Wait for frecency update.
spinner->Spin();
}
struct PlaceRecord
{
int64_t id;
@ -355,6 +330,41 @@ do_get_lastVisit(int64_t placeId, VisitRecord& result)
do_check_success(rv);
}
void
do_wait_async_updates() {
nsCOMPtr<mozIStorageConnection> db = do_get_db();
nsCOMPtr<mozIStorageAsyncStatement> stmt;
db->CreateAsyncStatement(NS_LITERAL_CSTRING("BEGIN EXCLUSIVE"),
getter_AddRefs(stmt));
nsCOMPtr<mozIStoragePendingStatement> pending;
(void)stmt->ExecuteAsync(nullptr, getter_AddRefs(pending));
db->CreateAsyncStatement(NS_LITERAL_CSTRING("COMMIT"),
getter_AddRefs(stmt));
nsRefPtr<AsyncStatementSpinner> spinner = new AsyncStatementSpinner();
(void)stmt->ExecuteAsync(spinner, getter_AddRefs(pending));
spinner->SpinUntilCompleted();
}
/**
* Adds a URI to the database.
*
* @param aURI
* The URI to add to the database.
*/
void
addURI(nsIURI* aURI)
{
nsCOMPtr<mozilla::IHistory> history = do_GetService(NS_IHISTORY_CONTRACTID);
do_check_true(history);
nsresult rv = history->VisitURI(aURI, nullptr, mozilla::IHistory::TOP_LEVEL);
do_check_success(rv);
do_wait_async_updates();
}
static const char TOPIC_PROFILE_CHANGE[] = "profile-before-change";
static const char TOPIC_PLACES_CONNECTION_CLOSED[] = "places-connection-closed";