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: // Test that the empty notice in the list view disappears as it should michael@0: michael@0: // Don't use a standard list view (e.g. "extension") to ensure that the list is michael@0: // initially empty. Don't need to worry about the list of categories displayed michael@0: // since only the list view itself is tested. michael@0: let VIEW_ID = "addons://list/mock-addon"; michael@0: michael@0: let LIST_ID = "addon-list"; michael@0: let EMPTY_ID = "addon-list-empty"; michael@0: michael@0: let gManagerWindow; michael@0: let gProvider; michael@0: let gItem; michael@0: michael@0: let gInstallProperties = { michael@0: name: "Bug 591663 Mock Install", michael@0: type: "mock-addon" michael@0: }; michael@0: let gAddonProperties = { michael@0: id: "test1@tests.mozilla.org", michael@0: name: "Bug 591663 Mock Add-on", michael@0: type: "mock-addon" michael@0: }; michael@0: let gExtensionProperties = { michael@0: name: "Bug 591663 Extension Install", michael@0: type: "extension" michael@0: }; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gProvider = new MockProvider(true, [{ michael@0: id: "mock-addon", michael@0: name: "Mock Add-ons", michael@0: uiPriority: 4500, michael@0: flags: AddonManager.TYPE_UI_VIEW_LIST michael@0: }]); michael@0: michael@0: open_manager(VIEW_ID, function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: close_manager(gManagerWindow, finish); michael@0: } michael@0: michael@0: /** michael@0: * Check that the list view is as expected michael@0: * michael@0: * @param aItem michael@0: * The expected item in the list, or null if list should be empty michael@0: */ michael@0: function check_list(aItem) { michael@0: // Check state of the empty notice michael@0: let emptyNotice = gManagerWindow.document.getElementById(EMPTY_ID); michael@0: ok(emptyNotice != null, "Should have found the empty notice"); michael@0: is(!emptyNotice.hidden, (aItem == null), "Empty notice should be showing if list empty"); michael@0: michael@0: // Check the children of the list michael@0: let list = gManagerWindow.document.getElementById(LIST_ID); michael@0: is(list.itemCount, aItem ? 1 : 0, "Should get expected number of items in list"); michael@0: if (aItem != null) { michael@0: let itemName = list.firstChild.getAttribute("name"); michael@0: is(itemName, aItem.name, "List item should have correct name"); michael@0: } michael@0: } michael@0: michael@0: michael@0: // Test that the empty notice is showing and no items are showing in list michael@0: add_test(function() { michael@0: check_list(null); michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // Test that a new, non-active, install does not affect the list view michael@0: add_test(function() { michael@0: gItem = gProvider.createInstalls([gInstallProperties])[0]; michael@0: check_list(null); michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // Test that onInstallStarted properly hides empty notice and adds install to list michael@0: add_test(function() { michael@0: gItem.addTestListener({ michael@0: onDownloadStarted: function() { michael@0: // Install type unknown until download complete michael@0: check_list(null); michael@0: }, michael@0: onInstallStarted: function() { michael@0: check_list(gItem); michael@0: }, michael@0: onInstallEnded: function() { michael@0: check_list(gItem); michael@0: run_next_test(); michael@0: } michael@0: }); michael@0: michael@0: gItem.install(); michael@0: }); michael@0: michael@0: // Test that restarting the manager does not change list michael@0: add_test(function() { michael@0: restart_manager(gManagerWindow, VIEW_ID, function(aManagerWindow) { michael@0: gManagerWindow = aManagerWindow; michael@0: check_list(gItem); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: // Test that onInstallCancelled removes install and shows empty notice michael@0: add_test(function() { michael@0: gItem.cancel(); michael@0: gItem = null; michael@0: check_list(null); michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // Test that add-ons of a different type do not show up in the list view michael@0: add_test(function() { michael@0: let extension = gProvider.createInstalls([gExtensionProperties])[0]; michael@0: check_list(null); michael@0: michael@0: extension.addTestListener({ michael@0: onDownloadStarted: function() { michael@0: check_list(null); michael@0: }, michael@0: onInstallStarted: function() { michael@0: check_list(null); michael@0: }, michael@0: onInstallEnded: function() { michael@0: check_list(null); michael@0: extension.cancel(); michael@0: run_next_test(); michael@0: } michael@0: }); michael@0: michael@0: extension.install(); michael@0: }); michael@0: michael@0: // Test that onExternalInstall properly hides empty notice and adds install to list michael@0: add_test(function() { michael@0: gItem = gProvider.createAddons([gAddonProperties])[0]; michael@0: check_list(gItem); michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // Test that restarting the manager does not change list michael@0: add_test(function() { michael@0: restart_manager(gManagerWindow, VIEW_ID, function(aManagerWindow) { michael@0: gManagerWindow = aManagerWindow; michael@0: check_list(gItem); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: