Backed out 2 changesets (bug 1908320) for causing wr failures on align-items-baseline...
[gecko.git] / remote / shared / RecommendedPreferences.sys.mjs
blob4c66ba4543c1f78e7a331a16ec83e5940ff90c6e
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
7 const lazy = {};
9 ChromeUtils.defineESModuleGetters(lazy, {
10   Log: "chrome://remote/content/shared/Log.sys.mjs",
11 });
13 XPCOMUtils.defineLazyPreferenceGetter(
14   lazy,
15   "useRecommendedPrefs",
16   "remote.prefs.recommended",
17   false
20 ChromeUtils.defineLazyGetter(lazy, "logger", () => lazy.Log.get());
22 // Ensure we are in the parent process.
23 if (Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
24   throw new Error(
25     "RecommendedPreferences should only be loaded in the parent process"
26   );
29 // ALL CHANGES TO THIS LIST MUST HAVE REVIEW FROM A WEBDRIVER PEER!
31 // Preferences are set for automation on startup, unless
32 // remote.prefs.recommended has been set to false.
34 // Note: Clients do not always use the latest version of the application. As
35 // such backward compatibility has to be ensured at least for the last three
36 // releases.
38 // INSTRUCTIONS TO ADD A NEW PREFERENCE
40 // Preferences for remote control and automation can be set from several entry
41 // points:
42 // - remote/shared/RecommendedPreferences.sys.mjs
43 // - remote/test/puppeteer/packages/browsers/src/browser-data/firefox.ts
44 // - testing/geckodriver/src/prefs.rs
45 // - testing/marionette/client/marionette_driver/geckoinstance.py
47 // The preferences in `firefox.ts`, `prefs.rs` and `geckoinstance.py`
48 // will be applied before the application starts, and should typically be used
49 // for preferences which cannot be updated during the lifetime of the application.
51 // The preferences in `RecommendedPreferences.sys.mjs` are applied after
52 // the application has started, which means that the application must apply this
53 // change dynamically and behave correctly. Note that you can also define
54 // protocol specific preferences (CDP, WebDriver, ...) which are merged with the
55 // COMMON_PREFERENCES from `RecommendedPreferences.sys.mjs`.
57 // Additionally, users relying on the Marionette Python client (ie. using
58 // geckoinstance.py) set `remote.prefs.recommended = false`. This means that
59 // preferences from `RecommendedPreferences.sys.mjs` are not applied and have to
60 // be added to the list of preferences in that Python file. Note that there are
61 // several lists of preferences, either common or specific to a given application
62 // (Firefox Desktop, Fennec, Thunderbird).
64 // Depending on how users interact with the Remote Agent, they will use different
65 // combinations of preferences. So it's important to update the preferences files
66 // so that all users have the proper preferences.
68 // When adding a new preference, follow this guide to decide where to add it:
69 // - Add the preference to `geckoinstance.py`
70 // - If the preference has to be set before startup:
71 //   - Add the preference to `prefs.rs`
72 //   - Add the preference `browser-data/firefox.ts` in the puppeteer folder
73 //   - Create a PR to upstream the change on `browser-data/firefox.ts` to puppeteer
74 // - Otherwise, if the preference can be set after startup:
75 //   - Add the preference to `RecommendedPreferences.sys.mjs`
76 const COMMON_PREFERENCES = new Map([
77   // Make sure Shield doesn't hit the network.
78   ["app.normandy.api_url", ""],
80   // Disable automatically upgrading Firefox
81   //
82   // Note: This preference should have already been set by the client when
83   // creating the profile. But if not and to absolutely make sure that updates
84   // of Firefox aren't downloaded and applied, enforce its presence.
85   ["app.update.disabledForTesting", true],
87   // Increase the APZ content response timeout in tests to 1 minute.
88   // This is to accommodate the fact that test environments tends to be
89   // slower than production environments (with the b2g emulator being
90   // the slowest of them all), resulting in the production timeout value
91   // sometimes being exceeded and causing false-positive test failures.
92   //
93   // (bug 1176798, bug 1177018, bug 1210465)
94   ["apz.content_response_timeout", 60000],
96   // Don't show the content blocking introduction panel.
97   // We use a larger number than the default 22 to have some buffer
98   // This can be removed once Firefox 69 and 68 ESR and are no longer supported.
99   ["browser.contentblocking.introCount", 99],
101   // Indicate that the download panel has been shown once so that
102   // whichever download test runs first doesn't show the popup
103   // inconsistently.
104   ["browser.download.panel.shown", true],
106   // Make sure newtab weather doesn't hit the network to retrieve weather data.
107   [
108     "browser.newtabpage.activity-stream.discoverystream.region-weather-config",
109     "",
110   ],
112   // Make sure newtab wallpapers don't hit the network to retrieve wallpaper data.
113   ["browser.newtabpage.activity-stream.newtabWallpapers.enabled", false],
114   ["browser.newtabpage.activity-stream.newtabWallpapers.v2.enabled", false],
116   // Make sure Topsites doesn't hit the network to retrieve sponsored tiles.
117   ["browser.newtabpage.activity-stream.showSponsoredTopSites", false],
119   // Always display a blank page
120   ["browser.newtabpage.enabled", false],
122   // Background thumbnails in particular cause grief, and disabling
123   // thumbnails in general cannot hurt
124   ["browser.pagethumbnails.capturing_disabled", true],
126   // Disable geolocation ping(#1)
127   ["browser.region.network.url", ""],
129   // Disable safebrowsing components.
130   //
131   // These should also be set in the profile prior to starting Firefox,
132   // as it is picked up at runtime.
133   ["browser.safebrowsing.blockedURIs.enabled", false],
134   ["browser.safebrowsing.downloads.enabled", false],
135   ["browser.safebrowsing.malware.enabled", false],
136   ["browser.safebrowsing.phishing.enabled", false],
138   // Disable updates to search engines.
139   //
140   // Should be set in profile.
141   ["browser.search.update", false],
143   // Do not restore the last open set of tabs if the browser has crashed
144   ["browser.sessionstore.resume_from_crash", false],
146   // Don't check for the default web browser during startup.
147   //
148   // These should also be set in the profile prior to starting Firefox,
149   // as it is picked up at runtime.
150   ["browser.shell.checkDefaultBrowser", false],
152   // Disable session restore infobar
153   ["browser.startup.couldRestoreSession.count", -1],
155   // Do not redirect user when a milstone upgrade of Firefox is detected
156   ["browser.startup.homepage_override.mstone", "ignore"],
158   // Unload the previously selected tab immediately
159   ["browser.tabs.remote.unloadDelayMs", 0],
161   // Don't unload tabs when available memory is running low
162   ["browser.tabs.unloadOnLowMemory", false],
164   // Do not warn when closing all open tabs
165   ["browser.tabs.warnOnClose", false],
167   // Do not warn when closing all other open tabs
168   ["browser.tabs.warnOnCloseOtherTabs", false],
170   // Do not warn when multiple tabs will be opened
171   ["browser.tabs.warnOnOpen", false],
173   // Don't show the Bookmarks Toolbar on any tab (the above pref that
174   // disables the New Tab Page ends up showing the toolbar on about:blank).
175   ["browser.toolbars.bookmarks.visibility", "never"],
177   // Make sure Topsites doesn't hit the network to retrieve tiles from Contile.
178   ["browser.topsites.contile.enabled", false],
180   // Disable first run splash page on Windows 10
181   ["browser.usedOnWindows10.introURL", ""],
183   // Turn off Merino suggestions in the location bar so as not to trigger
184   // network connections.
185   ["browser.urlbar.merino.endpointURL", ""],
187   // Turn off search suggestions in the location bar so as not to trigger
188   // network connections.
189   ["browser.urlbar.suggest.searches", false],
191   // Do not warn on quitting Firefox
192   ["browser.warnOnQuit", false],
194   // Do not show datareporting policy notifications which can
195   // interfere with tests
196   [
197     "datareporting.healthreport.documentServerURI",
198     "http://%(server)s/dummy/healthreport/",
199   ],
200   ["datareporting.healthreport.logging.consoleEnabled", false],
201   ["datareporting.healthreport.service.enabled", false],
202   ["datareporting.healthreport.service.firstRun", false],
203   ["datareporting.healthreport.uploadEnabled", false],
204   ["datareporting.policy.dataSubmissionEnabled", false],
205   ["datareporting.policy.dataSubmissionPolicyAccepted", false],
206   ["datareporting.policy.dataSubmissionPolicyBypassNotification", true],
208   // Disable popup-blocker
209   ["dom.disable_open_during_load", false],
211   // Enabling the support for File object creation in the content process
212   ["dom.file.createInChild", true],
214   // Disable delayed user input event handling
215   ["dom.input_events.security.minNumTicks", 0],
216   ["dom.input_events.security.minTimeElapsedInMS", 0],
218   // Disable the ProcessHangMonitor
219   ["dom.ipc.reportProcessHangs", false],
221   // Disable slow script dialogues
222   ["dom.max_chrome_script_run_time", 0],
223   ["dom.max_script_run_time", 0],
225   // Disable location change rate limitation
226   ["dom.navigation.locationChangeRateLimit.count", 0],
228   // DOM Push
229   ["dom.push.connection.enabled", false],
231   // Screen Orientation API
232   ["dom.screenorientation.allow-lock", true],
234   // Disable dialog abuse if alerts are triggered too quickly.
235   ["dom.successive_dialog_time_limit", 0],
237   // Only load extensions from the application and user profile
238   // AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
239   //
240   // Should be set in profile.
241   ["extensions.autoDisableScopes", 0],
242   ["extensions.enabledScopes", 5],
244   // Disable metadata caching for installed add-ons by default
245   ["extensions.getAddons.cache.enabled", false],
247   // Disable installing any distribution extensions or add-ons.
248   // Should be set in profile.
249   ["extensions.installDistroAddons", false],
251   // Turn off extension updates so they do not bother tests
252   ["extensions.update.enabled", false],
253   ["extensions.update.notifyUser", false],
255   // Make sure opening about:addons will not hit the network
256   ["extensions.getAddons.discovery.api_url", "data:, "],
258   // Redirect various extension update URLs
259   [
260     "extensions.blocklist.detailsURL",
261     "http://%(server)s/extensions-dummy/blocklistDetailsURL",
262   ],
263   [
264     "extensions.blocklist.itemURL",
265     "http://%(server)s/extensions-dummy/blocklistItemURL",
266   ],
267   ["extensions.hotfix.url", "http://%(server)s/extensions-dummy/hotfixURL"],
268   [
269     "extensions.systemAddon.update.url",
270     "http://%(server)s/dummy-system-addons.xml",
271   ],
272   [
273     "extensions.update.background.url",
274     "http://%(server)s/extensions-dummy/updateBackgroundURL",
275   ],
276   ["extensions.update.url", "http://%(server)s/extensions-dummy/updateURL"],
278   // Make sure opening about: addons won't hit the network
279   ["extensions.getAddons.discovery.api_url", "data:, "],
280   [
281     "extensions.getAddons.get.url",
282     "http://%(server)s/extensions-dummy/repositoryGetURL",
283   ],
284   [
285     "extensions.getAddons.search.browseURL",
286     "http://%(server)s/extensions-dummy/repositoryBrowseURL",
287   ],
289   // Allow the application to have focus even it runs in the background
290   ["focusmanager.testmode", true],
292   // Disable useragent updates
293   ["general.useragent.updates.enabled", false],
295   // Disable geolocation ping(#2)
296   ["geo.provider.network.url", ""],
298   // Always use network provider for geolocation tests so we bypass the
299   // macOS dialog raised by the corelocation provider
300   ["geo.provider.testing", true],
302   // Do not scan Wifi
303   ["geo.wifi.scan", false],
305   // Disable Firefox accounts ping
306   ["identity.fxaccounts.auth.uri", "https://{server}/dummy/fxa"],
308   // Disable connectivity service pings
309   ["network.connectivity-service.enabled", false],
311   // Do not prompt with long usernames or passwords in URLs
312   ["network.http.phishy-userpass-length", 255],
314   // Do not prompt for temporary redirects
315   ["network.http.prompt-temp-redirect", false],
317   // Do not automatically switch between offline and online
318   ["network.manage-offline-status", false],
320   // Make sure SNTP requests do not hit the network
321   ["network.sntp.pools", "%(server)s"],
323   // Privacy and Tracking Protection
324   ["privacy.trackingprotection.enabled", false],
326   // Used to check if recommended preferences are applied
327   ["remote.prefs.recommended.applied", true],
329   // Don't do network connections for mitm priming
330   ["security.certerrors.mitm.priming.enabled", false],
332   // Local documents have access to all other local documents,
333   // including directory listings
334   ["security.fileuri.strict_origin_policy", false],
336   // Tests do not wait for the notification button security delay
337   ["security.notification_enable_delay", 0],
339   // Do not download intermediate certificates
340   ["security.remote_settings.intermediates.enabled", false],
342   // Ensure remote settings do not hit the network
343   ["services.settings.server", "data:,#remote-settings-dummy/v1"],
345   // Do not automatically fill sign-in forms with known usernames and
346   // passwords
347   ["signon.autofillForms", false],
349   // Disable password capture, so that tests that include forms are not
350   // influenced by the presence of the persistent doorhanger notification
351   ["signon.rememberSignons", false],
353   // Disable first-run welcome page
354   ["startup.homepage_welcome_url", "about:blank"],
355   ["startup.homepage_welcome_url.additional", ""],
357   // Prevent starting into safe mode after application crashes
358   ["toolkit.startup.max_resumed_crashes", -1],
360   // Disable all telemetry pings
361   ["toolkit.telemetry.server", "https://%(server)s/telemetry-dummy/"],
363   // Disable window occlusion on Windows, which can prevent webdriver commands
364   // such as WebDriver:FindElements from working properly (Bug 1802473).
365   ["widget.windows.window_occlusion_tracking.enabled", false],
368 export const RecommendedPreferences = {
369   alteredPrefs: new Set(),
371   isInitialized: false,
373   /**
374    * Apply the provided map of preferences.
375    *
376    * Note, that they will be automatically reset on application shutdown.
377    *
378    * @param {Map<string, object>=} preferences
379    *     Map of preference name to preference value.
380    */
381   applyPreferences(preferences = new Map()) {
382     if (!lazy.useRecommendedPrefs) {
383       // If remote.prefs.recommended is set to false, do not set any preference
384       // here. Needed for our Firefox CI.
385       return;
386     }
388     // Only apply common recommended preferences on first call to
389     // applyPreferences.
390     if (!this.isInitialized) {
391       // Merge common preferences and optionally provided preferences in a
392       // single map. Hereby the extra preferences have higher priority.
393       preferences = new Map([...COMMON_PREFERENCES, ...preferences]);
395       Services.obs.addObserver(this, "quit-application");
396       this.isInitialized = true;
397     }
399     for (const [k, v] of preferences) {
400       if (!Services.prefs.prefHasUserValue(k)) {
401         lazy.logger.debug(`Setting recommended pref ${k} to ${v}`);
403         switch (typeof v) {
404           case "string":
405             Services.prefs.setStringPref(k, v);
406             break;
407           case "boolean":
408             Services.prefs.setBoolPref(k, v);
409             break;
410           case "number":
411             Services.prefs.setIntPref(k, v);
412             break;
413           default:
414             throw new TypeError(`Invalid preference type: ${typeof v}`);
415         }
417         // Keep track all the altered preferences to restore them on
418         // quit-application.
419         this.alteredPrefs.add(k);
420       }
421     }
422   },
424   observe(subject, topic) {
425     if (topic === "quit-application") {
426       Services.obs.removeObserver(this, "quit-application");
427       this.restoreAllPreferences();
428     }
429   },
431   /**
432    * Restore all the altered preferences.
433    */
434   restoreAllPreferences() {
435     this.restorePreferences(this.alteredPrefs);
436     this.isInitialized = false;
437   },
439   /**
440    * Restore provided preferences.
441    *
442    * @param {Map} preferences
443    *     Map of preferences that should be restored.
444    */
445   restorePreferences(preferences) {
446     for (const k of preferences.keys()) {
447       lazy.logger.debug(`Resetting recommended pref ${k}`);
448       Services.prefs.clearUserPref(k);
449       this.alteredPrefs.delete(k);
450     }
451   },