summaryrefslogtreecommitdiff
path: root/toolkit/mozapps/extensions/test/xpcshell/test_bug563256.js
blob: 2437cf7480aef6681e06dcb43bb046dc7b13ff74 (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// This verifies that the themes switch as expected

const PREF_GENERAL_SKINS_SELECTEDSKIN = "general.skins.selectedSkin";

const profileDir = gProfD.clone();
profileDir.append("extensions");

function run_test() {
  do_test_pending();
  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");

  writeInstallRDFForExtension({
    id: "default@tests.mozilla.org",
    version: "1.0",
    name: "Default",
    internalName: "classic/1.0",
    targetApplications: [{
      id: "xpcshell@tests.mozilla.org",
      minVersion: "1",
      maxVersion: "2"
    }]
  }, profileDir);

  writeInstallRDFForExtension({
    id: "alternate@tests.mozilla.org",
    version: "1.0",
    name: "Test 1",
    type: 4,
    internalName: "alternate/1.0",
    targetApplications: [{
      id: "xpcshell@tests.mozilla.org",
      minVersion: "1",
      maxVersion: "2"
    }]
  }, profileDir);

  startupManager();
                                     
  do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");

  AddonManager.getAddonsByIDs(["default@tests.mozilla.org",
                               "alternate@tests.mozilla.org"], function([d, a]) {
    do_check_neq(d, null);
    do_check_false(d.userDisabled);
    do_check_false(d.appDisabled);
    do_check_true(d.isActive);
    do_check_true(isThemeInAddonsList(profileDir, d.id));
    do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));

    do_check_neq(a, null);
    do_check_true(a.userDisabled);
    do_check_false(a.appDisabled);
    do_check_false(a.isActive);
    do_check_false(isThemeInAddonsList(profileDir, a.id));
    do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));

    run_test_1(d, a);
  });
}

function end_test() {
  do_execute_soon(do_test_finished);
}

// Checks switching to a different theme and back again leaves everything the
// same
function run_test_1(d, a) {
  a.userDisabled = false;

  do_check_true(d.userDisabled);
  do_check_false(d.appDisabled);
  do_check_true(d.isActive);
  do_check_true(isThemeInAddonsList(profileDir, d.id));
  do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
  do_check_true(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));

  do_check_false(a.userDisabled);
  do_check_false(a.appDisabled);
  do_check_false(a.isActive);
  do_check_false(isThemeInAddonsList(profileDir, a.id));
  do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
  do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));

  do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");

  d.userDisabled = false;

  do_check_false(d.userDisabled);
  do_check_false(d.appDisabled);
  do_check_true(d.isActive);
  do_check_true(isThemeInAddonsList(profileDir, d.id));
  do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
  do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));

  do_check_true(a.userDisabled);
  do_check_false(a.appDisabled);
  do_check_false(a.isActive);
  do_check_false(isThemeInAddonsList(profileDir, a.id));
  do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
  do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));

  do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");

  do_execute_soon(run_test_2);
}

// Tests that after the restart themes can be changed as expected
function run_test_2() {
  restartManager();
  AddonManager.getAddonsByIDs(["default@tests.mozilla.org",
                               "alternate@tests.mozilla.org"], function([d, a]) {
    do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");

    do_check_neq(d, null);
    do_check_false(d.userDisabled);
    do_check_false(d.appDisabled);
    do_check_true(d.isActive);
    do_check_true(isThemeInAddonsList(profileDir, d.id));
    do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));

    do_check_neq(a, null);
    do_check_true(a.userDisabled);
    do_check_false(a.appDisabled);
    do_check_false(a.isActive);
    do_check_false(isThemeInAddonsList(profileDir, a.id));
    do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));

    do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");

    a.userDisabled = false;

    do_check_true(d.userDisabled);
    do_check_false(d.appDisabled);
    do_check_true(d.isActive);
    do_check_true(isThemeInAddonsList(profileDir, d.id));
    do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_true(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));

    do_check_false(a.userDisabled);
    do_check_false(a.appDisabled);
    do_check_false(a.isActive);
    do_check_false(isThemeInAddonsList(profileDir, a.id));
    do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));

    do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");

    d.userDisabled = false;

    do_check_false(d.userDisabled);
    do_check_false(d.appDisabled);
    do_check_true(d.isActive);
    do_check_true(isThemeInAddonsList(profileDir, d.id));
    do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));

    do_check_true(a.userDisabled);
    do_check_false(a.appDisabled);
    do_check_false(a.isActive);
    do_check_false(isThemeInAddonsList(profileDir, a.id));
    do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));

    do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");

    a.userDisabled = false;

    do_check_true(d.userDisabled);
    do_check_false(d.appDisabled);
    do_check_true(d.isActive);
    do_check_true(isThemeInAddonsList(profileDir, d.id));
    do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_true(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));

    do_check_false(a.userDisabled);
    do_check_false(a.appDisabled);
    do_check_false(a.isActive);
    do_check_false(isThemeInAddonsList(profileDir, a.id));
    do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));

    do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");

    do_execute_soon(check_test_2);
  });
}

function check_test_2() {
  restartManager();
  AddonManager.getAddonsByIDs(["default@tests.mozilla.org",
                               "alternate@tests.mozilla.org"], callback_soon(function([d, a]) {
    do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "alternate/1.0");

    do_check_true(d.userDisabled);
    do_check_false(d.appDisabled);
    do_check_false(d.isActive);
    do_check_false(isThemeInAddonsList(profileDir, d.id));
    do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_true(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));

    do_check_false(a.userDisabled);
    do_check_false(a.appDisabled);
    do_check_true(a.isActive);
    do_check_true(isThemeInAddonsList(profileDir, a.id));
    do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));

    d.userDisabled = false;

    do_check_false(d.userDisabled);
    do_check_false(d.appDisabled);
    do_check_false(d.isActive);
    do_check_false(isThemeInAddonsList(profileDir, d.id));
    do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));

    do_check_true(a.userDisabled);
    do_check_false(a.appDisabled);
    do_check_true(a.isActive);
    do_check_true(isThemeInAddonsList(profileDir, a.id));
    do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
    do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));

    do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "alternate/1.0");

    restartManager();

    do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");

    AddonManager.getAddonsByIDs(["default@tests.mozilla.org",
                                 "alternate@tests.mozilla.org"], function([d, a]) {
      do_check_neq(d, null);
      do_check_false(d.userDisabled);
      do_check_false(d.appDisabled);
      do_check_true(d.isActive);
      do_check_true(isThemeInAddonsList(profileDir, d.id));
      do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_DISABLE));
      do_check_false(hasFlag(d.permissions, AddonManager.PERM_CAN_ENABLE));

      do_check_neq(a, null);
      do_check_true(a.userDisabled);
      do_check_false(a.appDisabled);
      do_check_false(a.isActive);
      do_check_false(isThemeInAddonsList(profileDir, a.id));
      do_check_false(hasFlag(a.permissions, AddonManager.PERM_CAN_DISABLE));
      do_check_true(hasFlag(a.permissions, AddonManager.PERM_CAN_ENABLE));

      end_test();
    });
  }));
}