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.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | // Tests the selection part of the post-app-update dialog |
michael@0 | 6 | |
michael@0 | 7 | var gProvider; |
michael@0 | 8 | var gWin; |
michael@0 | 9 | |
michael@0 | 10 | const PROFILE = AddonManager.SCOPE_PROFILE; |
michael@0 | 11 | const USER = AddonManager.SCOPE_USER; |
michael@0 | 12 | const APP = AddonManager.SCOPE_APPLICATION; |
michael@0 | 13 | const SYSTEM = AddonManager.SCOPE_SYSTEM; |
michael@0 | 14 | const DIST = -1; |
michael@0 | 15 | |
michael@0 | 16 | // The matrix of testcases for the selection part of the UI |
michael@0 | 17 | // Note that the isActive flag has the value it had when the previous version |
michael@0 | 18 | // of the application ran with this add-on. |
michael@0 | 19 | var ADDONS = [ |
michael@0 | 20 | //userDisabled wasAppDisabled isAppDisabled isActive hasUpdate autoUpdate scope defaultKeep position keepString disableString |
michael@0 | 21 | [false, true, false, false, false, true, PROFILE, true, 42, "enabled", ""], // 0 |
michael@0 | 22 | [false, true, false, false, true, true, PROFILE, true, 43, "enabled", ""], // 1 |
michael@0 | 23 | [false, true, false, false, true, false, PROFILE, true, 52, "unneededupdate", ""], // 2 |
michael@0 | 24 | [false, false, false, true, false, true, PROFILE, true, 53, "", "disabled"], // 3 |
michael@0 | 25 | [false, false, false, true, true, true, PROFILE, true, 54, "", "disabled"], // 4 |
michael@0 | 26 | [false, false, false, true, true, false, PROFILE, true, 55, "unneededupdate", "disabled"], // 5 |
michael@0 | 27 | [false, true, true, false, false, true, PROFILE, true, 56, "incompatible", ""], // 6 |
michael@0 | 28 | [false, true, true, false, true, true, PROFILE, true, 57, "autoupdate", ""], // 7 |
michael@0 | 29 | [false, true, true, false, true, false, PROFILE, true, 58, "neededupdate", ""], // 8 |
michael@0 | 30 | [false, false, true, true, false, true, PROFILE, true, 59, "incompatible", "disabled"], // 9 |
michael@0 | 31 | [false, true, true, true, true, true, PROFILE, true, 44, "autoupdate", "disabled"], // 10 |
michael@0 | 32 | [false, true, true, true, true, false, PROFILE, true, 45, "neededupdate", "disabled"], // 11 |
michael@0 | 33 | [true, false, false, false, false, true, PROFILE, false, 46, "enabled", ""], // 12 |
michael@0 | 34 | [true, false, false, false, true, true, PROFILE, false, 47, "enabled", ""], // 13 |
michael@0 | 35 | [true, false, false, false, true, false, PROFILE, false, 48, "unneededupdate", ""], // 14 |
michael@0 | 36 | |
michael@0 | 37 | // userDisabled and isActive cannot be true on startup |
michael@0 | 38 | |
michael@0 | 39 | [true, true, true, false, false, true, PROFILE, false, 49, "incompatible", ""], // 15 |
michael@0 | 40 | [true, true, true, false, true, true, PROFILE, false, 50, "autoupdate", ""], // 16 |
michael@0 | 41 | [true, true, true, false, true, false, PROFILE, false, 51, "neededupdate", ""], // 17 |
michael@0 | 42 | |
michael@0 | 43 | // userDisabled and isActive cannot be true on startup |
michael@0 | 44 | |
michael@0 | 45 | // Being in a different scope should make little difference except no updates are possible so don't exhaustively test each |
michael@0 | 46 | [false, false, false, true, true, false, USER, false, 0, "", "disabled"], // 18 |
michael@0 | 47 | [true, true, false, false, true, false, USER, false, 1, "enabled", ""], // 19 |
michael@0 | 48 | [false, true, true, true, true, false, USER, false, 2, "incompatible", "disabled"], // 20 |
michael@0 | 49 | [true, true, true, false, true, false, USER, false, 3, "incompatible", ""], // 21 |
michael@0 | 50 | [false, false, false, true, true, false, SYSTEM, false, 4, "", "disabled"], // 22 |
michael@0 | 51 | [true, true, false, false, true, false, SYSTEM, false, 5, "enabled", ""], // 23 |
michael@0 | 52 | [false, true, true, true, true, false, SYSTEM, false, 6, "incompatible", "disabled"], // 24 |
michael@0 | 53 | [true, true, true, false, true, false, SYSTEM, false, 7, "incompatible", ""], // 25 |
michael@0 | 54 | [false, false, false, true, true, false, APP, false, 8, "", "disabled"], // 26 |
michael@0 | 55 | [true, true, false, false, true, false, APP, false, 9, "enabled", ""], // 27 |
michael@0 | 56 | [false, true, true, true, true, false, APP, false, 10, "incompatible", "disabled"], // 28 |
michael@0 | 57 | [true, true, true, false, true, false, APP, false, 11, "incompatible", ""], // 29 |
michael@0 | 58 | ]; |
michael@0 | 59 | |
michael@0 | 60 | function waitForView(aView, aCallback) { |
michael@0 | 61 | var view = gWin.document.getElementById(aView); |
michael@0 | 62 | if (view.parentNode.selectedPanel == view) { |
michael@0 | 63 | aCallback(); |
michael@0 | 64 | return; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | view.addEventListener("ViewChanged", function() { |
michael@0 | 68 | view.removeEventListener("ViewChanged", arguments.callee, false); |
michael@0 | 69 | aCallback(); |
michael@0 | 70 | }, false); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | function getString(aName) { |
michael@0 | 74 | if (!aName) |
michael@0 | 75 | return ""; |
michael@0 | 76 | |
michael@0 | 77 | var strings = Services.strings.createBundle("chrome://mozapps/locale/extensions/selectAddons.properties"); |
michael@0 | 78 | return strings.GetStringFromName("action." + aName); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function getSourceString(aSource) { |
michael@0 | 82 | if (!aSource) |
michael@0 | 83 | return ""; |
michael@0 | 84 | |
michael@0 | 85 | var strings = Services.strings.createBundle("chrome://mozapps/locale/extensions/selectAddons.properties"); |
michael@0 | 86 | switch (aSource) { |
michael@0 | 87 | case PROFILE: |
michael@0 | 88 | return strings.GetStringFromName("source.profile"); |
michael@0 | 89 | case DIST: |
michael@0 | 90 | return strings.GetStringFromName("source.bundled"); |
michael@0 | 91 | default: |
michael@0 | 92 | return strings.GetStringFromName("source.other"); |
michael@0 | 93 | } |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | function test() { |
michael@0 | 97 | waitForExplicitFinish(); |
michael@0 | 98 | |
michael@0 | 99 | gProvider = new MockProvider(); |
michael@0 | 100 | |
michael@0 | 101 | // Set prefs for Distributed Extension Source tests. |
michael@0 | 102 | Services.prefs.setBoolPref("extensions.installedDistroAddon.test3@tests.mozilla.org", true); |
michael@0 | 103 | Services.prefs.setBoolPref("extensions.installedDistroAddon.test12@tests.mozilla.org", true); |
michael@0 | 104 | Services.prefs.setBoolPref("extensions.installedDistroAddon.test15@tests.mozilla.org", true); |
michael@0 | 105 | |
michael@0 | 106 | for (let pos in ADDONS) { |
michael@0 | 107 | let addonItem = ADDONS[pos]; |
michael@0 | 108 | let addon = new MockAddon("test" + pos + "@tests.mozilla.org", |
michael@0 | 109 | "Test Add-on " + pos, "extension"); |
michael@0 | 110 | addon.version = "1.0"; |
michael@0 | 111 | addon.userDisabled = addonItem[0]; |
michael@0 | 112 | addon.appDisabled = addonItem[1]; |
michael@0 | 113 | addon.isActive = addonItem[3]; |
michael@0 | 114 | addon.applyBackgroundUpdates = addonItem[5] ? AddonManager.AUTOUPDATE_ENABLE |
michael@0 | 115 | : AddonManager.AUTOUPDATE_DISABLE; |
michael@0 | 116 | addon.scope = addonItem[6]; |
michael@0 | 117 | |
michael@0 | 118 | // Remove the upgrade permission from non-profile add-ons |
michael@0 | 119 | if (addon.scope != AddonManager.SCOPE_PROFILE) |
michael@0 | 120 | addon._permissions -= AddonManager.PERM_CAN_UPGRADE; |
michael@0 | 121 | |
michael@0 | 122 | addon.findUpdates = function(aListener, aReason, aAppVersion, aPlatformVersion) { |
michael@0 | 123 | addon.appDisabled = addonItem[2]; |
michael@0 | 124 | addon.isActive = addon.shouldBeActive; |
michael@0 | 125 | |
michael@0 | 126 | if (addonItem[4]) { |
michael@0 | 127 | var newAddon = new MockAddon(this.id, this.name, "extension"); |
michael@0 | 128 | newAddon.version = "2.0"; |
michael@0 | 129 | var install = new MockInstall(this.name, this.type, newAddon); |
michael@0 | 130 | install.existingAddon = this; |
michael@0 | 131 | aListener.onUpdateAvailable(this, install); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | aListener.onUpdateFinished(this, AddonManager.UPDATE_STATUS_NO_ERROR); |
michael@0 | 135 | }; |
michael@0 | 136 | |
michael@0 | 137 | gProvider.addAddon(addon); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | gWin = Services.ww.openWindow(null, |
michael@0 | 141 | "chrome://mozapps/content/extensions/selectAddons.xul", |
michael@0 | 142 | "", |
michael@0 | 143 | "chrome,centerscreen,dialog,titlebar", |
michael@0 | 144 | null); |
michael@0 | 145 | waitForFocus(function() { |
michael@0 | 146 | waitForView("select", run_next_test); |
michael@0 | 147 | }, gWin); |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | function end_test() { |
michael@0 | 151 | gWin.close(); |
michael@0 | 152 | finish(); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | // Minimal test for the checking UI |
michael@0 | 156 | add_test(function checking_test() { |
michael@0 | 157 | // By the time we're here the progress bar should be full |
michael@0 | 158 | var progress = gWin.document.getElementById("checking-progress"); |
michael@0 | 159 | is(progress.mode, "determined", "Should be a determined progress bar"); |
michael@0 | 160 | is(progress.value, progress.max, "Should be at full progress"); |
michael@0 | 161 | |
michael@0 | 162 | run_next_test(); |
michael@0 | 163 | }); |
michael@0 | 164 | |
michael@0 | 165 | // Tests that the selection UI behaves correctly |
michael@0 | 166 | add_test(function selection_test() { |
michael@0 | 167 | function check_state() { |
michael@0 | 168 | var str = addon[keep.checked ? 9 : 10]; |
michael@0 | 169 | var expected = getString(str); |
michael@0 | 170 | var showCheckbox = str == "neededupdate" || str == "unneededupdate"; |
michael@0 | 171 | is(action.textContent, expected, "Action message should have the right text"); |
michael@0 | 172 | is(!is_hidden(update), showCheckbox, "Checkbox should have the right visibility"); |
michael@0 | 173 | is(is_hidden(action), showCheckbox, "Message should have the right visibility"); |
michael@0 | 174 | if (showCheckbox) |
michael@0 | 175 | ok(update.checked, "Optional update checkbox should be checked"); |
michael@0 | 176 | |
michael@0 | 177 | if (keep.checked) { |
michael@0 | 178 | is(row.hasAttribute("active"), !addon[2] || hasUpdate, |
michael@0 | 179 | "Add-on will be active if it isn't appDisabled or an update is available"); |
michael@0 | 180 | |
michael@0 | 181 | if (showCheckbox) { |
michael@0 | 182 | info("Flipping update checkbox"); |
michael@0 | 183 | EventUtils.synthesizeMouseAtCenter(update, { }, gWin); |
michael@0 | 184 | is(row.hasAttribute("active"), str == "unneededupdate", |
michael@0 | 185 | "If the optional update isn't needed then the add-on will still be active"); |
michael@0 | 186 | |
michael@0 | 187 | info("Flipping update checkbox"); |
michael@0 | 188 | EventUtils.synthesizeMouseAtCenter(update, { }, gWin); |
michael@0 | 189 | is(row.hasAttribute("active"), !addon[2] || hasUpdate, |
michael@0 | 190 | "Add-on will be active if it isn't appDisabled or an update is available"); |
michael@0 | 191 | } |
michael@0 | 192 | } |
michael@0 | 193 | else { |
michael@0 | 194 | ok(!row.hasAttribute("active"), "Add-on won't be active when not keeping"); |
michael@0 | 195 | |
michael@0 | 196 | if (showCheckbox) { |
michael@0 | 197 | info("Flipping update checkbox"); |
michael@0 | 198 | EventUtils.synthesizeMouseAtCenter(update, { }, gWin); |
michael@0 | 199 | ok(!row.hasAttribute("active"), |
michael@0 | 200 | "Unchecking the update checkbox shouldn't make the add-on active"); |
michael@0 | 201 | |
michael@0 | 202 | info("Flipping update checkbox"); |
michael@0 | 203 | EventUtils.synthesizeMouseAtCenter(update, { }, gWin); |
michael@0 | 204 | ok(!row.hasAttribute("active"), |
michael@0 | 205 | "Re-checking the update checkbox shouldn't make the add-on active"); |
michael@0 | 206 | } |
michael@0 | 207 | } |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | is(gWin.document.getElementById("view-deck").selectedPanel.id, "select", |
michael@0 | 211 | "Should be on the right view"); |
michael@0 | 212 | |
michael@0 | 213 | var pos = 0; |
michael@0 | 214 | var scrollbox = gWin.document.getElementById("select-scrollbox"); |
michael@0 | 215 | var scrollBoxObject = scrollbox.boxObject.QueryInterface(Ci.nsIScrollBoxObject); |
michael@0 | 216 | for (var row = gWin.document.getElementById("select-rows").firstChild; row; row = row.nextSibling) { |
michael@0 | 217 | // Ignore separators but increase the position by a large amount so we |
michael@0 | 218 | // can verify they were in the right place |
michael@0 | 219 | if (row.localName == "separator") { |
michael@0 | 220 | pos += 30; |
michael@0 | 221 | continue; |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | is(row._addon.type, "extension", "Should only be listing extensions"); |
michael@0 | 225 | |
michael@0 | 226 | // Ignore non-test add-ons that may be present |
michael@0 | 227 | if (row.id.substr(-18) != "@tests.mozilla.org") |
michael@0 | 228 | continue; |
michael@0 | 229 | |
michael@0 | 230 | var id = parseInt(row.id.substring(4, row.id.length - 18)); |
michael@0 | 231 | var addon = ADDONS[id]; |
michael@0 | 232 | |
michael@0 | 233 | info("Testing add-on " + id); |
michael@0 | 234 | scrollBoxObject.ensureElementIsVisible(row); |
michael@0 | 235 | var keep = gWin.document.getAnonymousElementByAttribute(row, "anonid", "keep"); |
michael@0 | 236 | var action = gWin.document.getAnonymousElementByAttribute(row, "class", "addon-action-message"); |
michael@0 | 237 | var update = gWin.document.getAnonymousElementByAttribute(row, "anonid", "update"); |
michael@0 | 238 | var source = gWin.document.getAnonymousElementByAttribute(row, "class", "addon-source"); |
michael@0 | 239 | |
michael@0 | 240 | if (id == 3 || id == 12 || id == 15) { |
michael@0 | 241 | // Distro Installed To Profile |
michael@0 | 242 | is(source.textContent, getSourceString(DIST), "Source message should have the right text for Distributed Addons"); |
michael@0 | 243 | } else { |
michael@0 | 244 | is(source.textContent, getSourceString(addon[6]), "Source message should have the right text"); |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | // Non-profile add-ons don't appear to have updates since we won't install |
michael@0 | 248 | // them |
michael@0 | 249 | var hasUpdate = addon[4] && addon[6] == PROFILE; |
michael@0 | 250 | |
michael@0 | 251 | is(pos, addon[8], "Should have been in the right position"); |
michael@0 | 252 | is(keep.checked, addon[7], "Keep checkbox should be in the right state"); |
michael@0 | 253 | |
michael@0 | 254 | check_state(); |
michael@0 | 255 | |
michael@0 | 256 | info("Flipping keep"); |
michael@0 | 257 | EventUtils.synthesizeMouseAtCenter(keep, { }, gWin); |
michael@0 | 258 | is(keep.checked, !addon[7], "Keep checkbox should be in the right state"); |
michael@0 | 259 | |
michael@0 | 260 | check_state(); |
michael@0 | 261 | |
michael@0 | 262 | pos++; |
michael@0 | 263 | } |
michael@0 | 264 | |
michael@0 | 265 | is(pos, 60, "Should have seen the right number of add-ons"); |
michael@0 | 266 | |
michael@0 | 267 | run_next_test(); |
michael@0 | 268 | }); |