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 the recent updates pane michael@0: michael@0: var gProvider; michael@0: var gManagerWindow; michael@0: var gCategoryUtilities; 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: "updated 6 hours ago", michael@0: version: "1.0", michael@0: updateDate: new Date(Date.now() - (1000 * 60 * 60 * 6)), michael@0: releaseNotesURI: Services.io.newURI(TESTROOT + "releaseNotes.xhtml", null, null) michael@0: }, { michael@0: id: "addon2@tests.mozilla.org", michael@0: name: "updated 5 seconds ago", michael@0: version: "1.0", michael@0: updateDate: new Date(Date.now() - (1000 * 5)) michael@0: }, { michael@0: id: "addon3@tests.mozilla.org", michael@0: name: "updated 1 month ago", michael@0: version: "1.0", michael@0: updateDate: new Date(Date.now() - (1000 * 60 * 60 * 25 * 30)) 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: info("Checking menuitem for Recent Updates opens that pane"); michael@0: var recentCat = gManagerWindow.gCategories.get("addons://updates/recent"); michael@0: is(gCategoryUtilities.isVisible(recentCat), false, "Recent Updates category should initially be hidden"); michael@0: michael@0: var utilsBtn = gManagerWindow.document.getElementById("header-utils-btn"); michael@0: utilsBtn.addEventListener("popupshown", function() { michael@0: utilsBtn.removeEventListener("popupshown", arguments.callee, false); michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: is(gCategoryUtilities.isVisible(recentCat), true, "Recent Updates category should now be visible"); michael@0: is(gManagerWindow.document.getElementById("categories").selectedItem.value, "addons://updates/recent", "Recent Updates category should now be selected"); michael@0: is(gManagerWindow.gViewController.currentViewId, "addons://updates/recent", "Recent Updates view should be the current view"); michael@0: run_next_test(); michael@0: }, true); michael@0: var menuitem = gManagerWindow.document.getElementById("utils-viewUpdates"); michael@0: EventUtils.synthesizeMouse(menuitem, 2, 2, { }, gManagerWindow); michael@0: }, false); michael@0: EventUtils.synthesizeMouse(utilsBtn, 2, 2, { }, gManagerWindow); michael@0: }); michael@0: michael@0: michael@0: add_test(function() { michael@0: var updatesList = gManagerWindow.document.getElementById("updates-list"); michael@0: var sorters = gManagerWindow.document.getElementById("updates-sorters"); michael@0: var dateSorter = gManagerWindow.document.getAnonymousElementByAttribute(sorters, "anonid", "date-btn"); michael@0: var nameSorter = gManagerWindow.document.getAnonymousElementByAttribute(sorters, "anonid", "name-btn"); michael@0: michael@0: function check_order(expected) { michael@0: var items = updatesList.getElementsByTagName("richlistitem"); michael@0: var possible = ["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", "addon3@tests.mozilla.org"]; michael@0: for (let item of items) { michael@0: let itemId = item.mAddon.id; michael@0: if (possible.indexOf(itemId) == -1) michael@0: continue; // skip over any other addons, such as shipped addons that would update on every build michael@0: isnot(expected.length, 0, "Should be expecting more items"); michael@0: is(itemId, expected.shift(), "Should get expected item based on sort order"); michael@0: if (itemId == "addon1@tests.mozilla.org") michael@0: is_element_visible(item._relNotesToggle, "Release notes toggle should be visible for addon with release notes"); michael@0: else michael@0: is_element_hidden(item._relNotesToggle, "Release notes toggle should be hidden for addon with no release notes"); michael@0: } michael@0: } michael@0: michael@0: is_element_visible(dateSorter); michael@0: is_element_visible(nameSorter); michael@0: michael@0: // sorted by date, descending michael@0: check_order(["addon2@tests.mozilla.org", "addon1@tests.mozilla.org"]); michael@0: michael@0: // sorted by date, ascending michael@0: EventUtils.synthesizeMouseAtCenter(dateSorter, { }, gManagerWindow); michael@0: check_order(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org"]); michael@0: michael@0: // sorted by name, ascending michael@0: EventUtils.synthesizeMouseAtCenter(nameSorter, { }, gManagerWindow); michael@0: check_order(["addon2@tests.mozilla.org", "addon1@tests.mozilla.org"]); michael@0: michael@0: // sorted by name, descending michael@0: EventUtils.synthesizeMouseAtCenter(nameSorter, { }, gManagerWindow); michael@0: check_order(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org"]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: michael@0: add_test(function() { 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: michael@0: var recentCat = gManagerWindow.gCategories.get("addons://updates/recent"); michael@0: is(gCategoryUtilities.isVisible(recentCat), true, "Recent Updates category should still be visible"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: });