summaryrefslogtreecommitdiffstats
path: root/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_handle_multiaction.js
blob: 709f4515ad938620d77e78d2b8fbbdb5058e79d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_handle_multi_action() {
  const action = {
    type: "MULTI_ACTION",
    data: {
      actions: [
        {
          type: "DISABLE_DOH",
        },
        {
          type: "OPEN_AWESOME_BAR",
        },
      ],
    },
  };
  const DOH_DOORHANGER_DECISION_PREF = "doh-rollout.doorhanger-decision";
  const NETWORK_TRR_MODE_PREF = "network.trr.mode";

  await SpecialPowers.pushPrefEnv({
    set: [
      [DOH_DOORHANGER_DECISION_PREF, "mochitest"],
      [NETWORK_TRR_MODE_PREF, 0],
    ],
  });

  await SMATestUtils.executeAndValidateAction(action);

  Assert.equal(
    Services.prefs.getStringPref(DOH_DOORHANGER_DECISION_PREF, ""),
    "UIDisabled",
    "Pref should be set on disabled"
  );
  Assert.equal(
    Services.prefs.getIntPref(NETWORK_TRR_MODE_PREF, 0),
    5,
    "Pref should be set on disabled"
  );

  Assert.ok(gURLBar.focused, "Focus should be on awesome bar");
});

add_task(async function test_handle_multi_action_with_invalid_action() {
  const action = {
    type: "MULTI_ACTION",
    data: {
      actions: [
        {
          type: "NONSENSE",
        },
      ],
    },
  };

  await SMATestUtils.validateAction(action);

  let error;
  try {
    await SpecialMessageActions.handleAction(action, gBrowser);
  } catch (e) {
    error = e;
  }

  ok(error, "should throw if an unexpected event is handled");
  Assert.equal(
    error.message,
    "Error in MULTI_ACTION event: Special message action with type NONSENSE is unsupported."
  );
});