"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "browser/components/preferences/tests/browser_connection_dnsoverhttps.js" between
firefox-90.0.1.source.tar.xz and firefox-90.0.2.source.tar.xz

About: Firefox is Mozilla’s standalone Web browser. Source code.

browser_connection_dnsoverhttps.js  (firefox-90.0.1.source.tar.xz):browser_connection_dnsoverhttps.js  (firefox-90.0.2.source.tar.xz)
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
requestLongerTimeout(2);
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter( ChromeUtils.defineModuleGetter(
this, this,
"DoHController", "DoHController",
"resource:///modules/DoHController.jsm" "resource:///modules/DoHController.jsm"
); );
ChromeUtils.defineModuleGetter(
this,
"DoHConfigController",
"resource:///modules/DoHConfig.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"DoHTestUtils",
"resource://testing-common/DoHTestUtils.jsm"
);
const SUBDIALOG_URL = const SUBDIALOG_URL =
"chrome://browser/content/preferences/dialogs/connection.xhtml"; "chrome://browser/content/preferences/dialogs/connection.xhtml";
const TRR_MODE_PREF = "network.trr.mode"; const TRR_MODE_PREF = "network.trr.mode";
const TRR_URI_PREF = "network.trr.uri"; const TRR_URI_PREF = "network.trr.uri";
const TRR_RESOLVERS_PREF = "network.trr.resolvers";
const TRR_CUSTOM_URI_PREF = "network.trr.custom_uri"; const TRR_CUSTOM_URI_PREF = "network.trr.custom_uri";
const ROLLOUT_ENABLED_PREF = "doh-rollout.enabled"; const ROLLOUT_ENABLED_PREF = "doh-rollout.enabled";
const ROLLOUT_SELF_ENABLED_PREF = "doh-rollout.self-enabled"; const ROLLOUT_SELF_ENABLED_PREF = "doh-rollout.self-enabled";
const HEURISTICS_DISABLED_PREF = "doh-rollout.disable-heuristics"; const HEURISTICS_DISABLED_PREF = "doh-rollout.disable-heuristics";
const DEFAULT_RESOLVER_VALUE = "https://mozilla.cloudflare-dns.com/dns-query"; const FIRST_RESOLVER_VALUE = DoHTestUtils.providers[0].uri;
const NEXTDNS_RESOLVER_VALUE = "https://firefox.dns.nextdns.io/"; const SECOND_RESOLVER_VALUE = DoHTestUtils.providers[1].uri;
const DEFAULT_RESOLVER_VALUE = FIRST_RESOLVER_VALUE;
const modeCheckboxSelector = "#networkDnsOverHttps"; const modeCheckboxSelector = "#networkDnsOverHttps";
const uriTextboxSelector = "#networkCustomDnsOverHttpsInput"; const uriTextboxSelector = "#networkCustomDnsOverHttpsInput";
const resolverMenulistSelector = "#networkDnsOverHttpsResolverChoices"; const resolverMenulistSelector = "#networkDnsOverHttpsResolverChoices";
const defaultPrefValues = Object.freeze({ const defaultPrefValues = Object.freeze({
[TRR_MODE_PREF]: 0, [TRR_MODE_PREF]: 0,
[TRR_URI_PREF]: "https://mozilla.cloudflare-dns.com/dns-query",
[TRR_RESOLVERS_PREF]: JSON.stringify([
{ name: "Cloudflare", url: DEFAULT_RESOLVER_VALUE },
{ name: "example.org", url: "https://example.org/dns-query" },
]),
[TRR_CUSTOM_URI_PREF]: "", [TRR_CUSTOM_URI_PREF]: "",
}); });
async function resetPrefs() { async function resetPrefs() {
await DoHTestUtils.resetRemoteSettingsConfig();
await DoHController._uninit(); await DoHController._uninit();
Services.prefs.clearUserPref(TRR_MODE_PREF); Services.prefs.clearUserPref(TRR_MODE_PREF);
Services.prefs.clearUserPref(TRR_URI_PREF); Services.prefs.clearUserPref(TRR_URI_PREF);
Services.prefs.clearUserPref(TRR_RESOLVERS_PREF);
Services.prefs.clearUserPref(TRR_CUSTOM_URI_PREF); Services.prefs.clearUserPref(TRR_CUSTOM_URI_PREF);
Services.prefs.getChildList("doh-rollout.").forEach(pref => { Services.prefs.getChildList("doh-rollout.").forEach(pref => {
Services.prefs.clearUserPref(pref); Services.prefs.clearUserPref(pref);
}); });
// Clear out any telemetry events generated by DoHController so that we don't // Clear out any telemetry events generated by DoHController so that we don't
// confuse tests running after this one that are looking at those. // confuse tests running after this one that are looking at those.
Services.telemetry.clearEvents(); Services.telemetry.clearEvents();
await DoHController.init(); await DoHController.init();
} }
Services.prefs.setStringPref("network.trr.confirmationNS", "skip"); Services.prefs.setStringPref("network.trr.confirmationNS", "skip");
let preferencesOpen = new Promise(res => open_preferences(res)); let preferencesOpen = new Promise(res => open_preferences(res));
registerCleanupFunction(() => { registerCleanupFunction(async () => {
resetPrefs(); await resetPrefs();
gBrowser.removeCurrentTab(); gBrowser.removeCurrentTab();
Services.prefs.clearUserPref("network.trr.confirmationNS"); Services.prefs.clearUserPref("network.trr.confirmationNS");
}); });
async function openConnectionsSubDialog() { async function openConnectionsSubDialog() {
/* /*
The connection dialog has type="child", So it has to be opened as a sub dial og The connection dialog has type="child", So it has to be opened as a sub dial og
of the main pref tab. Prefs only get updated after the subdialog is confirme d & closed of the main pref tab. Prefs only get updated after the subdialog is confirme d & closed
*/ */
let dialog = await openAndLoadSubDialog(SUBDIALOG_URL); let dialog = await openAndLoadSubDialog(SUBDIALOG_URL);
skipping to change at line 125 skipping to change at line 137
} }
if (props.hasOwnProperty(TRR_CUSTOM_URI_PREF)) { if (props.hasOwnProperty(TRR_CUSTOM_URI_PREF)) {
Services.prefs.setStringPref( Services.prefs.setStringPref(
TRR_CUSTOM_URI_PREF, TRR_CUSTOM_URI_PREF,
props[TRR_CUSTOM_URI_PREF] props[TRR_CUSTOM_URI_PREF]
); );
} }
if (props.hasOwnProperty(TRR_URI_PREF)) { if (props.hasOwnProperty(TRR_URI_PREF)) {
Services.prefs.setStringPref(TRR_URI_PREF, props[TRR_URI_PREF]); Services.prefs.setStringPref(TRR_URI_PREF, props[TRR_URI_PREF]);
} }
if (props.hasOwnProperty(TRR_RESOLVERS_PREF)) {
info(`Setting ${TRR_RESOLVERS_PREF} to ${props[TRR_RESOLVERS_PREF]}`);
Services.prefs.setStringPref(TRR_RESOLVERS_PREF, props[TRR_RESOLVERS_PREF]);
}
let dialog = await openConnectionsSubDialog(); let dialog = await openConnectionsSubDialog();
await dialog.uiReady; await dialog.uiReady;
info( info(
Date.now() - startTime + ": testWithProperties: connections dialog now open" Date.now() - startTime + ": testWithProperties: connections dialog now open"
); );
let doc = dialog.document; let doc = dialog.document;
let win = doc.ownerGlobal; let win = doc.ownerGlobal;
let dialogElement = doc.getElementById("ConnectionsDialog"); let dialogElement = doc.getElementById("ConnectionsDialog");
let dialogClosingPromise = BrowserTestUtils.waitForEvent( let dialogClosingPromise = BrowserTestUtils.waitForEvent(
skipping to change at line 266 skipping to change at line 274
": testWithProperties: waiting for any of uri and mode prefs to change" ": testWithProperties: waiting for any of uri and mode prefs to change"
); );
await Promise.all([ await Promise.all([
uriPrefChangedPromise, uriPrefChangedPromise,
modePrefChangedPromise, modePrefChangedPromise,
disableHeuristicsPrefChangedPromise, disableHeuristicsPrefChangedPromise,
]); ]);
info(Date.now() - startTime + ": testWithProperties: prefs changed"); info(Date.now() - startTime + ": testWithProperties: prefs changed");
if (props.hasOwnProperty("expectedFinalUriPref")) { if (props.hasOwnProperty("expectedFinalUriPref")) {
let uriPref = Services.prefs.getStringPref(TRR_URI_PREF); if (props.expectedFinalUriPref) {
is( let uriPref = Services.prefs.getStringPref(TRR_URI_PREF);
uriPref, is(
props.expectedFinalUriPref, uriPref,
"uri pref ended up with the expected value" props.expectedFinalUriPref,
); "uri pref ended up with the expected value"
);
} else {
ok(
!Services.prefs.prefHasUserValue(TRR_URI_PREF),
"uri pref ended up with the expected value (unset)"
);
}
} }
if (props.hasOwnProperty("expectedModePref")) { if (props.hasOwnProperty("expectedModePref")) {
let modePref = Services.prefs.getIntPref(TRR_MODE_PREF); let modePref = Services.prefs.getIntPref(TRR_MODE_PREF);
is( is(
modePref, modePref,
props.expectedModePref, props.expectedModePref,
"mode pref ended up with the expected value" "mode pref ended up with the expected value"
); );
} }
skipping to change at line 308 skipping to change at line 323
props.expectedFinalCustomUriPref, props.expectedFinalCustomUriPref,
"custom_uri pref ended up with the expected value" "custom_uri pref ended up with the expected value"
); );
} }
info(Date.now() - startTime + ": testWithProperties: fin"); info(Date.now() - startTime + ": testWithProperties: fin");
} }
add_task(async function default_values() { add_task(async function default_values() {
let customUriPref = Services.prefs.getStringPref(TRR_CUSTOM_URI_PREF); let customUriPref = Services.prefs.getStringPref(TRR_CUSTOM_URI_PREF);
let uriPref = Services.prefs.getStringPref(TRR_URI_PREF); let uriPrefHasUserValue = Services.prefs.prefHasUserValue(TRR_URI_PREF);
let modePref = Services.prefs.getIntPref(TRR_MODE_PREF); let modePref = Services.prefs.getIntPref(TRR_MODE_PREF);
is( is(
modePref, modePref,
defaultPrefValues[TRR_MODE_PREF], defaultPrefValues[TRR_MODE_PREF],
`Actual value of ${TRR_MODE_PREF} matches expected default value` `Actual value of ${TRR_MODE_PREF} matches expected default value`
); );
is( ok(
uriPref, !uriPrefHasUserValue,
defaultPrefValues[TRR_URI_PREF], `Actual value of ${TRR_URI_PREF} matches expected default value (unset)`
`Actual value of ${TRR_URI_PREF} matches expected default value`
); );
is( is(
customUriPref, customUriPref,
defaultPrefValues[TRR_CUSTOM_URI_PREF], defaultPrefValues[TRR_CUSTOM_URI_PREF],
`Actual value of ${TRR_CUSTOM_URI_PREF} matches expected default value` `Actual value of ${TRR_CUSTOM_URI_PREF} matches expected default value`
); );
}); });
let testVariations = [ let testVariations = [
// verify state with defaults // verify state with defaults
{ name: "default", expectedModePref: 0, expectedUriValue: "" }, { name: "default", expectedModePref: 5, expectedUriValue: "" },
// verify each of the modes maps to the correct checked state // verify each of the modes maps to the correct checked state
{ name: "mode 0", [TRR_MODE_PREF]: 0, expectedModeChecked: false }, { name: "mode 0", [TRR_MODE_PREF]: 0, expectedModeChecked: false },
{ {
name: "mode 1", name: "mode 1",
[TRR_MODE_PREF]: 1, [TRR_MODE_PREF]: 1,
expectedModeChecked: false, expectedModeChecked: false,
expectedFinalUriPref: DEFAULT_RESOLVER_VALUE,
}, },
{ {
name: "mode 2", name: "mode 2",
[TRR_MODE_PREF]: 2, [TRR_MODE_PREF]: 2,
expectedModeChecked: true, expectedModeChecked: true,
expectedFinalUriPref: DEFAULT_RESOLVER_VALUE, expectedFinalUriPref: DEFAULT_RESOLVER_VALUE,
}, },
{ {
name: "mode 3", name: "mode 3",
[TRR_MODE_PREF]: 3, [TRR_MODE_PREF]: 3,
expectedModeChecked: true, expectedModeChecked: true,
expectedFinalUriPref: DEFAULT_RESOLVER_VALUE, expectedFinalUriPref: DEFAULT_RESOLVER_VALUE,
}, },
{ {
name: "mode 4", name: "mode 4",
[TRR_MODE_PREF]: 4, [TRR_MODE_PREF]: 4,
expectedModeChecked: false, expectedModeChecked: false,
expectedFinalUriPref: DEFAULT_RESOLVER_VALUE,
}, },
{ name: "mode 5", [TRR_MODE_PREF]: 5, expectedModeChecked: false }, { name: "mode 5", [TRR_MODE_PREF]: 5, expectedModeChecked: false },
// verify an out of bounds mode value maps to the correct checked state // verify an out of bounds mode value maps to the correct checked state
{ {
name: "mode out-of-bounds", name: "mode out-of-bounds",
[TRR_MODE_PREF]: 77, [TRR_MODE_PREF]: 77,
expectedModeChecked: false, expectedModeChecked: false,
}, },
// verify automatic heuristics states // verify automatic heuristics states
skipping to change at line 419 skipping to change at line 431
[ROLLOUT_ENABLED_PREF]: true, [ROLLOUT_ENABLED_PREF]: true,
expectedModeChecked: true, expectedModeChecked: true,
clickMode: true, clickMode: true,
expectedModePref: 5, expectedModePref: 5,
expectedDisabledHeuristics: true, expectedDisabledHeuristics: true,
}, },
// Test selecting non-default, non-custom TRR provider, NextDNS. // Test selecting non-default, non-custom TRR provider, NextDNS.
{ {
name: "Select NextDNS as TRR provider", name: "Select NextDNS as TRR provider",
[TRR_MODE_PREF]: 2, [TRR_MODE_PREF]: 2,
selectResolver: NEXTDNS_RESOLVER_VALUE, selectResolver: SECOND_RESOLVER_VALUE,
expectedFinalUriPref: NEXTDNS_RESOLVER_VALUE, expectedFinalUriPref: SECOND_RESOLVER_VALUE,
},
// Test selecting non-default, non-custom TRR provider, NextDNS,
// with DoH not enabled. The provider selection should stick.
{
name: "Select NextDNS as TRR provider in mode 0",
[TRR_MODE_PREF]: 0,
selectResolver: SECOND_RESOLVER_VALUE,
expectedFinalUriPref: SECOND_RESOLVER_VALUE,
}, },
{ {
name: "return to default from NextDNS", name: "return to default from NextDNS",
[TRR_MODE_PREF]: 2, [TRR_MODE_PREF]: 2,
[TRR_URI_PREF]: NEXTDNS_RESOLVER_VALUE, [TRR_URI_PREF]: SECOND_RESOLVER_VALUE,
expectedResolverListValue: NEXTDNS_RESOLVER_VALUE, expectedResolverListValue: SECOND_RESOLVER_VALUE,
selectResolver: DEFAULT_RESOLVER_VALUE, selectResolver: DEFAULT_RESOLVER_VALUE,
expectedFinalUriPref: DEFAULT_RESOLVER_VALUE, expectedFinalUriPref: DEFAULT_RESOLVER_VALUE,
}, },
// test that selecting Custom, when we have a TRR_CUSTOM_URI_PREF subsequently changes TRR_URI_PREF // test that selecting Custom, when we have a TRR_CUSTOM_URI_PREF subsequently changes TRR_URI_PREF
{ {
name: "select custom with existing custom_uri pref value", name: "select custom with existing custom_uri pref value",
[TRR_MODE_PREF]: 2, [TRR_MODE_PREF]: 2,
[TRR_CUSTOM_URI_PREF]: "https://example.com", [TRR_CUSTOM_URI_PREF]: "https://example.com",
expectedModeValue: true, expectedModeValue: true,
selectResolver: "custom", selectResolver: "custom",
skipping to change at line 477 skipping to change at line 497
[TRR_URI_PREF]: "https://example.com", [TRR_URI_PREF]: "https://example.com",
[TRR_CUSTOM_URI_PREF]: "https://example.com", [TRR_CUSTOM_URI_PREF]: "https://example.com",
expectedUriValue: "https://example.com", expectedUriValue: "https://example.com",
expectedResolverListValue: "custom", expectedResolverListValue: "custom",
inputUriKeys: "", inputUriKeys: "",
expectedFinalUriPref: DEFAULT_RESOLVER_VALUE, expectedFinalUriPref: DEFAULT_RESOLVER_VALUE,
expectedFinalCustomUriPref: "", expectedFinalCustomUriPref: "",
}, },
{ {
name: "empty default resolver list", name: "empty default resolver list",
[TRR_RESOLVERS_PREF]: "",
[TRR_MODE_PREF]: 2, [TRR_MODE_PREF]: 2,
[TRR_URI_PREF]: "https://example.com", [TRR_URI_PREF]: "https://example.com",
[TRR_CUSTOM_URI_PREF]: "", [TRR_CUSTOM_URI_PREF]: "",
[TRR_RESOLVERS_PREF]: "",
expectedUriValue: "https://example.com", expectedUriValue: "https://example.com",
expectedResolverListValue: "custom", expectedResolverListValue: "custom",
expectedFinalUriPref: "https://example.com", expectedFinalUriPref: "https://example.com",
expectedFinalCustomUriPref: "https://example.com", expectedFinalCustomUriPref: "https://example.com",
}, },
]; ];
for (let props of testVariations) { for (let props of testVariations) {
add_task(async function testVariation() { add_task(async function testVariation() {
await preferencesOpen; await preferencesOpen;
let startTime = Date.now(); let startTime = Date.now();
await resetPrefs();
info("starting test: " + props.name); info("starting test: " + props.name);
await testWithProperties(props, startTime); await testWithProperties(props, startTime);
await resetPrefs();
}); });
} }
add_task(async function testRemoteSettingsEnable() {
// Enable the rollout.
await DoHTestUtils.loadRemoteSettingsConfig({
providers: "example-1, example-2",
rolloutEnabled: true,
steeringEnabled: false,
steeringProviders: "",
autoDefaultEnabled: false,
autoDefaultProviders: "",
id: "global",
});
let doTest = async (cancelOrAccept = "cancel") => {
let dialog = await openConnectionsSubDialog();
await dialog.uiReady;
let doc = dialog.document;
let dialogElement = doc.getElementById("ConnectionsDialog");
let modeCheckbox = doc.querySelector(modeCheckboxSelector);
ok(modeCheckbox.checked, "The mode checkbox should be checked.");
let dialogClosingPromise = BrowserTestUtils.waitForEvent(
dialogElement,
"dialogclosing"
);
if (cancelOrAccept == "cancel") {
dialogElement.cancelDialog();
} else {
dialogElement.acceptDialog();
}
await dialogClosingPromise;
if (cancelOrAccept == "cancel") {
try {
await TestUtils.waitForCondition(() =>
Services.prefs.prefHasUserValue("doh-rollout.disable-heuristics")
);
ok(false, "Heuristics were disabled when they shouldn't have been!");
} catch (e) {
ok(true, "Heuristics remained enabled.");
}
is(Services.prefs.getStringPref("network.trr.uri"), "");
ok(!Services.prefs.prefHasUserValue("network.trr.mode"));
} else {
// If accepting, the chosen provider is persisted to network.trr.uri
// and heuristics should get disabled.
await TestUtils.waitForCondition(() =>
Services.prefs.prefHasUserValue("doh-rollout.disable-heuristics")
);
ok(
Services.prefs.getBoolPref("doh-rollout.disable-heuristics"),
"Heurstics were disabled."
);
is(
Services.prefs.getStringPref("network.trr.uri"),
DEFAULT_RESOLVER_VALUE
);
is(Services.prefs.getIntPref("network.trr.mode"), 2);
}
};
for (let action of ["cancel", "accept"]) {
await doTest(action);
}
});
 End of changes. 22 change blocks. 
36 lines changed or deleted 54 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)