|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Tests that the visible delay in showing the "Language" category occurs |
|
6 // very minimally |
|
7 |
|
8 var gManagerWindow; |
|
9 var gCategoryUtilities; |
|
10 var gProvider; |
|
11 var gInstall; |
|
12 var gInstallProperties = [{ |
|
13 name: "Locale Category Test", |
|
14 type: "locale" |
|
15 }]; |
|
16 |
|
17 function test() { |
|
18 try { |
|
19 if (Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).D2DEnabled) { |
|
20 requestLongerTimeout(2); |
|
21 } |
|
22 } catch(e) {} |
|
23 waitForExplicitFinish(); |
|
24 |
|
25 gProvider = new MockProvider(); |
|
26 |
|
27 open_manager("addons://list/extension", function(aWindow) { |
|
28 gManagerWindow = aWindow; |
|
29 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
30 run_next_test(); |
|
31 }); |
|
32 } |
|
33 |
|
34 function end_test() { |
|
35 close_manager(gManagerWindow, finish); |
|
36 } |
|
37 |
|
38 function install_locale(aCallback) { |
|
39 gInstall = gProvider.createInstalls(gInstallProperties)[0]; |
|
40 gInstall.addTestListener({ |
|
41 onInstallEnded: function(aInstall) { |
|
42 gInstall.removeTestListener(this); |
|
43 aCallback(); |
|
44 } |
|
45 }); |
|
46 gInstall.install(); |
|
47 } |
|
48 |
|
49 function check_hidden(aExpectedHidden) { |
|
50 var hidden = !gCategoryUtilities.isTypeVisible("locale"); |
|
51 is(hidden, !!aExpectedHidden, "Should have correct hidden state"); |
|
52 } |
|
53 |
|
54 function run_open_test(aTestSetup, aLoadHidden, aInitializedHidden, aSelected) { |
|
55 function loadCallback(aManagerWindow) { |
|
56 gManagerWindow = aManagerWindow; |
|
57 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
58 check_hidden(aLoadHidden); |
|
59 } |
|
60 |
|
61 function run() { |
|
62 open_manager(null, function() { |
|
63 check_hidden(aInitializedHidden); |
|
64 var selected = (gCategoryUtilities.selectedCategory == "locale"); |
|
65 is(selected, !!aSelected, "Should have correct selected state"); |
|
66 |
|
67 run_next_test(); |
|
68 }, loadCallback); |
|
69 } |
|
70 |
|
71 close_manager(gManagerWindow, function() { |
|
72 // Allow for asynchronous functions to run before the manager opens |
|
73 aTestSetup ? aTestSetup(run) : run(); |
|
74 }); |
|
75 } |
|
76 |
|
77 |
|
78 // Tests that the locale category is hidden when there are no locales installed |
|
79 add_test(function() { |
|
80 run_open_test(null, true, true); |
|
81 }); |
|
82 |
|
83 // Tests that installing a locale while the Add-on Manager is open shows the |
|
84 // locale category |
|
85 add_test(function() { |
|
86 check_hidden(true); |
|
87 install_locale(function() { |
|
88 check_hidden(false); |
|
89 run_next_test(); |
|
90 }); |
|
91 }); |
|
92 |
|
93 // Tests that the locale category is shown with no delay when restarting |
|
94 // Add-on Manager |
|
95 add_test(function() { |
|
96 run_open_test(null, false, false); |
|
97 }); |
|
98 |
|
99 // Tests that cancelling the locale install and restarting the Add-on Manager |
|
100 // causes the locale category to be hidden with an acceptable delay |
|
101 add_test(function() { |
|
102 gInstall.cancel(); |
|
103 run_open_test(null, false, true) |
|
104 }); |
|
105 |
|
106 // Tests that the locale category is hidden with no delay when restarting |
|
107 // Add-on Manager |
|
108 add_test(function() { |
|
109 run_open_test(null, true, true); |
|
110 }); |
|
111 |
|
112 // Tests that installing a locale when the Add-on Manager is closed, and then |
|
113 // opening the Add-on Manager causes the locale category to be shown with an |
|
114 // acceptable delay |
|
115 add_test(function() { |
|
116 run_open_test(install_locale, true, false); |
|
117 }); |
|
118 |
|
119 // Tests that selection of the locale category persists |
|
120 add_test(function() { |
|
121 gCategoryUtilities.openType("locale", function() { |
|
122 run_open_test(null, false, false, true); |
|
123 }); |
|
124 }); |
|
125 |
|
126 // Tests that cancelling the locale install and restarting the Add-on Manager |
|
127 // causes the locale category to be hidden and not selected |
|
128 add_test(function() { |
|
129 gInstall.cancel(); |
|
130 run_open_test(null, false, true); |
|
131 }); |
|
132 |