Backed out 2 changesets (bug 1819093) for causing bustage due to toolkitsearch.manifest. CLOSED TREE

Backed out changeset 0ebcef1f64fc (bug 1819093)
Backed out changeset a44650eb4094 (bug 1819093)
This commit is contained in:
Csoregi Natalia 2023-03-07 12:37:03 +02:00
Родитель 422f2645bd
Коммит 7cbf20e7cb
5 изменённых файлов: 48 добавлений и 150 удалений

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

@ -39,23 +39,12 @@ XPCOMUtils.defineLazyGetter(lazy, "logConsole", () => {
});
});
XPCOMUtils.defineLazyServiceGetter(
lazy,
"timerManager",
"@mozilla.org/updates/timer-manager;1",
"nsIUpdateTimerManager"
);
const TOPIC_LOCALES_CHANGE = "intl:app-locales-changed";
const QUIT_APPLICATION_TOPIC = "quit-application";
// The update timer for OpenSearch engines checks in once a day.
const OPENSEARCH_UPDATE_TIMER_TOPIC = "search-engine-update-timer";
const OPENSEARCH_UPDATE_TIMER_INTERVAL = 60 * 60 * 24;
// The default engine update interval, in days. This is only used if an engine
// specifies an updateURL, but not an updateInterval.
const OPENSEARCH_DEFAULT_UPDATE_INTERVAL = 7;
const SEARCH_DEFAULT_UPDATE_INTERVAL = 7;
// This is the amount of time we'll be idle for before applying any configuration
// changes.
@ -656,7 +645,6 @@ export class SearchService {
errCode || Cr.NS_ERROR_FAILURE
);
}
this.#maybeStartOpenSearchUpdateTimer();
return engine;
}
@ -911,19 +899,26 @@ export class SearchService {
);
}
/**
* This is a nsITimerCallback for the timerManager notification that is
* registered for handling updates to search engines. Only OpenSearch engines
* have these updates and hence, only those are handled here.
*/
notify() {
// nsITimerCallbactk
notify(timer) {
lazy.logConsole.debug("notify: checking for updates");
// Walk the engine list, looking for engines whose update time has expired.
if (
!Services.prefs.getBoolPref(
lazy.SearchUtils.BROWSER_SEARCH_PREF + "update",
true
)
) {
return;
}
// Our timer has expired, but unfortunately, we can't get any data from it.
// Therefore, we need to walk our engine-list, looking for expired engines
var currentTime = Date.now();
lazy.logConsole.debug("currentTime:" + currentTime);
for (let engine of this._engines.values()) {
if (!(engine instanceof lazy.OpenSearchEngine && engine._hasUpdates)) {
for (let e of this._engines.values()) {
let engine = e.wrappedJSObject;
if (!engine._hasUpdates) {
continue;
}
@ -1116,13 +1111,6 @@ export class SearchService {
*/
#observersAdded = false;
/**
* Keeps track to see if the OpenSearch update timer has been started or not.
*
* @type {boolean}
*/
#openSearchUpdateTimerStarted = false;
get #sortedEngines() {
if (!this._cachedSortedEngines) {
return this.#buildSortedEngineList();
@ -1360,8 +1348,6 @@ export class SearchService {
this.#checkNimbusPrefs(true);
});
this.#maybeStartOpenSearchUpdateTimer();
return this.#initRV;
}
@ -3497,43 +3483,11 @@ export class SearchService {
newCurrentEngine
);
}
/**
* Maybe starts the timer for OpenSearch engine updates. This will be set
* only if updates are enabled and there are OpenSearch engines installed
* which have updates.
*/
#maybeStartOpenSearchUpdateTimer() {
if (
this.#openSearchUpdateTimerStarted ||
!Services.prefs.getBoolPref(
lazy.SearchUtils.BROWSER_SEARCH_PREF + "update",
true
)
) {
return;
}
let engineWithUpdates = [...this._engines.values()].find(
engine => engine instanceof lazy.OpenSearchEngine && engine._hasUpdates
);
if (engineWithUpdates) {
lazy.logConsole.debug("Engine with updates found, setting update timer");
lazy.timerManager.registerTimer(
OPENSEARCH_UPDATE_TIMER_TOPIC,
this,
OPENSEARCH_UPDATE_TIMER_INTERVAL,
true
);
this.#openSearchUpdateTimerStarted = true;
}
}
} // end SearchService class
var engineUpdateService = {
scheduleNextUpdate(engine) {
var interval = engine._updateInterval || OPENSEARCH_DEFAULT_UPDATE_INTERVAL;
var interval = engine._updateInterval || SEARCH_DEFAULT_UPDATE_INTERVAL;
var milliseconds = interval * 86400000; // |interval| is in days
engine.setAttr("updateexpir", Date.now() + milliseconds);
},

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

@ -32,6 +32,10 @@ EXTRA_JS_MODULES += [
"UserSearchEngine.sys.mjs",
]
EXTRA_COMPONENTS += [
"toolkitsearch.manifest",
]
XPCOM_MANIFESTS += [
"components.conf",
]

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

@ -2,8 +2,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Dynamically create an OpenSearch search engine offering search suggestions
* via searchSuggestions.sjs.
* Dynamically create a search engine offering search suggestions via searchSuggestions.sjs.
*
* The engine is constructed by passing a JSON object with engine details as the query string.
*/
@ -34,8 +33,8 @@ function handleRequest(request, response) {
* Information about the search engine to write to the response.
*/
function createOpenSearchEngine(response, engineData) {
let params = "";
let queryString = "";
let params = "",
queryString = "";
if (engineData.method == "POST") {
params = "<Param name='q' value='{searchTerms}'/>";
} else {
@ -49,13 +48,6 @@ function createOpenSearchEngine(response, engineData) {
if (engineData.image) {
image = `<Image width="16" height="16">${engineData.baseURL}${engineData.image}</Image>`;
}
let updateFile = "";
if (engineData.updateFile) {
updateFile = `<Url type="application/opensearchdescription+xml"
rel="self"
template="${engineData.baseURL}${engineData.updateFile}" />
`;
}
let result = `<?xml version='1.0' encoding='utf-8'?>
<OpenSearchDescription xmlns='http://a9.com/-/spec/opensearch/1.1/'>
@ -70,7 +62,6 @@ function createOpenSearchEngine(response, engineData) {
</Url>
<Url type='text/html' method='${engineData.method}'
template='${engineData.baseURL}${queryString}'/>
${updateFile}
</OpenSearchDescription>
`;
response.write(result);

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

@ -5,87 +5,31 @@
"use strict";
const KEYWORD = "keyword";
let timerManager;
add_task(async function setup() {
let server = useHttpServer("");
server.registerContentType("sjs", "sjs");
useHttpServer();
await AddonTestUtils.promiseStartupManager();
await Services.search.init();
timerManager = Cc["@mozilla.org/updates/timer-manager;1"].getService(
Ci.nsIUpdateTimerManager
);
});
add_task(async function test_installEngine_with_updates_disabled() {
const engineData = {
baseURL: gDataUrl,
name: "test engine",
method: "GET",
updateFile: "opensearch/simple.xml",
};
Services.prefs.setBoolPref(SearchUtils.BROWSER_SEARCH_PREF + "update", false);
Assert.ok(
!("search-engine-update-timer" in timerManager.wrappedJSObject._timers),
"Should not have registered the update timer already"
);
await SearchTestUtils.promiseNewSearchEngine({
url: `${gDataUrl}data/engineMaker.sjs?${JSON.stringify(engineData)}`,
});
Assert.ok(
Services.search.getEngineByName("test engine"),
"Should have added the test engine."
);
Assert.ok(
!("search-engine-update-timer" in timerManager.wrappedJSObject._timers),
"Should have not registered the update timer when updates are disabled"
);
});
add_task(async function test_installEngine_with_updates_enabled() {
const engineData = {
baseURL: gDataUrl,
name: "original engine",
method: "GET",
updateFile: "opensearch/simple.xml",
};
Services.prefs.setBoolPref(SearchUtils.BROWSER_SEARCH_PREF + "update", true);
Assert.ok(
!("search-engine-update-timer" in timerManager.wrappedJSObject._timers),
"Should not have registered the update timer already"
);
add_task(async function test_engineUpdate() {
const KEYWORD = "keyword";
const ONE_DAY_IN_MS = 24 * 60 * 60 * 1000;
let engine = await SearchTestUtils.promiseNewSearchEngine({
url: `${gDataUrl}data/engineMaker.sjs?${JSON.stringify(engineData)}`,
url: `${gDataUrl}engine.xml`,
});
Assert.ok(
"search-engine-update-timer" in timerManager.wrappedJSObject._timers,
"Should have registered the update timer"
);
engine.alias = KEYWORD;
await Services.search.moveEngine(engine, 0);
Assert.ok(
!!Services.search.getEngineByName("original engine"),
"Should be able to get the engine by the original name"
);
Assert.ok(
!Services.search.getEngineByName("simple"),
!Services.search.getEngineByName("A second test engine"),
"Should not be able to get the engine by the new name"
);
});
add_task(async function test_engineUpdate() {
const ONE_DAY_IN_MS = 24 * 60 * 60 * 1000;
// can't have an accurate updateURL in the file since we can't know the test
// server origin, so manually set it
engine.wrappedJSObject._updateURL = gDataUrl + "engine2.xml";
let promiseUpdate = SearchTestUtils.promiseSearchNotification(
SearchUtils.MODIFIED_TYPE.CHANGED,
@ -94,27 +38,30 @@ add_task(async function test_engineUpdate() {
// set last update to 8 days ago, since the default interval is 7, then
// trigger an update
let engine = Services.search.getEngineByName("original engine");
engine.wrappedJSObject.setAttr("updateexpir", Date.now() - ONE_DAY_IN_MS * 8);
Services.search.QueryInterface(Ci.nsITimerCallback).notify(null);
await promiseUpdate;
let changedEngine = await promiseUpdate;
Assert.equal(engine.name, "simple", "Should have updated the engine's name");
Assert.equal(engine.alias, KEYWORD, "Should have kept the keyword");
Assert.equal(
engine.wrappedJSObject.getAttr("order"),
engine.name,
"A second test engine",
"Should have update the engines name"
);
Assert.equal(changedEngine.alias, KEYWORD, "Keyword not cleared by update");
Assert.equal(
changedEngine.wrappedJSObject.getAttr("order"),
1,
"Should have kept the order"
"Order not cleared by update"
);
Assert.ok(
!!Services.search.getEngineByName("simple"),
!!Services.search.getEngineByName("A second test engine"),
"Should be able to get the engine by the new name"
);
Assert.ok(
!Services.search.getEngineByName("original engine"),
!Services.search.getEngineByName("Test search engine"),
"Should not be able to get the engine by the old name"
);
});

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

@ -0,0 +1,2 @@
# 21600 == 6 hours
category update-timer nsSearchService @mozilla.org/browser/search-service;1,getService,search-engine-update-timer,browser.search.update.interval,21600