Bug 1589865 - Search in a Private Window appears for the search restriction token. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D49888

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Marco Bonardo 2019-10-22 14:21:15 +00:00
Родитель 8fb59cb8ed
Коммит d6c6a3496f
2 изменённых файлов: 75 добавлений и 3 удалений

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

@ -19,6 +19,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
SkippableTimer: "resource:///modules/UrlbarUtils.jsm", SkippableTimer: "resource:///modules/UrlbarUtils.jsm",
UrlbarProvider: "resource:///modules/UrlbarUtils.jsm", UrlbarProvider: "resource:///modules/UrlbarUtils.jsm",
UrlbarResult: "resource:///modules/UrlbarResult.jsm", UrlbarResult: "resource:///modules/UrlbarResult.jsm",
UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.jsm",
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm", UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
}); });
@ -76,7 +77,11 @@ class ProviderPrivateSearch extends UrlbarProvider {
* @returns {boolean} Whether this provider should be invoked for the search. * @returns {boolean} Whether this provider should be invoked for the search.
*/ */
isActive(queryContext) { isActive(queryContext) {
return separatePrivateDefaultUIEnabled && !queryContext.isPrivate; return (
separatePrivateDefaultUIEnabled &&
!queryContext.isPrivate &&
queryContext.tokens.length
);
} }
/** /**
@ -99,6 +104,24 @@ class ProviderPrivateSearch extends UrlbarProvider {
*/ */
async startQuery(queryContext, addCallback) { async startQuery(queryContext, addCallback) {
logger.info(`Starting query for ${queryContext.searchString}`); logger.info(`Starting query for ${queryContext.searchString}`);
let searchString = queryContext.searchString.trim();
if (
queryContext.tokens.some(
t => t.type == UrlbarTokenizer.TYPE.RESTRICT_SEARCH
)
) {
if (queryContext.tokens.length == 1) {
// There's only the restriction token, bail out.
return;
}
// Remove the restriction char from the search string.
searchString = queryContext.tokens
.filter(t => t.type != UrlbarTokenizer.TYPE.RESTRICT_SEARCH)
.map(t => t.value)
.join(" ");
}
let instance = {}; let instance = {};
this.queries.set(queryContext, instance); this.queries.set(queryContext, instance);
@ -122,7 +145,7 @@ class ProviderPrivateSearch extends UrlbarProvider {
UrlbarUtils.RESULT_SOURCE.SEARCH, UrlbarUtils.RESULT_SOURCE.SEARCH,
...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { ...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, {
engine: [engine.name, UrlbarUtils.HIGHLIGHT.TYPED], engine: [engine.name, UrlbarUtils.HIGHLIGHT.TYPED],
query: [queryContext.searchString.trim(), UrlbarUtils.HIGHLIGHT.TYPED], query: [searchString, UrlbarUtils.HIGHLIGHT.TYPED],
icon: [engine.iconURI ? engine.iconURI.spec : null], icon: [engine.iconURI ? engine.iconURI.spec : null],
inPrivateWindow: true, inPrivateWindow: true,
isPrivateEngine, isPrivateEngine,

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

@ -93,6 +93,7 @@ async function AssertPrivateResult(win, engine, isPrivateEngine) {
engine.name, engine.name,
"Check the search engine" "Check the search engine"
); );
return result;
} }
add_task(async function test_nonsearch() { add_task(async function test_nonsearch() {
@ -358,7 +359,7 @@ add_task(async function test_oneoff_selected_with_private_engine_keyboard() {
add_task(async function test_alias() { add_task(async function test_alias() {
info( info(
"Test that 'Search in a Private Window' doesn's appear if an alias is typed" "Test that 'Search in a Private Window' doesn't appear if an alias is typed"
); );
await UrlbarTestUtils.promiseAutocompleteResultPopup({ await UrlbarTestUtils.promiseAutocompleteResultPopup({
window, window,
@ -374,3 +375,51 @@ add_task(async function test_alias() {
}); });
await AssertNoPrivateResult(window); await AssertNoPrivateResult(window);
}); });
add_task(async function test_restrict() {
info(
"Test that 'Search in a Private Window' doesn's appear for just the restriction token"
);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
waitForFocus,
value: UrlbarTokenizer.RESTRICT.SEARCH,
});
await AssertNoPrivateResult(window);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
waitForFocus,
value: UrlbarTokenizer.RESTRICT.SEARCH + " ",
});
await AssertNoPrivateResult(window);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
waitForFocus,
value: " " + UrlbarTokenizer.RESTRICT.SEARCH,
});
await AssertNoPrivateResult(window);
});
add_task(async function test_restrict_search() {
info(
"Test that 'Search in a Private Window' has the right string with the restriction token"
);
let engine = await Services.search.getDefaultPrivate();
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
waitForFocus,
value: UrlbarTokenizer.RESTRICT.SEARCH + "test",
});
let result = await AssertPrivateResult(window, engine, true);
Assert.equal(result.searchParams.query, "test");
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
waitForFocus,
value: "test" + UrlbarTokenizer.RESTRICT.SEARCH,
});
result = await AssertPrivateResult(window, engine, true);
Assert.equal(result.searchParams.query, "test");
});