tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_ext_manifest.js (3965B)


      1 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* vim: set sts=2 sw=2 et tw=80: */
      3 "use strict";
      4 
      5 async function testManifest(manifest, expectedError) {
      6  ExtensionTestUtils.failOnSchemaWarnings(false);
      7  let normalized = await ExtensionTestUtils.normalizeManifest(manifest);
      8  ExtensionTestUtils.failOnSchemaWarnings(true);
      9 
     10  if (expectedError) {
     11    ok(
     12      expectedError.test(normalized.error),
     13      `Should have an error for ${JSON.stringify(manifest)}, got ${
     14        normalized.error
     15      }`
     16    );
     17  } else {
     18    ok(
     19      !normalized.error,
     20      `Should not have an error ${JSON.stringify(manifest)}, ${
     21        normalized.error
     22      }`
     23    );
     24  }
     25  return normalized.errors;
     26 }
     27 
     28 const all_actions = [
     29  "action",
     30  "browser_action",
     31  "page_action",
     32  "sidebar_action",
     33 ];
     34 
     35 add_task(async function test_manifest() {
     36  let badpaths = ["", " ", "\t", "http://foo.com/icon.png"];
     37  for (let path of badpaths) {
     38    for (let action of all_actions) {
     39      let manifest_version = action == "action" ? 3 : 2;
     40      let manifest = { manifest_version };
     41      manifest[action] = { default_icon: path };
     42      let error = new RegExp(`Error processing ${action}.default_icon`);
     43      await testManifest(manifest, error);
     44 
     45      manifest[action] = { default_icon: { 16: path } };
     46      await testManifest(manifest, error);
     47    }
     48  }
     49 
     50  let paths = [
     51    "icon.png",
     52    "/icon.png",
     53    "./icon.png",
     54    "path to an icon.png",
     55    " icon.png",
     56  ];
     57  for (let path of paths) {
     58    for (let action of all_actions) {
     59      let manifest_version = action == "action" ? 3 : 2;
     60      let manifest = { manifest_version };
     61      manifest[action] = { default_icon: path };
     62      if (action == "sidebar_action") {
     63        // Sidebar requires panel.
     64        manifest[action].default_panel = "foo.html";
     65      }
     66      await testManifest(manifest);
     67 
     68      manifest[action] = { default_icon: { 16: path } };
     69      if (action == "sidebar_action") {
     70        manifest[action].default_panel = "foo.html";
     71      }
     72      await testManifest(manifest);
     73    }
     74  }
     75 });
     76 
     77 add_task(async function test_action_version() {
     78  let warnings = await testManifest({
     79    manifest_version: 3,
     80    browser_action: {
     81      default_panel: "foo.html",
     82    },
     83  });
     84  Assert.deepEqual(
     85    warnings,
     86    [`Property "browser_action" is unsupported in Manifest Version 3`],
     87    `Manifest v3 with "browser_action" key logs an error.`
     88  );
     89 
     90  warnings = await testManifest({
     91    manifest_version: 2,
     92    action: {
     93      default_icon: "",
     94      default_panel: "foo.html",
     95    },
     96  });
     97 
     98  Assert.deepEqual(
     99    warnings,
    100    [`Property "action" is unsupported in Manifest Version 2`],
    101    `Manifest v2 with "action" key first warning is clear.`
    102  );
    103 });
    104 
    105 // Verify that extended F13-F19 keys are invalid when specified in the
    106 // extensions manifest.
    107 //
    108 // Other related tests:
    109 // - browser_manage_shortcuts.js include a test that makes sure the F13-F19 keys are valid when
    110 //   assigned by a user through about:addons "Manage Shortcuts".
    111 // - browser_ext_commands_update.js include a test that makes sure the F13-F19 keys
    112 //   are valid when dynamically assigned by the extension through
    113 //   browser.commands.update API calls.
    114 add_task(async function test_invalid_extended_function_keys() {
    115  info("Verify F13-19 are invalid when assigned from the extension manifest");
    116  ExtensionTestUtils.failOnSchemaWarnings(false);
    117  let normalized = await ExtensionTestUtils.normalizeManifest({
    118    commands: {
    119      invalidFnKeyCommand: {
    120        suggested_key: {
    121          default: "Alt+F13",
    122        },
    123      },
    124    },
    125  });
    126  const EXPECTED_ERROR_REGEX = new RegExp(
    127    `Value ".*" must not include extended F13-F19 keys. F13-F19 keys can only be used for user-defined keyboard shortcuts`
    128  );
    129  ExtensionTestUtils.failOnSchemaWarnings(true);
    130  ok(
    131    EXPECTED_ERROR_REGEX.test(normalized.error),
    132    `Should have reported F13 as an invalid key manifest error, got: ${normalized.error}`
    133  );
    134 });