Skip to content

Commit b14035e

Browse files
committed
Bug 1693857 - [remote] Only apply custom preferences if provided. r=webdriver-reviewers,jdescottes
If we aren't checking that extra preferences are actually provided, we will fail completely in setting recommended preferences. Differential Revision: https://phabricator.services.mozilla.com/D198698
1 parent ac1ced1 commit b14035e

File tree

2 files changed

+49
-35
lines changed

2 files changed

+49
-35
lines changed

remote/shared/RecommendedPreferences.sys.mjs

+12-5
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,11 @@ export const RecommendedPreferences = {
356356

357357
/**
358358
* Apply the provided map of preferences.
359-
* They will be automatically reset on application shutdown.
360359
*
361-
* @param {Map} preferences
362-
* Map of preference key to preference value.
360+
* Note, that they will be automatically reset on application shutdown.
361+
*
362+
* @param {Map<string, object>=} preferences
363+
* Map of preference name to preference value.
363364
*/
364365
applyPreferences(preferences) {
365366
if (!lazy.useRecommendedPrefs) {
@@ -371,8 +372,14 @@ export const RecommendedPreferences = {
371372
// Only apply common recommended preferences on first call to
372373
// applyPreferences.
373374
if (!this.isInitialized) {
374-
// Merge common preferences and provided preferences in a single map.
375-
preferences = new Map([...COMMON_PREFERENCES, ...preferences]);
375+
// Merge common preferences and optionally provided preferences in a
376+
// single map. Hereby the extra preferences have higher priority.
377+
if (preferences) {
378+
preferences = new Map([...COMMON_PREFERENCES, ...preferences]);
379+
} else {
380+
preferences = COMMON_PREFERENCES;
381+
}
382+
376383
Services.obs.addObserver(this, "quit-application");
377384
this.isInitialized = true;
378385
}

remote/shared/test/xpcshell/test_RecommendedPreferences.js

+37-30
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const { RecommendedPreferences } = ChromeUtils.importESModule(
88

99
const COMMON_PREF = "toolkit.startup.max_resumed_crashes";
1010

11-
const MARIONETTE_PREF = "dom.disable_beforeunload";
12-
const MARIONETTE_RECOMMENDED_PREFS = new Map([[MARIONETTE_PREF, true]]);
11+
const PROTOCOL_1_PREF = "dom.disable_beforeunload";
12+
const PROTOCOL_1_RECOMMENDED_PREFS = new Map([[PROTOCOL_1_PREF, true]]);
1313

14-
const CDP_PREF = "browser.contentblocking.features.standard";
15-
const CDP_RECOMMENDED_PREFS = new Map([
16-
[CDP_PREF, "-tp,tpPrivate,cookieBehavior0,-cm,-fp"],
14+
const PROTOCOL_2_PREF = "browser.contentblocking.features.standard";
15+
const PROTOCOL_2_RECOMMENDED_PREFS = new Map([
16+
[PROTOCOL_2_PREF, "-tp,tpPrivate,cookieBehavior0,-cm,-fp"],
1717
]);
1818

1919
function cleanup() {
@@ -27,55 +27,62 @@ function cleanup() {
2727
// - via registerCleanupFunction in case a test crashes/times out
2828
registerCleanupFunction(cleanup);
2929

30-
add_task(async function test_RecommendedPreferences() {
30+
add_task(async function test_multipleClients() {
3131
info("Check initial values for the test preferences");
32-
checkPreferences({ cdp: false, common: false, marionette: false });
32+
checkPreferences({ common: false, protocol_1: false, protocol_2: false });
3333

34-
checkPreferences({ cdp: false, common: false, marionette: false });
34+
checkPreferences({ common: false, protocol_1: false, protocol_2: false });
3535

36-
info("Apply recommended preferences for a marionette client");
37-
RecommendedPreferences.applyPreferences(MARIONETTE_RECOMMENDED_PREFS);
38-
checkPreferences({ cdp: false, common: true, marionette: true });
36+
info("Apply recommended preferences for a protocol_1 client");
37+
RecommendedPreferences.applyPreferences(PROTOCOL_1_RECOMMENDED_PREFS);
38+
checkPreferences({ common: true, protocol_1: true, protocol_2: false });
3939

40-
info("Apply recommended preferences for a cdp client");
41-
RecommendedPreferences.applyPreferences(CDP_RECOMMENDED_PREFS);
42-
checkPreferences({ cdp: true, common: true, marionette: true });
40+
info("Apply recommended preferences for a protocol_2 client");
41+
RecommendedPreferences.applyPreferences(PROTOCOL_2_RECOMMENDED_PREFS);
42+
checkPreferences({ common: true, protocol_1: true, protocol_2: true });
4343

44-
info("Restore marionette preferences");
45-
RecommendedPreferences.restorePreferences(MARIONETTE_RECOMMENDED_PREFS);
46-
checkPreferences({ cdp: true, common: true, marionette: false });
44+
info("Restore protocol_1 preferences");
45+
RecommendedPreferences.restorePreferences(PROTOCOL_1_RECOMMENDED_PREFS);
46+
checkPreferences({ common: true, protocol_1: false, protocol_2: true });
4747

48-
info("Restore cdp preferences");
49-
RecommendedPreferences.restorePreferences(CDP_RECOMMENDED_PREFS);
50-
checkPreferences({ cdp: false, common: true, marionette: false });
48+
info("Restore protocol_2 preferences");
49+
RecommendedPreferences.restorePreferences(PROTOCOL_2_RECOMMENDED_PREFS);
50+
checkPreferences({ common: true, protocol_1: false, protocol_2: false });
5151

5252
info("Restore all the altered preferences");
5353
RecommendedPreferences.restoreAllPreferences();
54-
checkPreferences({ cdp: false, common: false, marionette: false });
54+
checkPreferences({ common: false, protocol_1: false, protocol_2: false });
5555

5656
info("Attemps to restore again");
5757
RecommendedPreferences.restoreAllPreferences();
58-
checkPreferences({ cdp: false, common: false, marionette: false });
58+
checkPreferences({ common: false, protocol_1: false, protocol_2: false });
5959

6060
cleanup();
6161
});
6262

63-
add_task(async function test_RecommendedPreferences_disabled() {
63+
add_task(async function test_disabled() {
6464
info("Disable RecommendedPreferences");
6565
Services.prefs.setBoolPref("remote.prefs.recommended", false);
6666

6767
info("Check initial values for the test preferences");
68-
checkPreferences({ cdp: false, common: false, marionette: false });
68+
checkPreferences({ common: false, protocol_1: false, protocol_2: false });
6969

7070
info("Recommended preferences are not applied, applyPreferences is a no-op");
71-
RecommendedPreferences.applyPreferences(MARIONETTE_RECOMMENDED_PREFS);
72-
checkPreferences({ cdp: false, common: false, marionette: false });
71+
RecommendedPreferences.applyPreferences(PROTOCOL_1_RECOMMENDED_PREFS);
72+
checkPreferences({ common: false, protocol_1: false, protocol_2: false });
73+
74+
cleanup();
75+
});
76+
77+
add_task(async function test_noCustomPreferences() {
78+
info("Applying preferences without any custom preference should not throw");
79+
RecommendedPreferences.applyPreferences();
7380

7481
cleanup();
7582
});
7683

7784
// Check that protocols can override common preferences.
78-
add_task(async function test_RecommendedPreferences_override() {
85+
add_task(async function test_override() {
7986
info("Make sure the common preference has no user value");
8087
Services.prefs.clearUserPref(COMMON_PREF);
8188

@@ -94,10 +101,10 @@ add_task(async function test_RecommendedPreferences_override() {
94101
cleanup();
95102
});
96103

97-
function checkPreferences({ cdp, common, marionette }) {
104+
function checkPreferences({ common, protocol_1, protocol_2 }) {
98105
checkPreference(COMMON_PREF, { hasValue: common });
99-
checkPreference(MARIONETTE_PREF, { hasValue: marionette });
100-
checkPreference(CDP_PREF, { hasValue: cdp });
106+
checkPreference(PROTOCOL_1_PREF, { hasValue: protocol_1 });
107+
checkPreference(PROTOCOL_2_PREF, { hasValue: protocol_2 });
101108
}
102109

103110
function checkPreference(pref, { hasValue }) {

0 commit comments

Comments
 (0)