зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
8fb59cb8ed
Коммит
d6c6a3496f
|
@ -19,6 +19,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
SkippableTimer: "resource:///modules/UrlbarUtils.jsm",
|
||||
UrlbarProvider: "resource:///modules/UrlbarUtils.jsm",
|
||||
UrlbarResult: "resource:///modules/UrlbarResult.jsm",
|
||||
UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.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.
|
||||
*/
|
||||
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) {
|
||||
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 = {};
|
||||
this.queries.set(queryContext, instance);
|
||||
|
||||
|
@ -122,7 +145,7 @@ class ProviderPrivateSearch extends UrlbarProvider {
|
|||
UrlbarUtils.RESULT_SOURCE.SEARCH,
|
||||
...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, {
|
||||
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],
|
||||
inPrivateWindow: true,
|
||||
isPrivateEngine,
|
||||
|
|
|
@ -93,6 +93,7 @@ async function AssertPrivateResult(win, engine, isPrivateEngine) {
|
|||
engine.name,
|
||||
"Check the search engine"
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
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() {
|
||||
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({
|
||||
window,
|
||||
|
@ -374,3 +375,51 @@ add_task(async function test_alias() {
|
|||
});
|
||||
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");
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче