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.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 // Test that the empty notice in the list view disappears as it should
7 // Don't use a standard list view (e.g. "extension") to ensure that the list is
8 // initially empty. Don't need to worry about the list of categories displayed
9 // since only the list view itself is tested.
10 let VIEW_ID = "addons://list/mock-addon";
12 let LIST_ID = "addon-list";
13 let EMPTY_ID = "addon-list-empty";
15 let gManagerWindow;
16 let gProvider;
17 let gItem;
19 let gInstallProperties = {
20 name: "Bug 591663 Mock Install",
21 type: "mock-addon"
22 };
23 let gAddonProperties = {
24 id: "test1@tests.mozilla.org",
25 name: "Bug 591663 Mock Add-on",
26 type: "mock-addon"
27 };
28 let gExtensionProperties = {
29 name: "Bug 591663 Extension Install",
30 type: "extension"
31 };
33 function test() {
34 waitForExplicitFinish();
36 gProvider = new MockProvider(true, [{
37 id: "mock-addon",
38 name: "Mock Add-ons",
39 uiPriority: 4500,
40 flags: AddonManager.TYPE_UI_VIEW_LIST
41 }]);
43 open_manager(VIEW_ID, function(aWindow) {
44 gManagerWindow = aWindow;
45 run_next_test();
46 });
47 }
49 function end_test() {
50 close_manager(gManagerWindow, finish);
51 }
53 /**
54 * Check that the list view is as expected
55 *
56 * @param aItem
57 * The expected item in the list, or null if list should be empty
58 */
59 function check_list(aItem) {
60 // Check state of the empty notice
61 let emptyNotice = gManagerWindow.document.getElementById(EMPTY_ID);
62 ok(emptyNotice != null, "Should have found the empty notice");
63 is(!emptyNotice.hidden, (aItem == null), "Empty notice should be showing if list empty");
65 // Check the children of the list
66 let list = gManagerWindow.document.getElementById(LIST_ID);
67 is(list.itemCount, aItem ? 1 : 0, "Should get expected number of items in list");
68 if (aItem != null) {
69 let itemName = list.firstChild.getAttribute("name");
70 is(itemName, aItem.name, "List item should have correct name");
71 }
72 }
75 // Test that the empty notice is showing and no items are showing in list
76 add_test(function() {
77 check_list(null);
78 run_next_test();
79 });
81 // Test that a new, non-active, install does not affect the list view
82 add_test(function() {
83 gItem = gProvider.createInstalls([gInstallProperties])[0];
84 check_list(null);
85 run_next_test();
86 });
88 // Test that onInstallStarted properly hides empty notice and adds install to list
89 add_test(function() {
90 gItem.addTestListener({
91 onDownloadStarted: function() {
92 // Install type unknown until download complete
93 check_list(null);
94 },
95 onInstallStarted: function() {
96 check_list(gItem);
97 },
98 onInstallEnded: function() {
99 check_list(gItem);
100 run_next_test();
101 }
102 });
104 gItem.install();
105 });
107 // Test that restarting the manager does not change list
108 add_test(function() {
109 restart_manager(gManagerWindow, VIEW_ID, function(aManagerWindow) {
110 gManagerWindow = aManagerWindow;
111 check_list(gItem);
112 run_next_test();
113 });
114 });
116 // Test that onInstallCancelled removes install and shows empty notice
117 add_test(function() {
118 gItem.cancel();
119 gItem = null;
120 check_list(null);
121 run_next_test();
122 });
124 // Test that add-ons of a different type do not show up in the list view
125 add_test(function() {
126 let extension = gProvider.createInstalls([gExtensionProperties])[0];
127 check_list(null);
129 extension.addTestListener({
130 onDownloadStarted: function() {
131 check_list(null);
132 },
133 onInstallStarted: function() {
134 check_list(null);
135 },
136 onInstallEnded: function() {
137 check_list(null);
138 extension.cancel();
139 run_next_test();
140 }
141 });
143 extension.install();
144 });
146 // Test that onExternalInstall properly hides empty notice and adds install to list
147 add_test(function() {
148 gItem = gProvider.createAddons([gAddonProperties])[0];
149 check_list(gItem);
150 run_next_test();
151 });
153 // Test that restarting the manager does not change list
154 add_test(function() {
155 restart_manager(gManagerWindow, VIEW_ID, function(aManagerWindow) {
156 gManagerWindow = aManagerWindow;
157 check_list(gItem);
158 run_next_test();
159 });
160 });