Bug 1500383 - Migrate tmp addon reload & remove tests to new about:debugging;r=daisuke

Depends on D15466

Removed one of the test methods from the original test as I couldn't see the added value

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Julian Descottes 2019-01-07 10:27:56 +00:00
Родитель 3dfa0f47c7
Коммит 53e84aa3af
5 изменённых файлов: 164 добавлений и 1 удалений

Просмотреть файл

@ -51,7 +51,7 @@ class TemporaryExtensionAction extends PureComponent {
},
dom.button(
{
className: "default-button",
className: "default-button js-temporary-extension-reload-button",
onClick: e => this.reload(),
},
"Reload",

Просмотреть файл

@ -14,6 +14,7 @@ support-files =
helper-serviceworker.js
mocks/*
resources/bad-extension/*
resources/packaged-extension/*
resources/service-workers/*
resources/test-adb-extension/*
resources/test-temporary-extension/*
@ -25,6 +26,7 @@ support-files =
[browser_aboutdebugging_addons_manifest_url.js]
skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
[browser_aboutdebugging_addons_remote_runtime.js]
[browser_aboutdebugging_addons_temporary_addon_buttons.js]
[browser_aboutdebugging_connect_networklocations.js]
[browser_aboutdebugging_connect_toggle_usb_devices.js]
skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638

Просмотреть файл

@ -0,0 +1,96 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/* import-globals-from helper-addons.js */
Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
// Test that the reload button updates the addon list with the correct metadata.
add_task(async function() {
const { document, tab } = await openAboutDebugging();
const ORIGINAL_EXTENSION_NAME = "Temporary web extension (original)";
const UPDATED_EXTENSION_NAME = "Temporary web extension (updated)";
const EXTENSION_ID = "test-devtools@mozilla.org";
const manifestBase = {
"manifest_version": 2,
"name": ORIGINAL_EXTENSION_NAME,
"version": "1.0",
"applications": {
"gecko": {
"id": EXTENSION_ID,
},
},
};
const tempExt = new TemporaryExtension(EXTENSION_ID);
tempExt.writeManifest(manifestBase);
info("Install a temporary extension (original)");
await AddonManager.installTemporaryAddon(tempExt.sourceDir);
info("Wait until a debug target item appears");
await waitUntil(() => findDebugTargetByText(ORIGINAL_EXTENSION_NAME, document));
const originalTarget = findDebugTargetByText(ORIGINAL_EXTENSION_NAME, document);
ok(!!originalTarget, "The temporary extension isinstalled with the expected name");
info("Update the name of the temporary extension in the manifest");
tempExt.writeManifest(Object.assign({}, manifestBase, {name: UPDATED_EXTENSION_NAME}));
info("Click on the reload button for the temporary extension");
const reloadButton =
originalTarget.querySelector(".js-temporary-extension-reload-button");
reloadButton.click();
info("Wait until the debug target with the original extension name disappears");
await waitUntil(() => !findDebugTargetByText(ORIGINAL_EXTENSION_NAME, document));
info("Wait until the debug target with the updated extension name appears");
await waitUntil(() => findDebugTargetByText(UPDATED_EXTENSION_NAME, document));
const updatedTarget = findDebugTargetByText(UPDATED_EXTENSION_NAME, document);
ok(!!updatedTarget, "The temporary extension name has been updated");
info("Click on the remove button for the temporary extension");
const removeButton =
updatedTarget.querySelector(".js-temporary-extension-remove-button");
removeButton.click();
info("Wait until the debug target with the updated extension name disappears");
await waitUntil(() => !findDebugTargetByText(UPDATED_EXTENSION_NAME, document));
info("Remove the temporary web extension");
tempExt.remove();
await removeTab(tab);
});
add_task(async function() {
const PACKAGED_EXTENSION_ID = "packaged-extension@tests";
const PACKAGED_EXTENSION_NAME = "Packaged extension";
const { document, tab } = await openAboutDebugging();
await installRegularAddon("resources/packaged-extension/packaged-extension.xpi");
info("Wait until extension appears in about:debugging");
await waitUntil(() => findDebugTargetByText(PACKAGED_EXTENSION_NAME, document));
const target = findDebugTargetByText(PACKAGED_EXTENSION_NAME, document);
const reloadButton = target.querySelector(".js-temporary-extension-reload-button");
ok(!reloadButton, "No reload button displayed for a regularly installed extension");
const removeButton = target.querySelector(".js-temporary-extension-remove-button");
ok(!removeButton, "No remove button displayed for a regularly installed extension");
info("Retrieve the extension instance from the addon manager, and uninstall it");
const extension = await AddonManager.getAddonByID(PACKAGED_EXTENSION_ID);
extension.uninstall();
info("Wait until the addon disappears from about:debugging");
await waitUntil(() => !findDebugTargetByText(PACKAGED_EXTENSION_NAME, document));
await removeTab(tab);
});

Просмотреть файл

@ -59,3 +59,68 @@ function prepareMockFilePicker(path) {
MockFilePicker.setFiles([_getSupportsFile(path).file]);
}
/* exported prepareMockFilePicker */
/**
* Creates a web extension from scratch in a temporary location.
* The object must be removed when you're finished working with it.
*/
class TemporaryExtension {
constructor(addonId) {
this.addonId = addonId;
this.tmpDir = FileUtils.getDir("TmpD", ["browser_addons_reload"]);
if (!this.tmpDir.exists()) {
this.tmpDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
}
this.sourceDir = this.tmpDir.clone();
this.sourceDir.append(this.addonId);
if (!this.sourceDir.exists()) {
this.sourceDir.create(Ci.nsIFile.DIRECTORY_TYPE,
FileUtils.PERMS_DIRECTORY);
}
}
writeManifest(manifestData) {
const manifest = this.sourceDir.clone();
manifest.append("manifest.json");
if (manifest.exists()) {
manifest.remove(true);
}
const fos = Cc["@mozilla.org/network/file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream);
fos.init(manifest,
FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE |
FileUtils.MODE_TRUNCATE,
FileUtils.PERMS_FILE, 0);
const manifestString = JSON.stringify(manifestData);
fos.write(manifestString, manifestString.length);
fos.close();
}
remove() {
return this.tmpDir.remove(true);
}
}
/* exported TemporaryExtension */
/**
* Install an add-on using the AddonManager so it does not show up as temporary.
*/
function installRegularAddon(filePath) {
const file = _getSupportsFile(filePath).file;
return new Promise(async (resolve, reject) => {
const install = await AddonManager.getInstallForFile(file);
if (!install) {
throw new Error(`An install was not created for ${filePath}`);
}
install.addListener({
onDownloadFailed: reject,
onDownloadCancelled: reject,
onInstallFailed: reject,
onInstallCancelled: reject,
onInstallEnded: resolve,
});
install.install();
});
}
/* exported installRegularAddon */

Двоичный файл не отображается.