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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Tests the confirmation part of the post-app-update dialog
var gProvider;
var gWin;
function waitForView(aView, aCallback) {
var view = gWin.document.getElementById(aView);
if (view.parentNode.selectedPanel == view) {
aCallback();
return;
}
view.addEventListener("ViewChanged", function() {
view.removeEventListener("ViewChanged", arguments.callee, false);
try {
aCallback();
}
catch (e) {
ok(false, e);
}
}, false);
}
/**
* Creates 4 test add-ons. Two are disabled and two enabled.
*
* @param aAppDisabled
* The appDisabled property for the test add-ons
* @param aUpdateAvailable
* True if the test add-ons should claim to have an update available
*/
function setupUI(aAppDisabled, aUpdateAvailable, aCallback) {
if (gProvider)
gProvider.unregister();
gProvider = new MockProvider();
for (var i = 1; i < 5; i++) {
var addon = new MockAddon("test" + i + "@tests.mozilla.org",
"Test Add-on " + i, "extension");
addon.version = "1.0";
addon.userDisabled = (i > 2);
addon.appDisabled = aAppDisabled;
addon.isActive = !addon.userDisabled && !addon.appDisabled;
addon.findUpdates = function(aListener, aReason, aAppVersion, aPlatformVersion) {
if (aUpdateAvailable) {
var newAddon = new MockAddon(this.id, this.name, "extension");
newAddon.version = "2.0";
var install = new MockInstall(this.name, this.type, newAddon);
install.existingAddon = this;
aListener.onUpdateAvailable(this, install);
}
aListener.onUpdateFinished(this, AddonManager.UPDATE_STATUS_NO_ERROR);
};
gProvider.addAddon(addon);
}
gWin = Services.ww.openWindow(null,
"chrome://mozapps/content/extensions/selectAddons.xul",
"",
"chrome,centerscreen,dialog,titlebar",
null);
waitForFocus(function() {
waitForView("select", function() {
var row = gWin.document.getElementById("select-rows").firstChild.nextSibling;
while (row) {
if (!row.id || row.id.indexOf("@tests.mozilla.org") < 0) {
// not a test add-on
row = row.nextSibling;
continue;
}
if (row.id == "test2@tests.mozilla.org" ||
row.id == "test4@tests.mozilla.org") {
row.disable();
}
else {
row.keep();
}
row = row.nextSibling;
}
waitForView("confirm", aCallback);
EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin);
});
}, gWin);
}
function test() {
waitForExplicitFinish();
run_next_test();
}
function end_test() {
finish();
}
// Test for disabling
add_test(function disabling_test() {
setupUI(false, false, function() {
ok(gWin.document.getElementById("incompatible-list").hidden, "Incompatible list should be hidden");
ok(gWin.document.getElementById("update-list").hidden, "Update list should be hidden");
var list = gWin.document.getElementById("disable-list");
ok(!list.hidden, "Disable list should be visible");
is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)");
is(list.childNodes[1].id, "test2@tests.mozilla.org", "Should be the right add-on ID");
is(list.childNodes[1].getAttribute("name"), "Test Add-on 2", "Should be the right add-on name");
var list = gWin.document.getElementById("enable-list");
ok(!list.hidden, "Enable list should be visible");
is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)");
is(list.childNodes[1].id, "test3@tests.mozilla.org", "Should be the right add-on ID");
is(list.childNodes[1].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name");
ok(gWin.document.getElementById("next").hidden, "Next button should be hidden");
ok(!gWin.document.getElementById("done").hidden, "Done button should be visible");
gWin.close();
run_next_test();
});
});
// Test for incompatible
add_test(function incompatible_test() {
setupUI(true, false, function() {
ok(gWin.document.getElementById("update-list").hidden, "Update list should be hidden");
ok(gWin.document.getElementById("disable-list").hidden, "Disable list should be hidden");
ok(gWin.document.getElementById("enable-list").hidden, "Enable list should be hidden");
var list = gWin.document.getElementById("incompatible-list");
ok(!list.hidden, "Incompatible list should be visible");
is(list.childNodes.length, 3, "Should be two add-ons waiting to be compatible (plus the header)");
is(list.childNodes[1].id, "test1@tests.mozilla.org", "Should be the right add-on ID");
is(list.childNodes[1].getAttribute("name"), "Test Add-on 1", "Should be the right add-on name");
is(list.childNodes[2].id, "test3@tests.mozilla.org", "Should be the right add-on ID");
is(list.childNodes[2].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name");
ok(gWin.document.getElementById("next").hidden, "Next button should be hidden");
ok(!gWin.document.getElementById("done").hidden, "Done button should be visible");
gWin.close();
run_next_test();
});
});
// Test for updates
add_test(function update_test() {
setupUI(false, true, function() {
ok(gWin.document.getElementById("incompatible-list").hidden, "Incompatible list should be hidden");
ok(gWin.document.getElementById("enable-list").hidden, "Enable list should be hidden");
var list = gWin.document.getElementById("update-list");
ok(!list.hidden, "Update list should be visible");
is(list.childNodes.length, 3, "Should be two add-ons waiting to be updated (plus the header)");
is(list.childNodes[1].id, "test1@tests.mozilla.org", "Should be the right add-on ID");
is(list.childNodes[1].getAttribute("name"), "Test Add-on 1", "Should be the right add-on name");
is(list.childNodes[2].id, "test3@tests.mozilla.org", "Should be the right add-on ID");
is(list.childNodes[2].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name");
list = gWin.document.getElementById("disable-list");
ok(!list.hidden, "Disable list should be visible");
is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)");
is(list.childNodes[1].id, "test2@tests.mozilla.org", "Should be the right add-on ID");
is(list.childNodes[1].getAttribute("name"), "Test Add-on 2", "Should be the right add-on name");
ok(!gWin.document.getElementById("next").hidden, "Next button should be visible");
ok(gWin.document.getElementById("done").hidden, "Done button should be hidden");
gWin.close();
run_next_test();
});
});
|