1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_bug591663.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,161 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// Test that the empty notice in the list view disappears as it should 1.9 + 1.10 +// Don't use a standard list view (e.g. "extension") to ensure that the list is 1.11 +// initially empty. Don't need to worry about the list of categories displayed 1.12 +// since only the list view itself is tested. 1.13 +let VIEW_ID = "addons://list/mock-addon"; 1.14 + 1.15 +let LIST_ID = "addon-list"; 1.16 +let EMPTY_ID = "addon-list-empty"; 1.17 + 1.18 +let gManagerWindow; 1.19 +let gProvider; 1.20 +let gItem; 1.21 + 1.22 +let gInstallProperties = { 1.23 + name: "Bug 591663 Mock Install", 1.24 + type: "mock-addon" 1.25 +}; 1.26 +let gAddonProperties = { 1.27 + id: "test1@tests.mozilla.org", 1.28 + name: "Bug 591663 Mock Add-on", 1.29 + type: "mock-addon" 1.30 +}; 1.31 +let gExtensionProperties = { 1.32 + name: "Bug 591663 Extension Install", 1.33 + type: "extension" 1.34 +}; 1.35 + 1.36 +function test() { 1.37 + waitForExplicitFinish(); 1.38 + 1.39 + gProvider = new MockProvider(true, [{ 1.40 + id: "mock-addon", 1.41 + name: "Mock Add-ons", 1.42 + uiPriority: 4500, 1.43 + flags: AddonManager.TYPE_UI_VIEW_LIST 1.44 + }]); 1.45 + 1.46 + open_manager(VIEW_ID, function(aWindow) { 1.47 + gManagerWindow = aWindow; 1.48 + run_next_test(); 1.49 + }); 1.50 +} 1.51 + 1.52 +function end_test() { 1.53 + close_manager(gManagerWindow, finish); 1.54 +} 1.55 + 1.56 +/** 1.57 + * Check that the list view is as expected 1.58 + * 1.59 + * @param aItem 1.60 + * The expected item in the list, or null if list should be empty 1.61 + */ 1.62 +function check_list(aItem) { 1.63 + // Check state of the empty notice 1.64 + let emptyNotice = gManagerWindow.document.getElementById(EMPTY_ID); 1.65 + ok(emptyNotice != null, "Should have found the empty notice"); 1.66 + is(!emptyNotice.hidden, (aItem == null), "Empty notice should be showing if list empty"); 1.67 + 1.68 + // Check the children of the list 1.69 + let list = gManagerWindow.document.getElementById(LIST_ID); 1.70 + is(list.itemCount, aItem ? 1 : 0, "Should get expected number of items in list"); 1.71 + if (aItem != null) { 1.72 + let itemName = list.firstChild.getAttribute("name"); 1.73 + is(itemName, aItem.name, "List item should have correct name"); 1.74 + } 1.75 +} 1.76 + 1.77 + 1.78 +// Test that the empty notice is showing and no items are showing in list 1.79 +add_test(function() { 1.80 + check_list(null); 1.81 + run_next_test(); 1.82 +}); 1.83 + 1.84 +// Test that a new, non-active, install does not affect the list view 1.85 +add_test(function() { 1.86 + gItem = gProvider.createInstalls([gInstallProperties])[0]; 1.87 + check_list(null); 1.88 + run_next_test(); 1.89 +}); 1.90 + 1.91 +// Test that onInstallStarted properly hides empty notice and adds install to list 1.92 +add_test(function() { 1.93 + gItem.addTestListener({ 1.94 + onDownloadStarted: function() { 1.95 + // Install type unknown until download complete 1.96 + check_list(null); 1.97 + }, 1.98 + onInstallStarted: function() { 1.99 + check_list(gItem); 1.100 + }, 1.101 + onInstallEnded: function() { 1.102 + check_list(gItem); 1.103 + run_next_test(); 1.104 + } 1.105 + }); 1.106 + 1.107 + gItem.install(); 1.108 +}); 1.109 + 1.110 +// Test that restarting the manager does not change list 1.111 +add_test(function() { 1.112 + restart_manager(gManagerWindow, VIEW_ID, function(aManagerWindow) { 1.113 + gManagerWindow = aManagerWindow; 1.114 + check_list(gItem); 1.115 + run_next_test(); 1.116 + }); 1.117 +}); 1.118 + 1.119 +// Test that onInstallCancelled removes install and shows empty notice 1.120 +add_test(function() { 1.121 + gItem.cancel(); 1.122 + gItem = null; 1.123 + check_list(null); 1.124 + run_next_test(); 1.125 +}); 1.126 + 1.127 +// Test that add-ons of a different type do not show up in the list view 1.128 +add_test(function() { 1.129 + let extension = gProvider.createInstalls([gExtensionProperties])[0]; 1.130 + check_list(null); 1.131 + 1.132 + extension.addTestListener({ 1.133 + onDownloadStarted: function() { 1.134 + check_list(null); 1.135 + }, 1.136 + onInstallStarted: function() { 1.137 + check_list(null); 1.138 + }, 1.139 + onInstallEnded: function() { 1.140 + check_list(null); 1.141 + extension.cancel(); 1.142 + run_next_test(); 1.143 + } 1.144 + }); 1.145 + 1.146 + extension.install(); 1.147 +}); 1.148 + 1.149 +// Test that onExternalInstall properly hides empty notice and adds install to list 1.150 +add_test(function() { 1.151 + gItem = gProvider.createAddons([gAddonProperties])[0]; 1.152 + check_list(gItem); 1.153 + run_next_test(); 1.154 +}); 1.155 + 1.156 +// Test that restarting the manager does not change list 1.157 +add_test(function() { 1.158 + restart_manager(gManagerWindow, VIEW_ID, function(aManagerWindow) { 1.159 + gManagerWindow = aManagerWindow; 1.160 + check_list(gItem); 1.161 + run_next_test(); 1.162 + }); 1.163 +}); 1.164 +