browser_Addon.js (2245B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const lazy = {}; 8 9 ChromeUtils.defineESModuleGetters(lazy, { 10 Addon: "chrome://remote/content/shared/Addon.sys.mjs", 11 AddonManager: "resource://gre/modules/AddonManager.sys.mjs", 12 FileUtils: "resource://gre/modules/FileUtils.sys.mjs", 13 }); 14 15 add_task(async function test_installWithPath() { 16 const addonPath = getSupportFilePath("amosigned.xpi"); 17 const addonId = await lazy.Addon.installWithPath(addonPath, true, false); 18 try { 19 is(addonId, "amosigned-xpi@tests.mozilla.org"); 20 } finally { 21 const addon = await lazy.AddonManager.getAddonByID(addonId); 22 await addon.uninstall(); 23 } 24 }); 25 26 add_task(async function test_installWithPath_failure() { 27 await Assert.rejects( 28 lazy.Addon.installWithPath("", true, false), 29 /UnknownError: Expected absolute path/, 30 "Expected error was returned" 31 ); 32 }); 33 34 add_task(async function test_installWithBase64() { 35 const addonPath = getSupportFilePath("amosigned.xpi"); 36 const addonBase64 = await readFileAsBase64(addonPath); 37 const addonId = await lazy.Addon.installWithBase64(addonBase64, true, false); 38 try { 39 is(addonId, "amosigned-xpi@tests.mozilla.org"); 40 } finally { 41 const addon = await lazy.AddonManager.getAddonByID(addonId); 42 await addon.uninstall(); 43 } 44 }); 45 46 add_task(async function test_installWithBase64_failure() { 47 await Assert.rejects( 48 lazy.Addon.installWithBase64("", true, false), 49 /InvalidWebExtensionError: Could not install Add-on: Component returned failure code/, 50 "Expected error was returned" 51 ); 52 }); 53 54 add_task(async function test_uninstall() { 55 const addonPath = getSupportFilePath("amosigned.xpi"); 56 const file = new lazy.FileUtils.File(addonPath); 57 await lazy.AddonManager.installTemporaryAddon(file); 58 is(await lazy.Addon.uninstall("amosigned-xpi@tests.mozilla.org"), undefined); 59 }); 60 61 add_task(async function test_uninstall_failure() { 62 await Assert.rejects( 63 lazy.Addon.uninstall("test"), 64 /NoSuchWebExtensionError: Add-on with ID "test" is not installed/, 65 "Expected error was returned" 66 ); 67 });