backing out due to unit test failures

This commit is contained in:
Dietrich Ayala 2009-03-18 19:13:10 -07:00
parent 53c5b02134
commit 4cc7fe5d41
8 changed files with 398 additions and 445 deletions

View File

@ -973,13 +973,26 @@ PlacesController.prototype = {
} }
} }
else if (PlacesUtils.nodeIsDay(node)) { else if (PlacesUtils.nodeIsDay(node)) {
var query = node.getQueries({})[0]; // this is the oldest date
var beginTime = query.beginTime; // for the last node endDate is end of epoch
var endTime = query.endTime; var beginDate = 0;
NS_ASSERT(query && beginTime && endTime, // this is the newest date
"A valid date container query should exist!"); // day nodes have time property set to the last day in the interval
// We want to exclude beginTime from the removal var endDate = node.time;
bhist.removePagesByTimeframe(beginTime+1, endTime);
var nodeIdx = 0;
var cc = root.childCount;
// Find index of current day node
while (nodeIdx < cc && root.getChild(nodeIdx) != node)
++nodeIdx;
// We have an older day
if (nodeIdx+1 < cc)
beginDate = root.getChild(nodeIdx+1).time;
// we want to exclude beginDate from the removal
bhist.removePagesByTimeframe(beginDate+1, endDate);
} }
} }

View File

@ -54,6 +54,7 @@
#include "nsCollationCID.h" #include "nsCollationCID.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsDateTimeFormatCID.h"
#include "nsDebug.h" #include "nsDebug.h"
#include "nsEnumeratorUtils.h" #include "nsEnumeratorUtils.h"
#include "nsFaviconService.h" #include "nsFaviconService.h"
@ -3002,6 +3003,8 @@ PRBool NeedToFilterResultSet(const nsCOMArray<nsNavHistoryQuery>& aQueries,
// ** Helper class for ConstructQueryString **/ // ** Helper class for ConstructQueryString **/
static const PRInt32 MAX_HISTORY_DAYS = 6;
class PlacesSQLQueryBuilder class PlacesSQLQueryBuilder
{ {
public: public:
@ -3476,164 +3479,141 @@ nsresult
PlacesSQLQueryBuilder::SelectAsDay() PlacesSQLQueryBuilder::SelectAsDay()
{ {
mSkipOrderBy = PR_TRUE; mSkipOrderBy = PR_TRUE;
PRBool asDayQuery =
mResultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY;
PRUint16 resultType = mQueryString = nsPrintfCString(255,
mResultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY ? "SELECT null, "
nsINavHistoryQueryOptions::RESULTS_AS_URI : "'place:type=%ld&sort=%ld&beginTime='||beginTime||'&endTime='||endTime, "
nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY; "dayTitle, null, null, endTime, null, null, null, null "
"FROM (", // TOUTER BEGIN
(asDayQuery
?nsINavHistoryQueryOptions::RESULTS_AS_URI
:nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY),
nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING);
// beginTime will become the node's time property, we don't use endTime nsNavHistory* history = nsNavHistory::GetHistoryService();
// because it could overlap, and we use time to sort containers and find NS_ENSURE_STATE(history);
// insert position in a result.
mQueryString = nsPrintfCString(1024,
"SELECT null, "
"'place:type=%ld&sort=%ld&beginTime='||beginTime||'&endTime='||endTime, "
"dayTitle, null, null, beginTime, null, null, null, null "
"FROM (", // TOUTER BEGIN
resultType,
nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING);
nsNavHistory* history = nsNavHistory::GetHistoryService();
NS_ENSURE_STATE(history);
// These are the day containers and catch-all final container. struct Midnight
PRInt32 additionalContainers = 3; {
// We use a guess of the number of months considering all of them 30 days Midnight() {
// long, but we split only the last 6 months. mNow = NormalizeTimeRelativeToday(PR_Now());
PRInt32 monthContainers = PR_MIN(6, (history->mExpireDaysMax/30)); }
PRInt32 numContainers = monthContainers + additionalContainers; PRTime Get(PRInt32 aDayOffset) {
for (PRInt32 i = 0; i <= numContainers; i++) { PRTime result;
nsCAutoString dateName; LL_MUL(result, aDayOffset, USECS_PER_DAY);
// Timeframes are calculated as BeginTime <= container < EndTime. LL_ADD(result, result, mNow);
// Notice times can't be relative to now, since to recognize a query we return result;
// must ensure it won't change based on the time it is built. }
// So, to select till now, we really select till start of tomorrow, that is PRTime mNow;
// a fixed timestamp. } midnight;
nsCAutoString sqlFragmentBeginTime;
nsCAutoString sqlFragmentEndTime; nsCAutoString dateParam;
switch(i) { nsCAutoString dateName;
case 0:
// Today for (PRInt32 i = 0; i <= MAX_HISTORY_DAYS; i++) {
history->GetStringFromName( dateParam = nsPrintfCString(":dayTitle%d", i);
NS_LITERAL_STRING("finduri-AgeInDays-is-0").get(), dateName); switch (i)
// From start of today {
sqlFragmentBeginTime = NS_LITERAL_CSTRING( case 0:
"(strftime('%s','now','start of day','utc')*1000000)");
// To now (tomorrow)
sqlFragmentEndTime = NS_LITERAL_CSTRING(
"(strftime('%s','now','start of day','+1 day','utc')*1000000)");
break;
case 1:
// Yesterday
history->GetStringFromName(
NS_LITERAL_STRING("finduri-AgeInDays-is-1").get(), dateName);
// From start of yesterday
sqlFragmentBeginTime = NS_LITERAL_CSTRING(
"(strftime('%s','now','start of day','-1 day','utc')*1000000)");
// To start of today
sqlFragmentEndTime = NS_LITERAL_CSTRING(
"(strftime('%s','now','start of day','utc')*1000000)");
break;
case 2:
// Last 7 days
history->GetAgeInDaysString(7,
NS_LITERAL_STRING("finduri-AgeInDays-last-is").get(), dateName);
// From start of 7 days ago
sqlFragmentBeginTime = NS_LITERAL_CSTRING(
"(strftime('%s','now','start of day','-7 days','utc')*1000000)");
// To now (tomorrow)
sqlFragmentEndTime = NS_LITERAL_CSTRING(
"(strftime('%s','now','start of day','+1 day','utc')*1000000)");
break;
case 3:
// This month
history->GetStringFromName( history->GetStringFromName(
NS_LITERAL_STRING("finduri-AgeInMonths-is-0").get(), dateName); NS_LITERAL_STRING("finduri-AgeInDays-is-0").get(), dateName);
// From start of this month break;
sqlFragmentBeginTime = NS_LITERAL_CSTRING( case 1:
"(strftime('%s','now','start of month','utc')*1000000)"); history->GetStringFromName(
// To now (tomorrow) NS_LITERAL_STRING("finduri-AgeInDays-is-1").get(), dateName);
sqlFragmentEndTime = NS_LITERAL_CSTRING( break;
"(strftime('%s','now','start of day','+1 day','utc')*1000000)"); default:
break; history->GetAgeInDaysString(i,
default: NS_LITERAL_STRING("finduri-AgeInDays-is").get(), dateName);
if (i == additionalContainers + 6) {
// Older than 6 months
history->GetAgeInDaysString(6,
NS_LITERAL_STRING("finduri-AgeInMonths-isgreater").get(), dateName);
// From start of epoch
sqlFragmentBeginTime = NS_LITERAL_CSTRING(
"(datetime(0, 'unixepoch')*1000000)");
// To start of 6 months ago
sqlFragmentEndTime = NS_LITERAL_CSTRING(
"(strftime('%s','now','start of day','-6 months','utc')*1000000)");
break;
}
PRInt32 MonthIndex = i - additionalContainers;
// Previous months' titles are month's name if inside this year,
// month's name and year for previous years.
PRExplodedTime tm;
PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &tm);
PRUint16 currentYear = tm.tm_year;
tm.tm_month -= MonthIndex;
PR_NormalizeTime(&tm, PR_LocalTimeParameters);
// tm_month starts from 0 while GetMonthName expects a 1-based index.
history->GetMonthName(tm.tm_month+1, dateName);
// If the container is for a past year, add the year as suffix.
if (tm.tm_year < currentYear)
dateName.Append(nsPrintfCString(" %d", tm.tm_year));
// From start of MonthIndex + 1 months ago
sqlFragmentBeginTime = NS_LITERAL_CSTRING(
"(strftime('%s','now','start of month','-");
sqlFragmentBeginTime.AppendInt(MonthIndex);
sqlFragmentBeginTime.Append(NS_LITERAL_CSTRING(
" months','utc')*1000000)"));
// To start of MonthIndex months ago
sqlFragmentEndTime = NS_LITERAL_CSTRING(
"(strftime('%s','now','start of month','-");
sqlFragmentEndTime.AppendInt(MonthIndex - 1);
sqlFragmentEndTime.Append(NS_LITERAL_CSTRING(
" months','utc')*1000000)"));
break; break;
} }
nsPrintfCString dayRange(1024, mAddParams.Put(dateParam, dateName);
"SELECT '%s' AS dayTitle, "
"%s AS beginTime, " PRInt32 fromDayAgo = -i;
"%s AS endTime " PRInt32 toDayAgo = -i + 1;
"WHERE EXISTS ( "
"SELECT id FROM moz_historyvisits_temp " nsPrintfCString dayRange(1024,
"WHERE visit_date >= %s " "SELECT * "
"AND visit_date < %s " "FROM ( "
"SELECT %d dayOrder, "
"'%d' dayRange, "
"%s dayTitle, " // This will be bound
"%llu beginTime, "
"%llu endTime "
"WHERE EXISTS ( "
"SELECT id FROM moz_historyvisits_temp "
"WHERE visit_date >= %llu "
"AND visit_date < %llu "
"AND visit_type NOT IN (0,%d) " "AND visit_type NOT IN (0,%d) "
"{QUERY_OPTIONS} " "{QUERY_OPTIONS} "
"UNION ALL " "LIMIT 1 "
"SELECT id FROM moz_historyvisits " ") "
"WHERE visit_date >= %s " "OR EXISTS ( "
"AND visit_date < %s " "SELECT * FROM moz_historyvisits "
"AND visit_type NOT IN (0,%d) " "WHERE visit_date >= %llu "
"{QUERY_OPTIONS} " "AND visit_date < %llu "
"LIMIT 1 " "AND visit_type NOT IN (0,%d) "
") ", "{QUERY_OPTIONS} "
dateName.get(), "LIMIT 1 "
sqlFragmentBeginTime.get(), ") "
sqlFragmentEndTime.get(), "LIMIT 1) TUNION%d UNION ",
sqlFragmentBeginTime.get(), i, i, dateParam.get(),
sqlFragmentEndTime.get(), midnight.Get(fromDayAgo),
nsINavHistoryService::TRANSITION_EMBED, midnight.Get(toDayAgo),
sqlFragmentBeginTime.get(), midnight.Get(fromDayAgo),
sqlFragmentEndTime.get(), midnight.Get(toDayAgo),
nsINavHistoryService::TRANSITION_EMBED); nsINavHistoryService::TRANSITION_EMBED,
midnight.Get(fromDayAgo),
midnight.Get(toDayAgo),
nsINavHistoryService::TRANSITION_EMBED,
i);
mQueryString.Append(dayRange); mQueryString.Append( dayRange );
if (i < numContainers)
mQueryString.Append(NS_LITERAL_CSTRING(" UNION ALL "));
} }
mQueryString.Append(NS_LITERAL_CSTRING(") ")); // TOUTER END dateParam = nsPrintfCString(":dayTitle%d", MAX_HISTORY_DAYS+1);
history->GetAgeInDaysString(MAX_HISTORY_DAYS,
NS_LITERAL_STRING("finduri-AgeInDays-isgreater").get(), dateName);
mAddParams.Put(dateParam, dateName);
mQueryString.Append(nsPrintfCString(1024,
"SELECT * "
"FROM ("
"SELECT %d dayOrder, "
"'%d+' dayRange, "
"%s dayTitle, " // This will be bound
"1 beginTime, "
"%llu endTime "
"WHERE EXISTS ( "
"SELECT id FROM moz_historyvisits_temp "
"WHERE visit_date < %llu "
"AND visit_type NOT IN (0,%d) "
"{QUERY_OPTIONS} "
"LIMIT 1 "
") "
"OR EXISTS ( "
"SELECT id FROM moz_historyvisits "
"WHERE visit_date < %llu "
"AND visit_type NOT IN (0,%d) "
"{QUERY_OPTIONS} "
"LIMIT 1 "
") "
"LIMIT 1) TUNIONLAST "
") TOUTER " // TOUTER END
"ORDER BY dayOrder ASC",
MAX_HISTORY_DAYS+1,
MAX_HISTORY_DAYS+1,
dateParam.get(),
midnight.Get(-MAX_HISTORY_DAYS),
midnight.Get(-MAX_HISTORY_DAYS),
nsINavHistoryService::TRANSITION_EMBED,
midnight.Get(-MAX_HISTORY_DAYS),
nsINavHistoryService::TRANSITION_EMBED
));
return NS_OK; return NS_OK;
} }
@ -4198,7 +4178,7 @@ nsNavHistory::GetQueryResults(nsNavHistoryQueryResultNode *aResultNode,
nsCString queryString; nsCString queryString;
PRBool paramsPresent = PR_FALSE; PRBool paramsPresent = PR_FALSE;
nsNavHistory::StringHash addParams; nsNavHistory::StringHash addParams;
addParams.Init(1); addParams.Init(MAX_HISTORY_DAYS+1);
nsresult rv = ConstructQueryString(aQueries, aOptions, queryString, nsresult rv = ConstructQueryString(aQueries, aOptions, queryString,
paramsPresent, addParams); paramsPresent, addParams);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
@ -4207,6 +4187,11 @@ nsNavHistory::GetQueryResults(nsNavHistoryQueryResultNode *aResultNode,
printf("Constructed the query: %s\n", PromiseFlatCString(queryString).get()); printf("Constructed the query: %s\n", PromiseFlatCString(queryString).get());
#endif #endif
// Put this in a transaction. Even though we are only reading, this will
// speed up the grouped queries to the annotation service for titles and
// full text searching.
mozStorageTransaction transaction(mDBConn, PR_FALSE);
// create statement // create statement
nsCOMPtr<mozIStorageStatement> statement; nsCOMPtr<mozIStorageStatement> statement;
rv = mDBConn->CreateStatement(queryString, getter_AddRefs(statement)); rv = mDBConn->CreateStatement(queryString, getter_AddRefs(statement));
@ -6269,7 +6254,7 @@ nsNavHistory::FilterResultSet(nsNavHistoryQueryResultNode* aQueryNode,
mozStorageStatementScoper scoper(mDBGetTags); mozStorageStatementScoper scoper(mDBGetTags);
rv = mDBGetTags->BindStringParameter(0, NS_LITERAL_STRING(" ")); rv = mDBGetTags->BindStringParameter(0, NS_LITERAL_STRING(" "));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = mDBGetTags->BindInt64Parameter(1, GetTagsFolder()); rv = mDBGetTags->BindInt32Parameter(1, GetTagsFolder());
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = mDBGetTags->BindUTF8StringParameter(2, aSet[nodeIndex]->mURI); rv = mDBGetTags->BindUTF8StringParameter(2, aSet[nodeIndex]->mURI);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -6312,12 +6297,12 @@ nsNavHistory::FilterResultSet(nsNavHistoryQueryResultNode* aQueryNode,
// stop once we've seen max results // stop once we've seen max results
if (aOptions->MaxResults() > 0 && if (aOptions->MaxResults() > 0 &&
(PRUint32)aFiltered->Count() >= aOptions->MaxResults()) aFiltered->Count() >= aOptions->MaxResults())
break; break;
} }
// de-allocate the matrixes // de-allocate the matrixes
for (PRInt32 i = 0; i < aQueries.Count(); i++) { for (PRUint32 i=0; i < aQueries.Count(); i++) {
delete terms[i]; delete terms[i];
delete includeFolders[i]; delete includeFolders[i];
delete excludeFolders[i]; delete excludeFolders[i];
@ -6693,24 +6678,22 @@ nsNavHistory::TitleForDomain(const nsCString& domain, nsACString& aTitle)
} }
void void
nsNavHistory::GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName, nsNavHistory::GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName, nsACString& aResult)
nsACString& aResult)
{ {
nsIStringBundle *bundle = GetBundle(); nsIStringBundle *bundle = GetBundle();
if (!bundle) if (!bundle)
aResult.Truncate(0); aResult.Truncate(0);
else {
nsAutoString intString; nsAutoString intString;
intString.AppendInt(aInt); intString.AppendInt(aInt);
const PRUnichar* strings[1] = { intString.get() }; const PRUnichar* strings[1] = { intString.get() };
nsXPIDLString value; nsXPIDLString value;
nsresult rv = bundle->FormatStringFromName(aName, strings, nsresult rv = bundle->FormatStringFromName(aName, strings,
1, getter_Copies(value)); 1, getter_Copies(value));
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv))
CopyUTF16toUTF8(value, aResult); CopyUTF16toUTF8(value, aResult);
else else
aResult.Truncate(0); aResult.Truncate(0);
}
} }
void void
@ -6728,24 +6711,6 @@ nsNavHistory::GetStringFromName(const PRUnichar *aName, nsACString& aResult)
aResult.Truncate(0); aResult.Truncate(0);
} }
void
nsNavHistory::GetMonthName(PRInt32 aIndex, nsACString& aResult)
{
nsIStringBundle *bundle = GetDateFormatBundle();
if (!bundle)
aResult.Truncate(0);
else {
nsCString name = nsPrintfCString("month.%d.name", aIndex);
nsXPIDLString value;
nsresult rv = bundle->GetStringFromName(NS_ConvertUTF8toUTF16(name).get(),
getter_Copies(value));
if (NS_SUCCEEDED(rv))
CopyUTF16toUTF8(value, aResult);
else
aResult.Truncate(0);
}
}
// nsNavHistory::SetPageTitleInternal // nsNavHistory::SetPageTitleInternal
// //
// Called to set the title for the given URI. Used as a // Called to set the title for the given URI. Used as a
@ -7133,7 +7098,7 @@ void ParseSearchTermsFromQueries(const nsCOMArray<nsNavHistoryQuery>& aQueries,
nsTArray<nsTArray<nsString>*>* aTerms) nsTArray<nsTArray<nsString>*>* aTerms)
{ {
PRInt32 lastBegin = -1; PRInt32 lastBegin = -1;
for (PRInt32 i = 0; i < aQueries.Count(); i++) { for (PRUint32 i=0; i < aQueries.Count(); i++) {
nsTArray<nsString> *queryTerms = new nsTArray<nsString>(); nsTArray<nsString> *queryTerms = new nsTArray<nsString>();
PRBool hasSearchTerms; PRBool hasSearchTerms;
if (NS_SUCCEEDED(aQueries[i]->GetHasSearchTerms(&hasSearchTerms)) && if (NS_SUCCEEDED(aQueries[i]->GetHasSearchTerms(&hasSearchTerms)) &&
@ -7369,7 +7334,7 @@ nsNavHistory::CalculateFrecencyInternal(PRInt64 aPlaceId,
else else
weight = mDefaultWeight; weight = mDefaultWeight;
pointsForSampledVisits += (float)(weight * (bonus / 100.0)); pointsForSampledVisits += weight * (bonus / 100.0);
} }
} }
@ -7567,31 +7532,18 @@ nsNavHistory::GetCollation()
nsIStringBundle * nsIStringBundle *
nsNavHistory::GetBundle() nsNavHistory::GetBundle()
{ {
if (!mBundle) { if (mBundle)
nsCOMPtr<nsIStringBundleService> bundleService = return mBundle;
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
NS_ENSURE_TRUE(bundleService, nsnull);
nsresult rv = bundleService->CreateBundle(
"chrome://places/locale/places.properties",
getter_AddRefs(mBundle));
NS_ENSURE_SUCCESS(rv, nsnull);
}
return mBundle;
}
nsIStringBundle * nsCOMPtr<nsIStringBundleService> bundleService =
nsNavHistory::GetDateFormatBundle() do_GetService(NS_STRINGBUNDLE_CONTRACTID);
{ NS_ENSURE_TRUE(bundleService, nsnull);
if (!mDateFormatBundle) { nsresult rv = bundleService->CreateBundle(
nsCOMPtr<nsIStringBundleService> bundleService = "chrome://places/locale/places.properties",
do_GetService(NS_STRINGBUNDLE_CONTRACTID); getter_AddRefs(mBundle));
NS_ENSURE_TRUE(bundleService, nsnull); NS_ENSURE_SUCCESS(rv, nsnull);
nsresult rv = bundleService->CreateBundle(
"chrome://global/locale/dateFormat.properties", return mBundle;
getter_AddRefs(mDateFormatBundle));
NS_ENSURE_SUCCESS(rv, nsnull);
}
return mDateFormatBundle;
} }
mozIStorageStatement * mozIStorageStatement *

View File

@ -62,6 +62,7 @@
#endif #endif
#include "nsIBrowserHistory.h" #include "nsIBrowserHistory.h"
#include "nsICollation.h" #include "nsICollation.h"
#include "nsIDateTimeFormat.h"
#include "nsIGlobalHistory.h" #include "nsIGlobalHistory.h"
#include "nsIGlobalHistory3.h" #include "nsIGlobalHistory3.h"
#include "nsIDownloadHistory.h" #include "nsIDownloadHistory.h"
@ -241,12 +242,10 @@ public:
* objects for places components. * objects for places components.
*/ */
nsIStringBundle* GetBundle(); nsIStringBundle* GetBundle();
nsIStringBundle* GetDateFormatBundle();
nsICollation* GetCollation(); nsICollation* GetCollation();
void GetStringFromName(const PRUnichar* aName, nsACString& aResult); void GetStringFromName(const PRUnichar* aName, nsACString& aResult);
void GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName, void GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName,
nsACString& aResult); nsACString& aResult);
void GetMonthName(PRInt32 aIndex, nsACString& aResult);
// returns true if history has been disabled // returns true if history has been disabled
PRBool IsHistoryDisabled() { return mExpireDaysMax == 0 || InPrivateBrowsingMode(); } PRBool IsHistoryDisabled() { return mExpireDaysMax == 0 || InPrivateBrowsingMode(); }
@ -633,7 +632,6 @@ protected:
// localization // localization
nsCOMPtr<nsIStringBundle> mBundle; nsCOMPtr<nsIStringBundle> mBundle;
nsCOMPtr<nsIStringBundle> mDateFormatBundle;
nsCOMPtr<nsICollation> mCollation; nsCOMPtr<nsICollation> mCollation;
// annotation service : MAY BE NULL! // annotation service : MAY BE NULL!

View File

@ -4283,13 +4283,107 @@ nsNavHistoryResult::OnVisit(nsIURI* aURI, PRInt64 aVisitId, PRTime aTime,
aReferringId, aTransitionType, &added)); aReferringId, aTransitionType, &added));
if (!added && mRootNode->mExpanded) { if (!added && mRootNode->mExpanded) {
nsresult rv;
// None of registered query observers has accepted our URI, this means, // None of registered query observers has accepted our URI, this means,
// that a matching query either was not expanded or it does not exist. // that a matching query either was not expanded or it does not exist.
// If it just was not expanded, we can ignore it, but if it did not
// exist, we have to add the query to the right place.
PRUint32 resultType = mRootNode->mOptions->ResultType(); PRUint32 resultType = mRootNode->mOptions->ResultType();
nsNavHistoryResultNode * siteRoot = mRootNode;
nsCAutoString dateRange;
// For day based queries we just check whether the first item is Today,
if (resultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY || if (resultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY ||
resultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_SITE_QUERY || resultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_SITE_QUERY) {
resultType == nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY) nsNavHistory* history = nsNavHistory::GetHistoryService();
mRootNode->GetAsQuery()->Refresh(); NS_ENSURE_TRUE(history, 0);
// code borrowed from xpfe/components/history/src/nsGlobalHistory.cpp
// pass in a pre-normalized now and a date, and we'll find
// the difference since midnight on each of the days.
//
// USECS_PER_DAY == PR_USEC_PER_SEC * 60 * 60 * 24;
static const PRInt64 USECS_PER_DAY = LL_INIT(20, 500654080);
dateRange = nsPrintfCString(255,
"&beginTime=%lld&endTime=%lld",
history->NormalizeTime(
nsINavHistoryQuery::TIME_RELATIVE_TODAY, 0),
history->NormalizeTime(
nsINavHistoryQuery::TIME_RELATIVE_TODAY, USECS_PER_DAY));
PRBool todayIsMissing = PR_FALSE;
PRUint32 childCount;
rv = mRootNode->GetChildCount(&childCount);
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString todayLabel;
history->GetStringFromName(
NS_LITERAL_STRING("finduri-AgeInDays-is-0").get(), todayLabel);
if (!childCount) {
todayIsMissing = PR_TRUE;
} else {
nsCOMPtr<nsINavHistoryResultNode> firstChild;
rv = mRootNode->GetChild(0, getter_AddRefs(firstChild));
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString title;
rv = firstChild->GetTitle( title);
NS_ENSURE_SUCCESS(rv, rv);
if (todayLabel.Equals(title)) {
siteRoot = static_cast<nsNavHistoryResultNode *>(firstChild.get());
} else {
todayIsMissing = PR_TRUE;
}
}
if (todayIsMissing) { // Add "Today"
nsCAutoString queryUri;
queryUri = nsPrintfCString(255,
"place:type=%ld&sort=%ld%s",
resultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY
?nsINavHistoryQueryOptions::RESULTS_AS_URI
:nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY,
nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING,
dateRange.get());
nsRefPtr<nsNavHistoryQueryResultNode> todayNode;
todayNode = new nsNavHistoryQueryResultNode(todayLabel,
EmptyCString(), queryUri);
rv = mRootNode->InsertChildAt( todayNode, 0);
NS_ENSURE_SUCCESS(rv, rv);
}
// "Today" was missing or we had day query
if (resultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY ||
todayIsMissing)
return NS_OK; // No more processing necessary
}
if (siteRoot->IsQuery() && siteRoot->GetAsQuery()->mContentsValid &&
(resultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_SITE_QUERY ||
resultType == nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY)) {
nsCAutoString host;
rv = aURI->GetAsciiHost(host);
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString queryUri;
queryUri = nsPrintfCString(255,
"place:type=%ld&sort=%ld&domain=%s&domainIsHost=true%s",
nsINavHistoryQueryOptions::RESULTS_AS_URI,
nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING,
host.get(),
dateRange.get());
nsRefPtr<nsNavHistoryQueryResultNode> siteNode;
siteNode = new nsNavHistoryQueryResultNode(host, EmptyCString(), queryUri);
rv = siteRoot->GetAsContainer()->InsertSortedChild(
siteNode, PR_FALSE, PR_TRUE/*Ignore duplicates*/);
NS_ENSURE_SUCCESS(rv, rv);
}
} }
return NS_OK; return NS_OK;

View File

@ -37,13 +37,11 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
// Get history service // Get history service
var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. try {
getService(Ci.nsINavHistoryService); var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
var bh = hs.QueryInterface(Ci.nsIBrowserHistory); } catch(ex) {
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. do_throw("Could not get history service\n");
getService(Ci.nsINavBookmarksService); }
var ps = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
/** /**
* Adds a test URI visit to the database, and checks for a valid place ID. * Adds a test URI visit to the database, and checks for a valid place ID.
@ -54,202 +52,205 @@ var ps = Cc["@mozilla.org/preferences-service;1"].
* The referring URI for the given URI. This can be null. * The referring URI for the given URI. This can be null.
* @returns the place id for aURI. * @returns the place id for aURI.
*/ */
function add_normalized_visit(aURI, aTime, aDayOffset) { function add_visit(aURI, aDayOffset) {
var dateObj = new Date(aTime); var placeID = histsvc.addVisit(aURI,
// Normalize to midnight (Date.now() + aDayOffset*86400000) * 1000,
dateObj.setHours(0); null,
dateObj.setMinutes(0); histsvc.TRANSITION_TYPED, // user typed in URL bar
dateObj.setSeconds(0); false, // not redirect
dateObj.setMilliseconds(0); 0);
// Substract aDayOffset do_check_true(placeID > 0);
var PRTimeWithOffset = (dateObj.getTime() + aDayOffset * 86400000) * 1000; return placeID;
print("Adding visit to " + aURI.spec + " at " + new Date(PRTimeWithOffset/1000));
var visitId = hs.addVisit(aURI,
PRTimeWithOffset,
null,
hs.TRANSITION_TYPED, // user typed in URL bar
false, // not redirect
0);
do_check_true(visitId > 0);
return visitId;
} }
var nowObj = new Date(); // Can I rely on en-US locales during units tests?
// This test relies on en-US locale var dayLabels =
// Offset is number of days [
var containers = [ "Today",
{ label: "Today", offset: 0 }, "Yesterday",
{ label: "Yesterday", offset: -1 }, "2 days ago",
{ label: "Last 7 days", offset: -3 }, "3 days ago",
{ label: "This month", offset: -8 }, "4 days ago",
{ label: "", offset: -nowObj.getDate()-1 }, "5 days ago",
{ label: "Older than 6 months", offset: -nowObj.getDate()-186 }, "6 days ago",
"Older than 6 days"
]; ];
/** // Fills history and checks if date labels are correct for partially filled history
* Fills history and checks containers' labels.
*/
function fill_history() { function fill_history() {
print("\n\n*** TEST Fill History\n"); const checkOlderOffset = 4;
// We can't use "now" because our hardcoded offsets would be invalid for some
// date. So we hardcode a date. // add visits for the older days
for (var i = 0; i < containers.length; i++) { for (var i=checkOlderOffset; i<dayLabels.length; i++)
var container = containers[i]; {
var testURI = uri("http://mirror"+i+".mozilla.com/b"); var testURI = uri("http://mirror"+i+".mozilla.com/b");
add_normalized_visit(testURI, nowObj.getTime(), container.offset); add_visit(testURI, -i);
var testURI = uri("http://mirror"+i+".mozilla.com/a"); var testURI = uri("http://mirror"+i+".mozilla.com/a");
add_normalized_visit(testURI, nowObj.getTime(), container.offset); add_visit(testURI, -i);
var testURI = uri("http://mirror"+i+".google.com/b"); var testURI = uri("http://mirror"+i+".google.com/b");
add_normalized_visit(testURI, nowObj.getTime(), container.offset); add_visit(testURI, -i);
var testURI = uri("http://mirror"+i+".google.com/a"); var testURI = uri("http://mirror"+i+".google.com/a");
add_normalized_visit(testURI, nowObj.getTime(), container.offset); add_visit(testURI, -i);
} }
var options = hs.getNewQueryOptions(); var options = histsvc.getNewQueryOptions();
options.resultType = options.RESULTS_AS_DATE_SITE_QUERY; options.resultType = options.RESULTS_AS_DATE_SITE_QUERY;
var query = hs.getNewQuery(); var query = histsvc.getNewQuery();
var result = histsvc.executeQuery(query, options);
var result = hs.executeQuery(query, options);
var root = result.root; var root = result.root;
root.containerOpen = true; root.containerOpen = true;
do_check_eq(root.childCount, dayLabels.length - checkOlderOffset);
var cc = root.childCount; for (var i=checkOlderOffset; i<dayLabels.length; i++)
print("Found containers:"); {
for (var i = 0; i < cc; i++) { var node = root.getChild(i-checkOlderOffset);
var container = containers[i]; do_check_eq(node.title, dayLabels[i]);
var node = root.getChild(i);
print(node.title);
if (container.label)
do_check_eq(node.title, container.label);
} }
do_check_eq(cc, containers.length);
// When I close the root container here, it would generate a warning
// on next call to addVisit.
root.containerOpen = false;
// add visits for the most recent days
for (var i=0; i<checkOlderOffset; i++)
{
var testURI = uri("http://mirror"+i+".mozilla.com/d");
add_visit(testURI, -i);
var testURI = uri("http://mirror"+i+".mozilla.com/c");
add_visit(testURI, -i);
var testURI = uri("http://mirror"+i+".google.com/d");
add_visit(testURI, -i);
var testURI = uri("http://mirror"+i+".google.com/c");
add_visit(testURI, -i);
}
root.containerOpen = false; root.containerOpen = false;
} }
/**
* Queries history grouped by date and site, checking containers' labels and
* children.
*/
function test_RESULTS_AS_DATE_SITE_QUERY() { function test_RESULTS_AS_DATE_SITE_QUERY() {
print("\n\n*** TEST RESULTS_AS_DATE_SITE_QUERY\n");
var options = hs.getNewQueryOptions(); var options = histsvc.getNewQueryOptions();
options.resultType = options.RESULTS_AS_DATE_SITE_QUERY; options.resultType = options.RESULTS_AS_DATE_SITE_QUERY;
var query = hs.getNewQuery(); var query = histsvc.getNewQuery();
var result = hs.executeQuery(query, options); var result = histsvc.executeQuery(query, options);
var root = result.root; var root = result.root;
root.containerOpen = true; root.containerOpen = true;
do_check_eq(root.childCount, dayLabels.length);
// Now we check whether we have all the labels
for (var i=0; i<dayLabels.length; i++)
{
var node = root.getChild(i);
do_check_eq(node.title, dayLabels[i]);
}
// Check one of the days // Check one of the days
var dayNode = root.getChild(0) var dayNode = root.getChild(4).QueryInterface(Ci.nsINavHistoryContainerResultNode);
.QueryInterface(Ci.nsINavHistoryContainerResultNode);
dayNode.containerOpen = true; dayNode.containerOpen = true;
do_check_eq(dayNode.childCount, 2); do_check_eq(dayNode.childCount, 2);
// Items should be sorted by host // Items should be sorted by host
var site1 = dayNode.getChild(0) var site1 = dayNode.getChild(0).QueryInterface(Ci.nsINavHistoryContainerResultNode);
.QueryInterface(Ci.nsINavHistoryContainerResultNode); do_check_eq(site1.title, "mirror4.google.com");
do_check_eq(site1.title, "mirror0.google.com");
var site2 = dayNode.getChild(1) var site2 = dayNode.getChild(1).QueryInterface(Ci.nsINavHistoryContainerResultNode);
.QueryInterface(Ci.nsINavHistoryContainerResultNode); do_check_eq(site2.title, "mirror4.mozilla.com");
do_check_eq(site2.title, "mirror0.mozilla.com");
site1.containerOpen = true; site1.containerOpen = true;
do_check_eq(site1.childCount, 2); do_check_eq(site1.childCount, 2);
// Inside of host sites are sorted by title // Inside of host sites are sorted by title
var site1visit = site1.getChild(0); var site1visit = site1.getChild(0);
do_check_eq(site1visit.uri, "http://mirror0.google.com/a"); do_check_eq(site1visit.uri, "http://mirror4.google.com/a");
site1.containerOpen = false; site1.containerOpen = false;
dayNode.containerOpen = false; dayNode.containerOpen = false;
root.containerOpen = false; root.containerOpen = false;
} }
/**
* Queries history grouped by date, checking containers' labels and children.
*/
function test_RESULTS_AS_DATE_QUERY() { function test_RESULTS_AS_DATE_QUERY() {
print("\n\n*** TEST RESULTS_AS_DATE_QUERY\n");
var options = hs.getNewQueryOptions(); var options = histsvc.getNewQueryOptions();
options.resultType = options.RESULTS_AS_DATE_QUERY; options.resultType = options.RESULTS_AS_DATE_QUERY;
var query = hs.getNewQuery(); var query = histsvc.getNewQuery();
var result = hs.executeQuery(query, options); var result = histsvc.executeQuery(query, options);
var root = result.root; var root = result.root;
root.containerOpen = true; root.containerOpen = true;
do_check_eq(root.childCount, dayLabels.length);
var cc = root.childCount; // Now we check whether we have all the labels
do_check_eq(cc, containers.length); for (var i=0; i<dayLabels.length; i++)
print("Found containers:"); {
for (var i = 0; i < cc; i++) {
var container = containers[i];
var node = root.getChild(i); var node = root.getChild(i);
print(node.title); do_check_eq(node.title, dayLabels[i]);
if (container.label)
do_check_eq(node.title, container.label);
} }
// Check one of the days // Check one of the days
var dayNode = root.getChild(0) var dayNode = root.getChild(3).QueryInterface(Ci.nsINavHistoryContainerResultNode);
.QueryInterface(Ci.nsINavHistoryContainerResultNode);
dayNode.containerOpen = true; dayNode.containerOpen = true;
do_check_eq(dayNode.childCount, 4); do_check_eq(dayNode.childCount, 4);
do_check_eq(dayNode.title, "3 days ago");
// Items should be sorted by title // Items should be sorted title
var visit1 = dayNode.getChild(0); var visit1 = dayNode.getChild(0);
do_check_eq(visit1.uri, "http://mirror0.google.com/a"); do_check_eq(visit1.uri, "http://mirror3.google.com/c");
var visit2 = dayNode.getChild(3); var visit2 = dayNode.getChild(3);
do_check_eq(visit2.uri, "http://mirror0.mozilla.com/b"); do_check_eq(visit2.uri, "http://mirror3.mozilla.com/d");
dayNode.containerOpen = false; dayNode.containerOpen = false;
root.containerOpen = false; root.containerOpen = false;
} }
/**
* Queries history grouped by site, checking containers' labels and children.
*/
function test_RESULTS_AS_SITE_QUERY() { 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
bs.insertBookmark(bs.toolbarFolder, uri("http://foobar"),
bs.DEFAULT_INDEX, "");
var options = hs.getNewQueryOptions(); // add a bookmark with a domain not in the set of visits in the db
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
bmsvc.insertBookmark(bmsvc.toolbarFolder, uri("http://foobar"),
bmsvc.DEFAULT_INDEX, "");
var options = histsvc.getNewQueryOptions();
options.resultType = options.RESULTS_AS_SITE_QUERY; options.resultType = options.RESULTS_AS_SITE_QUERY;
var query = hs.getNewQuery(); var query = histsvc.getNewQuery();
var result = hs.executeQuery(query, options); var result = histsvc.executeQuery(query, options);
var root = result.root; var root = result.root;
root.containerOpen = true; root.containerOpen = true;
do_check_eq(root.childCount, containers.length * 2); do_check_eq(root.childCount, dayLabels.length*2);
/* Expected results: // We include this here, so that maintainer knows what is the expected result
var expectedResult =
[
"mirror0.google.com", "mirror0.google.com",
"mirror0.mozilla.com", "mirror0.mozilla.com",
"mirror1.google.com", "mirror1.google.com",
"mirror1.mozilla.com", "mirror1.mozilla.com",
"mirror2.google.com", "mirror2.google.com",
"mirror2.mozilla.com", "mirror2.mozilla.com",
"mirror3.google.com", <== We check for this site (index 6) "mirror3.google.com",
"mirror3.mozilla.com", "mirror3.mozilla.com",
"mirror4.google.com", "mirror4.google.com",
"mirror4.mozilla.com", "mirror4.mozilla.com",
"mirror5.google.com", "mirror5.google.com", // We check for this site
"mirror5.mozilla.com", "mirror5.mozilla.com",
... "mirror6.google.com",
*/ "mirror6.mozilla.com",
"mirror7.google.com",
"mirror7.mozilla.com"
];
// Items should be sorted by host // Items should be sorted by host
var siteNode = root.getChild(6) var siteNode = root.getChild(dayLabels.length+2).QueryInterface(Ci.nsINavHistoryContainerResultNode);
.QueryInterface(Ci.nsINavHistoryContainerResultNode); do_check_eq(siteNode.title, expectedResult[dayLabels.length+2] );
do_check_eq(siteNode.title, "mirror3.google.com");
siteNode.containerOpen = true; siteNode.containerOpen = true;
do_check_eq(siteNode.childCount, 2); do_check_eq(siteNode.childCount, 2);
// Inside of host sites are sorted by title // Inside of host sites are sorted by title
var visitNode = siteNode.getChild(0); var visit = siteNode.getChild(0);
do_check_eq(visitNode.uri, "http://mirror3.google.com/a"); do_check_eq(visit.uri, "http://mirror5.google.com/a");
siteNode.containerOpen = false; siteNode.containerOpen = false;
root.containerOpen = false; root.containerOpen = false;
@ -257,11 +258,6 @@ function test_RESULTS_AS_SITE_QUERY() {
// main // main
function run_test() { function run_test() {
// Increase history limit to 1 year
ps.setIntPref("browser.history_expire_days", 365);
// Cleanup.
bh.removeAllPages();
fill_history(); fill_history();
test_RESULTS_AS_DATE_SITE_QUERY(); test_RESULTS_AS_DATE_SITE_QUERY();

View File

@ -1,92 +0,0 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is OEone Calendar Code, released October 31st, 2001.
#
# The Initial Developer of the Original Code is
# OEone Corporation.
# Portions created by OEone Corporation are Copyright (C) 2001
# OEone Corporation. All Rights Reserved.
#
# Contributor(s):
# Garth Smedley <garths@oeone.com>
# Martin Schroeder <mschroeder@mozilla.x-home.org>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
month.1.Mmm=Jan
month.2.Mmm=Feb
month.3.Mmm=Mar
month.4.Mmm=Apr
month.5.Mmm=May
month.6.Mmm=Jun
month.7.Mmm=Jul
month.8.Mmm=Aug
month.9.Mmm=Sep
month.10.Mmm=Oct
month.11.Mmm=Nov
month.12.Mmm=Dec
month.1.name=January
month.2.name=February
month.3.name=March
month.4.name=April
month.5.name=May
month.6.name=June
month.7.name=July
month.8.name=August
month.9.name=September
month.10.name=October
month.11.name=November
month.12.name=December
day.1.name=Sunday
day.2.name=Monday
day.3.name=Tuesday
day.4.name=Wednesday
day.5.name=Thursday
day.6.name=Friday
day.7.name=Saturday
day.1.Mmm=Sun
day.2.Mmm=Mon
day.3.Mmm=Tue
day.4.Mmm=Wed
day.5.Mmm=Thu
day.6.Mmm=Fri
day.7.Mmm=Sat
day.1.short=Su
day.2.short=Mo
day.3.short=Tu
day.4.short=We
day.5.short=Th
day.6.short=Fr
day.7.short=Sa
noon=Noon
midnight=Midnight
AllDay=All Day

View File

@ -3,18 +3,11 @@ BookmarksToolbarFolderTitle=Bookmarks Toolbar
UnsortedBookmarksFolderTitle=Unsorted Bookmarks UnsortedBookmarksFolderTitle=Unsorted Bookmarks
TagsFolderTitle=Tags TagsFolderTitle=Tags
# LOCALIZATION NOTE (dateName):
# These are used to generate history containers when history is grouped by date
finduri-AgeInDays-is-0=Today finduri-AgeInDays-is-0=Today
finduri-AgeInDays-is-1=Yesterday finduri-AgeInDays-is-1=Yesterday
finduri-AgeInDays-is=%S days ago finduri-AgeInDays-is=%S days ago
finduri-AgeInDays-last-is=Last %S days
finduri-AgeInDays-isgreater=Older than %S days finduri-AgeInDays-isgreater=Older than %S days
finduri-AgeInMonths-is-0=This month
finduri-AgeInMonths-isgreater=Older than %S months
# LOCALIZATION NOTE (localFiles):
# This is used to generate local files container when history is grouped by site
localhost=(local files) localhost=(local files)
# LOCALIZATION NOTE (bookmarksArchiveFilename): # LOCALIZATION NOTE (bookmarksArchiveFilename):

View File

@ -18,7 +18,6 @@
+ locale/@AB_CD@/global/customizeToolbar.dtd (%chrome/global/customizeToolbar.dtd) + locale/@AB_CD@/global/customizeToolbar.dtd (%chrome/global/customizeToolbar.dtd)
+ locale/@AB_CD@/global/customizeToolbar.properties (%chrome/global/customizeToolbar.properties) + locale/@AB_CD@/global/customizeToolbar.properties (%chrome/global/customizeToolbar.properties)
+ locale/@AB_CD@/global/datetimepicker.dtd (%chrome/global/datetimepicker.dtd) + locale/@AB_CD@/global/datetimepicker.dtd (%chrome/global/datetimepicker.dtd)
locale/@AB_CD@/global/dateFormat.properties (%chrome/global/dateFormat.properties)
* locale/@AB_CD@/global/dialogOverlay.dtd (%chrome/global/dialogOverlay.dtd) * locale/@AB_CD@/global/dialogOverlay.dtd (%chrome/global/dialogOverlay.dtd)
locale/@AB_CD@/global/downloadProgress.properties (%chrome/global/downloadProgress.properties) locale/@AB_CD@/global/downloadProgress.properties (%chrome/global/downloadProgress.properties)
+ locale/@AB_CD@/global/editMenuOverlay.dtd (%chrome/global/editMenuOverlay.dtd) + locale/@AB_CD@/global/editMenuOverlay.dtd (%chrome/global/editMenuOverlay.dtd)