tor-browser

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

ExtensionDoorhanger.test.jsx (3310B)


      1 import { CFRMessageProvider } from "modules/CFRMessageProvider.sys.mjs";
      2 import CFRDoorhangerSchema from "content-src/templates/CFR/templates/ExtensionDoorhanger.schema.json";
      3 import CFRChicletSchema from "content-src/templates/CFR/templates/CFRUrlbarChiclet.schema.json";
      4 import InfoBarSchema from "content-src/templates/CFR/templates/InfoBar.schema.json";
      5 
      6 const SCHEMAS = {
      7  cfr_urlbar_chiclet: CFRChicletSchema,
      8  cfr_doorhanger: CFRDoorhangerSchema,
      9  milestone_message: CFRDoorhangerSchema,
     10  infobar: InfoBarSchema,
     11 };
     12 
     13 const DEFAULT_CONTENT = {
     14  layout: "addon_recommendation",
     15  category: "dummyCategory",
     16  bucket_id: "some_bucket_id",
     17  notification_text: "Recommendation",
     18  heading_text: "Recommended Extension",
     19  info_icon: {
     20    label: { attributes: { tooltiptext: "Why am I seeing this" } },
     21    sumo_path: "extensionrecommendations",
     22  },
     23  addon: {
     24    id: "1234",
     25    title: "Addon name",
     26    icon: "https://mozilla.org/icon",
     27    author: "Author name",
     28    amo_url: "https://example.com",
     29  },
     30  text: "Description of addon",
     31  buttons: {
     32    primary: {
     33      label: {
     34        value: "Add Now",
     35        attributes: { accesskey: "A" },
     36      },
     37      action: {
     38        type: "INSTALL_ADDON_FROM_URL",
     39        data: { url: "https://example.com" },
     40      },
     41    },
     42    secondary: [
     43      {
     44        label: {
     45          value: "Not Now",
     46          attributes: { accesskey: "N" },
     47        },
     48        action: { type: "CANCEL" },
     49      },
     50    ],
     51  },
     52 };
     53 
     54 const L10N_CONTENT = {
     55  layout: "addon_recommendation",
     56  category: "dummyL10NCategory",
     57  bucket_id: "some_bucket_id",
     58  notification_text: { string_id: "notification_text_id" },
     59  heading_text: { string_id: "heading_text_id" },
     60  info_icon: {
     61    label: { string_id: "why_seeing_this" },
     62    sumo_path: "extensionrecommendations",
     63  },
     64  addon: {
     65    id: "1234",
     66    title: "Addon name",
     67    icon: "https://mozilla.org/icon",
     68    author: "Author name",
     69    amo_url: "https://example.com",
     70  },
     71  text: { string_id: "text_id" },
     72  buttons: {
     73    primary: {
     74      label: { string_id: "btn_ok_id" },
     75      action: {
     76        type: "INSTALL_ADDON_FROM_URL",
     77        data: { url: "https://example.com" },
     78      },
     79    },
     80    secondary: [
     81      {
     82        label: { string_id: "btn_cancel_id" },
     83        action: { type: "CANCEL" },
     84      },
     85    ],
     86  },
     87 };
     88 
     89 describe("ExtensionDoorhanger", () => {
     90  it("should validate DEFAULT_CONTENT", async () => {
     91    const messages = await CFRMessageProvider.getMessages();
     92    let doorhangerMessage = messages.find(m => m.id === "FACEBOOK_CONTAINER_3");
     93    assert.ok(doorhangerMessage, "Message found");
     94    assert.jsonSchema(
     95      { ...doorhangerMessage, content: DEFAULT_CONTENT },
     96      CFRDoorhangerSchema
     97    );
     98  });
     99  it("should validate L10N_CONTENT", async () => {
    100    const messages = await CFRMessageProvider.getMessages();
    101    let doorhangerMessage = messages.find(m => m.id === "FACEBOOK_CONTAINER_3");
    102    assert.ok(doorhangerMessage, "Message found");
    103    assert.jsonSchema(
    104      { ...doorhangerMessage, content: L10N_CONTENT },
    105      CFRDoorhangerSchema
    106    );
    107  });
    108  it("should validate all messages from CFRMessageProvider", async () => {
    109    const messages = await CFRMessageProvider.getMessages();
    110    messages.forEach(msg => assert.jsonSchema(msg, SCHEMAS[msg.template]));
    111  });
    112 });