Bug 485122 - When the user selects to only display history in the location bar, don't display the star and tag icons for items that happen to be bookmarked or tagged. r=dietrich

Pretend a page isn't bookmarked/tagged when searching for only history unless the user explicitly wants them. Test by updating special searches test to ignore tags when searching for history ^.
This commit is contained in:
Edward Lee 2009-05-12 10:17:57 -05:00
Родитель 5b39be8eb8
Коммит 78e016cdd8
3 изменённых файлов: 35 добавлений и 9 удалений

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

@ -1141,6 +1141,13 @@ nsNavHistory::AutoCompleteProcessSearch(mozIStorageStatement* aQuery,
// Always prefer to show tags if we have them // Always prefer to show tags if we have them
PRBool showTags = !entryTags.IsEmpty(); PRBool showTags = !entryTags.IsEmpty();
// Pretend a page isn't bookmarked/tagged if the user only wants history,
// but still show the star and tag if the user explicitly wants them
if (GET_BEHAVIOR(History) && !(GET_BEHAVIOR(Bookmark) || GET_BEHAVIOR(Tag))) {
showTags = PR_FALSE;
style = NS_LITERAL_STRING("favicon");
}
// Add the tags to the title if necessary // Add the tags to the title if necessary
if (showTags) if (showTags)
title += TITLE_TAGS_SEPARATOR + entryTags; title += TITLE_TAGS_SEPARATOR + entryTags;

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

@ -79,6 +79,14 @@ function toURI(aSpec)
return iosvc.newURI(aSpec, null, null); return iosvc.newURI(aSpec, null, null);
} }
let appendTags = true;
// Helper to turn off tag matching in results
function ignoreTags()
{
print("Ignoring tags from results");
appendTags = false;
}
function ensure_results(aSearch, aExpected) function ensure_results(aSearch, aExpected)
{ {
let controller = Cc["@mozilla.org/autocomplete/controller;1"]. let controller = Cc["@mozilla.org/autocomplete/controller;1"].
@ -116,7 +124,7 @@ function ensure_results(aSearch, aExpected)
// Load the real uri and titles and tags if necessary // Load the real uri and titles and tags if necessary
uri = toURI(kURIs[uri]).spec; uri = toURI(kURIs[uri]).spec;
title = kTitles[title]; title = kTitles[title];
if (tags) if (tags && appendTags)
title += " \u2013 " + tags.map(function(aTag) kTitles[aTag]); title += " \u2013 " + tags.map(function(aTag) kTitles[aTag]);
// Got a match on both uri and title? // Got a match on both uri and title?
@ -349,6 +357,9 @@ function run_test() {
let [description, search, expected, func] = gTests[current_test]; let [description, search, expected, func] = gTests[current_test];
print(description); print(description);
// By default assume we want to match tags
appendTags = true;
// Do an extra function if necessary // Do an extra function if necessary
if (func) if (func)
func(); func();
@ -370,3 +381,4 @@ function markTyped(aURIs)
histsvc.addVisit(toURI(kURIs[uri]), Date.now() * 1000, null, histsvc.addVisit(toURI(kURIs[uri]), Date.now() * 1000, null,
histsvc.TRANSITION_TYPED, false, 0); histsvc.TRANSITION_TYPED, false, 0);
} }

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

@ -37,6 +37,9 @@
/** /**
* Test for bug 395161 that allows special searches that restrict results to * Test for bug 395161 that allows special searches that restrict results to
* history/bookmark/tagged items and title/url matches. * history/bookmark/tagged items and title/url matches.
*
* Test 485122 by making sure results don't have tags when restricting result
* to just history either by default behavior or dynamic query restrict.
*/ */
// Define some shared uris and titles (each page needs its own uri) // Define some shared uris and titles (each page needs its own uri)
@ -88,7 +91,7 @@ markTyped([0,3,10]);
let gTests = [ let gTests = [
// Test restricting searches // Test restricting searches
["0: History restrict", ["0: History restrict",
"^", [0,1,2,3,5,10]], "^", [0,1,2,3,5,10], ignoreTags],
["1: Star restrict", ["1: Star restrict",
"*", [4,5,6,7,8,9,10,11]], "*", [4,5,6,7,8,9,10,11]],
["2: Tag restrict", ["2: Tag restrict",
@ -96,15 +99,15 @@ let gTests = [
// Test specials as any word position // Test specials as any word position
["3: Special as first word", ["3: Special as first word",
"^ foo bar", [1,2,3,5,10]], "^ foo bar", [1,2,3,5,10], ignoreTags],
["4: Special as middle word", ["4: Special as middle word",
"foo ^ bar", [1,2,3,5,10]], "foo ^ bar", [1,2,3,5,10], ignoreTags],
["5: Special as last word", ["5: Special as last word",
"foo bar ^", [1,2,3,5,10]], "foo bar ^", [1,2,3,5,10], ignoreTags],
// Test restricting and matching searches with a term // Test restricting and matching searches with a term
["6: foo ^ -> history", ["6: foo ^ -> history",
"foo ^", [1,2,3,5,10]], "foo ^", [1,2,3,5,10], ignoreTags],
["7: foo * -> is star", ["7: foo * -> is star",
"foo *", [5,6,7,8,9,10,11]], "foo *", [5,6,7,8,9,10,11]],
["8: foo # -> in title", ["8: foo # -> in title",
@ -120,13 +123,13 @@ let gTests = [
["11: foo ^ * -> history, is star", ["11: foo ^ * -> history, is star",
"foo ^ *", [5,10]], "foo ^ *", [5,10]],
["12: foo ^ # -> history, in title", ["12: foo ^ # -> history, in title",
"foo ^ #", [1,3,5,10]], "foo ^ #", [1,3,5,10], ignoreTags],
["13: foo ^ @ -> history, in url", ["13: foo ^ @ -> history, in url",
"foo ^ @", [2,3,10]], "foo ^ @", [2,3,10], ignoreTags],
["14: foo ^ + -> history, is tag", ["14: foo ^ + -> history, is tag",
"foo ^ +", [10]], "foo ^ +", [10]],
["14.1: foo ^ ~ -> history, is typed", ["14.1: foo ^ ~ -> history, is typed",
"foo ^ ~", [3,10]], "foo ^ ~", [3,10], ignoreTags],
["15: foo * # -> is star, in title", ["15: foo * # -> is star, in title",
"foo * #", [5,7,8,9,10,11]], "foo * #", [5,7,8,9,10,11]],
["16: foo * @ -> is star, in url", ["16: foo * @ -> is star, in url",
@ -166,5 +169,9 @@ let gTests = [
]; ];
function makeDefault(aDefault) { function makeDefault(aDefault) {
// We want to ignore tags if we're restricting to history unless we're showing
if ((aDefault & 1) && !((aDefault & 2) || (aDefault & 4)))
ignoreTags();
prefs.setIntPref("browser.urlbar.default.behavior", aDefault); prefs.setIntPref("browser.urlbar.default.behavior", aDefault);
} }