diff --git a/devtools/client/aboutdebugging/test/browser_addons_debugging_initial_state.js b/devtools/client/aboutdebugging/test/browser_addons_debugging_initial_state.js index 73168628c8d1..897ff00f000d 100644 --- a/devtools/client/aboutdebugging/test/browser_addons_debugging_initial_state.js +++ b/devtools/client/aboutdebugging/test/browser_addons_debugging_initial_state.js @@ -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); } diff --git a/devtools/client/aboutdebugging/test/browser_addons_install.js b/devtools/client/aboutdebugging/test/browser_addons_install.js index 64d236253cb8..4e3d3eae759a 100644 --- a/devtools/client/aboutdebugging/test/browser_addons_install.js +++ b/devtools/client/aboutdebugging/test/browser_addons_install.js @@ -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); }); diff --git a/devtools/client/aboutdebugging/test/browser_addons_toggle_debug.js b/devtools/client/aboutdebugging/test/browser_addons_toggle_debug.js index 91cf128f8d06..8632a79698d8 100644 --- a/devtools/client/aboutdebugging/test/browser_addons_toggle_debug.js +++ b/devtools/client/aboutdebugging/test/browser_addons_toggle_debug.js @@ -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); }); diff --git a/devtools/client/aboutdebugging/test/head.js b/devtools/client/aboutdebugging/test/head.js index f3699c569efd..6cbc54a06971 100644 --- a/devtools/client/aboutdebugging/test/head.js +++ b/devtools/client/aboutdebugging/test/head.js @@ -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); } /**