mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 1835918 - Add test to check urlbar shows history and bookmark results when search service has failed to initialize. r=Standard8,mak
Differential Revision: https://phabricator.services.mozilla.com/D184866
This commit is contained in:
parent
594c41f9cc
commit
54a9eedf39
@ -0,0 +1,114 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* Tests history and bookmark results show up when search service
|
||||
* initialization has failed.
|
||||
*/
|
||||
|
||||
const { PromiseTestUtils } = ChromeUtils.importESModule(
|
||||
"resource://testing-common/PromiseTestUtils.sys.mjs"
|
||||
);
|
||||
|
||||
const searchService = Services.search.wrappedJSObject;
|
||||
|
||||
add_setup(async function setup() {
|
||||
searchService.willThrowErrorDuringInitInTest = true;
|
||||
|
||||
// When search service fails, we want the promise rejection to be uncaught
|
||||
// so we can continue running the test. 2147500037 is the exception message
|
||||
// for Cr.NS_ERROR_FAILURE.
|
||||
PromiseTestUtils.expectUncaughtRejection(/2147500037/);
|
||||
|
||||
registerCleanupFunction(async () => {
|
||||
searchService.willThrowErrorDuringInitInTest = false;
|
||||
await cleanupPlaces();
|
||||
});
|
||||
});
|
||||
|
||||
add_task(
|
||||
async function test_bookmark_results_are_shown_when_search_service_failed() {
|
||||
Assert.equal(
|
||||
searchService.isInitialized,
|
||||
false,
|
||||
"Search Service should not be initialized."
|
||||
);
|
||||
|
||||
info("Add a bookmark");
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
url: "http://cat.com/",
|
||||
title: "cat",
|
||||
});
|
||||
|
||||
let context = createContext("cat", {
|
||||
isPrivate: false,
|
||||
allowAutofill: false,
|
||||
});
|
||||
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeVisitResult(context, {
|
||||
uri: "http://cat/",
|
||||
heuristic: true,
|
||||
source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
|
||||
fallbackTitle: "http://cat/",
|
||||
}),
|
||||
makeBookmarkResult(context, {
|
||||
title: "cat",
|
||||
uri: "http://cat.com/",
|
||||
source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
Assert.equal(
|
||||
searchService.isInitialized,
|
||||
true,
|
||||
"Search Service should have finished its attempt to initialize."
|
||||
);
|
||||
|
||||
Assert.equal(
|
||||
searchService.hasSuccessfullyInitialized,
|
||||
false,
|
||||
"Search Service should have failed to initialize."
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
add_task(
|
||||
async function test_history_results_are_shown_when_search_service_failed() {
|
||||
Assert.equal(
|
||||
searchService.isInitialized,
|
||||
true,
|
||||
"Search Service should have finished its attempt to initialize in the previous test."
|
||||
);
|
||||
|
||||
Assert.equal(
|
||||
searchService.hasSuccessfullyInitialized,
|
||||
false,
|
||||
"Search Service should have failed to initialize."
|
||||
);
|
||||
|
||||
info("visit a url in history");
|
||||
await PlacesTestUtils.addVisits({
|
||||
uri: "http://example.com/",
|
||||
title: "example",
|
||||
});
|
||||
|
||||
let context = createContext("example", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
matches: [
|
||||
makeVisitResult(context, {
|
||||
type: 3,
|
||||
title: "example",
|
||||
uri: "http://example.com/",
|
||||
heuristic: true,
|
||||
source: UrlbarUtils.RESULT_SOURCE.HISTORY,
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
);
|
@ -34,6 +34,7 @@ prefs = places.frecency.origins.alternative.featureGate=true
|
||||
[test_frecency_alternative_nimbus.js]
|
||||
[test_heuristic_cancel.js]
|
||||
[test_hideSponsoredHistory.js]
|
||||
[test_history_bookmark_results_on_search_service_failure.js]
|
||||
[test_keywords.js]
|
||||
skip-if = os == 'linux' # bug 1474616
|
||||
[test_l10nCache.js]
|
||||
|
@ -463,6 +463,14 @@ export class SearchService {
|
||||
this.#initializationStatus = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test only variable to indicate an error should occur during
|
||||
* search service initialization.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
willThrowErrorDuringInitInTest = false;
|
||||
|
||||
// Test-only function to reset just the engine selector so that it can
|
||||
// load a different configuration.
|
||||
resetEngineSelector() {
|
||||
@ -1326,6 +1334,13 @@ export class SearchService {
|
||||
|
||||
let result = Cr.NS_OK;
|
||||
try {
|
||||
if (
|
||||
Services.env.exists("XPCSHELL_TEST_PROFILE_DIR") &&
|
||||
this.willThrowErrorDuringInitInTest
|
||||
) {
|
||||
throw new Error("Fake error during search service initialization.");
|
||||
}
|
||||
|
||||
// Create the search engine selector.
|
||||
this.#engineSelector = new lazy.SearchEngineSelector(
|
||||
this.#handleConfigurationUpdated.bind(this)
|
||||
|
Loading…
Reference in New Issue
Block a user