Commit 9db98ad6 authored by Noemi Erli's avatar Noemi Erli
Browse files

Backed out changeset f706ae697922 (bug 1541317) for failures in...

Backed out changeset f706ae697922 (bug 1541317) for failures in test_ext_settings_overrides_search.js
parent 49c82ac7
......@@ -181,14 +181,14 @@ this.chrome_settings_overrides = class extends ExtensionAPI {
let homepageUrl = manifest.chrome_settings_overrides.homepage;
if (homepageUrl) {
// Determine inControl before applying any update so that if a controlling extension
// updates its homepage url, the pref will get updated properly.
let item = await ExtensionPreferencesManager.getSetting("homepage_override");
let inControl = item && (item.id == extension.id);
if (["ADDON_INSTALL", "ADDON_ENABLE", "ADDON_UPGRADE"].includes(extension.startupReason)) {
const setAsCurrentHomepage = inControl || extension.startupReason === "ADDON_INSTALL";
let inControl;
if (extension.startupReason == "ADDON_INSTALL" ||
extension.startupReason == "ADDON_ENABLE") {
inControl = await ExtensionPreferencesManager.setSetting(
extension.id, "homepage_override", homepageUrl, setAsCurrentHomepage);
extension.id, "homepage_override", homepageUrl);
} else {
let item = await ExtensionPreferencesManager.getSetting("homepage_override");
inControl = item.id == extension.id;
}
// We need to add the listener here too since onPrefsChanged won't trigger on a
// restart (the prefs are already set).
......
"use strict";
/* exported createHttpServer, promiseConsoleOutput, delay */
/* exported createHttpServer, promiseConsoleOutput */
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
......@@ -16,15 +16,10 @@ XPCOMUtils.defineLazyModuleGetters(this, {
NetUtil: "resource://gre/modules/NetUtil.jsm",
Schemas: "resource://gre/modules/Schemas.jsm",
TestUtils: "resource://testing-common/TestUtils.jsm",
setTimeout: "resource://gre/modules/Timer.jsm",
});
Services.prefs.setBoolPref("extensions.webextensions.remote", false);
function delay(ms = 0) {
return new Promise(resolve => setTimeout(resolve, ms));
}
ExtensionTestUtils.init(this);
......
......@@ -5,28 +5,16 @@
const {AddonTestUtils} = ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm");
const {HomePage} = ChromeUtils.import("resource:///modules/HomePage.jsm");
const {
createAppInfo,
promiseShutdownManager,
promiseStartupManager,
} = AddonTestUtils;
AddonTestUtils.init(this);
AddonTestUtils.overrideCertDB();
AddonTestUtils.createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
const HOMEPAGE_URL_PREF = "browser.startup.homepage";
function promisePrefChanged(value) {
return new Promise((resolve, reject) => {
Services.prefs.addObserver(HOMEPAGE_URL_PREF, function observer() {
if (HomePage.get().endsWith(value)) {
Services.prefs.removeObserver(HOMEPAGE_URL_PREF, observer);
resolve();
}
});
});
}
add_task(async function startup() {
await AddonTestUtils.promiseStartupManager();
});
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
add_task(async function test_overrides_update_removal() {
/* This tests the scenario where the manifest key for homepage and/or
......@@ -36,6 +24,21 @@ add_task(async function test_overrides_update_removal() {
const EXTENSION_ID = "test_overrides_update@tests.mozilla.org";
const HOMEPAGE_URI = "webext-homepage-1.html";
const HOMEPAGE_URL_PREF = "browser.startup.homepage";
function promisePrefChanged(value) {
return new Promise((resolve, reject) => {
Services.prefs.addObserver(HOMEPAGE_URL_PREF, function observer() {
if (HomePage.get().endsWith(value)) {
Services.prefs.removeObserver(HOMEPAGE_URL_PREF, observer);
resolve();
}
});
});
}
await promiseStartupManager();
let extensionInfo = {
useAddonManager: "permanent",
manifest: {
......@@ -68,15 +71,10 @@ add_task(async function test_overrides_update_removal() {
equal(extension.version, "1.0", "The installed addon has the expected version.");
ok(HomePage.get().endsWith(HOMEPAGE_URI),
"Home page url is overridden by the extension.");
let engine = await Services.search.getDefault();
equal(engine.name, "DuckDuckGo",
equal((await Services.search.getDefault()).name,
"DuckDuckGo",
"Default engine is overridden by the extension");
// Extensions cannot change a built-in search engine.
let url = engine._getURLOfType("text/html").template;
equal(url, "https://duckduckgo.com/",
"Extension cannot override default engine search template.");
// test changing the homepage
extensionInfo.manifest = {
"version": "2.0",
"applications": {
......@@ -84,46 +82,13 @@ add_task(async function test_overrides_update_removal() {
"id": EXTENSION_ID,
},
},
"chrome_settings_overrides": {
"homepage": "webext-homepage-2.html",
"search_provider": {
"name": "DuckDuckGo",
"search_url": "https://example.org/?q={searchTerms}",
"is_default": true,
},
},
};
prefPromise = promisePrefChanged("webext-homepage-2.html");
await extension.upgrade(extensionInfo);
await AddonTestUtils.waitForSearchProviderStartup(extension);
await prefPromise;
equal(extension.version, "2.0", "The installed addon has the expected version.");
ok(HomePage.get().endsWith("webext-homepage-2.html"),
"Home page url is overridden by the extension.");
engine = await Services.search.getDefault();
equal(engine.name, "DuckDuckGo",
"Default engine is overridden by the extension");
url = engine._getURLOfType("text/html").template;
// Extensions cannot change a built-in search engine.
equal(url, "https://duckduckgo.com/",
"Default engine is overridden by the extension");
extensionInfo.manifest = {
"version": "3.0",
"applications": {
"gecko": {
"id": EXTENSION_ID,
},
},
};
prefPromise = promisePrefChanged(defaultHomepageURL);
await extension.upgrade(extensionInfo);
await prefPromise;
equal(extension.version, "3.0", "The updated addon has the expected version.");
equal(extension.version, "2.0", "The updated addon has the expected version.");
equal(HomePage.get(),
defaultHomepageURL,
"Home page url reverted to the default after update.");
......@@ -132,132 +97,6 @@ add_task(async function test_overrides_update_removal() {
"Default engine reverted to the default after update.");
await extension.unload();
});
add_task(async function test_overrides_update_adding() {
/* This tests the scenario where an addon adds support for
* a homepage or search service when upgrading. Neither
* should override existing entries for those when added
* in an upgrade. */
const EXTENSION_ID = "test_overrides_update@tests.mozilla.org";
const HOMEPAGE_URI = "webext-homepage-1.html";
let extensionInfo = {
useAddonManager: "permanent",
manifest: {
"version": "1.0",
"applications": {
"gecko": {
"id": EXTENSION_ID,
},
},
},
};
let extension = ExtensionTestUtils.loadExtension(extensionInfo);
let defaultHomepageURL = HomePage.get();
let defaultEngineName = (await Services.search.getDefault()).name;
await extension.startup();
equal(extension.version, "1.0", "The installed addon has the expected version.");
equal(HomePage.get(),
defaultHomepageURL,
"Home page url is the default after startup.");
equal((await Services.search.getDefault()).name,
defaultEngineName,
"Default engine is the default after startup.");
extensionInfo.manifest = {
"version": "2.0",
"applications": {
"gecko": {
"id": EXTENSION_ID,
},
},
"chrome_settings_overrides": {
"homepage": HOMEPAGE_URI,
"search_provider": {
"name": "MozSearch",
"search_url": "https://example.com/?q={searchTerms}",
"is_default": true,
},
},
};
await extension.upgrade(extensionInfo);
// The homepage pref shouldn't change here, we delay a tick to give
// a pref change a chance in case it were to happen.
await Promise.all([
AddonTestUtils.waitForSearchProviderStartup(extension),
delay(),
]);
equal(extension.version, "2.0", "The updated addon has the expected version.");
ok(HomePage.get().endsWith(defaultHomepageURL),
"Home page url is not overridden by the extension during upgrade.");
ok(!!Services.search.getEngineByName("MozSearch"),
"Engine was installed by extension");
// An upgraded extension adding a search engine cannot override
// the default engine.
equal((await Services.search.getDefault()).name,
defaultEngineName,
"Default engine is the default after startup.");
await extension.unload();
});
add_task(async function test_overrides_update_changing() {
/* This tests the scenario where the homepage url changes
* due to the upgrade. */
const EXTENSION_ID = "test_overrides_changing@tests.mozilla.org";
const HOMEPAGE_URI = "webext-homepage-1.html";
let extensionInfo = {
useAddonManager: "temporary",
manifest: {
"version": "1.0",
"applications": {
"gecko": {
"id": EXTENSION_ID,
},
},
"chrome_settings_overrides": {
"homepage": HOMEPAGE_URI,
},
},
};
let extension = ExtensionTestUtils.loadExtension(extensionInfo);
let prefPromise = promisePrefChanged(HOMEPAGE_URI);
await extension.startup();
await prefPromise;
equal(extension.version, "1.0", "The installed addon has the expected version.");
ok(HomePage.get().endsWith(HOMEPAGE_URI),
"Home page url is the default after startup.");
extensionInfo.manifest = {
"version": "2.0",
"applications": {
"gecko": {
"id": EXTENSION_ID,
},
},
"chrome_settings_overrides": {
"homepage": HOMEPAGE_URI + ".2",
},
};
prefPromise = promisePrefChanged(HOMEPAGE_URI + ".2");
await extension.upgrade(extensionInfo);
await prefPromise;
equal(extension.version, "2.0", "The updated addon has the expected version.");
ok(HomePage.get().endsWith(HOMEPAGE_URI + ".2"),
"Home page url is not overridden by the extension during upgrade.");
await extension.unload();
await promiseShutdownManager();
});
......@@ -96,6 +96,7 @@ add_task(async function test_extension_adding_engine_with_spaces() {
ok(!engine, "Engine should not exist");
});
add_task(async function test_upgrade_default_position_engine() {
let ext1 = ExtensionTestUtils.loadExtension({
manifest: {
......@@ -194,61 +195,3 @@ add_task(async function test_extension_post_params() {
await ext1.unload();
});
// Test that an upgrade changing the search engine url will work.
add_task(async function test_upgrade_searchengine_url() {
let ext1 = ExtensionTestUtils.loadExtension({
manifest: {
"chrome_settings_overrides": {
"search_provider": {
"name": "MozSearch",
"keyword": "MozSearch",
"search_url": "https://example.com/?q={searchTerms}",
},
},
"applications": {
"gecko": {
"id": "testengine@mozilla.com",
},
},
"version": "0.1",
},
useAddonManager: "temporary",
});
await ext1.startup();
await AddonTestUtils.waitForSearchProviderStartup(ext1);
let engine = await Services.search.getDefault();
equal(engine.name, "MozSearch", "engine is default");
let url = engine._getURLOfType("text/html").template;
equal(url, "https://example.com/?q={searchTerms}",
"engine url is correct");
await ext1.upgrade({
manifest: {
"chrome_settings_overrides": {
"search_provider": {
"name": "MozSearch",
"keyword": "MozSearch",
"search_url": "https://example.org/?q={searchTerms}",
},
},
"applications": {
"gecko": {
"id": "testengine@mozilla.com",
},
},
"version": "0.2",
},
useAddonManager: "temporary",
});
await AddonTestUtils.waitForSearchProviderStartup(ext1);
engine = await Services.search.getDefault();
equal(engine.name, "MozSearch", "engine is default");
url = engine._getURLOfType("text/html").template;
equal(url, "https://example.org/?q={searchTerms}",
"engine url is correct");
await ext1.unload();
});
......@@ -185,19 +185,17 @@ this.ExtensionPreferencesManager = {
* @param {any} value
* The value to be stored in the settings store for this
* group of preferences.
* @param {boolean} setPref
* Update the prefs after adding the setting. Defaults to true.
*
* @returns {Promise}
* Resolves to true if the preferences were changed and to false if
* the preferences were not changed.
*/
async setSetting(id, name, value, setPref = true) {
async setSetting(id, name, value) {
let setting = settingsMap.get(name);
await ExtensionSettingsStore.initialize();
let item = await ExtensionSettingsStore.addSetting(
id, STORE_TYPE, name, value, initialValueCallback.bind(setting));
if (item && setPref) {
if (item) {
setPrefs(setting, item);
return true;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment