test_addons_actor.js (3528B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 async function connect() { 7 DevToolsServer.init(); 8 DevToolsServer.registerAllActors(); 9 10 const client = new DevToolsClient(DevToolsServer.connectPipe()); 11 await client.connect(); 12 13 const addons = await client.mainRoot.getFront("addons"); 14 return [client, addons]; 15 } 16 17 function getPlatformFilePath(path) { 18 const allowMissing = false; 19 const usePlatformSeparator = true; 20 return getFilePath(path, allowMissing, usePlatformSeparator); 21 } 22 23 // The AddonsManager test helper can only be called once per test script. 24 // This `setup` task will run first. 25 add_setup(async () => { 26 await startupAddonsManager(); 27 }); 28 29 add_task(async function testSuccessfulInstall() { 30 const [client, addons] = await connect(); 31 32 const addonPath = getPlatformFilePath("addons/web-extension"); 33 const installedAddon = await addons.installTemporaryAddon(addonPath, false); 34 equal(installedAddon.id, "test-addons-actor@mozilla.org"); 35 // The returned object is currently not a proper actor. 36 equal(installedAddon.actor, false); 37 38 const addonList = await client.mainRoot.listAddons(); 39 ok(addonList && addonList.map(a => a.name), "Received list of add-ons"); 40 const addon = addonList.find(a => a.id === installedAddon.id); 41 ok(addon, "Test add-on appeared in root install list"); 42 43 await close(client); 44 }); 45 46 add_task(async function testNonExistantPath() { 47 const [client, addons] = await connect(); 48 49 await Assert.rejects( 50 addons.installTemporaryAddon("some-non-existant-path", false), 51 /Could not install add-on.*Component returned failure/ 52 ); 53 54 await close(client); 55 }); 56 57 add_task(async function testInvalidExtensionMissingManifestJson() { 58 const [client, addons] = await connect(); 59 60 await Assert.rejects( 61 addons.installTemporaryAddon(getPlatformFilePath("addons"), false), 62 /Could not install add-on.*does not contain a valid manifest/ 63 ); 64 65 await close(client); 66 }); 67 68 add_task(async function testInvalidExtensionManifestJsonIsNotJson() { 69 const [client, addons] = await connect(); 70 71 await Assert.rejects( 72 addons.installTemporaryAddon( 73 getPlatformFilePath("addons/invalid-extension-manifest-badjson"), 74 false 75 ), 76 // It would be ideal if the error message contained manifest.json, but at 77 // least having some description is better than nothing. 78 /Could not install add-on.*SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data/ 79 ); 80 81 await close(client); 82 }); 83 84 add_task(async function testInvalidExtensionManifestJsonMissingRequiredKey() { 85 const [client, addons] = await connect(); 86 87 await Assert.rejects( 88 addons.installTemporaryAddon( 89 getPlatformFilePath("addons/invalid-extension-manifest"), 90 false 91 ), 92 /Could not install add-on.*Error: Extension is invalid\nReading manifest: Property "name" is required/ 93 ); 94 95 await close(client); 96 }); 97 98 add_task(async function testInvalidExtensionMissingLocales() { 99 const [client, addons] = await connect(); 100 101 await Assert.rejects( 102 addons.installTemporaryAddon( 103 getPlatformFilePath("addons/invalid-extension-missing-locales"), 104 false 105 ), 106 // It would be ideal if the error message contained manifest.json, but at 107 // least having some description is better than nothing. 108 /Could not install add-on.*Error: Extension is invalid\nLoading locale file _locales\/en\/messages.json: .*NS_ERROR_FILE_NOT_FOUND/ 109 ); 110 111 await close(client); 112 });