Bug 499828 - kill LAZY_ADD and use async storage instead. r=sdwilsh

This commit is contained in:
Marco Bonardo 2010-07-22 14:09:10 +02:00
Родитель 4beb474637
Коммит 34df2d1f07
14 изменённых файлов: 128 добавлений и 463 удалений

Просмотреть файл

@ -27,6 +27,9 @@ function test() {
// branch won't be called and the test will timeout,
// resulting in a failure
historyService.removeObserver(historyObserver, false);
gBrowser.removeCurrentTab();
finish();
}
},
@ -76,11 +79,6 @@ function test() {
EventUtils.sendMouseEvent({type:'click'}, 'firefox-link',
gBrowser.selectedBrowser.contentWindow);
// Give the event system enough time to do its things
setTimeout(function() {
gBrowser.removeCurrentTab();
}, 100);
// Test finishes in historyObserver.onTitleChanged() above
}

Просмотреть файл

@ -92,18 +92,25 @@
ok(snapshotsEqual(refLink, snapshotWindow(TestWindow.getWindow())),
"link should initially be blue");
// Because adding visits is async, we will not be notified imemdiately.
let visitObserver = {
observe: function(aSubject, aTopic, aData)
{
if (!testURI.equals(aSubject.QueryInterface(Ci.nsIURI))) {
return;
}
os.removeObserver(this, aTopic);
SimpleTest.executeSoon(nextTest);
},
};
os.addObserver(visitObserver, "uri-visit-saved", false);
// Load the page that the link on the previous page points to.
doPageNavigation({
uri: getHttpUrl("bug293235_p2.html"),
onNavComplete: nextTest
uri: getHttpUrl("bug293235_p2.html")
});
yield;
// Because of LAZY_ADD, we will not be notified for three seconds
// Wait for four seconds just to be safe.
setTimeout(nextTest, 4000);
yield;
// And the nodes get notified after the "link-visited" topic, so
// we need to execute soon...
SimpleTest.executeSoon(nextTest);

Просмотреть файл

@ -332,7 +332,7 @@ GetEffectivePageStep::HandleResult(mozIStorageResultSet* aResultSet)
rv = row->GetUTF8String(0, spec);
FAVICONSTEP_FAIL_IF_FALSE_RV(NS_SUCCEEDED(rv), rv);
// We always want to use the bookmark uri.
rv = mStepper->mPageURI->SetSpec(spec);
rv = NS_NewURI(getter_AddRefs(mStepper->mPageURI), spec);
FAVICONSTEP_FAIL_IF_FALSE_RV(NS_SUCCEEDED(rv), rv);
// Since we got a result, this is a bookmark.
mIsBookmarked = true;

Просмотреть файл

@ -493,24 +493,11 @@ nsFaviconService::SetAndLoadFaviconForPage(nsIURI* aPageURI,
if (mFaviconsExpirationRunning)
return NS_OK;
#ifdef LAZY_ADD
// Unfortunatly, even if DoSetAndLoadFaviconForPage is completely async,
// this method still needs to enqueue a lazy message, because in case of first
// visit to a page, the moz_places entry would not yet exists.
// So the icon has to wait for visits addition. Once visits addition will be
// async, this can go away.
nsNavHistory* historyService = nsNavHistory::GetHistoryService();
NS_ENSURE_TRUE(historyService, NS_ERROR_OUT_OF_MEMORY);
return historyService->AddLazyLoadFaviconMessage(aPageURI,
aFaviconURI,
aForceReload,
aCallback);
#else
return DoSetAndLoadFaviconForPage(aPageURI,
aFaviconURI,
aForceReload,
aCallback);
#endif
nsresult rv = DoSetAndLoadFaviconForPage(aPageURI, aFaviconURI, aForceReload,
aCallback);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}

Просмотреть файл

@ -162,17 +162,6 @@ using namespace mozilla::places;
// USECS_PER_DAY == PR_USEC_PER_SEC * 60 * 60 * 24;
static const PRInt64 USECS_PER_DAY = LL_INIT(20, 500654080);
#ifdef LAZY_ADD
// time that we'll wait before committing messages
#define LAZY_MESSAGE_TIMEOUT (3 * PR_MSEC_PER_SEC)
// the maximum number of times we'll postpone a lazy timer before committing
// See StartLazyTimer()
#define MAX_LAZY_TIMER_DEFERMENTS 2
#endif // LAZY_ADD
// character-set annotation
#define CHARSET_ANNO NS_LITERAL_CSTRING("URIProperties/characterSet")
@ -377,10 +366,6 @@ nsNavHistory::nsNavHistory()
, mCanNotify(true)
, mCacheObservers("history-observers")
{
#ifdef LAZY_ADD
mLazyTimerSet = PR_TRUE;
mLazyTimerDeferments = 0;
#endif
NS_ASSERTION(!gHistoryService,
"Attempting to create two instances of the service!");
gHistoryService = this;
@ -2036,17 +2021,6 @@ nsNavHistory::FindLastVisit(nsIURI* aURI,
PRBool nsNavHistory::IsURIStringVisited(const nsACString& aURIString)
{
#ifdef LAZY_ADD
// check the lazy list to see if this has recently been added
for (PRUint32 i = 0; i < mLazyMessages.Length(); i ++) {
if (mLazyMessages[i].type == LazyMessage::Type_AddURI) {
if (aURIString.Equals(mLazyMessages[i].uriSpec))
return PR_TRUE;
}
}
#endif
// check the main DB
mozStorageStatementScoper scoper(mDBIsPageVisited);
nsresult rv = URIBinder::Bind(mDBIsPageVisited, 0, aURIString);
NS_ENSURE_SUCCESS(rv, PR_FALSE);
@ -2640,7 +2614,6 @@ nsNavHistory::CalculateFullVisitCount(PRInt64 aPlaceId, PRInt32 *aVisitCount)
// transition type of the visit.
// Later, in AddVisitChain() the next visit to this page will be associated to
// TRANSITION_BOOKMARK.
// Note, AddVisitChain() is not called immediately if LAZY_ADD is enabled.
//
// @see MarkPageAsTyped
@ -4616,11 +4589,6 @@ nsNavHistory::RemovePages(nsIURI **aURIs, PRUint32 aLength, PRBool aDoBatchNotif
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
NS_ENSURE_ARG(aURIs);
#ifdef LAZY_ADD
// We must ensure to remove pages from the lazy messages queue too.
CommitLazyMessages();
#endif
nsresult rv;
// build a list of place ids to delete
nsCString deletePlaceIdsQueryString;
@ -4690,11 +4658,6 @@ nsNavHistory::RemovePagesFromHost(const nsACString& aHost, PRBool aEntireDomain)
{
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
#ifdef LAZY_ADD
// We must ensure to remove pages from the lazy messages queue too.
CommitLazyMessages();
#endif
nsresult rv;
// Local files don't have any host name. We don't want to delete all files in
// history when we get passed an empty string, so force to exact match
@ -4783,11 +4746,6 @@ nsNavHistory::RemovePagesByTimeframe(PRTime aBeginTime, PRTime aEndTime)
{
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
#ifdef LAZY_ADD
// We must ensure to remove pages from the lazy messages queue too.
CommitLazyMessages();
#endif
nsresult rv;
// build a list of place ids to delete
nsCString deletePlaceIdsQueryString;
@ -4859,11 +4817,6 @@ nsNavHistory::RemoveVisitsByTimeframe(PRTime aBeginTime, PRTime aEndTime)
{
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
#ifdef LAZY_ADD
// We must ensure to remove pages from the lazy messages queue too.
CommitLazyMessages();
#endif
nsresult rv;
// Build a list of place IDs whose visits fall entirely within the timespan.
@ -4956,11 +4909,6 @@ nsNavHistory::RemoveAllPages()
mozStorageTransaction transaction(mDBConn, PR_FALSE);
#ifdef LAZY_ADD
// We must ensure to remove pages from the lazy messages queue too.
CommitLazyMessages();
#endif
// reset frecency for all items that will _not_ be deleted
// Note, we set frecency to -visit_count since we use that value in our
// idle query to figure out which places to recalcuate frecency first.
@ -5034,7 +4982,6 @@ nsNavHistory::HidePage(nsIURI *aURI)
// transition type of the visit.
// Later, in AddVisitChain() the next visit to this page will be associated to
// TRANSITION_TYPED.
// Note, AddVisitChain() is not called immediately if LAZY_ADD is enabled.
//
// @see MarkPageAsFollowedBookmark
@ -5069,7 +5016,6 @@ nsNavHistory::MarkPageAsTyped(nsIURI *aURI)
// transition type of the visit.
// Later, in AddVisitChain() the next visit to this page will be associated to
// TRANSITION_FRAMED_LINK or TRANSITION_LINK.
// Note, AddVisitChain() is not called immediately if LAZY_ADD is enabled.
//
// @see MarkPageAsTyped
@ -5118,7 +5064,7 @@ nsNavHistory::RegisterOpenPage(nsIURI* aURI)
PRInt64 placeId;
// Note: If the URI has never been added to history (but can be added),
// LAZY_ADD will cause this to add an orphan page, until the visit is added.
// this could add an orphan page, until the visit is added.
rv = GetUrlIdFor(aURI, &placeId, canAdd);
NS_ENSURE_SUCCESS(rv, rv);
if (placeId == 0)
@ -5252,23 +5198,8 @@ nsNavHistory::AddURI(nsIURI *aURI, PRBool aRedirect,
PRTime now = PR_Now();
#ifdef LAZY_ADD
LazyMessage message;
rv = message.Init(LazyMessage::Type_AddURI, aURI);
NS_ENSURE_SUCCESS(rv, rv);
message.isRedirect = aRedirect;
message.isToplevel = aToplevel;
if (aReferrer) {
rv = aReferrer->Clone(getter_AddRefs(message.referrer));
NS_ENSURE_SUCCESS(rv, rv);
}
message.time = now;
rv = AddLazyMessage(message);
NS_ENSURE_SUCCESS(rv, rv);
#else
rv = AddURIInternal(aURI, now, aRedirect, aToplevel, aReferrer);
NS_ENSURE_SUCCESS(rv, rv);
#endif
return NS_OK;
}
@ -5503,22 +5434,19 @@ nsNavHistory::SetPageTitle(nsIURI* aURI,
// We don't want to set it to an empty string, but to a NULL value,
// so we use SetIsVoid and SetPageTitleInternal will take care of that
#ifdef LAZY_ADD
LazyMessage message;
nsresult rv = message.Init(LazyMessage::Type_Title, aURI);
NS_ENSURE_SUCCESS(rv, rv);
message.title = aTitle;
if (aTitle.IsEmpty())
message.title.SetIsVoid(PR_TRUE);
return AddLazyMessage(message);
#else
nsresult rv;
if (aTitle.IsEmpty()) {
// Using a void string to bind a NULL in the database.
nsString voidString;
voidString.SetIsVoid(PR_TRUE);
return SetPageTitleInternal(aURI, voidString);
rv = SetPageTitleInternal(aURI, voidString);
}
return SetPageTitleInternal(aURI, aTitle);
#endif
else {
rv = SetPageTitleInternal(aURI, aTitle);
}
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP
@ -5793,18 +5721,6 @@ nsNavHistory::Observe(nsISupports *aSubject, const char *aTopic,
if (prefService)
prefService->SavePrefFile(nsnull);
#ifdef LAZY_ADD
// Commit all pending lazy messages.
CommitLazyMessages(PR_TRUE);
// Kill lazy timer or it could fire later when statements won't be valid
// anymore.
if (mLazyTimer) {
mLazyTimer->Cancel();
mLazyTimer = 0;
}
#endif
// Finalize all statements.
nsresult rv = FinalizeInternalStatements();
NS_ENSURE_SUCCESS(rv, rv);
@ -5864,25 +5780,9 @@ nsNavHistory::Observe(nsISupports *aSubject, const char *aTopic,
else if (strcmp(aTopic, NS_PRIVATE_BROWSING_SWITCH_TOPIC) == 0) {
if (NS_LITERAL_STRING(NS_PRIVATE_BROWSING_ENTER).Equals(aData)) {
#ifdef LAZY_ADD
// Commit all lazy messages in order to protect against edge cases where a
// lazy message which is not allowed in private browsing mode has been
// added before entering the private browsing mode, and is going to be
// scheduled to be processed after entering the private browsing mode.
CommitLazyMessages();
#endif
mInPrivateBrowsing = PR_TRUE;
}
else if (NS_LITERAL_STRING(NS_PRIVATE_BROWSING_LEAVE).Equals(aData)) {
#ifdef LAZY_ADD
// Commit all lazy messages in order to protect against edge cases where a
// lazy message which should be processed in private browsing mode has been
// added before leaving the private browsing mode, and is going to be
// scheduled to be processed after leaving the private browsing mode.
CommitLazyMessages();
#endif
mInPrivateBrowsing = PR_FALSE;
}
}
@ -6058,124 +5958,6 @@ nsNavHistory::DecayFrecency()
return NS_OK;
}
// Lazy stuff ******************************************************************
#ifdef LAZY_ADD
nsresult
nsNavHistory::AddLazyLoadFaviconMessage(nsIURI* aPageURI,
nsIURI* aFaviconURI,
PRBool aForceReload,
nsIFaviconDataCallback* aCallback)
{
LazyMessage message;
nsresult rv = message.Init(LazyMessage::Type_Favicon, aPageURI);
NS_ENSURE_SUCCESS(rv, rv);
rv = aFaviconURI->Clone(getter_AddRefs(message.favicon));
NS_ENSURE_SUCCESS(rv, rv);
message.alwaysLoadFavicon = aForceReload;
message.callback = aCallback;
return AddLazyMessage(message);
}
// nsNavHistory::StartLazyTimer
//
// This schedules flushing of the lazy message queue for the future.
//
// If we already have timer set, we canel it and schedule a new timer in
// the future. This saves you from having to wait if you open a bunch of
// pages in a row. However, we don't want to defer too long, so we'll only
// push it back MAX_LAZY_TIMER_DEFERMENTS times. After that we always
// let the timer go the next time.
nsresult
nsNavHistory::StartLazyTimer()
{
if (! mLazyTimer) {
mLazyTimer = do_CreateInstance("@mozilla.org/timer;1");
if (! mLazyTimer)
return NS_ERROR_OUT_OF_MEMORY;
} else {
if (mLazyTimerSet) {
if (mLazyTimerDeferments >= MAX_LAZY_TIMER_DEFERMENTS) {
// already set and we don't want to push it back any later, use that one
return NS_OK;
} else {
// push back the active timer
mLazyTimer->Cancel();
mLazyTimerDeferments ++;
}
}
}
nsresult rv = mLazyTimer->InitWithFuncCallback(LazyTimerCallback, this,
LAZY_MESSAGE_TIMEOUT,
nsITimer::TYPE_ONE_SHOT);
NS_ENSURE_SUCCESS(rv, rv);
mLazyTimerSet = PR_TRUE;
return NS_OK;
}
// nsNavHistory::AddLazyMessage
nsresult
nsNavHistory::AddLazyMessage(const LazyMessage& aMessage)
{
if (! mLazyMessages.AppendElement(aMessage))
return NS_ERROR_OUT_OF_MEMORY;
return StartLazyTimer();
}
// nsNavHistory::LazyTimerCallback
void // static
nsNavHistory::LazyTimerCallback(nsITimer* aTimer, void* aClosure)
{
nsNavHistory* that = static_cast<nsNavHistory*>(aClosure);
that->mLazyTimerSet = PR_FALSE;
that->mLazyTimerDeferments = 0;
that->CommitLazyMessages();
}
// nsNavHistory::CommitLazyMessages
void
nsNavHistory::CommitLazyMessages(PRBool aIsShutdown)
{
mozStorageTransaction transaction(mDBConn, PR_TRUE);
for (PRUint32 i = 0; i < mLazyMessages.Length(); i ++) {
LazyMessage& message = mLazyMessages[i];
switch (message.type) {
case LazyMessage::Type_AddURI:
AddURIInternal(message.uri, message.time, message.isRedirect,
message.isToplevel, message.referrer);
break;
case LazyMessage::Type_Title:
SetPageTitleInternal(message.uri, message.title);
break;
case LazyMessage::Type_Favicon: {
// Favicons cannot use async channels after shutdown.
if (aIsShutdown)
continue;
nsFaviconService* faviconService = nsFaviconService::GetFaviconService();
if (faviconService) {
faviconService->DoSetAndLoadFaviconForPage(message.uri,
message.favicon,
message.alwaysLoadFavicon,
message.callback);
}
break;
}
default:
NS_NOTREACHED("Invalid lazy message type");
}
}
mLazyMessages.Clear();
}
#endif // LAZY_ADD
// Query stuff *****************************************************************

Просмотреть файл

@ -70,9 +70,6 @@
#include "mozilla/storage.h"
// define to enable lazy link adding
#define LAZY_ADD
#define QUERYUPDATE_TIME 0
#define QUERYUPDATE_SIMPLE 1
#define QUERYUPDATE_COMPLEX 2
@ -193,17 +190,6 @@ public:
return gHistoryService;
}
#ifdef LAZY_ADD
/**
* Adds a lazy message for adding a favicon. Used by the favicon service so
* that favicons are handled lazily just like page adds.
*/
nsresult AddLazyLoadFaviconMessage(nsIURI* aPageURI,
nsIURI* aFaviconURI,
PRBool aForceReload,
nsIFaviconDataCallback* aCallback);
#endif
/**
* Returns the database ID for the given URI, or 0 if not found and autoCreate
* is false.
@ -620,59 +606,6 @@ protected:
*/
static void expireNowTimerCallback(nsITimer* aTimer, void* aClosure);
#ifdef LAZY_ADD
// lazy add committing
struct LazyMessage {
enum MessageType { Type_Invalid, Type_AddURI, Type_Title, Type_Favicon };
LazyMessage()
{
type = Type_Invalid;
isRedirect = PR_FALSE;
isToplevel = PR_FALSE;
time = 0;
alwaysLoadFavicon = PR_FALSE;
}
// call this with common parms to initialize. Caller is responsible for
// setting other elements manually depending on type.
nsresult Init(MessageType aType, nsIURI* aURI)
{
NS_ENSURE_ARG_POINTER(aURI);
type = aType;
nsresult rv = aURI->Clone(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv);
return uri->GetSpec(uriSpec);
}
// common elements
MessageType type;
nsCOMPtr<nsIURI> uri;
nsCString uriSpec; // stringified version of URI, for quick isVisited
// valid when type == Type_AddURI
nsCOMPtr<nsIURI> referrer;
PRBool isRedirect;
PRBool isToplevel;
PRTime time;
// valid when type == Type_Title
nsString title;
// valid when type == LAZY_FAVICON
nsCOMPtr<nsIURI> favicon;
PRBool alwaysLoadFavicon;
nsCOMPtr<nsIFaviconDataCallback> callback;
};
nsTArray<LazyMessage> mLazyMessages;
nsCOMPtr<nsITimer> mLazyTimer;
PRBool mLazyTimerSet;
PRUint32 mLazyTimerDeferments; // see StartLazyTimer
nsresult StartLazyTimer();
nsresult AddLazyMessage(const LazyMessage& aMessage);
static void LazyTimerCallback(nsITimer* aTimer, void* aClosure);
void CommitLazyMessages(PRBool aIsShutdown = PR_FALSE);
#endif
nsresult ConstructQueryString(const nsCOMArray<nsNavHistoryQuery>& aQueries,
nsNavHistoryQueryOptions* aOptions,
nsCString& queryString,

Просмотреть файл

@ -38,10 +38,10 @@
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
gBrowser.selectedTab = gBrowser.addTab();
function test() {
// Due to LAZY_ADD this is an async test.
waitForExplicitFinish();
const LAZY_ADD_TIMER = 3000;
var URIs = [
"http://example.com/tests/toolkit/components/places/tests/browser/399606-window.location.href.html",
@ -77,14 +77,30 @@ function test() {
};
hs.addObserver(historyObserver, false);
/**
* Clears history invoking callback when done.
*/
function waitForClearHistory(aCallback)
{
let observer = {
observe: function(aSubject, aTopic, aData)
{
Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
aCallback(aSubject, aTopic, aData);
}
};
Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
PlacesUtils.bhistory.removeAllPages();
}
function confirm_results() {
gBrowser.removeCurrentTab();
hs.removeObserver(historyObserver, false);
for (let aURI in historyObserver.visitCount) {
is(historyObserver.visitCount[aURI], 1,
"onVisit has been received right number of times for " + aURI);
}
hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
finish();
waitForClearHistory(finish);
}
var loadCount = 0;
@ -107,7 +123,7 @@ function test() {
content.location.href = uri;
}
else {
setTimeout(confirm_results, LAZY_ADD_TIMER * 2.5);
confirm_results();
}
}
executeSoon(check_next_uri);

Просмотреть файл

@ -287,8 +287,7 @@ function check_no_bookmarks() {
/**
* Sets title synchronously for a page in moz_places synchronously.
* History.SetPageTitle uses LAZY_ADD so we can't rely on it.
* Sets title synchronously for a page in moz_places.
*
* @param aURI
* An nsIURI to set the title for.
@ -296,37 +295,10 @@ function check_no_bookmarks() {
* The title to set the page to.
* @throws if the page is not found in the database.
*
* @note this function only exists because we have no API to do this. It should
* be added in bug 421897.
* @note This is just a test compatibility mock.
*/
function setPageTitle(aURI, aTitle) {
// Check that the page exists.
let stmt = DBConn().createStatement(
"SELECT id FROM moz_places_view WHERE url = :url"
);
stmt.params.url = aURI.spec;
try {
if (!stmt.executeStep()) {
do_throw("Unable to find page " + aURI.spec);
return;
}
}
finally {
stmt.finalize();
}
// Update the title
stmt = DBConn().createStatement(
"UPDATE moz_places_view SET title = :title WHERE url = :url"
);
stmt.params.title = aTitle;
stmt.params.url = aURI.spec;
try {
stmt.execute();
}
finally {
stmt.finalize();
}
PlacesUtils.history.setPageTitle(aURI, aTitle);
}

Просмотреть файл

@ -156,13 +156,6 @@ function checkDB(data){
var referrer = this.mChannel.QueryInterface(Ci.nsIHttpChannel).referrer;
ghist.addURI(this.mChannel.URI, true, true, referrer);
// We have to wait since we use lazy_add, lazy_timer is 3s
setTimeout("checkDBOnTimeout()", 4000);
}
function checkDBOnTimeout() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
// Get all pages visited from the original typed one
var sql = "SELECT url FROM moz_historyvisits_view " +
"JOIN moz_places_view h ON h.id = place_id " +

Просмотреть файл

@ -19,12 +19,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=461710
/** Test for Bug 461710 **/
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
SimpleTest.waitForExplicitFinish();
const Ci = Components.interfaces;
const Cc = Components.classes;
const Cr = Components.results;
Components.utils.import("resource://gre/modules/NetUtil.jsm");
const LAZY_ADD_TIMER = 3000;
Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
var gIframe = document.getElementById("iframe");
/**
* Helper function which waits until another function returns true, and
@ -68,13 +72,12 @@ var subtests = [
"link_page-3.html" // 4
];
var testNum = 0;
function loadNextTest() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
// run the initialization code for each test
switch (++ testNum) {
switch (++testNum) {
case 1:
// nothing to do here
break;
@ -97,19 +100,18 @@ function loadNextTest() {
ok(false, "Unexpected call to loadNextTest for test #" + testNum);
}
if (testNum == 1) {
// Because of LAZY_ADD, the page won't be marked as visited until three seconds,
// so wait for four seconds to be safe
setTimeout(handleLoad, LAZY_ADD_TIMER * 2);
} else {
if (testNum == 1)
observer.expectURL(prefix + subtests[0], "uri-visit-saved");
else
observer.expectURL(prefix + subtests[0]);
waitForTrue(function() observer.resolved, function() {
// And the nodes get notified after the "link-visited" topic, so
// we need to execute soon...
SimpleTest.executeSoon(handleLoad);
});
}
iframe.src = prefix + subtests[testNum-1];
waitForTrue(function() observer.resolved, function() {
// And the nodes get notified after the "link-visited" topic, so
// we need to execute soon...
SimpleTest.executeSoon(handleLoad);
});
gIframe.src = prefix + subtests[testNum-1];
}
function getColor(doc, win, id) {
@ -128,21 +130,21 @@ function checkTest() {
case 2:
// run outside of private mode, link should appear as visited
var doc = iframe.contentDocument;
var doc = gIframe.contentDocument;
var win = doc.defaultView;
is(getColor(doc, win, "link"), kRed, "Visited link coloring should work outside of private mode");
break;
case 3:
// run inside of private mode, link should appear as not visited
var doc = iframe.contentDocument;
var doc = gIframe.contentDocument;
var win = doc.defaultView;
is(getColor(doc, win, "link"), kBlue, "Visited link coloring should not work inside of private mode");
break;
case 4:
// run outside of private mode, link should appear as visited
var doc = iframe.contentDocument;
var doc = gIframe.contentDocument;
var win = doc.defaultView;
is(getColor(doc, win, "link"), kRed, "Visited link coloring should work outside of private mode");
break;
@ -176,34 +178,35 @@ function handleLoad() {
if (testNum < subtests.length) {
loadNextTest();
} else {
prefBranch.clearUserPref("browser.privatebrowsing.keep_current_session");
try {
Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
} catch(ex) {}
SimpleTest.finish();
}
}
const URI_VISITED_RESOLUTION_TOPIC = "visited-status-resolution";
var os, observer = {
var observer = {
uri: null,
resolved: true,
observe: function (aSubject, aTopic, aData) {
SimpleTest.is(aTopic, URI_VISITED_RESOLUTION_TOPIC, "Unexpected topic");
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
if (this.uri.equals(aSubject.QueryInterface(Ci.nsIURI))) {
this.resolved = true;
os.removeObserver(this, URI_VISITED_RESOLUTION_TOPIC);
Services.obs.removeObserver(this, aTopic);
}
},
expectURL: function (url) {
expectURL: function (url, aOverrideTopic) {
ok(this.resolved, "Can't set the expected URL when another is yet to be resolved");
this.resolved = false;
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
this.uri = NetUtil.newURI(url);
os.addObserver(this, URI_VISITED_RESOLUTION_TOPIC, false);
var topic = aOverrideTopic || URI_VISITED_RESOLUTION_TOPIC;
Services.obs.addObserver(this, topic, false);
}
};
@ -212,19 +215,7 @@ if (!pb) { // Private Browsing might not be available
ok(true, "Private Browsing is not available");
SimpleTest.finish();
} else {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
prefBranch.setBoolPref("browser.privatebrowsing.keep_current_session", true);
os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
var iframe = document.getElementById("iframe");
SimpleTest.waitForExplicitFinish();
Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
loadNextTest();
}

Просмотреть файл

@ -215,10 +215,6 @@ ChannelListener.prototype = {
// chain, but this is good, since it will test a special path.
ghist3.addURI(uri(FOUND_URL), false, true, uri(PERMA_REDIR_URL));
// This forces a CommitLazyMessages, so we don't have to wait for LAZY_ADD.
// Actually trying to delete visits in future.
hs.removeVisitsByTimeframe((Date.now() * 1000) + 1, (Date.now() * 1000) + 2);
continue_test();
},

Просмотреть файл

@ -36,25 +36,36 @@
*
* ***** END LICENSE BLOCK ***** */
// Get favicon service
try {
var faviconService = Cc["@mozilla.org/browser/favicon-service;1"].
getService(Ci.nsIFaviconService);
} catch(ex) {
do_throw("Could not get favicon service\n");
}
// main
function run_test() {
try {
faviconService.setAndLoadFaviconForPage(null, uri("http://www.mozilla.com/favicon.ico"), false);
do_throw("should throw because page param is null");
} catch (ex) {}
do_test_pending();
let exceptionCaught = false;
try {
faviconService.setAndLoadFaviconForPage(uri("http://www.mozilla.com"), null, false);
PlacesUtils.favicons.setAndLoadFaviconForPage(
null, uri("http://www.mozilla.com/favicon.ico"), false
);
} catch (ex) {
exceptionCaught = true;
}
do_check_true(exceptionCaught, "should throw because page param is null");
exceptionCaught = false;
try {
PlacesUtils.favicons.setAndLoadFaviconForPage(
uri("http://www.mozilla.com"), null, false
);
do_throw("should throw because favicon param is null");
} catch (ex) {}
} catch (ex) {
exceptionCaught = true;
}
do_check_true(exceptionCaught, "should throw because page param is null");
faviconService.setAndLoadFaviconForPage(uri("http://www.google.com"), uri("http://www.google.com/favicon.ico"), false);
PlacesUtils.favicons.setAndLoadFaviconForPage(
uri("http://www.google.com"), uri("http://www.google.com/favicon.ico"),
false, continue_test
);
}
function continue_test(aFaviconData) {
do_test_finished();
}

Просмотреть файл

@ -40,16 +40,12 @@
* Tests for nsIFaviconService::SetAndLoadFaviconForPage()
*/
var iconsvc = Cc["@mozilla.org/browser/favicon-service;1"].
getService(Ci.nsIFaviconService);
var iconsvc = PlacesUtils.favicons;
function addBookmark(aURI) {
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
return bmsvc.insertBookmark(bmsvc.unfiledBookmarksFolder,
aURI,
bmsvc.DEFAULT_INDEX,
aURI.spec);
var bs = PlacesUtils.bookmarks;
return bs.insertBookmark(bs.unfiledBookmarksFolder, aURI,
bs.DEFAULT_INDEX, aURI.spec);
}
function checkAddSucceeded(pageURI, mimetype, data) {
@ -194,9 +190,7 @@ function run_test() {
// check that the favicon loaded correctly
do_check_eq(favicons[0].data.length, 344);
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
hs.addObserver(historyObserver, false);
PlacesUtils.history.addObserver(historyObserver, false);
// Start the tests
tests[currentTestIndex].go();

Просмотреть файл

@ -44,18 +44,9 @@ const PB_KEEP_SESSION_PREF = "browser.privatebrowsing.keep_current_session";
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "iconsvc",
"@mozilla.org/browser/favicon-service;1",
"nsIFaviconService");
XPCOMUtils.defineLazyServiceGetter(this, "hs",
"@mozilla.org/browser/nav-history-service;1",
"nsINavHistoryService");
XPCOMUtils.defineLazyServiceGetter(this, "pb",
"@mozilla.org/privatebrowsing;1",
"nsIPrivateBrowsingService");
XPCOMUtils.defineLazyServiceGetter(this, "prefs",
"@mozilla.org/preferences-service;1",
"nsIPrefBranch");
let favicons = [
{
@ -79,7 +70,7 @@ let tests = [
pageURI: uri("about:test1"),
go: function go1() {
iconsvc.setAndLoadFaviconForPage(this.pageURI, favicons[0].uri, true);
PlacesUtils.favicons.setAndLoadFaviconForPage(this.pageURI, favicons[0].uri, true);
},
clean: function clean1() {}
},
@ -89,13 +80,13 @@ let tests = [
pageURI: uri("http://test2.bar/"),
go: function go2() {
// Temporarily disable history.
prefs.setBoolPref("places.history.enabled", false);
Services.prefs.setBoolPref("places.history.enabled", false);
iconsvc.setAndLoadFaviconForPage(this.pageURI, favicons[0].uri, true);
PlacesUtils.favicons.setAndLoadFaviconForPage(this.pageURI, favicons[0].uri, true);
},
clean: function clean2() {
try {
prefs.clearUserPref("places.history.enabled");
Services.prefs.clearUserPref("places.history.enabled");
} catch (ex) {}
}
},
@ -108,10 +99,10 @@ let tests = [
return;
// Enable PB mode.
prefs.setBoolPref(PB_KEEP_SESSION_PREF, true);
Services.prefs.setBoolPref(PB_KEEP_SESSION_PREF, true);
pb.privateBrowsingEnabled = true;
iconsvc.setAndLoadFaviconForPage(this.pageURI, favicons[0].uri, true);
PlacesUtils.favicons.setAndLoadFaviconForPage(this.pageURI, favicons[0].uri, true);
},
clean: function clean3() {
if (!("@mozilla.org/privatebrowsing;1" in Cc))
@ -125,7 +116,7 @@ let tests = [
desc: "test setAndLoadFaviconForPage for valid history uri",
pageURI: uri("http://test4.bar/"),
go: function go4() {
iconsvc.setAndLoadFaviconForPage(this.pageURI, favicons[1].uri, true);
PlacesUtils.favicons.setAndLoadFaviconForPage(this.pageURI, favicons[1].uri, true);
},
clean: function clean4() {}
},
@ -154,7 +145,7 @@ let historyObserver = {
do_check_true(pageURI.equals(uri("http://test4.bar/")));
// Ensure there is only one entry in favicons table.
let stmt = PlacesServices.DBConn.createStatement(
let stmt = DBConn().createStatement(
"SELECT url FROM moz_favicons"
);
let c = 0;
@ -178,12 +169,6 @@ let historyObserver = {
let currentTest = null;
function run_test() {
// Disabled till LAZY_ADD is killed, this test should be fixed, since the
// below timeout is clearly wrong due to 3s lazy timer. But fixing it right
// now would mean making it take about 12s to run. This is not acceptable.
// See bug 555519.
return;
do_test_pending();
// check that the favicon loaded correctly
@ -191,7 +176,7 @@ function run_test() {
do_check_eq(favicons[1].data.length, favicons[1].size);
// Observe history for onPageChanged notification.
hs.addObserver(historyObserver, false);
PlacesUtils.history.addObserver(historyObserver, false);
// We run all the tests, then we wait for an onPageChanged notification,
// ideally only the last test is successful, so it should be the only