fune/browser/components/preferences/in-content/tests/browser_connection_bug388287.js
Kris Maglione e930b89c34 Bug 1514594: Part 3 - Change ChromeUtils.import API.
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8

This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:

  ChromeUtils.import("resource://gre/modules/Services.jsm");

is approximately the same as the following, in the new model:

  var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");

Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs

This was done using the followng script:

https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs

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

--HG--
extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895
extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
2019-01-17 10:18:31 -08:00

124 lines
4.2 KiB
JavaScript

/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
function test() {
waitForExplicitFinish();
const connectionURL = "chrome://browser/content/preferences/connection.xul";
let closeable = false;
let finalTest = false;
// The changed preferences need to be backed up and restored because this mochitest
// changes them setting from the default
let oldNetworkProxyType = Services.prefs.getIntPref("network.proxy.type");
registerCleanupFunction(function() {
Services.prefs.setIntPref("network.proxy.type", oldNetworkProxyType);
Services.prefs.clearUserPref("network.proxy.share_proxy_settings");
for (let proxyType of ["http", "ssl", "ftp", "socks"]) {
Services.prefs.clearUserPref("network.proxy." + proxyType);
Services.prefs.clearUserPref("network.proxy." + proxyType + "_port");
if (proxyType == "http") {
continue;
}
Services.prefs.clearUserPref("network.proxy.backup." + proxyType);
Services.prefs.clearUserPref("network.proxy.backup." + proxyType + "_port");
}
});
/*
The connection dialog alone won't save onaccept since it uses type="child",
so it has to be opened as a sub dialog of the main pref tab.
Open the main tab here.
*/
open_preferences(async function tabOpened(aContentWindow) {
let dialog, dialogClosingPromise;
let doc, proxyTypePref, sharePref, httpPref, httpPortPref, ftpPref, ftpPortPref;
// Convenient function to reset the variables for the new window
async function setDoc() {
if (closeable) {
let dialogClosingEvent = await dialogClosingPromise;
ok(dialogClosingEvent, "Connection dialog closed");
}
if (finalTest) {
gBrowser.removeCurrentTab();
finish();
return;
}
dialog = await openAndLoadSubDialog(connectionURL);
dialogClosingPromise = BrowserTestUtils.waitForEvent(dialog.document.documentElement, "dialogclosing");
doc = dialog.document;
proxyTypePref = dialog.Preferences.get("network.proxy.type");
sharePref = dialog.Preferences.get("network.proxy.share_proxy_settings");
httpPref = dialog.Preferences.get("network.proxy.http");
httpPortPref = dialog.Preferences.get("network.proxy.http_port");
ftpPref = dialog.Preferences.get("network.proxy.ftp");
ftpPortPref = dialog.Preferences.get("network.proxy.ftp_port");
}
// This batch of tests should not close the dialog
await setDoc();
// Testing HTTP port 0 with share on
proxyTypePref.value = 1;
sharePref.value = true;
httpPref.value = "localhost";
httpPortPref.value = 0;
doc.documentElement.acceptDialog();
// Testing HTTP port 0 + FTP port 80 with share off
sharePref.value = false;
ftpPref.value = "localhost";
ftpPortPref.value = 80;
doc.documentElement.acceptDialog();
// Testing HTTP port 80 + FTP port 0 with share off
httpPortPref.value = 80;
ftpPortPref.value = 0;
doc.documentElement.acceptDialog();
// From now on, the dialog should close since we are giving it legitimate inputs.
// The test will timeout if the onbeforeaccept kicks in erroneously.
closeable = true;
// Both ports 80, share on
httpPortPref.value = 80;
ftpPortPref.value = 80;
doc.documentElement.acceptDialog();
// HTTP 80, FTP 0, with share on
await setDoc();
proxyTypePref.value = 1;
sharePref.value = true;
ftpPref.value = "localhost";
httpPref.value = "localhost";
httpPortPref.value = 80;
ftpPortPref.value = 0;
doc.documentElement.acceptDialog();
// HTTP host empty, port 0 with share on
await setDoc();
proxyTypePref.value = 1;
sharePref.value = true;
httpPref.value = "";
httpPortPref.value = 0;
doc.documentElement.acceptDialog();
// HTTP 0, but in no proxy mode
await setDoc();
proxyTypePref.value = 0;
sharePref.value = true;
httpPref.value = "localhost";
httpPortPref.value = 0;
// This is the final test, don't spawn another connection window
finalTest = true;
doc.documentElement.acceptDialog();
await setDoc();
});
}