Bug 378828 - Support sortingAnnotation in place: URIs. r=dietrich.

This commit is contained in:
mozilla.mano@sent.com 2007-04-27 03:04:13 -07:00
parent 425c75c6a1
commit 47eb048b72
2 changed files with 35 additions and 1 deletions

View File

@ -157,6 +157,7 @@ static void SetOptionsKeyUint32(const nsCString& aValue,
#define QUERYKEY_SEPARATOR "OR"
#define QUERYKEY_GROUP "group"
#define QUERYKEY_SORT "sort"
#define QUERYKEY_SORTING_ANNOTATION "sortingAnnotation"
#define QUERYKEY_RESULT_TYPE "type"
#define QUERYKEY_EXCLUDE_ITEMS "excludeItems"
#define QUERYKEY_EXCLUDE_QUERIES "excludeQueries"
@ -428,6 +429,19 @@ nsNavHistory::QueriesToQueryString(nsINavHistoryQuery **aQueries,
AppendAmpersandIfNonempty(queryString);
queryString += NS_LITERAL_CSTRING(QUERYKEY_SORT "=");
AppendInt16(queryString, options->SortingMode());
if (options->SortingMode() == nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_DESCENDING ||
options->SortingMode() == nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_ASCENDING) {
// sortingAnnotation
nsCAutoString sortingAnnotation;
if (NS_SUCCEEDED(options->GetSortingAnnotation(sortingAnnotation))) {
nsCString escaped;
if (!NS_Escape(sortingAnnotation, escaped, url_XAlphas))
return NS_ERROR_OUT_OF_MEMORY;
AppendAmpersandIfNonempty(queryString);
queryString += NS_LITERAL_CSTRING(QUERYKEY_SORTING_ANNOTATION "=");
queryString.Append(escaped);
}
}
}
// result type
@ -674,7 +688,12 @@ nsNavHistory::TokensToQueries(const nsTArray<QueryKeyValuePair>& aTokens,
} else if (kvp.key.EqualsLiteral(QUERYKEY_SORT)) {
SetOptionsKeyUint16(kvp.value, aOptions,
&nsINavHistoryQueryOptions::SetSortingMode);
// sorting annotation
} else if (kvp.key.EqualsLiteral(QUERYKEY_SORTING_ANNOTATION)) {
nsCString sortingAnnotation = kvp.value;
NS_UnescapeURL(sortingAnnotation);
rv = aOptions->SetSortingAnnotation(sortingAnnotation);
NS_ENSURE_SUCCESS(rv, rv);
// result type
} else if (kvp.key.EqualsLiteral(QUERYKEY_RESULT_TYPE)) {
SetOptionsKeyUint16(kvp.value, aOptions,

View File

@ -49,9 +49,24 @@ function run_test() {
// XXX Full testing coverage for QueriesToQueryString and
// QueryStringToQueries
const NHQO = Ci.nsINavHistoryQueryOptions;
// Bug 376798
var query = histsvc.getNewQuery();
query.setFolders([1],1);
do_check_eq(histsvc.queriesToQueryString([query], 1, histsvc.getNewQueryOptions()),
"place:folder=1");
// Bug 378828
var options = histsvc.getNewQueryOptions();
options.sortingAnnotation = "test anno";
options.sortingMode = NHQO.SORT_BY_ANNOTATION_DESCENDING;
var placeURI =
"place:folder=1&sort=" + NHQO.SORT_BY_ANNOTATION_DESCENDING +
"&sortingAnnotation=test%20anno";
do_check_eq(histsvc.queriesToQueryString([query], 1, options),
placeURI);
var options = {};
histsvc.queryStringToQueries(placeURI, { }, {}, options);
do_check_eq(options.value.sortingAnnotation, "test anno");
do_check_eq(options.value.sortingMode, NHQO.SORT_BY_ANNOTATION_DESCENDING);
}