test/more-apps.test.js (2101 bytes)
1 "use strict"; 2 const test = require("node:test"); 3 const assert = require("node:assert/strict"); 4 const fs = require("node:fs"); 5 const path = require("node:path"); 6 7 const read = (file) => fs.readFileSync(path.join(__dirname, "..", file), "utf8"); 8 9 // The links in the "More apps" section of the options page: the name, the 10 // address and the attributes of each. 11 function moreApps() { 12 const section = read("options.html").match(/<section id="more-apps">([\s\S]*?)<\/section>/); 13 assert.ok(section, "options.html has no More apps section"); 14 return [...section[1].matchAll(/<a ([^>]*)>([^<]*)<\/a>/g)].map(([, attrs, name]) => ({ 15 name, 16 attrs, 17 href: (attrs.match(/href="([^"]*)"/) || [])[1], 18 })); 19 } 20 21 test("More apps links to the other apps with https, each in a new tab", () => { 22 const apps = moreApps(); 23 assert.ok(apps.length > 1); 24 for (const app of apps) { 25 assert.match(app.href, /^https:\/\/[^?#]+$/, app.name); // no tracking parameters 26 assert.match(app.attrs, /target="_blank"/, app.name); 27 assert.match(app.attrs, /rel="noopener"/, app.name); 28 } 29 assert.equal(new Set(apps.map((app) => app.href)).size, apps.length); 30 assert.equal(apps.at(-1).href, "https://recentlywritten.com/projects.html"); 31 }); 32 33 test("More apps does not list the add-on itself", () => { 34 for (const app of moreApps()) assert.doesNotMatch(app.href, /sbm-extension/, app.name); 35 }); 36 37 test("the popup has one More apps link, to the section of the options page", () => { 38 const links = read("popup.html").match(/<a [^>]*>More apps<\/a>/g) || []; 39 assert.equal(links.length, 1); 40 assert.match(links[0], /href="options\.html#more-apps"/); 41 assert.match(links[0], /target="_blank"/); 42 assert.match(links[0], /rel="noopener"/); 43 }); 44 45 test("the add-on asks for no new permission and puts nothing into web pages", () => { 46 const manifest = JSON.parse(read("manifest.json")); 47 assert.deepEqual(manifest.permissions, ["storage", "activeTab", "alarms"]); 48 assert.deepEqual(manifest.optional_host_permissions, ["https://*/*", "http://*/*"]); 49 assert.equal(manifest.content_scripts, undefined); 50 });