Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 // Tests the confirmation part of the post-app-update dialog
7 var gProvider;
8 var gWin;
10 function waitForView(aView, aCallback) {
11 var view = gWin.document.getElementById(aView);
12 if (view.parentNode.selectedPanel == view) {
13 aCallback();
14 return;
15 }
17 view.addEventListener("ViewChanged", function() {
18 view.removeEventListener("ViewChanged", arguments.callee, false);
19 try {
20 aCallback();
21 }
22 catch (e) {
23 ok(false, e);
24 }
25 }, false);
26 }
28 /**
29 * Creates 4 test add-ons. Two are disabled and two enabled.
30 *
31 * @param aAppDisabled
32 * The appDisabled property for the test add-ons
33 * @param aUpdateAvailable
34 * True if the test add-ons should claim to have an update available
35 */
36 function setupUI(aAppDisabled, aUpdateAvailable, aCallback) {
37 if (gProvider)
38 gProvider.unregister();
40 gProvider = new MockProvider();
42 for (var i = 1; i < 5; i++) {
43 var addon = new MockAddon("test" + i + "@tests.mozilla.org",
44 "Test Add-on " + i, "extension");
45 addon.version = "1.0";
46 addon.userDisabled = (i > 2);
47 addon.appDisabled = aAppDisabled;
48 addon.isActive = !addon.userDisabled && !addon.appDisabled;
50 addon.findUpdates = function(aListener, aReason, aAppVersion, aPlatformVersion) {
51 if (aUpdateAvailable) {
52 var newAddon = new MockAddon(this.id, this.name, "extension");
53 newAddon.version = "2.0";
54 var install = new MockInstall(this.name, this.type, newAddon);
55 install.existingAddon = this;
56 aListener.onUpdateAvailable(this, install);
57 }
59 aListener.onUpdateFinished(this, AddonManager.UPDATE_STATUS_NO_ERROR);
60 };
62 gProvider.addAddon(addon);
63 }
65 gWin = Services.ww.openWindow(null,
66 "chrome://mozapps/content/extensions/selectAddons.xul",
67 "",
68 "chrome,centerscreen,dialog,titlebar",
69 null);
70 waitForFocus(function() {
71 waitForView("select", function() {
72 var row = gWin.document.getElementById("select-rows").firstChild.nextSibling;
73 while (row) {
74 if (!row.id || row.id.indexOf("@tests.mozilla.org") < 0) {
75 // not a test add-on
76 row = row.nextSibling;
77 continue;
78 }
80 if (row.id == "test2@tests.mozilla.org" ||
81 row.id == "test4@tests.mozilla.org") {
82 row.disable();
83 }
84 else {
85 row.keep();
86 }
87 row = row.nextSibling;
88 }
90 waitForView("confirm", aCallback);
91 EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin);
92 });
93 }, gWin);
94 }
96 function test() {
97 waitForExplicitFinish();
99 run_next_test();
100 }
102 function end_test() {
103 finish();
104 }
106 // Test for disabling
107 add_test(function disabling_test() {
108 setupUI(false, false, function() {
109 ok(gWin.document.getElementById("incompatible-list").hidden, "Incompatible list should be hidden");
110 ok(gWin.document.getElementById("update-list").hidden, "Update list should be hidden");
112 var list = gWin.document.getElementById("disable-list");
113 ok(!list.hidden, "Disable list should be visible");
114 is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)");
115 is(list.childNodes[1].id, "test2@tests.mozilla.org", "Should be the right add-on ID");
116 is(list.childNodes[1].getAttribute("name"), "Test Add-on 2", "Should be the right add-on name");
118 var list = gWin.document.getElementById("enable-list");
119 ok(!list.hidden, "Enable list should be visible");
120 is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)");
121 is(list.childNodes[1].id, "test3@tests.mozilla.org", "Should be the right add-on ID");
122 is(list.childNodes[1].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name");
124 ok(gWin.document.getElementById("next").hidden, "Next button should be hidden");
125 ok(!gWin.document.getElementById("done").hidden, "Done button should be visible");
126 gWin.close();
128 run_next_test();
129 });
130 });
132 // Test for incompatible
133 add_test(function incompatible_test() {
134 setupUI(true, false, function() {
135 ok(gWin.document.getElementById("update-list").hidden, "Update list should be hidden");
136 ok(gWin.document.getElementById("disable-list").hidden, "Disable list should be hidden");
137 ok(gWin.document.getElementById("enable-list").hidden, "Enable list should be hidden");
139 var list = gWin.document.getElementById("incompatible-list");
140 ok(!list.hidden, "Incompatible list should be visible");
141 is(list.childNodes.length, 3, "Should be two add-ons waiting to be compatible (plus the header)");
142 is(list.childNodes[1].id, "test1@tests.mozilla.org", "Should be the right add-on ID");
143 is(list.childNodes[1].getAttribute("name"), "Test Add-on 1", "Should be the right add-on name");
144 is(list.childNodes[2].id, "test3@tests.mozilla.org", "Should be the right add-on ID");
145 is(list.childNodes[2].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name");
147 ok(gWin.document.getElementById("next").hidden, "Next button should be hidden");
148 ok(!gWin.document.getElementById("done").hidden, "Done button should be visible");
149 gWin.close();
151 run_next_test();
152 });
153 });
155 // Test for updates
156 add_test(function update_test() {
157 setupUI(false, true, function() {
158 ok(gWin.document.getElementById("incompatible-list").hidden, "Incompatible list should be hidden");
159 ok(gWin.document.getElementById("enable-list").hidden, "Enable list should be hidden");
161 var list = gWin.document.getElementById("update-list");
162 ok(!list.hidden, "Update list should be visible");
163 is(list.childNodes.length, 3, "Should be two add-ons waiting to be updated (plus the header)");
164 is(list.childNodes[1].id, "test1@tests.mozilla.org", "Should be the right add-on ID");
165 is(list.childNodes[1].getAttribute("name"), "Test Add-on 1", "Should be the right add-on name");
166 is(list.childNodes[2].id, "test3@tests.mozilla.org", "Should be the right add-on ID");
167 is(list.childNodes[2].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name");
169 list = gWin.document.getElementById("disable-list");
170 ok(!list.hidden, "Disable list should be visible");
171 is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)");
172 is(list.childNodes[1].id, "test2@tests.mozilla.org", "Should be the right add-on ID");
173 is(list.childNodes[1].getAttribute("name"), "Test Add-on 2", "Should be the right add-on name");
175 ok(!gWin.document.getElementById("next").hidden, "Next button should be visible");
176 ok(gWin.document.getElementById("done").hidden, "Done button should be hidden");
177 gWin.close();
179 run_next_test();
180 });
181 });