michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Tests manual updates, including the Available Updates pane michael@0: michael@0: var gProvider; michael@0: var gManagerWindow; michael@0: var gCategoryUtilities; michael@0: var gAvailableCategory; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gProvider = new MockProvider(); michael@0: michael@0: gProvider.createAddons([{ michael@0: id: "addon1@tests.mozilla.org", michael@0: name: "auto updating addon", michael@0: version: "1.0", michael@0: applyBackgroundUpdates: AddonManager.AUTOUPDATE_ENABLE michael@0: }]); michael@0: michael@0: open_manager("addons://list/extension", function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: gCategoryUtilities = new CategoryUtilities(gManagerWindow); michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: close_manager(gManagerWindow, function() { michael@0: finish(); michael@0: }); michael@0: } michael@0: michael@0: michael@0: add_test(function() { michael@0: gAvailableCategory = gManagerWindow.gCategories.get("addons://updates/available"); michael@0: is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should initially be hidden"); michael@0: michael@0: gProvider.createAddons([{ michael@0: id: "addon2@tests.mozilla.org", michael@0: name: "manually updating addon", michael@0: version: "1.0", michael@0: isCompatible: false, michael@0: blocklistState: Ci.nsIBlocklistService.STATE_BLOCKED, michael@0: applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE michael@0: }]); michael@0: michael@0: is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should still be hidden"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: michael@0: add_test(function() { michael@0: gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() { michael@0: gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false); michael@0: is(gCategoryUtilities.isVisible(gAvailableCategory), true, "Available Updates category should now be visible"); michael@0: is(gAvailableCategory.badgeCount, 1, "Badge for Available Updates should now be 1"); michael@0: run_next_test(); michael@0: }, false); michael@0: michael@0: gCategoryUtilities.openType("extension", function() { michael@0: gProvider.createInstalls([{ michael@0: name: "manually updating addon (new and improved!)", michael@0: existingAddon: gProvider.addons[1], michael@0: version: "1.1", michael@0: releaseNotesURI: Services.io.newURI(TESTROOT + "thereIsNoFileHere.xhtml", null, null) michael@0: }]); michael@0: michael@0: var item = get_addon_element(gManagerWindow, "addon2@tests.mozilla.org"); michael@0: is(item._version.value, "1.0", "Should still show the old version in the normal list"); michael@0: }); michael@0: }); michael@0: michael@0: michael@0: add_test(function() { michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: is(gManagerWindow.document.getElementById("categories").selectedItem.value, "addons://updates/available", "Available Updates category should now be selected"); michael@0: is(gManagerWindow.gViewController.currentViewId, "addons://updates/available", "Available Updates view should be the current view"); michael@0: run_next_test(); michael@0: }, true); michael@0: EventUtils.synthesizeMouseAtCenter(gAvailableCategory, { }, gManagerWindow); michael@0: }); michael@0: michael@0: michael@0: add_test(function() { michael@0: var list = gManagerWindow.document.getElementById("updates-list"); michael@0: is(list.itemCount, 1, "Should be 1 available update listed"); michael@0: var item = list.firstChild; michael@0: is(item.mAddon.id, "addon2@tests.mozilla.org", "Update item should be for the manually updating addon"); michael@0: michael@0: // for manual update items, update-related properties are updated asynchronously, michael@0: // so we poll for one of the expected changes to know when its done michael@0: function waitForAsyncInit() { michael@0: if (item._version.value == "1.1") { michael@0: run_next_test(); michael@0: return; michael@0: } michael@0: info("Update item not initialized yet, checking again in 100ms"); michael@0: setTimeout(waitForAsyncInit, 100); michael@0: } michael@0: waitForAsyncInit(); michael@0: }); michael@0: michael@0: add_test(function() { michael@0: var list = gManagerWindow.document.getElementById("updates-list"); michael@0: var item = list.firstChild; michael@0: is(item._version.value, "1.1", "Update item should have version number of the update"); michael@0: var postfix = gManagerWindow.document.getAnonymousElementByAttribute(item, "class", "update-postfix"); michael@0: is_element_visible(postfix, "'Update' postfix should be visible"); michael@0: is_element_visible(item._updateAvailable, ""); michael@0: is_element_visible(item._relNotesToggle, "Release notes toggle should be visible"); michael@0: is_element_hidden(item._warning, "Incompatible warning should be hidden"); michael@0: is_element_hidden(item._error, "Blocklist error should be hidden"); michael@0: michael@0: info("Opening release notes"); michael@0: item.addEventListener("RelNotesToggle", function() { michael@0: item.removeEventListener("RelNotesToggle", arguments.callee, false); michael@0: info("Release notes now open"); michael@0: michael@0: is_element_hidden(item._relNotesLoading, "Release notes loading message should be hidden"); michael@0: is_element_visible(item._relNotesError, "Release notes error message should be visible"); michael@0: is(item._relNotes.childElementCount, 0, "Release notes should be empty"); michael@0: michael@0: info("Closing release notes"); michael@0: item.addEventListener("RelNotesToggle", function() { michael@0: item.removeEventListener("RelNotesToggle", arguments.callee, false); michael@0: info("Release notes now closed"); michael@0: info("Setting Release notes URI to something that should load"); michael@0: gProvider.installs[0].releaseNotesURI = Services.io.newURI(TESTROOT + "releaseNotes.xhtml", null, null) michael@0: michael@0: info("Re-opening release notes"); michael@0: item.addEventListener("RelNotesToggle", function() { michael@0: item.removeEventListener("RelNotesToggle", arguments.callee, false); michael@0: info("Release notes now open"); michael@0: michael@0: is_element_hidden(item._relNotesLoading, "Release notes loading message should be hidden"); michael@0: is_element_hidden(item._relNotesError, "Release notes error message should be hidden"); michael@0: isnot(item._relNotes.childElementCount, 0, "Release notes should have been inserted into container"); michael@0: run_next_test(); michael@0: michael@0: }, false); michael@0: EventUtils.synthesizeMouseAtCenter(item._relNotesToggle, { }, gManagerWindow); michael@0: is_element_visible(item._relNotesLoading, "Release notes loading message should be visible"); michael@0: michael@0: }, false); michael@0: EventUtils.synthesizeMouseAtCenter(item._relNotesToggle, { }, gManagerWindow); michael@0: michael@0: }, false); michael@0: EventUtils.synthesizeMouseAtCenter(item._relNotesToggle, { }, gManagerWindow); michael@0: is_element_visible(item._relNotesLoading, "Release notes loading message should be visible"); michael@0: }); michael@0: michael@0: michael@0: add_test(function() { michael@0: var badgeUpdated = false; michael@0: var installCompleted = false; michael@0: michael@0: gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() { michael@0: gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false); michael@0: if (installCompleted) michael@0: run_next_test(); michael@0: else michael@0: badgeUpdated = true; michael@0: }, false); michael@0: michael@0: var list = gManagerWindow.document.getElementById("updates-list"); michael@0: var item = list.firstChild; michael@0: var updateBtn = item._updateBtn; michael@0: is_element_visible(updateBtn, "Update button should be visible"); michael@0: michael@0: var install = gProvider.installs[0]; michael@0: var listener = { michael@0: onInstallStarted: function() { michael@0: info("Install started"); michael@0: is_element_visible(item._installStatus, "Install progress widget should be visible"); michael@0: }, michael@0: onInstallEnded: function() { michael@0: install.removeTestListener(this); michael@0: info("Install ended"); michael@0: is_element_hidden(item._installStatus, "Install progress widget should be hidden"); michael@0: michael@0: if (badgeUpdated) michael@0: run_next_test(); michael@0: else michael@0: installCompleted = true; michael@0: } michael@0: }; michael@0: install.addTestListener(listener); michael@0: EventUtils.synthesizeMouseAtCenter(updateBtn, { }, gManagerWindow); michael@0: }); michael@0: michael@0: michael@0: add_test(function() { michael@0: is(gCategoryUtilities.isVisible(gAvailableCategory), true, "Available Updates category should still be visible"); michael@0: is(gAvailableCategory.badgeCount, 0, "Badge for Available Updates should now be 0"); michael@0: michael@0: gCategoryUtilities.openType("extension", function() { michael@0: is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should be hidden"); michael@0: michael@0: close_manager(gManagerWindow, function() { michael@0: open_manager(null, function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: gCategoryUtilities = new CategoryUtilities(gManagerWindow); michael@0: gAvailableCategory = gManagerWindow.gCategories.get("addons://updates/available"); michael@0: michael@0: is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should be hidden"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: add_test(function() { michael@0: gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() { michael@0: gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false); michael@0: is(gCategoryUtilities.isVisible(gAvailableCategory), true, "Available Updates category should now be visible"); michael@0: is(gAvailableCategory.badgeCount, 1, "Badge for Available Updates should now be 1"); michael@0: michael@0: gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() { michael@0: gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false); michael@0: is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should now be hidden"); michael@0: michael@0: run_next_test(); michael@0: }, false); michael@0: michael@0: AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) { michael@0: aAddon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE; michael@0: }); michael@0: }, false); michael@0: michael@0: gProvider.createInstalls([{ michael@0: name: "manually updating addon (new and even more improved!)", michael@0: existingAddon: gProvider.addons[1], michael@0: version: "1.2", michael@0: releaseNotesURI: Services.io.newURI(TESTROOT + "thereIsNoFileHere.xhtml", null, null) michael@0: }]); michael@0: });