backing out due to unit test failures

This commit is contained in:
Dietrich Ayala 2009-03-18 19:13:10 -07:00
parent 8309f5298e
commit 688280cc02
8 changed files with 398 additions and 445 deletions

View File

@ -973,13 +973,26 @@ PlacesController.prototype = {
}
}
else if (PlacesUtils.nodeIsDay(node)) {
var query = node.getQueries({})[0];
var beginTime = query.beginTime;
var endTime = query.endTime;
NS_ASSERT(query && beginTime && endTime,
"A valid date container query should exist!");
// We want to exclude beginTime from the removal
bhist.removePagesByTimeframe(beginTime+1, endTime);
// this is the oldest date
// for the last node endDate is end of epoch
var beginDate = 0;
// this is the newest date
// day nodes have time property set to the last day in the interval
var endDate = node.time;
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 "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsDateTimeFormatCID.h"
#include "nsDebug.h"
#include "nsEnumeratorUtils.h"
#include "nsFaviconService.h"
@ -3002,6 +3003,8 @@ PRBool NeedToFilterResultSet(const nsCOMArray<nsNavHistoryQuery>& aQueries,
// ** Helper class for ConstructQueryString **/
static const PRInt32 MAX_HISTORY_DAYS = 6;
class PlacesSQLQueryBuilder
{
public:
@ -3476,164 +3479,141 @@ nsresult
PlacesSQLQueryBuilder::SelectAsDay()
{
mSkipOrderBy = PR_TRUE;
PRBool asDayQuery =
mResultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY;
PRUint16 resultType =
mResultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY ?
nsINavHistoryQueryOptions::RESULTS_AS_URI :
nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY;
mQueryString = nsPrintfCString(255,
"SELECT null, "
"'place:type=%ld&sort=%ld&beginTime='||beginTime||'&endTime='||endTime, "
"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
// because it could overlap, and we use time to sort containers and find
// 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);
nsNavHistory* history = nsNavHistory::GetHistoryService();
NS_ENSURE_STATE(history);
// These are the day containers and catch-all final container.
PRInt32 additionalContainers = 3;
// We use a guess of the number of months considering all of them 30 days
// long, but we split only the last 6 months.
PRInt32 monthContainers = PR_MIN(6, (history->mExpireDaysMax/30));
PRInt32 numContainers = monthContainers + additionalContainers;
for (PRInt32 i = 0; i <= numContainers; i++) {
nsCAutoString dateName;
// Timeframes are calculated as BeginTime <= container < EndTime.
// Notice times can't be relative to now, since to recognize a query we
// 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
// a fixed timestamp.
nsCAutoString sqlFragmentBeginTime;
nsCAutoString sqlFragmentEndTime;
switch(i) {
case 0:
// Today
history->GetStringFromName(
NS_LITERAL_STRING("finduri-AgeInDays-is-0").get(), dateName);
// From start of today
sqlFragmentBeginTime = NS_LITERAL_CSTRING(
"(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
struct Midnight
{
Midnight() {
mNow = NormalizeTimeRelativeToday(PR_Now());
}
PRTime Get(PRInt32 aDayOffset) {
PRTime result;
LL_MUL(result, aDayOffset, USECS_PER_DAY);
LL_ADD(result, result, mNow);
return result;
}
PRTime mNow;
} midnight;
nsCAutoString dateParam;
nsCAutoString dateName;
for (PRInt32 i = 0; i <= MAX_HISTORY_DAYS; i++) {
dateParam = nsPrintfCString(":dayTitle%d", i);
switch (i)
{
case 0:
history->GetStringFromName(
NS_LITERAL_STRING("finduri-AgeInMonths-is-0").get(), dateName);
// From start of this month
sqlFragmentBeginTime = NS_LITERAL_CSTRING(
"(strftime('%s','now','start of month','utc')*1000000)");
// To now (tomorrow)
sqlFragmentEndTime = NS_LITERAL_CSTRING(
"(strftime('%s','now','start of day','+1 day','utc')*1000000)");
break;
default:
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)"));
NS_LITERAL_STRING("finduri-AgeInDays-is-0").get(), dateName);
break;
case 1:
history->GetStringFromName(
NS_LITERAL_STRING("finduri-AgeInDays-is-1").get(), dateName);
break;
default:
history->GetAgeInDaysString(i,
NS_LITERAL_STRING("finduri-AgeInDays-is").get(), dateName);
break;
}
nsPrintfCString dayRange(1024,
"SELECT '%s' AS dayTitle, "
"%s AS beginTime, "
"%s AS endTime "
"WHERE EXISTS ( "
"SELECT id FROM moz_historyvisits_temp "
"WHERE visit_date >= %s "
"AND visit_date < %s "
mAddParams.Put(dateParam, dateName);
PRInt32 fromDayAgo = -i;
PRInt32 toDayAgo = -i + 1;
nsPrintfCString dayRange(1024,
"SELECT * "
"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) "
"{QUERY_OPTIONS} "
"UNION ALL "
"SELECT id FROM moz_historyvisits "
"WHERE visit_date >= %s "
"AND visit_date < %s "
"AND visit_type NOT IN (0,%d) "
"{QUERY_OPTIONS} "
"LIMIT 1 "
") ",
dateName.get(),
sqlFragmentBeginTime.get(),
sqlFragmentEndTime.get(),
sqlFragmentBeginTime.get(),
sqlFragmentEndTime.get(),
nsINavHistoryService::TRANSITION_EMBED,
sqlFragmentBeginTime.get(),
sqlFragmentEndTime.get(),
nsINavHistoryService::TRANSITION_EMBED);
"LIMIT 1 "
") "
"OR EXISTS ( "
"SELECT * FROM moz_historyvisits "
"WHERE visit_date >= %llu "
"AND visit_date < %llu "
"AND visit_type NOT IN (0,%d) "
"{QUERY_OPTIONS} "
"LIMIT 1 "
") "
"LIMIT 1) TUNION%d UNION ",
i, i, dateParam.get(),
midnight.Get(fromDayAgo),
midnight.Get(toDayAgo),
midnight.Get(fromDayAgo),
midnight.Get(toDayAgo),
nsINavHistoryService::TRANSITION_EMBED,
midnight.Get(fromDayAgo),
midnight.Get(toDayAgo),
nsINavHistoryService::TRANSITION_EMBED,
i);
mQueryString.Append(dayRange);
if (i < numContainers)
mQueryString.Append(NS_LITERAL_CSTRING(" UNION ALL "));
mQueryString.Append( dayRange );
}
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;
}
@ -4198,7 +4178,7 @@ nsNavHistory::GetQueryResults(nsNavHistoryQueryResultNode *aResultNode,
nsCString queryString;
PRBool paramsPresent = PR_FALSE;
nsNavHistory::StringHash addParams;
addParams.Init(1);
addParams.Init(MAX_HISTORY_DAYS+1);
nsresult rv = ConstructQueryString(aQueries, aOptions, queryString,
paramsPresent, addParams);
NS_ENSURE_SUCCESS(rv,rv);
@ -4207,6 +4187,11 @@ nsNavHistory::GetQueryResults(nsNavHistoryQueryResultNode *aResultNode,
printf("Constructed the query: %s\n", PromiseFlatCString(queryString).get());
#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
nsCOMPtr<mozIStorageStatement> statement;
rv = mDBConn->CreateStatement(queryString, getter_AddRefs(statement));
@ -6269,7 +6254,7 @@ nsNavHistory::FilterResultSet(nsNavHistoryQueryResultNode* aQueryNode,
mozStorageStatementScoper scoper(mDBGetTags);
rv = mDBGetTags->BindStringParameter(0, NS_LITERAL_STRING(" "));
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBGetTags->BindInt64Parameter(1, GetTagsFolder());
rv = mDBGetTags->BindInt32Parameter(1, GetTagsFolder());
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBGetTags->BindUTF8StringParameter(2, aSet[nodeIndex]->mURI);
NS_ENSURE_SUCCESS(rv, rv);
@ -6312,12 +6297,12 @@ nsNavHistory::FilterResultSet(nsNavHistoryQueryResultNode* aQueryNode,
// stop once we've seen max results
if (aOptions->MaxResults() > 0 &&
(PRUint32)aFiltered->Count() >= aOptions->MaxResults())
aFiltered->Count() >= aOptions->MaxResults())
break;
}
// de-allocate the matrixes
for (PRInt32 i = 0; i < aQueries.Count(); i++) {
for (PRUint32 i=0; i < aQueries.Count(); i++) {
delete terms[i];
delete includeFolders[i];
delete excludeFolders[i];
@ -6693,24 +6678,22 @@ nsNavHistory::TitleForDomain(const nsCString& domain, nsACString& aTitle)
}
void
nsNavHistory::GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName,
nsACString& aResult)
nsNavHistory::GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName, nsACString& aResult)
{
nsIStringBundle *bundle = GetBundle();
if (!bundle)
aResult.Truncate(0);
else {
nsAutoString intString;
intString.AppendInt(aInt);
const PRUnichar* strings[1] = { intString.get() };
nsXPIDLString value;
nsresult rv = bundle->FormatStringFromName(aName, strings,
1, getter_Copies(value));
if (NS_SUCCEEDED(rv))
CopyUTF16toUTF8(value, aResult);
else
aResult.Truncate(0);
}
nsAutoString intString;
intString.AppendInt(aInt);
const PRUnichar* strings[1] = { intString.get() };
nsXPIDLString value;
nsresult rv = bundle->FormatStringFromName(aName, strings,
1, getter_Copies(value));
if (NS_SUCCEEDED(rv))
CopyUTF16toUTF8(value, aResult);
else
aResult.Truncate(0);
}
void
@ -6728,24 +6711,6 @@ nsNavHistory::GetStringFromName(const PRUnichar *aName, nsACString& aResult)
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
//
// 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)
{
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>();
PRBool hasSearchTerms;
if (NS_SUCCEEDED(aQueries[i]->GetHasSearchTerms(&hasSearchTerms)) &&
@ -7369,7 +7334,7 @@ nsNavHistory::CalculateFrecencyInternal(PRInt64 aPlaceId,
else
weight = mDefaultWeight;
pointsForSampledVisits += (float)(weight * (bonus / 100.0));
pointsForSampledVisits += weight * (bonus / 100.0);
}
}
@ -7567,31 +7532,18 @@ nsNavHistory::GetCollation()
nsIStringBundle *
nsNavHistory::GetBundle()
{
if (!mBundle) {
nsCOMPtr<nsIStringBundleService> bundleService =
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;
}
if (mBundle)
return mBundle;
nsIStringBundle *
nsNavHistory::GetDateFormatBundle()
{
if (!mDateFormatBundle) {
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
NS_ENSURE_TRUE(bundleService, nsnull);
nsresult rv = bundleService->CreateBundle(
"chrome://global/locale/dateFormat.properties",
getter_AddRefs(mDateFormatBundle));
NS_ENSURE_SUCCESS(rv, nsnull);
}
return mDateFormatBundle;
nsCOMPtr<nsIStringBundleService> bundleService =
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;
}
mozIStorageStatement *

View File

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

View File

@ -4283,13 +4283,107 @@ nsNavHistoryResult::OnVisit(nsIURI* aURI, PRInt64 aVisitId, PRTime aTime,
aReferringId, aTransitionType, &added));
if (!added && mRootNode->mExpanded) {
nsresult rv;
// None of registered query observers has accepted our URI, this means,
// 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();
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 ||
resultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_SITE_QUERY ||
resultType == nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY)
mRootNode->GetAsQuery()->Refresh();
resultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_SITE_QUERY) {
nsNavHistory* history = nsNavHistory::GetHistoryService();
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;

View File

@ -37,13 +37,11 @@
* ***** END LICENSE BLOCK ***** */
// Get history service
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var bh = hs.QueryInterface(Ci.nsIBrowserHistory);
var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
var ps = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
try {
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
} catch(ex) {
do_throw("Could not get history service\n");
}
/**
* 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.
* @returns the place id for aURI.
*/
function add_normalized_visit(aURI, aTime, aDayOffset) {
var dateObj = new Date(aTime);
// Normalize to midnight
dateObj.setHours(0);
dateObj.setMinutes(0);
dateObj.setSeconds(0);
dateObj.setMilliseconds(0);
// Substract aDayOffset
var PRTimeWithOffset = (dateObj.getTime() + aDayOffset * 86400000) * 1000;
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;
function add_visit(aURI, aDayOffset) {
var placeID = histsvc.addVisit(aURI,
(Date.now() + aDayOffset*86400000) * 1000,
null,
histsvc.TRANSITION_TYPED, // user typed in URL bar
false, // not redirect
0);
do_check_true(placeID > 0);
return placeID;
}
var nowObj = new Date();
// This test relies on en-US locale
// Offset is number of days
var containers = [
{ label: "Today", offset: 0 },
{ label: "Yesterday", offset: -1 },
{ label: "Last 7 days", offset: -3 },
{ label: "This month", offset: -8 },
{ label: "", offset: -nowObj.getDate()-1 },
{ label: "Older than 6 months", offset: -nowObj.getDate()-186 },
// Can I rely on en-US locales during units tests?
var dayLabels =
[
"Today",
"Yesterday",
"2 days ago",
"3 days ago",
"4 days ago",
"5 days ago",
"6 days ago",
"Older than 6 days"
];
/**
* Fills history and checks containers' labels.
*/
// Fills history and checks if date labels are correct for partially filled history
function fill_history() {
print("\n\n*** TEST Fill History\n");
// We can't use "now" because our hardcoded offsets would be invalid for some
// date. So we hardcode a date.
for (var i = 0; i < containers.length; i++) {
var container = containers[i];
const checkOlderOffset = 4;
// add visits for the older days
for (var i=checkOlderOffset; i<dayLabels.length; i++)
{
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");
add_normalized_visit(testURI, nowObj.getTime(), container.offset);
add_visit(testURI, -i);
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");
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;
var query = hs.getNewQuery();
var result = hs.executeQuery(query, options);
var query = histsvc.getNewQuery();
var result = histsvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
do_check_eq(root.childCount, dayLabels.length - checkOlderOffset);
var cc = root.childCount;
print("Found containers:");
for (var i = 0; i < cc; i++) {
var container = containers[i];
var node = root.getChild(i);
print(node.title);
if (container.label)
do_check_eq(node.title, container.label);
for (var i=checkOlderOffset; i<dayLabels.length; i++)
{
var node = root.getChild(i-checkOlderOffset);
do_check_eq(node.title, dayLabels[i]);
}
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;
}
/**
* Queries history grouped by date and site, checking containers' labels and
* children.
*/
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;
var query = hs.getNewQuery();
var result = hs.executeQuery(query, options);
var query = histsvc.getNewQuery();
var result = histsvc.executeQuery(query, options);
var root = result.root;
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
var dayNode = root.getChild(0)
.QueryInterface(Ci.nsINavHistoryContainerResultNode);
var dayNode = root.getChild(4).QueryInterface(Ci.nsINavHistoryContainerResultNode);
dayNode.containerOpen = true;
do_check_eq(dayNode.childCount, 2);
// Items should be sorted by host
var site1 = dayNode.getChild(0)
.QueryInterface(Ci.nsINavHistoryContainerResultNode);
do_check_eq(site1.title, "mirror0.google.com");
var site1 = dayNode.getChild(0).QueryInterface(Ci.nsINavHistoryContainerResultNode);
do_check_eq(site1.title, "mirror4.google.com");
var site2 = dayNode.getChild(1)
.QueryInterface(Ci.nsINavHistoryContainerResultNode);
do_check_eq(site2.title, "mirror0.mozilla.com");
var site2 = dayNode.getChild(1).QueryInterface(Ci.nsINavHistoryContainerResultNode);
do_check_eq(site2.title, "mirror4.mozilla.com");
site1.containerOpen = true;
do_check_eq(site1.childCount, 2);
// Inside of host sites are sorted by title
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;
dayNode.containerOpen = false;
root.containerOpen = false;
}
/**
* Queries history grouped by date, checking containers' labels and children.
*/
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;
var query = hs.getNewQuery();
var result = hs.executeQuery(query, options);
var query = histsvc.getNewQuery();
var result = histsvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
do_check_eq(root.childCount, dayLabels.length);
var cc = root.childCount;
do_check_eq(cc, containers.length);
print("Found containers:");
for (var i = 0; i < cc; i++) {
var container = containers[i];
// Now we check whether we have all the labels
for (var i=0; i<dayLabels.length; i++)
{
var node = root.getChild(i);
print(node.title);
if (container.label)
do_check_eq(node.title, container.label);
do_check_eq(node.title, dayLabels[i]);
}
// Check one of the days
var dayNode = root.getChild(0)
.QueryInterface(Ci.nsINavHistoryContainerResultNode);
var dayNode = root.getChild(3).QueryInterface(Ci.nsINavHistoryContainerResultNode);
dayNode.containerOpen = true;
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);
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);
do_check_eq(visit2.uri, "http://mirror0.mozilla.com/b");
do_check_eq(visit2.uri, "http://mirror3.mozilla.com/d");
dayNode.containerOpen = false;
root.containerOpen = false;
}
/**
* Queries history grouped by site, checking containers' labels and children.
*/
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;
var query = hs.getNewQuery();
var result = hs.executeQuery(query, options);
var query = histsvc.getNewQuery();
var result = histsvc.executeQuery(query, options);
var root = result.root;
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.mozilla.com",
"mirror1.google.com",
"mirror1.mozilla.com",
"mirror2.google.com",
"mirror2.mozilla.com",
"mirror3.google.com", <== We check for this site (index 6)
"mirror3.google.com",
"mirror3.mozilla.com",
"mirror4.google.com",
"mirror4.mozilla.com",
"mirror5.google.com",
"mirror5.google.com", // We check for this site
"mirror5.mozilla.com",
...
*/
"mirror6.google.com",
"mirror6.mozilla.com",
"mirror7.google.com",
"mirror7.mozilla.com"
];
// Items should be sorted by host
var siteNode = root.getChild(6)
.QueryInterface(Ci.nsINavHistoryContainerResultNode);
do_check_eq(siteNode.title, "mirror3.google.com");
var siteNode = root.getChild(dayLabels.length+2).QueryInterface(Ci.nsINavHistoryContainerResultNode);
do_check_eq(siteNode.title, expectedResult[dayLabels.length+2] );
siteNode.containerOpen = true;
do_check_eq(siteNode.childCount, 2);
// Inside of host sites are sorted by title
var visitNode = siteNode.getChild(0);
do_check_eq(visitNode.uri, "http://mirror3.google.com/a");
var visit = siteNode.getChild(0);
do_check_eq(visit.uri, "http://mirror5.google.com/a");
siteNode.containerOpen = false;
root.containerOpen = false;
@ -257,11 +258,6 @@ function test_RESULTS_AS_SITE_QUERY() {
// main
function run_test() {
// Increase history limit to 1 year
ps.setIntPref("browser.history_expire_days", 365);
// Cleanup.
bh.removeAllPages();
fill_history();
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
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-1=Yesterday
finduri-AgeInDays-is=%S days ago
finduri-AgeInDays-last-is=Last %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)
# LOCALIZATION NOTE (bookmarksArchiveFilename):

View File

@ -18,7 +18,6 @@
+ locale/@AB_CD@/global/customizeToolbar.dtd (%chrome/global/customizeToolbar.dtd)
+ locale/@AB_CD@/global/customizeToolbar.properties (%chrome/global/customizeToolbar.properties)
+ 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/downloadProgress.properties (%chrome/global/downloadProgress.properties)
+ locale/@AB_CD@/global/editMenuOverlay.dtd (%chrome/global/editMenuOverlay.dtd)