Bug 1679890 - Change UrlbarProviderExtension.notificationTimeout into a pref. r=adw

Differential Revision: https://phabricator.services.mozilla.com/D98253
This commit is contained in:
harry 2020-12-01 05:35:45 +00:00
Родитель 56aff226ee
Коммит 9e16e8ed83
4 изменённых файлов: 18 добавлений и 32 удалений

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

@ -3,7 +3,6 @@
XPCOMUtils.defineLazyModuleGetters(this, {
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
PlacesTestUtils: "resource://testing-common/PlacesTestUtils.jsm",
UrlbarProviderExtension: "resource:///modules/UrlbarProviderExtension.jsm",
UrlbarProvidersManager: "resource:///modules/UrlbarProvidersManager.jsm",
UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.jsm",
});
@ -93,10 +92,8 @@ async function updateTopSites(condition, searchShortcuts = false) {
add_task(async function setUp() {
// Set the notification timeout to a really high value to avoid intermittent
// failures due to the mock extensions not responding in time.
let originalTimeout = UrlbarProviderExtension.notificationTimeout;
UrlbarProviderExtension.notificationTimeout = 5000;
registerCleanupFunction(() => {
UrlbarProviderExtension.notificationTimeout = originalTimeout;
await SpecialPowers.pushPrefEnv({
set: [["browser.urlbar.extension.timeout", 5000]],
});
});

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

@ -7,7 +7,6 @@ const { AddonTestUtils } = ChromeUtils.import(
XPCOMUtils.defineLazyModuleGetters(this, {
ExtensionParent: "resource://gre/modules/ExtensionParent.jsm",
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
UrlbarProviderExtension: "resource:///modules/UrlbarProviderExtension.jsm",
UrlbarProvidersManager: "resource:///modules/UrlbarProvidersManager.jsm",
UrlbarQueryContext: "resource:///modules/UrlbarUtils.jsm",
UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.jsm",
@ -47,9 +46,6 @@ function getPayload(result) {
return payload;
}
const ORIGINAL_NOTIFICATION_TIMEOUT =
UrlbarProviderExtension.notificationTimeout;
add_task(async function startup() {
Services.prefs.setCharPref("browser.search.region", "US");
Services.prefs.setIntPref("browser.search.addonLoadTimeout", 0);
@ -57,6 +53,14 @@ add_task(async function startup() {
"browser.search.separatePrivateDefault.ui.enabled",
false
);
// Set the notification timeout to a really high value to avoid intermittent
// failures due to the mock extensions not responding in time.
Services.prefs.setIntPref("browser.urlbar.extension.timeout", 5000);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("browser.urlbar.extension.timeout");
});
await AddonTestUtils.promiseStartupManager();
await UrlbarTestUtils.initXPCShellDependencies();
@ -68,10 +72,6 @@ add_task(async function startup() {
alias: "@testengine",
});
Services.search.defaultEngine = engine;
// Set the notification timeout to a really high value to avoid intermittent
// failures due to the mock extensions not responding in time.
UrlbarProviderExtension.notificationTimeout = 5000;
});
// Extensions must specify the "urlbar" permission to use browser.urlbar.
@ -1090,10 +1090,9 @@ add_task(async function test_onBehaviorRequestedTimeout() {
});
let controller = UrlbarTestUtils.newMockController();
let currentTimeout = UrlbarProviderExtension.notificationTimeout;
UrlbarProviderExtension.notificationTimeout = 0;
Services.prefs.setIntPref("browser.urlbar.extension.timeout", 0);
await controller.startQuery(context);
UrlbarProviderExtension.notificationTimeout = currentTimeout;
Services.prefs.clearUserPref("browser.urlbar.extension.timeout");
// Check isActive and priority.
Assert.ok(!provider.isActive(context));
@ -1150,15 +1149,7 @@ add_task(async function test_onResultsRequestedTimeout() {
});
let controller = UrlbarTestUtils.newMockController();
// Set the notification timeout. In test_onBehaviorRequestedTimeout above, we
// could set it to 0 because we were testing onBehaviorRequested, which is
// fired first. Here we're testing onResultsRequested, which is fired after
// onBehaviorRequested. So we must first respond to onBehaviorRequested but
// then time out on onResultsRequested, and that's why the timeout can't be 0.
let currentTimeout = UrlbarProviderExtension.notificationTimeout;
UrlbarProviderExtension.notificationTimeout = ORIGINAL_NOTIFICATION_TIMEOUT;
await controller.startQuery(context);
UrlbarProviderExtension.notificationTimeout = currentTimeout;
// Check isActive and priority.
Assert.ok(provider.isActive(context));

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

@ -91,6 +91,10 @@ const PREF_URLBAR_DEFAULTS = new Map([
// Whether we style the search mode indicator's close button on hover.
["experimental.searchModeIndicatorHover", false],
// When we send events to extensions, we wait this amount of time in
// milliseconds for them to respond before timing out.
["extension.timeout", 200],
// When true, `javascript:` URLs are not included in search results.
["filter.javascript", true],

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

@ -17,6 +17,7 @@ const { XPCOMUtils } = ChromeUtils.import(
XPCOMUtils.defineLazyModuleGetters(this, {
Services: "resource://gre/modules/Services.jsm",
SkippableTimer: "resource:///modules/UrlbarUtils.jsm",
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
UrlbarProvider: "resource:///modules/UrlbarUtils.jsm",
UrlbarProvidersManager: "resource:///modules/UrlbarProvidersManager.jsm",
UrlbarResult: "resource:///modules/UrlbarResult.jsm",
@ -24,11 +25,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
// When we send events to extensions, we wait this amount of time in ms for them
// to respond before timing out. Tests can override this by setting
// UrlbarProviderExtension.notificationTimeout.
const DEFAULT_NOTIFICATION_TIMEOUT = 200;
/**
* The browser.urlbar extension API allows extensions to create their own urlbar
* providers. The results from extension providers are integrated into the
@ -284,7 +280,7 @@ class UrlbarProviderExtension extends UrlbarProvider {
// so that we're not stuck waiting forever.
let timer = new SkippableTimer({
name: "UrlbarProviderExtension notification timer",
time: UrlbarProviderExtension.notificationTimeout,
time: UrlbarPrefs.get("extension.timeout"),
reportErrorOnTimeout: true,
logger: this.logger,
});
@ -389,5 +385,3 @@ UrlbarProviderExtension.SOURCE_TYPES = {
search: UrlbarUtils.RESULT_SOURCE.SEARCH,
tabs: UrlbarUtils.RESULT_SOURCE.TABS,
};
UrlbarProviderExtension.notificationTimeout = DEFAULT_NOTIFICATION_TIMEOUT;