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 manual updates, including the Available Updates pane |
michael@0 | 6 | |
michael@0 | 7 | var gProvider; |
michael@0 | 8 | var gManagerWindow; |
michael@0 | 9 | var gCategoryUtilities; |
michael@0 | 10 | var gAvailableCategory; |
michael@0 | 11 | |
michael@0 | 12 | function test() { |
michael@0 | 13 | waitForExplicitFinish(); |
michael@0 | 14 | |
michael@0 | 15 | gProvider = new MockProvider(); |
michael@0 | 16 | |
michael@0 | 17 | gProvider.createAddons([{ |
michael@0 | 18 | id: "addon1@tests.mozilla.org", |
michael@0 | 19 | name: "auto updating addon", |
michael@0 | 20 | version: "1.0", |
michael@0 | 21 | applyBackgroundUpdates: AddonManager.AUTOUPDATE_ENABLE |
michael@0 | 22 | }]); |
michael@0 | 23 | |
michael@0 | 24 | open_manager("addons://list/extension", function(aWindow) { |
michael@0 | 25 | gManagerWindow = aWindow; |
michael@0 | 26 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 27 | run_next_test(); |
michael@0 | 28 | }); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | function end_test() { |
michael@0 | 32 | close_manager(gManagerWindow, function() { |
michael@0 | 33 | finish(); |
michael@0 | 34 | }); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | |
michael@0 | 38 | add_test(function() { |
michael@0 | 39 | gAvailableCategory = gManagerWindow.gCategories.get("addons://updates/available"); |
michael@0 | 40 | is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should initially be hidden"); |
michael@0 | 41 | |
michael@0 | 42 | gProvider.createAddons([{ |
michael@0 | 43 | id: "addon2@tests.mozilla.org", |
michael@0 | 44 | name: "manually updating addon", |
michael@0 | 45 | version: "1.0", |
michael@0 | 46 | isCompatible: false, |
michael@0 | 47 | blocklistState: Ci.nsIBlocklistService.STATE_BLOCKED, |
michael@0 | 48 | applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE |
michael@0 | 49 | }]); |
michael@0 | 50 | |
michael@0 | 51 | is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should still be hidden"); |
michael@0 | 52 | |
michael@0 | 53 | run_next_test(); |
michael@0 | 54 | }); |
michael@0 | 55 | |
michael@0 | 56 | |
michael@0 | 57 | add_test(function() { |
michael@0 | 58 | gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() { |
michael@0 | 59 | gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false); |
michael@0 | 60 | is(gCategoryUtilities.isVisible(gAvailableCategory), true, "Available Updates category should now be visible"); |
michael@0 | 61 | is(gAvailableCategory.badgeCount, 1, "Badge for Available Updates should now be 1"); |
michael@0 | 62 | run_next_test(); |
michael@0 | 63 | }, false); |
michael@0 | 64 | |
michael@0 | 65 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 66 | gProvider.createInstalls([{ |
michael@0 | 67 | name: "manually updating addon (new and improved!)", |
michael@0 | 68 | existingAddon: gProvider.addons[1], |
michael@0 | 69 | version: "1.1", |
michael@0 | 70 | releaseNotesURI: Services.io.newURI(TESTROOT + "thereIsNoFileHere.xhtml", null, null) |
michael@0 | 71 | }]); |
michael@0 | 72 | |
michael@0 | 73 | var item = get_addon_element(gManagerWindow, "addon2@tests.mozilla.org"); |
michael@0 | 74 | is(item._version.value, "1.0", "Should still show the old version in the normal list"); |
michael@0 | 75 | }); |
michael@0 | 76 | }); |
michael@0 | 77 | |
michael@0 | 78 | |
michael@0 | 79 | add_test(function() { |
michael@0 | 80 | wait_for_view_load(gManagerWindow, function() { |
michael@0 | 81 | is(gManagerWindow.document.getElementById("categories").selectedItem.value, "addons://updates/available", "Available Updates category should now be selected"); |
michael@0 | 82 | is(gManagerWindow.gViewController.currentViewId, "addons://updates/available", "Available Updates view should be the current view"); |
michael@0 | 83 | run_next_test(); |
michael@0 | 84 | }, true); |
michael@0 | 85 | EventUtils.synthesizeMouseAtCenter(gAvailableCategory, { }, gManagerWindow); |
michael@0 | 86 | }); |
michael@0 | 87 | |
michael@0 | 88 | |
michael@0 | 89 | add_test(function() { |
michael@0 | 90 | var list = gManagerWindow.document.getElementById("updates-list"); |
michael@0 | 91 | is(list.itemCount, 1, "Should be 1 available update listed"); |
michael@0 | 92 | var item = list.firstChild; |
michael@0 | 93 | is(item.mAddon.id, "addon2@tests.mozilla.org", "Update item should be for the manually updating addon"); |
michael@0 | 94 | |
michael@0 | 95 | // for manual update items, update-related properties are updated asynchronously, |
michael@0 | 96 | // so we poll for one of the expected changes to know when its done |
michael@0 | 97 | function waitForAsyncInit() { |
michael@0 | 98 | if (item._version.value == "1.1") { |
michael@0 | 99 | run_next_test(); |
michael@0 | 100 | return; |
michael@0 | 101 | } |
michael@0 | 102 | info("Update item not initialized yet, checking again in 100ms"); |
michael@0 | 103 | setTimeout(waitForAsyncInit, 100); |
michael@0 | 104 | } |
michael@0 | 105 | waitForAsyncInit(); |
michael@0 | 106 | }); |
michael@0 | 107 | |
michael@0 | 108 | add_test(function() { |
michael@0 | 109 | var list = gManagerWindow.document.getElementById("updates-list"); |
michael@0 | 110 | var item = list.firstChild; |
michael@0 | 111 | is(item._version.value, "1.1", "Update item should have version number of the update"); |
michael@0 | 112 | var postfix = gManagerWindow.document.getAnonymousElementByAttribute(item, "class", "update-postfix"); |
michael@0 | 113 | is_element_visible(postfix, "'Update' postfix should be visible"); |
michael@0 | 114 | is_element_visible(item._updateAvailable, ""); |
michael@0 | 115 | is_element_visible(item._relNotesToggle, "Release notes toggle should be visible"); |
michael@0 | 116 | is_element_hidden(item._warning, "Incompatible warning should be hidden"); |
michael@0 | 117 | is_element_hidden(item._error, "Blocklist error should be hidden"); |
michael@0 | 118 | |
michael@0 | 119 | info("Opening release notes"); |
michael@0 | 120 | item.addEventListener("RelNotesToggle", function() { |
michael@0 | 121 | item.removeEventListener("RelNotesToggle", arguments.callee, false); |
michael@0 | 122 | info("Release notes now open"); |
michael@0 | 123 | |
michael@0 | 124 | is_element_hidden(item._relNotesLoading, "Release notes loading message should be hidden"); |
michael@0 | 125 | is_element_visible(item._relNotesError, "Release notes error message should be visible"); |
michael@0 | 126 | is(item._relNotes.childElementCount, 0, "Release notes should be empty"); |
michael@0 | 127 | |
michael@0 | 128 | info("Closing release notes"); |
michael@0 | 129 | item.addEventListener("RelNotesToggle", function() { |
michael@0 | 130 | item.removeEventListener("RelNotesToggle", arguments.callee, false); |
michael@0 | 131 | info("Release notes now closed"); |
michael@0 | 132 | info("Setting Release notes URI to something that should load"); |
michael@0 | 133 | gProvider.installs[0].releaseNotesURI = Services.io.newURI(TESTROOT + "releaseNotes.xhtml", null, null) |
michael@0 | 134 | |
michael@0 | 135 | info("Re-opening release notes"); |
michael@0 | 136 | item.addEventListener("RelNotesToggle", function() { |
michael@0 | 137 | item.removeEventListener("RelNotesToggle", arguments.callee, false); |
michael@0 | 138 | info("Release notes now open"); |
michael@0 | 139 | |
michael@0 | 140 | is_element_hidden(item._relNotesLoading, "Release notes loading message should be hidden"); |
michael@0 | 141 | is_element_hidden(item._relNotesError, "Release notes error message should be hidden"); |
michael@0 | 142 | isnot(item._relNotes.childElementCount, 0, "Release notes should have been inserted into container"); |
michael@0 | 143 | run_next_test(); |
michael@0 | 144 | |
michael@0 | 145 | }, false); |
michael@0 | 146 | EventUtils.synthesizeMouseAtCenter(item._relNotesToggle, { }, gManagerWindow); |
michael@0 | 147 | is_element_visible(item._relNotesLoading, "Release notes loading message should be visible"); |
michael@0 | 148 | |
michael@0 | 149 | }, false); |
michael@0 | 150 | EventUtils.synthesizeMouseAtCenter(item._relNotesToggle, { }, gManagerWindow); |
michael@0 | 151 | |
michael@0 | 152 | }, false); |
michael@0 | 153 | EventUtils.synthesizeMouseAtCenter(item._relNotesToggle, { }, gManagerWindow); |
michael@0 | 154 | is_element_visible(item._relNotesLoading, "Release notes loading message should be visible"); |
michael@0 | 155 | }); |
michael@0 | 156 | |
michael@0 | 157 | |
michael@0 | 158 | add_test(function() { |
michael@0 | 159 | var badgeUpdated = false; |
michael@0 | 160 | var installCompleted = false; |
michael@0 | 161 | |
michael@0 | 162 | gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() { |
michael@0 | 163 | gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false); |
michael@0 | 164 | if (installCompleted) |
michael@0 | 165 | run_next_test(); |
michael@0 | 166 | else |
michael@0 | 167 | badgeUpdated = true; |
michael@0 | 168 | }, false); |
michael@0 | 169 | |
michael@0 | 170 | var list = gManagerWindow.document.getElementById("updates-list"); |
michael@0 | 171 | var item = list.firstChild; |
michael@0 | 172 | var updateBtn = item._updateBtn; |
michael@0 | 173 | is_element_visible(updateBtn, "Update button should be visible"); |
michael@0 | 174 | |
michael@0 | 175 | var install = gProvider.installs[0]; |
michael@0 | 176 | var listener = { |
michael@0 | 177 | onInstallStarted: function() { |
michael@0 | 178 | info("Install started"); |
michael@0 | 179 | is_element_visible(item._installStatus, "Install progress widget should be visible"); |
michael@0 | 180 | }, |
michael@0 | 181 | onInstallEnded: function() { |
michael@0 | 182 | install.removeTestListener(this); |
michael@0 | 183 | info("Install ended"); |
michael@0 | 184 | is_element_hidden(item._installStatus, "Install progress widget should be hidden"); |
michael@0 | 185 | |
michael@0 | 186 | if (badgeUpdated) |
michael@0 | 187 | run_next_test(); |
michael@0 | 188 | else |
michael@0 | 189 | installCompleted = true; |
michael@0 | 190 | } |
michael@0 | 191 | }; |
michael@0 | 192 | install.addTestListener(listener); |
michael@0 | 193 | EventUtils.synthesizeMouseAtCenter(updateBtn, { }, gManagerWindow); |
michael@0 | 194 | }); |
michael@0 | 195 | |
michael@0 | 196 | |
michael@0 | 197 | add_test(function() { |
michael@0 | 198 | is(gCategoryUtilities.isVisible(gAvailableCategory), true, "Available Updates category should still be visible"); |
michael@0 | 199 | is(gAvailableCategory.badgeCount, 0, "Badge for Available Updates should now be 0"); |
michael@0 | 200 | |
michael@0 | 201 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 202 | is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should be hidden"); |
michael@0 | 203 | |
michael@0 | 204 | close_manager(gManagerWindow, function() { |
michael@0 | 205 | open_manager(null, function(aWindow) { |
michael@0 | 206 | gManagerWindow = aWindow; |
michael@0 | 207 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 208 | gAvailableCategory = gManagerWindow.gCategories.get("addons://updates/available"); |
michael@0 | 209 | |
michael@0 | 210 | is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should be hidden"); |
michael@0 | 211 | |
michael@0 | 212 | run_next_test(); |
michael@0 | 213 | }); |
michael@0 | 214 | }); |
michael@0 | 215 | }); |
michael@0 | 216 | }); |
michael@0 | 217 | |
michael@0 | 218 | add_test(function() { |
michael@0 | 219 | gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() { |
michael@0 | 220 | gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false); |
michael@0 | 221 | is(gCategoryUtilities.isVisible(gAvailableCategory), true, "Available Updates category should now be visible"); |
michael@0 | 222 | is(gAvailableCategory.badgeCount, 1, "Badge for Available Updates should now be 1"); |
michael@0 | 223 | |
michael@0 | 224 | gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() { |
michael@0 | 225 | gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false); |
michael@0 | 226 | is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should now be hidden"); |
michael@0 | 227 | |
michael@0 | 228 | run_next_test(); |
michael@0 | 229 | }, false); |
michael@0 | 230 | |
michael@0 | 231 | AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) { |
michael@0 | 232 | aAddon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE; |
michael@0 | 233 | }); |
michael@0 | 234 | }, false); |
michael@0 | 235 | |
michael@0 | 236 | gProvider.createInstalls([{ |
michael@0 | 237 | name: "manually updating addon (new and even more improved!)", |
michael@0 | 238 | existingAddon: gProvider.addons[1], |
michael@0 | 239 | version: "1.2", |
michael@0 | 240 | releaseNotesURI: Services.io.newURI(TESTROOT + "thereIsNoFileHere.xhtml", null, null) |
michael@0 | 241 | }]); |
michael@0 | 242 | }); |