This repository has been archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1599840 - part 2 - Set restricting behavior based on QueryContext…
… sources. r=adw Differential Revision: https://phabricator.services.mozilla.com/D56354
- Loading branch information
Showing
12 changed files
with
180 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
browser/components/urlbar/tests/unit/test_UrlbarQueryContext_restrictSource.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
/** | ||
* Test for restrictions set through UrlbarQueryContext.sources. | ||
*/ | ||
|
||
add_task(async function setup() { | ||
Services.prefs.setBoolPref("browser.urlbar.geoSpecificDefaults", false); | ||
let engine = await addTestSuggestionsEngine(); | ||
let oldDefaultEngine = await Services.search.getDefault(); | ||
Services.search.setDefault(engine); | ||
registerCleanupFunction(async () => | ||
Services.search.setDefault(oldDefaultEngine) | ||
); | ||
}); | ||
|
||
XPCOMUtils.defineLazyServiceGetter( | ||
this, | ||
"unifiedComplete", | ||
"@mozilla.org/autocomplete/search;1?name=unifiedcomplete", | ||
"nsIAutoCompleteSearch" | ||
); | ||
|
||
add_task(async function test_restrictions() { | ||
await PlacesTestUtils.addVisits([ | ||
{ uri: "http://history.com/", title: "match" }, | ||
]); | ||
await PlacesUtils.bookmarks.insert({ | ||
url: "http://bookmark.com/", | ||
parentGuid: PlacesUtils.bookmarks.unfiledGuid, | ||
title: "match", | ||
}); | ||
await UrlbarProviderOpenTabs.registerOpenTab("http://openpagematch.com/"); | ||
|
||
info("Bookmark restrict"); | ||
let results = await get_results({ | ||
sources: [UrlbarUtils.RESULT_SOURCE.BOOKMARKS], | ||
searchString: "match", | ||
}); | ||
// Skip the heuristic result. | ||
Assert.deepEqual(results.filter(r => !r.heuristic).map(r => r.payload.url), [ | ||
"http://bookmark.com/", | ||
]); | ||
|
||
info("History restrict"); | ||
results = await get_results({ | ||
sources: [UrlbarUtils.RESULT_SOURCE.HISTORY], | ||
searchString: "match", | ||
}); | ||
// Skip the heuristic result. | ||
Assert.deepEqual(results.filter(r => !r.heuristic).map(r => r.payload.url), [ | ||
"http://history.com/", | ||
]); | ||
|
||
info("tabs restrict"); | ||
results = await get_results({ | ||
sources: [UrlbarUtils.RESULT_SOURCE.TABS], | ||
searchString: "match", | ||
}); | ||
// Skip the heuristic result. | ||
Assert.deepEqual(results.filter(r => !r.heuristic).map(r => r.payload.url), [ | ||
"http://openpagematch.com/", | ||
]); | ||
|
||
info("search restrict"); | ||
results = await get_results({ | ||
sources: [UrlbarUtils.RESULT_SOURCE.SEARCH], | ||
searchString: "match", | ||
}); | ||
// Heuristic, private window, 2 suggestions. | ||
Assert.deepEqual( | ||
results.map(r => r.payload.engine), | ||
new Array(4).fill("engine-suggestions.xml") | ||
); | ||
}); | ||
|
||
async function get_results(test) { | ||
let controller = UrlbarTestUtils.newMockController(); | ||
let queryContext = createContext(test.searchString, { | ||
allowAutofill: false, | ||
isPrivate: false, | ||
maxResults: 10, | ||
sources: test.sources, | ||
}); | ||
await controller.startQuery(queryContext); | ||
info(JSON.stringify(queryContext.results)); | ||
return queryContext.results; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters