fune/browser/components/preferences/in-content/tests/browser_advanced_update.js
Andrew McCreight 5dec0e0beb Bug 1432992, part 1 - Remove definitions of Ci, Cr, Cc, and Cu. r=florian
This patch was autogenerated by my decomponents.py

It covers almost every file with the extension js, jsm, html, py,
xhtml, or xul.

It removes blank lines after removed lines, when the removed lines are
preceded by either blank lines or the start of a new block. The "start
of a new block" is defined fairly hackily: either the line starts with
//, ends with */, ends with {, <![CDATA[, """ or '''. The first two
cover comments, the third one covers JS, the fourth covers JS embedded
in XUL, and the final two cover JS embedded in Python. This also
applies if the removed line was the first line of the file.

It covers the pattern matching cases like "var {classes: Cc,
interfaces: Ci, utils: Cu, results: Cr} = Components;". It'll remove
the entire thing if they are all either Ci, Cr, Cc or Cu, or it will
remove the appropriate ones and leave the residue behind. If there's
only one behind, then it will turn it into a normal, non-pattern
matching variable definition. (For instance, "const { classes: Cc,
Constructor: CC, interfaces: Ci, utils: Cu } = Components" becomes
"const CC = Components.Constructor".)

MozReview-Commit-ID: DeSHcClQ7cG

--HG--
extra : rebase_source : d9c41878036c1ef7766ef5e91a7005025bc1d72b
2018-02-06 09:36:57 -08:00

158 lines
5.5 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const Cm = Components.manager;
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
const mockUpdateManager = {
contractId: "@mozilla.org/updates/update-manager;1",
_mockClassId: uuidGenerator.generateUUID(),
_originalClassId: "",
_originalFactory: null,
QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdateManager]),
createInstance(outer, iiD) {
if (outer) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
return this.QueryInterface(iiD);
},
register() {
let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
if (!registrar.isCIDRegistered(this._mockClassId)) {
this._originalClassId = registrar.contractIDToCID(this.contractId);
this._originalFactory = Cm.getClassObject(Cc[this.contractId], Ci.nsIFactory);
registrar.unregisterFactory(this._originalClassId, this._originalFactory);
registrar.registerFactory(this._mockClassId, "Unregister after testing", this.contractId, this);
}
},
unregister() {
let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
registrar.unregisterFactory(this._mockClassId, this);
registrar.registerFactory(this._originalClassId, "", this.contractId, this._originalFactory);
},
get updateCount() {
return this._updates.length;
},
getUpdateAt(index) {
return this._updates[index];
},
_updates: [
{
name: "Firefox Developer Edition 49.0a2",
statusText: "The Update was successfully installed",
buildID: "20160728004010",
installDate: 1469763105156,
detailsURL: "https://www.mozilla.org/firefox/aurora/"
},
{
name: "Firefox Developer Edition 43.0a2",
statusText: "The Update was successfully installed",
buildID: "20150929004011",
installDate: 1443585886224,
detailsURL: "https://www.mozilla.org/firefox/aurora/"
},
{
name: "Firefox Developer Edition 42.0a2",
statusText: "The Update was successfully installed",
buildID: "20150920004018",
installDate: 1442818147544,
detailsURL: "https://www.mozilla.org/firefox/aurora/"
}
]
};
function resetPreferences() {
Services.prefs.clearUserPref("browser.search.update");
}
function formatInstallDate(sec) {
var date = new Date(sec);
const dtOptions = { year: "numeric", month: "long", day: "numeric",
hour: "numeric", minute: "numeric", second: "numeric" };
return date.toLocaleString(undefined, dtOptions);
}
registerCleanupFunction(resetPreferences);
add_task(async function() {
await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
resetPreferences();
Services.prefs.setBoolPref("browser.search.update", false);
let doc = gBrowser.selectedBrowser.contentDocument;
let enableSearchUpdate = doc.getElementById("enableSearchUpdate");
is_element_visible(enableSearchUpdate, "Check search update preference is visible");
// Ensure that the update pref dialog reflects the actual pref value.
ok(!enableSearchUpdate.checked, "Ensure search updates are disabled");
Services.prefs.setBoolPref("browser.search.update", true);
ok(enableSearchUpdate.checked, "Ensure search updates are enabled");
gBrowser.removeCurrentTab();
});
add_task(async function() {
await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
let doc = gBrowser.selectedBrowser.contentDocument;
let showBtn = doc.getElementById("showUpdateHistory");
// eslint-disable-next-line mozilla/no-cpows-in-tests
let dialogOverlay = content.gSubDialog._preloadDialog._overlay;
// XXX: For unknown reasons, this mock cannot be loaded by
// XPCOMUtils.defineLazyServiceGetter() called in aboutDialog-appUpdater.js.
// It is registered here so that we could assert update history subdialog
// without stopping the preferences advanced pane from loading.
// See bug 1361929.
mockUpdateManager.register();
// Test the dialog window opens
is(dialogOverlay.style.visibility, "", "The dialog should be invisible");
let promiseSubDialogLoaded = promiseLoadSubDialog("chrome://mozapps/content/update/history.xul");
showBtn.doCommand();
await promiseSubDialogLoaded;
is(dialogOverlay.style.visibility, "visible", "The dialog should be visible");
let dialogFrame = dialogOverlay.querySelector(".dialogFrame");
let frameDoc = dialogFrame.contentDocument;
let updates = frameDoc.querySelectorAll("update");
// Test the update history numbers are correct
is(updates.length, mockUpdateManager.updateCount, "The update count is incorrect.");
// Test the updates are displayed correctly
let update = null;
let updateData = null;
for (let i = 0; i < updates.length; ++i) {
update = updates[i];
updateData = mockUpdateManager.getUpdateAt(i);
is(update.name, updateData.name + " (" + updateData.buildID + ")", "Wrong update name");
is(update.installDate, formatInstallDate(updateData.installDate), "Wrong update installDate");
is(update.detailsURL, updateData.detailsURL, "Wrong update detailsURL");
is(update.status, updateData.statusText, "Wrong update status");
}
// Test the dialog window closes
let closeBtn = dialogOverlay.querySelector(".dialogClose");
closeBtn.doCommand();
is(dialogOverlay.style.visibility, "", "The dialog should be invisible");
mockUpdateManager.unregister();
gBrowser.removeCurrentTab();
});