tor-browser

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

test_ext_manifest_commands.js (1719B)


      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 add_task(async function test_manifest_commands() {
      6  const validShortcuts = [
      7    "Ctrl+Y",
      8    "MacCtrl+Y",
      9    "Command+Y",
     10    "Alt+Shift+Y",
     11    "Ctrl+Alt+Y",
     12    "F1",
     13    "MediaNextTrack",
     14  ];
     15  const invalidShortcuts = ["Shift+Y", "Y", "Ctrl+Ctrl+Y", "Ctrl+Command+Y"];
     16 
     17  async function validateShortcut(shortcut, isValid) {
     18    let normalized = await ExtensionTestUtils.normalizeManifest({
     19      commands: {
     20        "toggle-feature": {
     21          suggested_key: { default: shortcut },
     22          description: "Send a 'toggle-feature' event to the extension",
     23        },
     24      },
     25    });
     26    if (isValid) {
     27      ok(!normalized.error, "There should be no manifest errors.");
     28    } else {
     29      let expectedError =
     30        String.raw`Error processing commands.toggle-feature.suggested_key.default: Error: ` +
     31        String.raw`Value "${shortcut}" must consist of ` +
     32        String.raw`either a combination of one or two modifiers, including ` +
     33        String.raw`a mandatory primary modifier and a key, separated by '+', ` +
     34        String.raw`or a media key. For details see: ` +
     35        String.raw`https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/commands#Key_combinations`;
     36 
     37      ok(
     38        normalized.error.includes(expectedError),
     39        `The manifest error ${JSON.stringify(
     40          normalized.error
     41        )} must contain ${JSON.stringify(expectedError)}`
     42      );
     43    }
     44  }
     45 
     46  for (let shortcut of validShortcuts) {
     47    await validateShortcut(shortcut, true);
     48  }
     49  for (let shortcut of invalidShortcuts) {
     50    await validateShortcut(shortcut, false);
     51  }
     52 });