Files
tubestation/toolkit/components/satchel/test/parent_utils.js
Andrew McCreight 272cee1e65 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
2018-02-06 09:36:57 -08:00

160 lines
4.5 KiB
JavaScript

/* eslint-env mozilla/frame-script */
// assert is available to chrome scripts loaded via SpecialPowers.loadChromeScript.
/* global assert */
ChromeUtils.import("resource://gre/modules/FormHistory.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://testing-common/ContentTaskUtils.jsm");
var gAutocompletePopup = Services.ww.activeWindow
.document
.getElementById("PopupAutoComplete");
assert.ok(gAutocompletePopup, "Got autocomplete popup");
var ParentUtils = {
getMenuEntries() {
let entries = [];
let numRows = gAutocompletePopup.view.matchCount;
for (let i = 0; i < numRows; i++) {
entries.push(gAutocompletePopup.view.getValueAt(i));
}
return entries;
},
cleanUpFormHist(callback) {
FormHistory.update({ op: "remove" }, {
handleCompletion: callback,
});
},
updateFormHistory(changes) {
let handler = {
handleError(error) {
assert.ok(false, error);
sendAsyncMessage("formHistoryUpdated", { ok: false });
},
handleCompletion(reason) {
if (!reason) {
sendAsyncMessage("formHistoryUpdated", { ok: true });
}
},
};
FormHistory.update(changes, handler);
},
popupshownListener() {
let results = this.getMenuEntries();
sendAsyncMessage("onpopupshown", { results });
},
countEntries(name, value) {
let obj = {};
if (name) {
obj.fieldname = name;
}
if (value) {
obj.value = value;
}
let count = 0;
let listener = {
handleResult(result) { count = result; },
handleError(error) {
assert.ok(false, error);
sendAsyncMessage("entriesCounted", { ok: false });
},
handleCompletion(reason) {
if (!reason) {
sendAsyncMessage("entriesCounted", { ok: true, count });
}
},
};
FormHistory.count(obj, listener);
},
checkRowCount(expectedCount, expectedFirstValue = null) {
ContentTaskUtils.waitForCondition(() => {
// This may be called before gAutocompletePopup has initialised
// which causes it to throw
try {
return gAutocompletePopup.view.matchCount === expectedCount &&
(!expectedFirstValue ||
expectedCount <= 1 ||
gAutocompletePopup.view.getValueAt(0) === expectedFirstValue);
} catch (e) {
return false;
}
}, "Waiting for row count change: " + expectedCount + " First value: " + expectedFirstValue)
.then(() => {
let results = this.getMenuEntries();
sendAsyncMessage("gotMenuChange", { results });
});
},
checkSelectedIndex(expectedIndex) {
ContentTaskUtils.waitForCondition(() => {
return gAutocompletePopup.popupOpen &&
gAutocompletePopup.selectedIndex === expectedIndex;
}, "Checking selected index").then(() => {
sendAsyncMessage("gotSelectedIndex");
});
},
getPopupState() {
sendAsyncMessage("gotPopupState", {
open: gAutocompletePopup.popupOpen,
selectedIndex: gAutocompletePopup.selectedIndex,
direction: gAutocompletePopup.style.direction,
});
},
observe(subject, topic, data) {
assert.ok(topic === "satchel-storage-changed");
sendAsyncMessage("satchel-storage-changed", { subject: null, topic, data });
},
cleanup() {
gAutocompletePopup.removeEventListener("popupshown", this._popupshownListener);
this.cleanUpFormHist(() => {
sendAsyncMessage("cleanup-done");
});
},
};
ParentUtils._popupshownListener =
ParentUtils.popupshownListener.bind(ParentUtils);
gAutocompletePopup.addEventListener("popupshown", ParentUtils._popupshownListener);
ParentUtils.cleanUpFormHist();
addMessageListener("updateFormHistory", (msg) => {
ParentUtils.updateFormHistory(msg.changes);
});
addMessageListener("countEntries", ({ name, value }) => {
ParentUtils.countEntries(name, value);
});
addMessageListener("waitForMenuChange", ({ expectedCount, expectedFirstValue }) => {
ParentUtils.checkRowCount(expectedCount, expectedFirstValue);
});
addMessageListener("waitForSelectedIndex", ({ expectedIndex }) => {
ParentUtils.checkSelectedIndex(expectedIndex);
});
addMessageListener("getPopupState", () => {
ParentUtils.getPopupState();
});
addMessageListener("addObserver", () => {
Services.obs.addObserver(ParentUtils, "satchel-storage-changed");
});
addMessageListener("removeObserver", () => {
Services.obs.removeObserver(ParentUtils, "satchel-storage-changed");
});
addMessageListener("cleanup", () => {
ParentUtils.cleanup();
});