summaryrefslogtreecommitdiffstats
path: root/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_popup_blocker.js
blob: b9573c7614c5e09b003a311a4d8d577c92678332 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

function restore_prefs() {
  Services.prefs.clearUserPref("dom.disable_open_during_load");
}

let ORIGINAL_PREF_VALUE = undefined;
add_setup(async function () {
  // It seems that this pref is given a special testing value for some reason.
  // Unset that value for this test, but save the old value
  if (Services.prefs.prefHasUserValue("dom.disable_open_during_load")) {
    ORIGINAL_PREF_VALUE = Services.prefs.getBoolPref(
      "dom.disable_open_during_load"
    );
    Services.prefs.clearUserPref("dom.disable_open_during_load");
  }
});
registerCleanupFunction(async function cleanup_prefs() {
  if (ORIGINAL_PREF_VALUE === undefined) {
    Services.prefs.clearUserPref("dom.disable_open_during_load");
  } else {
    Services.prefs.setBoolPref(
      "dom.disable_open_during_load",
      ORIGINAL_PREF_VALUE
    );
  }
});

async function test_popup_blocker_disabled({ disabled, locked }) {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "about:preferences#privacy"
  );
  await SpecialPowers.spawn(
    tab.linkedBrowser,
    [{ disabled, locked }],
    // eslint-disable-next-line no-shadow
    async function ({ disabled, locked }) {
      let checkbox = content.document.getElementById("popupPolicy");
      is(
        checkbox.checked,
        !disabled,
        "Checkbox checked state should match policy's Block status"
      );
      is(
        checkbox.disabled,
        locked,
        "Checkbox disabled state should match policy's Locked status"
      );
    }
  );
  BrowserTestUtils.removeTab(tab);

  is(
    Services.prefs.prefIsLocked("dom.disable_open_during_load"),
    locked,
    "Flash pref lock state should match policy lock state"
  );
}

add_task(async function test_initial_state() {
  await test_popup_blocker_disabled({ disabled: false, locked: false });
});

add_task(async function test_empty_policy() {
  await setupPolicyEngineWithJson({
    policies: {
      PopupBlocking: {},
    },
  });

  await test_popup_blocker_disabled({ disabled: false, locked: false });

  restore_prefs();
});

add_task(async function test_block() {
  await setupPolicyEngineWithJson({
    policies: {
      PopupBlocking: {
        Default: true,
      },
    },
  });

  await test_popup_blocker_disabled({ disabled: false, locked: false });

  restore_prefs();
});

add_task(async function test_block_locked() {
  await setupPolicyEngineWithJson({
    policies: {
      PopupBlocking: {
        Default: true,
        Locked: true,
      },
    },
  });

  await test_popup_blocker_disabled({ disabled: false, locked: true });

  restore_prefs();
});

add_task(async function test_locked() {
  await setupPolicyEngineWithJson({
    policies: {
      PopupBlocking: {
        Locked: true,
      },
    },
  });

  await test_popup_blocker_disabled({ disabled: false, locked: true });

  restore_prefs();
});

add_task(async function test_disabled() {
  await setupPolicyEngineWithJson({
    policies: {
      PopupBlocking: {
        Default: false,
      },
    },
  });

  await test_popup_blocker_disabled({ disabled: true, locked: false });

  restore_prefs();
});

add_task(async function test_disabled_locked() {
  await setupPolicyEngineWithJson({
    policies: {
      PopupBlocking: {
        Default: false,
        Locked: true,
      },
    },
  });

  await test_popup_blocker_disabled({ disabled: true, locked: true });

  restore_prefs();
});