зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1261055 - Always assert DOM when installing/uninstalling addons. r=janx
This commit is contained in:
Родитель
20b3420a9a
Коммит
966698b70a
|
@ -8,6 +8,7 @@
|
|||
// - devtools.debugger.remote-enabled
|
||||
|
||||
const ADDON_ID = "test-devtools@mozilla.org";
|
||||
const ADDON_NAME = "test-devtools";
|
||||
|
||||
const TEST_DATA = [
|
||||
{
|
||||
|
@ -48,7 +49,8 @@ function* testCheckboxState(testData) {
|
|||
let { tab, document } = yield openAboutDebugging("addons");
|
||||
|
||||
info("Install a test addon.");
|
||||
yield installAddon(document, "addons/unpacked/install.rdf", "test-devtools");
|
||||
yield installAddon(document, "addons/unpacked/install.rdf", ADDON_NAME,
|
||||
"test-devtools");
|
||||
|
||||
info("Test checkbox checked state.");
|
||||
let addonDebugCheckbox = document.querySelector("#enable-addon-debugging");
|
||||
|
@ -61,7 +63,7 @@ function* testCheckboxState(testData) {
|
|||
"Debug buttons should be in the expected state");
|
||||
|
||||
info("Uninstall test addon installed earlier.");
|
||||
yield uninstallAddon(ADDON_ID);
|
||||
yield uninstallAddon(document, ADDON_ID, ADDON_NAME);
|
||||
|
||||
yield closeAboutDebugging(tab);
|
||||
}
|
||||
|
|
|
@ -8,23 +8,12 @@ const ADDON_NAME = "test-devtools";
|
|||
add_task(function* () {
|
||||
let { tab, document } = yield openAboutDebugging("addons");
|
||||
|
||||
yield installAddon(document, "addons/unpacked/install.rdf", "test-devtools");
|
||||
// Install this add-on, and verify that it appears in the about:debugging UI
|
||||
yield installAddon(document, "addons/unpacked/install.rdf", ADDON_NAME,
|
||||
"test-devtools");
|
||||
|
||||
// Check that the addon appears in the UI
|
||||
let names = [...document.querySelectorAll("#addons .target-name")];
|
||||
names = names.map(element => element.textContent);
|
||||
ok(names.includes(ADDON_NAME),
|
||||
"The addon name appears in the list of addons: " + names);
|
||||
|
||||
// Now uninstall this addon
|
||||
yield uninstallAddon(ADDON_ID);
|
||||
|
||||
// Ensure that the UI removes the addon from the list
|
||||
names = [...document.querySelectorAll("#addons .target-name")];
|
||||
names = names.map(element => element.textContent);
|
||||
ok(!names.includes(ADDON_NAME),
|
||||
"After uninstall, the addon name disappears from the list of addons: "
|
||||
+ names);
|
||||
// Install the add-on, and verify that it disappears in the about:debugging UI
|
||||
yield uninstallAddon(document, ADDON_ID, ADDON_NAME);
|
||||
|
||||
yield closeAboutDebugging(tab);
|
||||
});
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
// Test that the buttons are updated dynamically if the preference changes.
|
||||
|
||||
const ADDON_ID = "test-devtools@mozilla.org";
|
||||
const ADDON_NAME = "test-devtools";
|
||||
|
||||
add_task(function* () {
|
||||
info("Turn off addon debugging.");
|
||||
|
@ -21,7 +22,8 @@ add_task(function* () {
|
|||
let { tab, document } = yield openAboutDebugging("addons");
|
||||
|
||||
info("Install a test addon.");
|
||||
yield installAddon(document, "addons/unpacked/install.rdf", "test-devtools");
|
||||
yield installAddon(document, "addons/unpacked/install.rdf", ADDON_NAME,
|
||||
"test-devtools");
|
||||
|
||||
let addonDebugCheckbox = document.querySelector("#enable-addon-debugging");
|
||||
ok(!addonDebugCheckbox.checked, "Addons debugging should be disabled.");
|
||||
|
@ -53,7 +55,7 @@ add_task(function* () {
|
|||
ok(debugButtons.every(b => b.disabled), "Debug buttons should be disabled");
|
||||
|
||||
info("Uninstall addon installed earlier.");
|
||||
yield uninstallAddon(ADDON_ID);
|
||||
yield uninstallAddon(document, ADDON_ID, ADDON_NAME);
|
||||
|
||||
yield closeAboutDebugging(tab);
|
||||
});
|
||||
|
|
|
@ -92,31 +92,44 @@ function getSupportsFile(path) {
|
|||
return fileurl.QueryInterface(Ci.nsIFileURL);
|
||||
}
|
||||
|
||||
function installAddon(document, path, evt) {
|
||||
function* installAddon(document, path, name, evt) {
|
||||
// Mock the file picker to select a test addon
|
||||
let MockFilePicker = SpecialPowers.MockFilePicker;
|
||||
MockFilePicker.init(null);
|
||||
let file = getSupportsFile(path);
|
||||
MockFilePicker.returnFiles = [file.file];
|
||||
|
||||
let addonList = document.querySelector("#addons .targets");
|
||||
let addonListMutation = waitForMutation(addonList, { childList: true });
|
||||
|
||||
// Wait for a message sent by the addon's bootstrap.js file
|
||||
let onAddonInstalled = new Promise(done => {
|
||||
Services.obs.addObserver(function listener() {
|
||||
Services.obs.removeObserver(listener, evt, false);
|
||||
ok(true, "Addon installed and running its bootstrap.js file");
|
||||
Services.obs.removeObserver(listener, evt);
|
||||
|
||||
done();
|
||||
}, evt, false);
|
||||
});
|
||||
// Trigger the file picker by clicking on the button
|
||||
document.getElementById("load-addon-from-file").click();
|
||||
|
||||
// Wait for the addon execution
|
||||
return onAddonInstalled;
|
||||
yield onAddonInstalled;
|
||||
ok(true, "Addon installed and running its bootstrap.js file");
|
||||
|
||||
// Check that the addon appears in the UI
|
||||
yield addonListMutation;
|
||||
let names = [...addonList.querySelectorAll(".target-name")];
|
||||
names = names.map(element => element.textContent);
|
||||
ok(names.includes(name),
|
||||
"The addon name appears in the list of addons: " + names);
|
||||
}
|
||||
|
||||
function uninstallAddon(addonId) {
|
||||
function* uninstallAddon(document, addonId, addonName) {
|
||||
let addonList = document.querySelector("#addons .targets");
|
||||
let addonListMutation = waitForMutation(addonList, { childList: true });
|
||||
|
||||
// Now uninstall this addon
|
||||
return new Promise(done => {
|
||||
yield new Promise(done => {
|
||||
AddonManager.getAddonByID(addonId, addon => {
|
||||
let listener = {
|
||||
onUninstalled: function(uninstalledAddon) {
|
||||
|
@ -124,6 +137,7 @@ function uninstallAddon(addonId) {
|
|||
return;
|
||||
}
|
||||
AddonManager.removeAddonListener(listener);
|
||||
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
@ -131,6 +145,14 @@ function uninstallAddon(addonId) {
|
|||
addon.uninstall();
|
||||
});
|
||||
});
|
||||
|
||||
// Ensure that the UI removes the addon from the list
|
||||
yield addonListMutation;
|
||||
let names = [...addonList.querySelectorAll(".target-name")];
|
||||
names = names.map(element => element.textContent);
|
||||
ok(!names.includes(addonName),
|
||||
"After uninstall, the addon name disappears from the list of addons: "
|
||||
+ names);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче