Bug 1495583 - Add a button to restore the default value for network.trr.uri preference. r=flod,jaws

This adds a button to the preferences UI to restore the default value for network.trr.uri preference.

Differential Revision: https://phabricator.services.mozilla.com/D11356

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Erica Wright 2018-11-09 03:44:03 +00:00
Родитель 6e53d58485
Коммит c327ca9308
6 изменённых файлов: 69 добавлений и 31 удалений

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

@ -35,6 +35,7 @@ Preferences.addAll([
{ id: "network.proxy.backup.socks_port", type: "int" },
{ id: "network.trr.mode", type: "int" },
{ id: "network.trr.uri", type: "string" },
{ id: "network.trr.custom_uri", "type": "string" },
]);
window.addEventListener("DOMContentLoaded", () => {
@ -55,6 +56,10 @@ window.addEventListener("DOMContentLoaded", () => {
var gConnectionsDialog = {
beforeAccept() {
if (document.getElementById("customDnsOverHttpsUrlRadio").selected) {
Services.prefs.setStringPref("network.trr.uri", document.getElementById("customDnsOverHttpsInput").value);
}
var proxyTypePref = Preferences.get("network.proxy.type");
if (proxyTypePref.value == 2) {
this.doAutoconfigURLFixup();
@ -304,16 +309,25 @@ var gConnectionsDialog = {
return trrModeCheckbox.checked ? 2 : 0;
},
writeDnsOverHttpsUri() {
// called to update pref with user input
let input = document.getElementById("networkDnsOverHttpsUrl");
let uriString = input.value.trim();
// turn an empty string into `undefined` to clear the pref back to the default
return uriString.length ? uriString : undefined;
updateDnsOverHttpsUI() {
// Disable the custom url input box if the parent checkbox and custom radio button attached to it is not selected.
// Disable the custom radio button if the parent checkbox is not selected.
let parentCheckbox = document.getElementById("networkDnsOverHttps");
let customDnsOverHttpsUrlRadio = document.getElementById("customDnsOverHttpsUrlRadio");
let customDnsOverHttpsInput = document.getElementById("customDnsOverHttpsInput");
customDnsOverHttpsInput.disabled = !parentCheckbox.checked || !customDnsOverHttpsUrlRadio.selected;
customDnsOverHttpsUrlRadio.disabled = !parentCheckbox.checked;
},
initDnsOverHttpsUI() {
let input = document.getElementById("networkDnsOverHttpsUrl");
input.placeholder = Preferences.get("network.trr.uri").defaultValue;
let defaultDnsOverHttpsUrlRadio = document.getElementById("defaultDnsOverHttpsUrlRadio");
let defaultPrefUrl = Preferences.get("network.trr.uri").defaultValue;
document.l10n.setAttributes(defaultDnsOverHttpsUrlRadio, "connection-dns-over-https-url-default", {
url: defaultPrefUrl,
});
defaultDnsOverHttpsUrlRadio.value = defaultPrefUrl;
let radioGroup = document.getElementById("DnsOverHttpsUrlRadioGroup");
radioGroup.selectedIndex = Preferences.get("network.trr.uri").hasUserValue ? 1 : 0;
this.updateDnsOverHttpsUI();
},
};

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

@ -152,11 +152,20 @@
data-l10n-id="connection-dns-over-https"
preference="network.trr.mode"
onsyncfrompreference="return gConnectionsDialog.readDnsOverHttpsMode();"
onsynctopreference="return gConnectionsDialog.writeDnsOverHttpsMode()" />
<hbox class="indent" flex="1" align="center">
<label control="networkDnsOverHttpsUrl" data-l10n-id="connection-dns-over-https-url"
data-l10n-attrs="tooltiptext"/>
<textbox id="networkDnsOverHttpsUrl" flex="1" preference="network.trr.uri"
onsynctopreference="return gConnectionsDialog.writeDnsOverHttpsUri()" />
</hbox>
onsynctopreference="return gConnectionsDialog.writeDnsOverHttpsMode();"
oncommand="gConnectionsDialog.updateDnsOverHttpsUI();"/>
<vbox class="indent" flex="1">
<radiogroup id="DnsOverHttpsUrlRadioGroup" orient="vertical">
<radio id="defaultDnsOverHttpsUrlRadio"
data-l10n-id="connection-dns-over-https-url-default"
preference="network.trr.uri"
oncommand="gConnectionsDialog.updateDnsOverHttpsUI();"/>
<hbox>
<radio id="customDnsOverHttpsUrlRadio"
data-l10n-id="connection-dns-over-https-url-custom"
oncommand="gConnectionsDialog.updateDnsOverHttpsUI();"/>
<textbox id="customDnsOverHttpsInput" flex="1" preference="network.trr.custom_uri"/>
</hbox>
</radiogroup>
</vbox>
</dialog>

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

@ -711,7 +711,8 @@
connection-proxy-autologin.label,
connection-proxy-socks-remote-dns.label,
connection-dns-over-https,
connection-dns-over-https-url
connection-dns-over-https-url-custom,
connection-dns-over-https-url-default,
" />
</hbox>
</hbox>

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

@ -3,17 +3,20 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
const SUBDIALOG_URL = "chrome://browser/content/preferences/connection.xul";
const TRR_MODE_PREF = "network.trr.mode";
const TRR_URI_PREF = "network.trr.uri";
const TRR_CUSTOM_URI_PREF = "network.trr.custom_uri";
const modeCheckboxSelector = "#networkDnsOverHttps";
const uriTextboxSelector = "#networkDnsOverHttpsUrl";
const uriTextboxSelector = "#customDnsOverHttpsInput";
const defaultPrefValues = Object.freeze({
[TRR_MODE_PREF]: 0,
[TRR_URI_PREF]: "https://mozilla.cloudflare-dns.com/dns-query",
[TRR_CUSTOM_URI_PREF]: "",
});
function resetPrefs() {
Services.prefs.clearUserPref(TRR_MODE_PREF);
Services.prefs.clearUserPref(TRR_URI_PREF);
Services.prefs.clearUserPref(TRR_CUSTOM_URI_PREF);
}
let preferencesOpen = new Promise(res => open_preferences(res));
@ -53,6 +56,9 @@ async function testWithProperties(props, startTime) {
if (props.hasOwnProperty(TRR_MODE_PREF)) {
Services.prefs.setIntPref(TRR_MODE_PREF, props[TRR_MODE_PREF]);
}
if (props.hasOwnProperty(TRR_CUSTOM_URI_PREF)) {
Services.prefs.setStringPref(TRR_CUSTOM_URI_PREF, props[TRR_CUSTOM_URI_PREF]);
}
if (props.hasOwnProperty(TRR_URI_PREF)) {
Services.prefs.setStringPref(TRR_URI_PREF, props[TRR_URI_PREF]);
}
@ -84,7 +90,7 @@ async function testWithProperties(props, startTime) {
}
if (props.hasOwnProperty("inputUriKeys")) {
info((Date.now() - startTime) + ": testWithProperties: inputUriKeys, waiting for the pref observer");
uriPrefChangedPromise = waitForPrefObserver(TRR_URI_PREF);
uriPrefChangedPromise = waitForPrefObserver(TRR_CUSTOM_URI_PREF);
info((Date.now() - startTime) + ": testWithProperties: inputUriKeys, pref changed, now enter the new value");
uriTextbox.focus();
uriTextbox.value = props.inputUriKeys;
@ -117,17 +123,20 @@ async function testWithProperties(props, startTime) {
}
add_task(async function default_values() {
let customUriPref = Services.prefs.getStringPref(TRR_CUSTOM_URI_PREF);
let uriPref = Services.prefs.getStringPref(TRR_URI_PREF);
let modePref = Services.prefs.getIntPref(TRR_MODE_PREF);
is(modePref, defaultPrefValues[TRR_MODE_PREF],
`Actual value of ${TRR_MODE_PREF} matches expected default value`);
is(uriPref, defaultPrefValues[TRR_URI_PREF],
`Actual value of ${TRR_MODE_PREF} matches expected default value`);
`Actual value of ${TRR_URI_PREF} matches expected default value`);
is(customUriPref, defaultPrefValues[TRR_CUSTOM_URI_PREF],
`Actual value of ${TRR_CUSTOM_URI_PREF} matches expected default value`);
});
let testVariations = [
// verify state with defaults
{ expectedModePref: 0, expectedUriValue: "https://mozilla.cloudflare-dns.com/dns-query" },
{ expectedModePref: 0, expectedUriValue: "" },
// verify each of the modes maps to the correct checked state
{ [TRR_MODE_PREF]: 0, expectedModeChecked: false },
@ -140,31 +149,27 @@ let testVariations = [
{ [TRR_MODE_PREF]: 77, expectedModeChecked: false },
// verify toggling the checkbox gives the right outcomes
{ clickMode: true, expectedModeValue: 2, expectedUriValue: "https://mozilla.cloudflare-dns.com/dns-query" },
{ clickMode: true, expectedModeValue: 2, expectedUriValue: "" },
{
[TRR_MODE_PREF]: 4,
expectedModeChecked: true, clickMode: true, expectedModePref: 0,
},
// test that setting TRR_CUSTOM_URI_PREF subsequently changes TRR_URI_PREF
{
[TRR_MODE_PREF]: 2, [TRR_URI_PREF]: "https://example.com",
[TRR_MODE_PREF]: 2, [TRR_CUSTOM_URI_PREF]: "https://example.com",
expectedModeValue: true, expectedUriValue: "https://example.com",
},
{
[TRR_URI_PREF]: "",
clickMode: true, inputUriKeys: "https://example.com",
expectedModePref: 2, expectedFinalUriPref: "https://example.com",
},
// verify the uri can be cleared
{
[TRR_MODE_PREF]: 2, [TRR_URI_PREF]: "https://example.com",
[TRR_MODE_PREF]: 2, [TRR_URI_PREF]: "https://example.com", [TRR_CUSTOM_URI_PREF]: "https://example.com",
expectedUriValue: "https://example.com", inputUriKeys: "", expectedFinalUriPref: "",
},
// verify uri gets sanitized
{
clickMode: true, inputUriKeys: " https://example.com ",
expectedModePref: 2, expectedFinalUriPref: "https://example.com",
},
];
for (let props of testVariations) {

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

@ -86,6 +86,14 @@ connection-dns-over-https =
.label = Enable DNS over HTTPS
.accesskey = b
connection-dns-over-https-url = URL
# Variables:
# $url (String) - URL for the DNS over HTTPS provider
connection-dns-over-https-url-default =
.label = Use default ({ $url })
.accesskey = U
.tooltiptext = URL for resolving DNS over HTTPS
.tooltiptext = Use the default URL for resolving DNS over HTTPS
connection-dns-over-https-url-custom =
.label = Custom
.accesskey = C
.tooltiptext = Enter your preferred URL for resolving DNS over HTTPS

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

@ -5457,6 +5457,7 @@ pref("network.trr.mode", 0);
pref("network.trr.uri", "https://mozilla.cloudflare-dns.com/dns-query");
// credentials to pass to DOH end-point
pref("network.trr.credentials", "");
pref("network.trr.custom_uri", "");
// Wait for captive portal confirmation before enabling TRR
#if defined(ANDROID)
// On Android, the captive portal is handled by the OS itself