summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_strictcompatibility.js
blob: 788e1ef79a5037c2b0132079342e103451e34621 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests AddonManager.strictCompatibility and it's related preference,
// extensions.strictCompatibility, and the strictCompatibility option in
// install.rdf


// Always compatible
var addon1 = {
  id: "addon1@tests.mozilla.org",
  version: "1.0",
  name: "Test 1",
  targetApplications: [{
    id: "xpcshell@tests.mozilla.org",
    minVersion: "1",
    maxVersion: "1"
  }]
};

// Incompatible in strict compatibility mode
var addon2 = {
  id: "addon2@tests.mozilla.org",
  version: "1.0",
  name: "Test 2",
  targetApplications: [{
    id: "xpcshell@tests.mozilla.org",
    minVersion: "0.7",
    maxVersion: "0.8"
  }]
};

// Theme - always uses strict compatibility, so is always incompatible
var addon3 = {
  id: "addon3@tests.mozilla.org",
  version: "1.0",
  name: "Test 3",
  internalName: "test-theme-3",
  targetApplications: [{
    id: "xpcshell@tests.mozilla.org",
    minVersion: "0.8",
    maxVersion: "0.9"
  }]
};

// Opt-in to strict compatibility - always incompatible
var addon4 = {
  id: "addon4@tests.mozilla.org",
  version: "1.0",
  name: "Test 4",
  strictCompatibility: true,
  targetApplications: [{
    id: "xpcshell@tests.mozilla.org",
    minVersion: "0.8",
    maxVersion: "0.9"
  }]
};

// Addon from the future - would be marked as compatibile-by-default,
// but minVersion is higher than the app version
var addon5 = {
  id: "addon5@tests.mozilla.org",
  version: "1.0",
  name: "Test 5",
  targetApplications: [{
    id: "xpcshell@tests.mozilla.org",
    minVersion: "3",
    maxVersion: "5"
  }]
};

// Extremely old addon - maxVersion is less than the mimimum compat version
// set in extensions.minCompatibleVersion
var addon6 = {
  id: "addon6@tests.mozilla.org",
  version: "1.0",
  name: "Test 6",
  targetApplications: [{
    id: "xpcshell@tests.mozilla.org",
    minVersion: "0.1",
    maxVersion: "0.2"
  }]
};

// Dictionary - incompatible in strict compatibility mode
var addon7= {
  id: "addon7@tests.mozilla.org",
  version: "1.0",
  name: "Test 7",
  type: "64",
  targetApplications: [{
    id: "xpcshell@tests.mozilla.org",
    minVersion: "0.8",
    maxVersion: "0.9"
  }]
};



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


function do_check_compat_status(aStrict, aAddonCompat, aCallback) {
  do_check_eq(AddonManager.strictCompatibility, aStrict);
  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                               "addon2@tests.mozilla.org",
                               "addon3@tests.mozilla.org",
                               "addon4@tests.mozilla.org",
                               "addon5@tests.mozilla.org",
                               "addon6@tests.mozilla.org",
                               "addon7@tests.mozilla.org"],
                              function([a1, a2, a3, a4, a5, a6, a7]) {
    do_check_neq(a1, null);
    do_check_eq(a1.isCompatible, aAddonCompat[0]);
    do_check_eq(a1.appDisabled, !aAddonCompat[0]);
    do_check_false(a1.strictCompatibility);

    do_check_neq(a2, null);
    do_check_eq(a2.isCompatible, aAddonCompat[1]);
    do_check_eq(a2.appDisabled, !aAddonCompat[1]);
    do_check_false(a2.strictCompatibility);

    do_check_neq(a3, null);
    do_check_eq(a3.isCompatible, aAddonCompat[2]);
    do_check_eq(a3.appDisabled, !aAddonCompat[2]);
    do_check_true(a3.strictCompatibility);

    do_check_neq(a4, null);
    do_check_eq(a4.isCompatible, aAddonCompat[3]);
    do_check_eq(a4.appDisabled, !aAddonCompat[3]);
    do_check_true(a4.strictCompatibility);

    do_check_neq(a5, null);
    do_check_eq(a5.isCompatible, aAddonCompat[4]);
    do_check_eq(a5.appDisabled, !aAddonCompat[4]);
    do_check_false(a5.strictCompatibility);

    do_check_neq(a6, null);
    do_check_eq(a6.isCompatible, aAddonCompat[5]);
    do_check_eq(a6.appDisabled, !aAddonCompat[5]);
    do_check_false(a6.strictCompatibility);

    do_check_neq(a7, null);
    do_check_eq(a7.isCompatible, aAddonCompat[6]);
    do_check_eq(a7.appDisabled, !aAddonCompat[6]);
    do_check_false(a7.strictCompatibility);

    do_execute_soon(aCallback);
  });
}


function run_test() {
  do_test_pending();
  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
  
  writeInstallRDFForExtension(addon1, profileDir);
  writeInstallRDFForExtension(addon2, profileDir);
  writeInstallRDFForExtension(addon3, profileDir);
  writeInstallRDFForExtension(addon4, profileDir);
  writeInstallRDFForExtension(addon5, profileDir);
  writeInstallRDFForExtension(addon6, profileDir);
  writeInstallRDFForExtension(addon7, profileDir);

  Services.prefs.setCharPref(PREF_EM_MIN_COMPAT_APP_VERSION, "0.1");

  startupManager();

  // Should default to enabling strict compat.
  do_check_compat_status(true, [true, false, false, false, false, false, false], run_test_1);
}

function run_test_1() {
  do_print("Test 1");
  Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
  do_check_compat_status(false, [true, true, false, false, false, true, true], run_test_2);
}

function run_test_2() {
  do_print("Test 2");
  restartManager();
  do_check_compat_status(false, [true, true, false, false, false, true, true], run_test_3);
}

function run_test_3() {
  do_print("Test 3");
  Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true);
  do_check_compat_status(true, [true, false, false, false, false, false, false], run_test_4);
}

function run_test_4() {
  do_print("Test 4");
  restartManager();
  do_check_compat_status(true, [true, false, false, false, false, false, false], run_test_5);
}

function run_test_5() {
  do_print("Test 5");
  Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
  Services.prefs.setCharPref(PREF_EM_MIN_COMPAT_APP_VERSION, "0.4");
  do_check_compat_status(false, [true, true, false, false, false, false, true], do_test_finished);
}